1 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 44 protected AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception { 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 65 protected boolean addMapping(String user, String domain, String 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 82 protected boolean removeMapping(String user, String domain, String 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 |