KickJava   Java API By Example, From Geeks To Geeks.

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


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.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.configuration.DefaultConfiguration;
24 import org.apache.avalon.framework.container.ContainerUtil;
25 import org.apache.avalon.framework.logger.ConsoleLogger;
26 import org.apache.james.services.UsersRepository;
27 import org.apache.james.test.mock.james.MockFileSystem;
28 import org.apache.james.test.mock.util.AttrValConfiguration;
29 import org.apache.james.test.util.Util;
30
31 import java.util.Iterator JavaDoc;
32
33 /**
34  * Test basic behaviours of UsersFileRepository
35  */

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

44     protected UsersRepository getUsersRepository() throws Exception JavaDoc {
45         ListUsersJdbcRepository res = new ListUsersJdbcRepository();
46         String JavaDoc tableString = "listusers";
47         configureAbstractJdbcUsersRepository(res, tableString);
48         return res;
49     }
50
51     protected boolean getPasswordsEnabled() {
52         return false;
53     }
54
55     
56     protected boolean getCheckCase() {
57         return true;
58     }
59
60     /**
61      * @param res
62      * @param tableString
63      * @throws Exception
64      * @throws ConfigurationException
65      */

66     protected void configureAbstractJdbcUsersRepository(AbstractJdbcUsersRepository res, String JavaDoc tableString) throws Exception JavaDoc, ConfigurationException {
67         res.setFileSystem(new MockFileSystem());
68         res.setDatasources(Util.getDataSourceSelector());
69         
70         DefaultConfiguration configuration = new DefaultConfiguration("test");
71         configuration.setAttribute("destinationURL", "db://maildb/"+tableString);
72         configuration.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
73         res.enableLogging(new ConsoleLogger());
74         res.configure(configuration );
75         res.initialize();
76     }
77
78     protected void disposeUsersRepository() {
79         Iterator JavaDoc i = this.usersRepository.list();
80         while (i.hasNext()) {
81             this.usersRepository.removeUser((String JavaDoc) i.next());
82         }
83         ContainerUtil.dispose(this.usersRepository);
84     }
85
86 }
87
Popular Tags