KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > vut > JDBCVirtualUserTableTest


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
21
22 package org.apache.james.vut;
23
24 import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.configuration.DefaultConfiguration;
27 import org.apache.avalon.framework.service.DefaultServiceManager;
28 import org.apache.avalon.framework.service.ServiceException;
29
30 import org.apache.james.services.DNSServer;
31 import org.apache.james.services.FileSystem;
32
33 import org.apache.james.test.mock.avalon.MockLogger;
34
35 import org.apache.james.test.mock.james.MockFileSystem;
36 import org.apache.james.test.mock.util.AttrValConfiguration;
37 import org.apache.james.test.util.Util;
38
39 public class JDBCVirtualUserTableTest extends AbstractVirtualUserTableTest {
40     
41     /**
42      * @see org.apache.james.vut.AbstractVirtualUserTableTest#getVirtalUserTable()
43      */

44     protected AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception JavaDoc {
45         DefaultServiceManager serviceManager = new DefaultServiceManager();
46         serviceManager.put(FileSystem.ROLE, new MockFileSystem());
47         serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());
48         serviceManager.put(DNSServer.ROLE, setUpDNSServer());
49         JDBCVirtualUserTable mr = new JDBCVirtualUserTable();
50         
51
52         mr.enableLogging(new MockLogger());
53         DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
54         defaultConfiguration.setAttribute("destinationURL","db://maildb/VirtualUserTable");
55         defaultConfiguration.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
56         mr.service(serviceManager);
57         mr.configure(defaultConfiguration);
58         mr.initialize();
59         return mr;
60     }
61     
62     /**
63      * @see org.apache.james.vut.AbstractVirtualUserTableTest#addMapping(java.lang.String, java.lang.String, java.lang.String, int)
64      */

65     protected boolean addMapping(String JavaDoc user, String JavaDoc domain, String JavaDoc mapping, int type) throws InvalidMappingException {
66         if (type == ERROR_TYPE) {
67             return virtualUserTable.addErrorMapping(user, domain, mapping);
68         } else if (type == REGEX_TYPE) {
69             return virtualUserTable.addRegexMapping(user, domain, mapping);
70         } else if (type == ADDRESS_TYPE) {
71             return virtualUserTable.addAddressMapping(user, domain, mapping);
72         } else if (type == ALIASDOMAIN_TYPE) {
73             return virtualUserTable.addAliasDomainMapping(domain, mapping);
74         } else {
75             return false;
76         }
77     }
78
79     /**
80      * @see org.apache.james.vut.AbstractVirtualUserTableTest#removeMapping(java.lang.String, java.lang.String, java.lang.String, int)
81      */

82     protected boolean removeMapping(String JavaDoc user, String JavaDoc domain, String JavaDoc mapping, int type) throws InvalidMappingException {
83         if (type == ERROR_TYPE) {
84             return virtualUserTable.removeErrorMapping(user, domain, mapping);
85         } else if (type == REGEX_TYPE) {
86             return virtualUserTable.removeRegexMapping(user, domain, mapping);
87         } else if (type == ADDRESS_TYPE) {
88             return virtualUserTable.removeAddressMapping(user, domain, mapping);
89         } else if (type == ALIASDOMAIN_TYPE) {
90             return virtualUserTable.removeAliasDomainMapping(domain, mapping);
91         } else {
92             return false;
93         }
94     }
95     
96 }
97
Popular Tags