1 6 package org.logicalcobwebs.proxool.configuration; 7 8 import org.apache.avalon.excalibur.component.DefaultRoleManager; 9 import org.apache.avalon.excalibur.component.ExcaliburComponentManager; 10 import org.apache.avalon.framework.configuration.Configuration; 11 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 12 import org.apache.avalon.framework.context.DefaultContext; 13 import org.apache.log.Hierarchy; 14 import org.apache.log.LogTarget; 15 import org.apache.log.Logger; 16 import org.apache.log.Priority; 17 import org.logicalcobwebs.proxool.AbstractProxoolTest; 18 import org.logicalcobwebs.proxool.ProxoolException; 19 import org.logicalcobwebs.proxool.ProxoolFacade; 20 import org.logicalcobwebs.proxool.TestHelper; 21 22 import java.io.File ; 23 24 32 public class AvalonConfiguratorTest extends AbstractProxoolTest { 33 private ExcaliburComponentManager componentManager; 34 35 38 public AvalonConfiguratorTest(String name) { 39 super(name); 40 } 41 42 48 public void testNoNamspaces() throws Exception { 49 initializeAvalon("src/java-test/org/logicalcobwebs/proxool/configuration/role.conf", 50 "src/java-test/org/logicalcobwebs/proxool/configuration/component.conf"); 51 this.componentManager.lookup(AvalonConfigurator.ROLE); 52 try { 53 TestHelper.equalsCompleteAlternativeProperties(ProxoolFacade.getConnectionPoolDefinition("avalon-test")); 54 } catch (ProxoolException e) { 55 throw e; 56 } 57 try { 58 TestHelper.equalsCompleteAlternativeProperties(ProxoolFacade.getConnectionPoolDefinition("avalon-test-2")); 59 } catch (ProxoolException e) { 60 throw e; 61 } 62 this.componentManager.dispose(); 63 } 64 65 70 public void testWithNamespaces() throws Exception { 71 initializeAvalon("src/java-test/org/logicalcobwebs/proxool/configuration/role.conf", 72 "src/java-test/org/logicalcobwebs/proxool/configuration/component-ns.conf"); 73 this.componentManager.lookup(AvalonConfigurator.ROLE); 74 try { 75 TestHelper.equalsCompleteAlternativeProperties(ProxoolFacade.getConnectionPoolDefinition("avalon-test-ns")); 76 } catch (ProxoolException e) { 77 throw e; 78 } 79 try { 80 TestHelper.equalsCompleteAlternativeProperties(ProxoolFacade.getConnectionPoolDefinition("avalon-test-ns-2")); 81 } catch (ProxoolException e) { 82 throw e; 83 } 84 ProxoolFacade.removeConnectionPool("avalon-test-ns"); 85 ProxoolFacade.removeConnectionPool("avalon-test-ns-2"); 86 this.componentManager.dispose(); 87 } 88 89 94 public void testDisposeOnClose() throws Exception { 95 initializeAvalon("src/java-test/org/logicalcobwebs/proxool/configuration/role.conf", 96 "src/java-test/org/logicalcobwebs/proxool/configuration/component.conf"); 97 this.componentManager.lookup(AvalonConfigurator.ROLE); 98 this.componentManager.dispose(); 99 try { 100 ProxoolFacade.getConnectionPoolDefinition("avalon-test"); 101 fail("ProxoolFacade found pool 'avalon-test' but we expected the configurator to have removed it."); 102 } catch (ProxoolException e) { 103 } 105 try { 106 ProxoolFacade.getConnectionPoolDefinition("avalon-test-2"); 107 fail("ProxoolFacade found pool 'avalon-test-2' but we expected the configurator to have removed it."); 108 } catch (ProxoolException e) { 109 } 111 } 112 113 118 public void testNotDisposeOnClose() throws Exception { 119 initializeAvalon("src/java-test/org/logicalcobwebs/proxool/configuration/role.conf", 120 "src/java-test/org/logicalcobwebs/proxool/configuration/component-ns.conf"); 121 this.componentManager.lookup(AvalonConfigurator.ROLE); 122 this.componentManager.dispose(); 123 try { 124 ProxoolFacade.getConnectionPoolDefinition("avalon-test-ns"); 125 } catch (ProxoolException e) { 126 fail("ProxoolFacade did not find pool 'avalon-test-ns' but we didn't expect the configurator to have removed it."); 127 } 128 try { 129 ProxoolFacade.getConnectionPoolDefinition("avalon-test-ns-2"); 130 } catch (ProxoolException e) { 131 fail("ProxoolFacade did not find pool 'avalon-ns-test-2' but we didn't expect the configurator to have removed it."); 132 } 133 ProxoolFacade.removeConnectionPool("avalon-test-ns"); 134 ProxoolFacade.removeConnectionPool("avalon-test-ns-2"); 135 } 136 137 private void initializeAvalon(String roleFile, String componentFile) throws Exception { 138 final LogTarget logTarget = new LogKitTargetAdapter(); 140 final Logger rootLogger = Hierarchy.getDefaultHierarchy().getLoggerFor("root"); 141 rootLogger.unsetLogTargets(); 142 rootLogger.setLogTargets(new LogTarget[]{logTarget}); 143 rootLogger.setPriority(Priority.WARN); 144 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(true); 145 final Configuration componentConfiguration = builder.buildFromFile(new File (componentFile)); 147 final Configuration roleConfiguration = builder.buildFromFile(new File (roleFile)); 149 this.componentManager = new ExcaliburComponentManager(); 151 this.componentManager.setLogger(rootLogger.getChildLogger(ExcaliburComponentManager.class.getName())); 152 DefaultRoleManager roleManager = new DefaultRoleManager(); 153 roleManager.setLogger(rootLogger.getChildLogger(DefaultRoleManager.class.getName())); 154 roleManager.configure(roleConfiguration); 155 componentManager.contextualize(new DefaultContext()); 156 componentManager.setRoleManager(roleManager); 157 componentManager.configure(componentConfiguration); 158 componentManager.initialize(); 159 } 160 161 } 162 163 214 | Popular Tags |