Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java Tue Dec 11 14:53:48 2018 @@ -1,5 +1,13 @@ package org.apache.fulcrum.yaafi.framework.container; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; +import org.apache.fulcrum.yaafi.TestComponent; +import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration; +import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; +import org.apache.fulcrum.yaafi.framework.role.RoleEntry; +import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -23,237 +31,217 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; -import org.apache.fulcrum.yaafi.TestComponent; -import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration; -import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; -import org.apache.fulcrum.yaafi.framework.role.RoleEntry; -import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService; - - /** * Test suite for the ServiceLifecycleManager. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ServiceLifecycleManagerTest extends TestCase -{ - private ServiceLifecycleManager lifecycleManager; - private ServiceContainer container; - - /** - * Constructor - * @param name the name of the test case - */ - public ServiceLifecycleManagerTest( String name ) - { - super(name); - } - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); - this.container = ServiceContainerFactory.create( config ); - this.lifecycleManager = this.container; - } - - /** - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception - { - ServiceContainerFactory.dispose(this.container); - super.tearDown(); - } - - public static Test suite() - { - TestSuite suite= new TestSuite(); - - suite.addTest( new ServiceLifecycleManagerTest("testGetServiceComponents") ); - suite.addTest( new ServiceLifecycleManagerTest("testGeneralReconfiguration") ); - suite.addTest( new ServiceLifecycleManagerTest("testGeneralDecommision") ); - suite.addTest( new ServiceLifecycleManagerTest("testGeneralReconfigurationAndDecommision") ); - suite.addTest( new ServiceLifecycleManagerTest("testIndividualDecommission") ); - suite.addTest( new ServiceLifecycleManagerTest("testException") ); - - return suite; - } - - /** - * Check our TestComponent. - * - * @throws Exception - */ - private void checkTestComponent() - throws Exception - { - TestComponent testComponent = (TestComponent) container.lookup( - TestComponent.ROLE - ); - - testComponent.test(); - - assertEquals( testComponent.getBar(), "BAR" ); - assertEquals( testComponent.getFoo(), "FOO" ); - - assertNotNull( testComponent.getUrnAvalonClassLoader() ); - assertNotNull( testComponent.getUrnAvaloneHome() ); - assertNotNull( testComponent.getUrnAvaloneTemp() ); - assertNotNull( testComponent.getUrnAvalonName() ); - assertNotNull( testComponent.getUrnAvalonPartition() ); - } - - /** - * Gets a list of all available services and dumps them - * on System.out. - */ - public void testGetServiceComponents() throws Exception - { - RoleEntry[] list = this.lifecycleManager.getRoleEntries(); - assertNotNull( list ); - assertTrue( list.length > 0 ); - - for( int i=0; i<list.length; i++ ) - { - System.out.println(list[i].toString()); - } - } - - /** - * Reconfigure the all services - */ - public void testGeneralReconfiguration() throws Exception - { - RoleEntry[] list = this.lifecycleManager.getRoleEntries(); - - for( int i=0; i<list.length; i++ ) - { - String serviceName = list[i].getName(); - System.out.println("Reconfiguring " + serviceName + " ..."); - - String[] serviceNames = {list[i].getName()}; - this.lifecycleManager.reconfigure(serviceNames); - assertTrue(this.container.hasService(serviceName)); - assertNotNull(this.container.lookup(serviceName)); - } - } - - /** - * Decommission and resurrect all services - */ - public void testGeneralDecommision() throws Exception - { - String serviceName = null; - RoleEntry[] list = this.lifecycleManager.getRoleEntries(); - - for( int i=0; i<list.length; i++ ) - { - serviceName = list[i].getName(); - System.out.println("Decommissiong " + serviceName + " ..."); - - assertTrue(this.container.hasService(serviceName)); - this.lifecycleManager.decommision(serviceName); - assertTrue(this.container.hasService(serviceName)); - this.container.lookup(serviceName); - assertTrue(this.container.hasService(serviceName)); - this.lifecycleManager.decommision(serviceName); - assertTrue(this.container.hasService(serviceName)); - } - } - - /** - * Decommission and resurrect all services - */ - public void testGeneralReconfigurationAndDecommision() throws Exception - { - String serviceName = null; - RoleEntry[] list = this.lifecycleManager.getRoleEntries(); - DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); - Configuration configuration = builder.buildFromFile( "./src/test/TestReconfigurationConfig.xml" ); - - for( int i=0; i<list.length; i++ ) - { - serviceName = list[i].getName(); - String[] serviceNames = {list[i].getName()}; - System.out.println("Processing " + serviceName + " ..."); - - // reconfigure/decommission/reconfigure the service - this.lifecycleManager.reconfigure(serviceNames); - this.lifecycleManager.decommision(serviceName); - this.lifecycleManager.reconfigure(serviceNames); - - // run a reconfiguration over all services - this.container.reconfigure(configuration); - - // reconfigure/decommission/reconfigure the service - this.container.lookup(serviceName); - this.lifecycleManager.reconfigure(serviceNames); - this.lifecycleManager.decommision(serviceName); - this.lifecycleManager.reconfigure(serviceNames); - } - } - - - /** - * Decommissions the TestComponent and ReconfigurationService - * to start them again. - */ - public void testIndividualDecommission() throws Exception - { - String serviceName = null; - - // teminate the TestComponent and run it again - - serviceName = TestComponent.class.getName(); - - this.checkTestComponent(); - this.lifecycleManager.decommision( serviceName ); - this.checkTestComponent(); - - // terminate the ReconfigurationService which is currently - // not instantiated and resurrect it. The moment the - // ReconfigurationService is instantiated it is starting to - // work - - serviceName = ReconfigurationService.class.getName(); - - this.lifecycleManager.decommision( ReconfigurationService.class.getName() ); - this.container.lookup( ReconfigurationService.class.getName() ); - - // now we should see that the service is starting up - - Thread.sleep( 5000 ); - - // and terminate it again - - this.lifecycleManager.decommision( ReconfigurationService.class.getName() ); - } - - /** - * Create an exception which should be handled by the JAMon interceptor. - */ - public void testException() throws Exception - { - TestComponent testComponent = (TestComponent) container.lookup( - TestComponent.ROLE - ); - - try - { - testComponent.createException("testException", this); - } - catch(Exception e) - { - return; - } +public class ServiceLifecycleManagerTest extends TestCase { + private ServiceLifecycleManager lifecycleManager; + private ServiceContainer container; + + /** + * Constructor + * + * @param name the name of the test case + */ + public ServiceLifecycleManagerTest(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + config.loadContainerConfiguration("./src/test/TestYaafiContainerConfig.xml"); + this.container = ServiceContainerFactory.create(config); + this.lifecycleManager = this.container; + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + ServiceContainerFactory.dispose(this.container); + super.tearDown(); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTest(new ServiceLifecycleManagerTest("testGetServiceComponents")); + suite.addTest(new ServiceLifecycleManagerTest("testGeneralReconfiguration")); + suite.addTest(new ServiceLifecycleManagerTest("testGeneralDecommision")); + suite.addTest(new ServiceLifecycleManagerTest("testGeneralReconfigurationAndDecommision")); + suite.addTest(new ServiceLifecycleManagerTest("testIndividualDecommission")); + suite.addTest(new ServiceLifecycleManagerTest("testException")); + + return suite; + } + + /** + * Check our TestComponent. + * + * @throws Exception generic exception + */ + private void checkTestComponent() throws Exception { + TestComponent testComponent = (TestComponent) container.lookup(TestComponent.ROLE); + + testComponent.test(); + + assertEquals(testComponent.getBar(), "BAR"); + assertEquals(testComponent.getFoo(), "FOO"); + + assertNotNull(testComponent.getUrnAvalonClassLoader()); + assertNotNull(testComponent.getUrnAvaloneHome()); + assertNotNull(testComponent.getUrnAvaloneTemp()); + assertNotNull(testComponent.getUrnAvalonName()); + assertNotNull(testComponent.getUrnAvalonPartition()); + } + + /** + * Gets a list of all available services and dumps them on System.out. + * + * @throws Exception generic exception + */ + public void testGetServiceComponents() throws Exception { + RoleEntry[] list = this.lifecycleManager.getRoleEntries(); + assertNotNull(list); + assertTrue(list.length > 0); + for (RoleEntry entry : list) + System.out.println(entry.toString()); + } + + /** + * Reconfigure the all services + * + * @throws Exception generic exception + */ + public void testGeneralReconfiguration() throws Exception { + RoleEntry[] list = this.lifecycleManager.getRoleEntries(); + + for (int i = 0; i < list.length; i++) { + String serviceName = list[i].getName(); + System.out.println("Reconfiguring " + serviceName + " ..."); + + String[] serviceNames = { list[i].getName() }; + this.lifecycleManager.reconfigure(serviceNames); + assertTrue(this.container.hasService(serviceName)); + assertNotNull(this.container.lookup(serviceName)); + } + } + + /** + * Decommission and resurrect all services + * + * @throws Exception generic exception + */ + public void testGeneralDecommision() throws Exception { + String serviceName = null; + RoleEntry[] list = this.lifecycleManager.getRoleEntries(); + + for (int i = 0; i < list.length; i++) { + serviceName = list[i].getName(); + System.out.println("Decommissiong " + serviceName + " ..."); + + assertTrue(this.container.hasService(serviceName)); + this.lifecycleManager.decommision(serviceName); + assertTrue(this.container.hasService(serviceName)); + this.container.lookup(serviceName); + assertTrue(this.container.hasService(serviceName)); + this.lifecycleManager.decommision(serviceName); + assertTrue(this.container.hasService(serviceName)); + } + } + + /** + * Decommission and resurrect all services + * + * @throws Exception generic exception + */ + public void testGeneralReconfigurationAndDecommision() throws Exception { + String serviceName = null; + RoleEntry[] list = this.lifecycleManager.getRoleEntries(); + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + Configuration configuration = builder.buildFromFile("./src/test/TestReconfigurationConfig.xml"); + + for (int i = 0; i < list.length; i++) { + serviceName = list[i].getName(); + String[] serviceNames = { list[i].getName() }; + System.out.println("Processing " + serviceName + " ..."); + + // reconfigure/decommission/reconfigure the service + this.lifecycleManager.reconfigure(serviceNames); + this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.reconfigure(serviceNames); + + // run a reconfiguration over all services + this.container.reconfigure(configuration); + + // reconfigure/decommission/reconfigure the service + this.container.lookup(serviceName); + this.lifecycleManager.reconfigure(serviceNames); + this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.reconfigure(serviceNames); + } + } + + /** + * Decommissions the TestComponent and ReconfigurationService to start them + * again. + * + * @throws Exception generic exception + */ + public void testIndividualDecommission() throws Exception { + String serviceName = null; + + // teminate the TestComponent and run it again + + serviceName = TestComponent.class.getName(); + + this.checkTestComponent(); + this.lifecycleManager.decommision(serviceName); + this.checkTestComponent(); + + // terminate the ReconfigurationService which is currently + // not instantiated and resurrect it. The moment the + // ReconfigurationService is instantiated it is starting to + // work + + serviceName = ReconfigurationService.class.getName(); + + this.lifecycleManager.decommision(ReconfigurationService.class.getName()); + this.container.lookup(ReconfigurationService.class.getName()); + + // now we should see that the service is starting up + + Thread.sleep(5000); + + // and terminate it again + + this.lifecycleManager.decommision(ReconfigurationService.class.getName()); + } + + /** + * Create an exception which should be handled by the JAMon interceptor. + * + * @throws Exception generic exception + */ + public void testException() throws Exception { + TestComponent testComponent = (TestComponent) container.lookup(TestComponent.ROLE); + + try { + testComponent.createException("testException", this); + } catch (Exception e) { + return; + } - } + } }
Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java Tue Dec 11 14:53:48 2018 @@ -22,8 +22,6 @@ package org.apache.fulcrum.yaafi.framewo import java.io.File; import java.io.IOException; -import junit.framework.TestCase; - import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationUtil; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; @@ -32,204 +30,202 @@ import org.apache.avalon.framework.servi import org.apache.fulcrum.yaafi.TestComponent; import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; +import junit.framework.TestCase; + /** * Test suite for the ServiceContainerFactory. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ServiceContainerFactoryTest extends TestCase -{ - private ServiceContainer container = null; - - /** - * Constructor - * @param name the name of the test case - */ - public ServiceContainerFactoryTest( String name ) - { - super(name); - } - - /** - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception - { - ServiceContainerFactory.dispose(this.container); - super.tearDown(); - } - - private void checkTestComponent() - throws Exception - { - TestComponent testComponent = this.getTestComponent(); - - testComponent.test(); - - assertEquals( testComponent.getBar(), "BAR" ); - assertEquals( testComponent.getFoo(), "FOO" ); - - assertNotNull( testComponent.getUrnAvalonClassLoader() ); - assertNotNull( testComponent.getUrnAvaloneHome() ); - assertNotNull( testComponent.getUrnAvaloneTemp() ); - assertNotNull( testComponent.getUrnAvalonName() ); - assertNotNull( testComponent.getUrnAvalonPartition() ); - - try - { - testComponent.createException("enforce exception", this); - } - catch( Exception e ) - { - // nothing to do - } - } - - /** - * @return get our simple test component - */ - private TestComponent getTestComponent() throws ServiceException - { - return (TestComponent) container.lookup( - TestComponent.ROLE - ); - } - - /** - * Creates a YAAFI container using a container configuration file - * which already contains most of the required settings - */ - public void testCreationWithContainerConfiguration() throws Exception - { - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); - this.container = ServiceContainerFactory.create( config ); - this.checkTestComponent(); - System.out.println(this.container.toString()); - return; - } - - /** - * Creates a YAAFI container using a non-existent container - * configuration file. Therefore the creation should fail. - */ - public void testCreationWithMissingContainerConfiguration() throws Exception - { - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - - try - { - config.loadContainerConfiguration( "./src/test/MissingTestContainerConfig.xml" ); - this.container = ServiceContainerFactory.create( config ); - fail("The creation of the YAAFI container must fail"); - } - catch (IOException e) - { - // nothing to do - } - catch (Exception e) - { - fail("We are expecting an IOException"); - } - } - - /** - * Creates a YAAFI container providing all required settings - * manually - */ - public void testCreationWithManualSettings() throws Exception - { - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - config.setComponentRolesLocation( "./src/test/TestRoleConfig.xml" ); - config.setComponentConfigurationLocation( "./src/test/TestComponentConfig.xml" ); - config.setParametersLocation( "./src/test/TestParameters.properties" ); - this.container = ServiceContainerFactory.create( config ); - this.checkTestComponent(); - } - - /** - * Creates a YAAFI container providing a Phoenix context - */ - public void testCreationWithPhoenixContext() throws Exception - { - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - DefaultContext context = new DefaultContext(); - - // use an existing container configuration - - config.loadContainerConfiguration( "./src/test/TestPhoenixContainerConfig.xml" ); - - // fill the context with Phoenix settings - - context.put( "app.name", "ServiceContainerFactoryTest" ); - context.put( "block.name", "fulcrum-yaafi" ); - context.put( "app.home", new File( new File("").getAbsolutePath() ) ); - - // create an instance - - this.container = ServiceContainerFactory.create( config, context ); - - // execute the test component - - this.checkTestComponent(); - } - - /** - * Creates a YAAFI container providing a Fortress context - */ - public void testCreationWithFortressContext() throws Exception - { - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - DefaultContext context = new DefaultContext(); - - // use an existing container configuration - - config.loadContainerConfiguration( "./src/test/TestFortressContainerConfig.xml" ); - - // fill the context with Fortress settings - - context.put( "component.id", "ServiceContainerFactoryTest" ); - context.put( "component.logger", "fulcrum-yaafi" ); - context.put( "context-root", new File( new File("").getAbsolutePath() ) ); - context.put( "impl.workDir", new File( new File("").getAbsolutePath() ) ); - - // create an instance - - this.container = ServiceContainerFactory.create( config, context ); - - // execute the test component - - this.checkTestComponent(); - } - - /** - * Reconfigures the YAAFI container with the "TestReconfigurationConfig.xml". - */ - public void testReconfiguration() throws Exception - { - // create a YAAFI instance - - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); - this.container = ServiceContainerFactory.create( config ); - this.checkTestComponent(); - - // load a different configuration and reconfigure YAAFI - - DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); - Configuration configuration = builder.buildFromFile( "./src/test/TestReconfigurationConfig.xml" ); - System.out.println(ConfigurationUtil.toString(configuration)); - - this.container.reconfigure( configuration ); - TestComponent testComponent = this.getTestComponent(); - testComponent.test(); +public class ServiceContainerFactoryTest extends TestCase { + private ServiceContainer container = null; + + /** + * Constructor + * + * @param name the name of the test case + */ + public ServiceContainerFactoryTest(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + ServiceContainerFactory.dispose(this.container); + super.tearDown(); + } + + /** + * @throws Exception generic exception + */ + private void checkTestComponent() throws Exception { + TestComponent testComponent = this.getTestComponent(); + + testComponent.test(); + + assertEquals(testComponent.getBar(), "BAR"); + assertEquals(testComponent.getFoo(), "FOO"); + + assertNotNull(testComponent.getUrnAvalonClassLoader()); + assertNotNull(testComponent.getUrnAvaloneHome()); + assertNotNull(testComponent.getUrnAvaloneTemp()); + assertNotNull(testComponent.getUrnAvalonName()); + assertNotNull(testComponent.getUrnAvalonPartition()); + + try { + testComponent.createException("enforce exception", this); + } catch (Exception e) { + // nothing to do + } + } + + /** + * @return get our simple test component + * @throws ServiceException if service not found + */ + private TestComponent getTestComponent() throws ServiceException { + return (TestComponent) container.lookup(TestComponent.ROLE); + } + + /** + * Creates a YAAFI container using a container configuration file which already + * contains most of the required settings + * + * @throws Exception generic exception + */ + public void testCreationWithContainerConfiguration() throws Exception { + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + config.loadContainerConfiguration("./src/test/TestYaafiContainerConfig.xml"); + this.container = ServiceContainerFactory.create(config); + this.checkTestComponent(); + System.out.println(this.container.toString()); + return; + } + + /** + * Creates a YAAFI container using a non-existent container configuration file. + * Therefore the creation should fail. + * + * @throws Exception generic exception + */ + public void testCreationWithMissingContainerConfiguration() throws Exception { + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + + try { + config.loadContainerConfiguration("./src/test/MissingTestContainerConfig.xml"); + this.container = ServiceContainerFactory.create(config); + fail("The creation of the YAAFI container must fail"); + } catch (IOException e) { + // nothing to do + } catch (Exception e) { + fail("We are expecting an IOException"); + } + } + + /** + * Creates a YAAFI container providing all required settings manually + * + * @throws Exception generic exception + */ + public void testCreationWithManualSettings() throws Exception { + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + config.setComponentRolesLocation("./src/test/TestRoleConfig.xml"); + config.setComponentConfigurationLocation("./src/test/TestComponentConfig.xml"); + config.setParametersLocation("./src/test/TestParameters.properties"); + this.container = ServiceContainerFactory.create(config); + this.checkTestComponent(); + } + + /** + * Creates a YAAFI container providing a Phoenix context + * + * @throws Exception generic exception + */ + public void testCreationWithPhoenixContext() throws Exception { + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + DefaultContext context = new DefaultContext(); + + // use an existing container configuration + + config.loadContainerConfiguration("./src/test/TestPhoenixContainerConfig.xml"); + + // fill the context with Phoenix settings + + context.put("app.name", "ServiceContainerFactoryTest"); + context.put("block.name", "fulcrum-yaafi"); + context.put("app.home", new File(new File("").getAbsolutePath())); + + // create an instance + + this.container = ServiceContainerFactory.create(config, context); + + // execute the test component + + this.checkTestComponent(); + } + + /** + * Creates a YAAFI container providing a Fortress context + * + * @throws Exception generic exception + */ + public void testCreationWithFortressContext() throws Exception { + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + DefaultContext context = new DefaultContext(); + + // use an existing container configuration + + config.loadContainerConfiguration("./src/test/TestFortressContainerConfig.xml"); + + // fill the context with Fortress settings + + context.put("component.id", "ServiceContainerFactoryTest"); + context.put("component.logger", "fulcrum-yaafi"); + context.put("context-root", new File(new File("").getAbsolutePath())); + context.put("impl.workDir", new File(new File("").getAbsolutePath())); + + // create an instance + + this.container = ServiceContainerFactory.create(config, context); + + // execute the test component + + this.checkTestComponent(); + } + + /** + * Reconfigures the YAAFI container with the "TestReconfigurationConfig.xml" + * + * @throws Exception generic exception + */ + public void testReconfiguration() throws Exception { + // create a YAAFI instance + + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + config.loadContainerConfiguration("./src/test/TestYaafiContainerConfig.xml"); + this.container = ServiceContainerFactory.create(config); + this.checkTestComponent(); + + // load a different configuration and reconfigure YAAFI + + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + Configuration configuration = builder.buildFromFile("./src/test/TestReconfigurationConfig.xml"); + System.out.println(ConfigurationUtil.toString(configuration)); + + this.container.reconfigure(configuration); + TestComponent testComponent = this.getTestComponent(); + testComponent.test(); - // the TestReconfigurationConfig.xml overwrites the - // TestComponentImpl.foo and the SystemProperty.FOO + // the TestReconfigurationConfig.xml overwrites the + // TestComponentImpl.foo and the SystemProperty.FOO - assertEquals( System.getProperty("FOO"), "YAAFI" ); - assertEquals( testComponent.getFoo(), "YAAFI" ); + assertEquals(System.getProperty("FOO"), "YAAFI"); + assertEquals(testComponent.getFoo(), "YAAFI"); - } + } } Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/AdviceServiceTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/AdviceServiceTest.java?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/AdviceServiceTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/AdviceServiceTest.java Tue Dec 11 14:53:48 2018 @@ -53,7 +53,7 @@ public class AdviceServiceTest extends T super(name); } - /** + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception @@ -65,7 +65,7 @@ public class AdviceServiceTest extends T service = (AdviceService) this.container.lookup(AdviceService.class.getName()); } - /** + /* (non-Javadoc) * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception @@ -89,7 +89,7 @@ public class AdviceServiceTest extends T /** * Advice a StringBuilder based on the CharSequence interface - * @throws Exception + * @throws Exception generic exception */ public void testSimpleAdvice() throws Exception { @@ -105,6 +105,7 @@ public class AdviceServiceTest extends T /** * Advice a StringBuilder based on the CharSequence interface + * @throws Exception generic exception */ public void testSimpleObject() throws Exception { @@ -120,6 +121,7 @@ public class AdviceServiceTest extends T /** * Advice a StringBuilder based on the CharSequenceInterface with default interceptors + * @throws Exception generic exception */ public void testDefaultAdvice() throws Exception { @@ -133,6 +135,7 @@ public class AdviceServiceTest extends T * The test implements the DependentTestComponent interface therefore we * are able to intercept the invocation of test(). Whereas test() invokes * another advised component. + * @throws Exception generic exception */ public void testChainedAdvices() throws Exception { @@ -143,6 +146,7 @@ public class AdviceServiceTest extends T /** * Advice a StringBuilder based on the CharSequenceInterface + * @throws Exception generic exception */ public void testMultipleProxies() throws Exception { @@ -155,8 +159,9 @@ public class AdviceServiceTest extends T assertTrue(this.service.isAdviced(advicedAdvicedObject)); } - /** + /* (non-Javadoc) * Advice a StringBuilder based on the CharSequenceInterface + * @see org.apache.fulcrum.yaafi.DependentTestComponent#test() */ public void test() { Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ReconfigurationTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ReconfigurationTest.java?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ReconfigurationTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ReconfigurationTest.java Tue Dec 11 14:53:48 2018 @@ -1,5 +1,12 @@ package org.apache.fulcrum.yaafi.service; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.fulcrum.yaafi.TestComponent; +import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; +import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration; +import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; +import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,80 +28,69 @@ package org.apache.fulcrum.yaafi.service import junit.framework.TestCase; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.fulcrum.yaafi.TestComponent; -import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; -import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration; -import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; -import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService; - /** - * Test suite for the ReconfigurationService. This test doesn't do - * anything apart from running a minute so you have some time to tinker - * with the component configuration file. + * Test suite for the ReconfigurationService. This test doesn't do anything + * apart from running a minute so you have some time to tinker with the + * component configuration file. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ReconfigurationTest extends TestCase -{ - private ServiceContainer container = null; - - /** - * Constructor - * @param name the name of the test case - */ - public ReconfigurationTest( String name ) - { - super(name); - } - - /** - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception - { - ServiceContainerFactory.dispose(this.container); - super.tearDown(); - } - - /** - * @return get our simple test component - */ - private TestComponent getTestComponent() throws ServiceException - { - return (TestComponent) container.lookup( - TestComponent.ROLE - ); - } - - /** - * Trigger the ReconfigurationService by instantiating it manually. - * @throws Exception - */ - public void testReconfigurationService() throws Exception - { - // instantiate a YAAFI container - - ServiceContainerConfiguration config = new ServiceContainerConfiguration(); - config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); - this.container = ServiceContainerFactory.create( config ); - - // the ReconfigurationService is configured to be instantiated on demand - // get an instance to start monitoring ... - - ReconfigurationService reconfigurationService = null; - - reconfigurationService = (ReconfigurationService) this.container.lookup( - ReconfigurationService.class.getName() - ); +public class ReconfigurationTest extends TestCase { + private ServiceContainer container = null; + + /** + * Constructor + * + * @param name the name of the test case + */ + public ReconfigurationTest(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + ServiceContainerFactory.dispose(this.container); + super.tearDown(); + } + + /** + * @return get our simple test component + * @throws ServiceException if service not found + */ + private TestComponent getTestComponent() throws ServiceException { + return (TestComponent) container.lookup(TestComponent.ROLE); + } + + /** + * Trigger the ReconfigurationService by instantiating it manually. + * + * @throws Exception generic exception + */ + public void testReconfigurationService() throws Exception { + // instantiate a YAAFI container + + ServiceContainerConfiguration config = new ServiceContainerConfiguration(); + config.loadContainerConfiguration("./src/test/TestYaafiContainerConfig.xml"); + this.container = ServiceContainerFactory.create(config); + + // the ReconfigurationService is configured to be instantiated on demand + // get an instance to start monitoring ... + + ReconfigurationService reconfigurationService = null; + + reconfigurationService = (ReconfigurationService) this.container.lookup(ReconfigurationService.class.getName()); - assertNotNull(reconfigurationService); + assertNotNull(reconfigurationService); - // comment out if you want to tinker with componentConfiguration manually + // comment out if you want to tinker with componentConfiguration manually - // Thread.sleep(60000); + // Thread.sleep(60000); - this.getTestComponent().test(); - } + this.getTestComponent().test(); + } } Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ServiceManagerServiceTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ServiceManagerServiceTest.java?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ServiceManagerServiceTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ServiceManagerServiceTest.java Tue Dec 11 14:53:48 2018 @@ -47,7 +47,7 @@ public class ServiceManagerServiceTest e super(name); } - /** + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception @@ -58,7 +58,7 @@ public class ServiceManagerServiceTest e this.container = ServiceContainerFactory.create( config ); } - /** + /* (non-Javadoc) * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception @@ -69,6 +69,7 @@ public class ServiceManagerServiceTest e /** * Access the ServiceManagerService + * @throws Exception if service manager not found */ public void testServiceManagerService() throws Exception { Modified: turbine/fulcrum/trunk/yaafi/xdocs/changes.xml URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/xdocs/changes.xml?rev=1848689&r1=1848688&r2=1848689&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/xdocs/changes.xml (original) +++ turbine/fulcrum/trunk/yaafi/xdocs/changes.xml Tue Dec 11 14:53:48 2018 @@ -24,6 +24,23 @@ </properties> <body> + <release version="1.0.8" date="as in SVN"> + <action dev="painter" type="update"> + Update javasimon to 4.1.4 + </action> + <action dev="painter" type="update"> + Replace byte array and input stream methods to JDK and commons managed code + </action> + <action dev="painter" type="update"> + Use new Turbine 5 parent pom + </action> + <action dev="painter" type="update"> + Use junit 4.12 + </action> + <action dev="painter" type="update"> + Use Java 8, clean up some issues from findbugs + </action> + </release> <release version="1.0.7-SNAPSHOT" date="as in SVN"> <action dev="sgoeschl" type="add" issue="TRB-97" data="2015-08-06"> Integrate JavaSimon for performance monitoring
