KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > userrepository > DefaultUsersJdbcRepositoryTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.userrepository;
21
22 import org.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourceSelector;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.configuration.DefaultConfiguration;
25 import org.apache.avalon.framework.container.ContainerUtil;
26 import org.apache.avalon.framework.logger.ConsoleLogger;
27 import org.apache.james.services.UsersRepository;
28 import org.apache.james.test.mock.james.MockFileSystem;
29 import org.apache.james.test.mock.util.AttrValConfiguration;
30 import org.apache.james.test.util.Util;
31
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * Test basic behaviours of UsersFileRepository
36  */

37 public class DefaultUsersJdbcRepositoryTest extends MockUsersRepositoryTest {
38
39     /**
40      * Create the repository to be tested.
41      *
42      * @return the user repository
43      * @throws Exception
44      */

45     protected UsersRepository getUsersRepository() throws Exception JavaDoc {
46         DefaultUsersJdbcRepository res = new DefaultUsersJdbcRepository();
47         String JavaDoc tableString = "defusers";
48         configureAbstractJdbcUsersRepository(res, tableString);
49         return res;
50     }
51
52     /**
53      * @param res
54      * @param tableString
55      * @throws Exception
56      * @throws ConfigurationException
57      */

58     protected void configureAbstractJdbcUsersRepository(AbstractJdbcUsersRepository res, String JavaDoc tableString) throws Exception JavaDoc, ConfigurationException {
59         res.setFileSystem(new MockFileSystem());
60         DefaultDataSourceSelector dataSourceSelector = Util.getDataSourceSelector();
61         
62         res.setDatasources(dataSourceSelector );
63         
64         DefaultConfiguration configuration = new DefaultConfiguration("test");
65         configuration.setAttribute("destinationURL", "db://maildb/"+tableString);
66         configuration.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
67         res.enableLogging(new ConsoleLogger());
68         res.configure(configuration );
69         res.initialize();
70     }
71
72     /**
73      * @return
74      */

75     protected boolean getCheckCase() {
76         return true;
77     }
78
79     protected void disposeUsersRepository() {
80         Iterator JavaDoc i = this.usersRepository.list();
81         while (i.hasNext()) {
82             this.usersRepository.removeUser((String JavaDoc) i.next());
83         }
84         ContainerUtil.dispose(this.usersRepository);
85     }
86
87 }
88
Popular Tags