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=1887964&r1=1887963&r2=1887964&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 Mar 23 14:42:37 2021 @@ -1,5 +1,9 @@ package org.apache.fulcrum.yaafi.framework.container; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.fulcrum.yaafi.TestComponent; @@ -7,6 +11,9 @@ import org.apache.fulcrum.yaafi.framewor import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; import org.apache.fulcrum.yaafi.framework.role.RoleEntry; import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -27,221 +34,215 @@ import org.apache.fulcrum.yaafi.service. * under the License. */ -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** * 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); - } - - /* - * (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.decommission(serviceName); - assertTrue(this.container.hasService(serviceName)); - this.container.lookup(serviceName); - assertTrue(this.container.hasService(serviceName)); - this.lifecycleManager.decommission(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.decommission(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.decommission(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.decommission(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.decommission(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.decommission(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; - } +public class ServiceLifecycleManagerTest +{ + private ServiceLifecycleManager lifecycleManager; + private ServiceContainer container; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @BeforeEach + protected void setUp() throws Exception + { + 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() + */ + @AfterEach + protected void tearDown() throws Exception + { + ServiceContainerFactory.dispose( this.container ); + } + + /** + * 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 + */ + @Test + 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 + */ + @Test + 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 + */ + @Test + 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.decommission( serviceName ); + assertTrue( this.container.hasService( serviceName ) ); + this.container.lookup( serviceName ); + assertTrue( this.container.hasService( serviceName ) ); + this.lifecycleManager.decommission( serviceName ); + assertTrue( this.container.hasService( serviceName ) ); + } + } + + /** + * Decommission and resurrect all services + * + * @throws Exception generic exception + */ + @Test + 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.decommission( 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.decommission( serviceName ); + this.lifecycleManager.reconfigure( serviceNames ); + } + } + + /** + * Decommissions the TestComponent and ReconfigurationService to start them again. + * + * @throws Exception generic exception + */ + @Test + public void testIndividualDecommission() throws Exception + { + String serviceName = null; + + // teminate the TestComponent and run it again + + serviceName = TestComponent.class.getName(); + + this.checkTestComponent(); + this.lifecycleManager.decommission( 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.decommission( 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.decommission( ReconfigurationService.class.getName() ); + } + + /** + * Create an exception which should be handled by the JAMon interceptor. + * + * @throws Exception generic exception + */ + @Test + public void testException() throws Exception + { + TestComponent testComponent = (TestComponent) container.lookup( TestComponent.ROLE ); + + try + { + testComponent.createException( "testException", this ); + } catch (Exception e) + { + return; + } - } + } }
Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords Tue Mar 23 14:42:37 2021 @@ -1 +1 @@ -Author Date Id Revision +Id 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=1887964&r1=1887963&r2=1887964&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 Mar 23 14:42:37 2021 @@ -1,5 +1,9 @@ package org.apache.fulcrum.yaafi.framework.factory; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -29,8 +33,8 @@ import org.apache.avalon.framework.conte import org.apache.avalon.framework.service.ServiceException; import org.apache.fulcrum.yaafi.TestComponent; import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; - -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; /** * Test suite for the ServiceContainerFactory. @@ -38,194 +42,201 @@ import junit.framework.TestCase; * @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); - } - - /* - * (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(); +public class ServiceContainerFactoryTest +{ + private ServiceContainer container = null; + + @AfterEach + protected void tearDown() throws Exception + { + ServiceContainerFactory.dispose( this.container ); + } + + /** + * @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 + */ + @Test + 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 + */ + @Test + 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 + */ + @Test + 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 + */ + @Test + 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 + */ + @Test + 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 + */ + @Test + 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" ); - } + } } Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords Tue Mar 23 14:42:37 2021 @@ -1 +1 @@ -Author Date Id Revision +Id Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java?rev=1887964&r1=1887963&r2=1887964&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java Tue Mar 23 14:42:37 2021 @@ -24,7 +24,9 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.Properties; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test suite for the SmartToStringBuilderImpl. @@ -32,259 +34,269 @@ import junit.framework.TestCase; * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ArgumentToStringBuilderTest extends TestCase +public class ArgumentToStringBuilderTest { private String result; private ArgumentToStringBuilderImpl toStringBuilder; private int maxArgLength = 100; int mode = 3; - - /** - * Constructor - * @param name the name of the test case - */ - public ArgumentToStringBuilderTest( String name ) - { - super(name); - } - /** * @see junit.framework.TestCase#setUp() */ + @BeforeEach protected void setUp() throws Exception { - super.setUp(); this.toStringBuilder = new ArgumentToStringBuilderImpl(); - this.toStringBuilder.setMaxArgLength(this.maxArgLength); - this.toStringBuilder.setMode(this.mode); - System.out.println( "=== " + this.getName() + " ===================================="); + this.toStringBuilder.setMaxArgLength( this.maxArgLength ); + this.toStringBuilder.setMode( this.mode ); + System.out.println( "=== " + this.getClass().getName() + " ====================================" ); } /** * @see junit.framework.TestCase#setUp() */ + @AfterEach protected void tearDown() throws Exception { - System.out.println(this.result); - super.tearDown(); + System.out.println( this.result ); } /** * Test with a simple String */ + @Test public void testString() { String target = "In vino veritas"; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a simple Integer */ + @Test public void testInteger() { - Integer target = new Integer(69); - this.toStringBuilder.setTarget(target); + Integer target = new Integer( 69 ); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an empty array */ + @Test public void testEmptyArray() { String[] target = {}; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a simple String[] */ + @Test public void testStringArray() { - String[] target = {"foo","bar"}; - this.toStringBuilder.setTarget(target); + String[] target = { "foo", "bar" }; + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a simple Integer[] */ + @Test public void testIntegerArray() { - Integer[] target = {new Integer(4711), new Integer(815)}; - this.toStringBuilder.setTarget(target); + Integer[] target = { new Integer( 4711 ), new Integer( 815 ) }; + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an Exception */ + @Test public void testException() { - Exception target = new RuntimeException(this.getName()); - this.toStringBuilder.setTarget(target); + Exception target = new RuntimeException( this.getClass().getName() ); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an NULL object */ + @Test public void testNull() { Object target = null; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an array containing NULL values */ + @Test public void testWithANullArray() { Object target = new String[] { "foo", null, "bar" }; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Create a plain vanilla Java object + * * @throws Exception generic exception */ + @Test public void testPlainVanillaObject() throws Exception { - File target = new File("./LICENSE.txt"); - this.toStringBuilder.setTarget(target); + File target = new File( "./LICENSE.txt" ); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a char[] */ + @Test public void testCharArray() { - char[] target = this.getName().toCharArray(); - this.toStringBuilder.setTarget(target); + char[] target = this.getClass().getName().toCharArray(); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a long char[] which will be truncated */ + @Test public void testLongCharArray() { char[] target = System.getProperties().toString().toCharArray(); - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a byte[] */ + @Test public void testByteArray() { - Exception target = new RuntimeException(this.getName()); - this.toStringBuilder.setTarget(target.toString().getBytes()); + Exception target = new RuntimeException( this.getClass().getName() ); + this.toStringBuilder.setTarget( target.toString().getBytes() ); result = toStringBuilder.toString(); } /** * Test with a multidimensional array */ - public void testMultiDimensionalArray() + @Test + public void testMultiDimensionalArray() { - String[] row1 = {"r1.1", "1.2", "r1.3" }; + String[] row1 = { "r1.1", "1.2", "r1.3" }; int[] row2 = { 1, 2, 3 }; - String[] row3 = {"r3.1" }; - Object[] target = { row1, row2, row3, this.getName().toCharArray() }; + String[] row3 = { "r3.1" }; + Object[] target = { row1, row2, row3, this.getClass().getName().toCharArray() }; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a hashtable */ + @Test public void testHashtable() { Hashtable target = new Hashtable(); - target.put("foo","foo"); - target.put("bar","bar"); + target.put( "foo", "foo" ); + target.put( "bar", "bar" ); - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a java.util.Properties */ + @Test public void testProperties() { Properties target = System.getProperties(); - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an ArrayList */ + @Test public void testArrayList() { ArrayList<String> target = new ArrayList<>(); - target.add("foo"); - target.add("bar"); + target.add( "foo" ); + target.add( "bar" ); - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with a non-empty int[] */ + @Test public void testIntArray() { int[] target = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an empty int[] */ + @Test public void testEmptyIntArray() { int[] target = {}; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an boolean[] */ + @Test public void testBooleanArray() { boolean[] target = { true, false }; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } /** * Test with an File[] */ + @Test public void testFileArray() { - File[] target = { new File("foo"), new File("bar") }; + File[] target = { new File( "foo" ), new File( "bar" ) }; - this.toStringBuilder.setTarget(target); + this.toStringBuilder.setTarget( target ); result = toStringBuilder.toString(); } - } Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java ------------------------------------------------------------------------------ svn:keywords = Id 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=1887964&r1=1887963&r2=1887964&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 Mar 23 14:42:37 2021 @@ -1,5 +1,8 @@ package org.apache.fulcrum.yaafi.service; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,9 +22,6 @@ package org.apache.fulcrum.yaafi.service * under the License. */ -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.avalon.framework.service.ServiceException; import org.apache.fulcrum.yaafi.DependentTestComponent; @@ -30,6 +30,9 @@ import org.apache.fulcrum.yaafi.framewor import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; import org.apache.fulcrum.yaafi.interceptor.logging.LoggingInterceptorService; import org.apache.fulcrum.yaafi.service.advice.AdviceService; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test suite for the ServiceManagereService. @@ -37,60 +40,33 @@ import org.apache.fulcrum.yaafi.service. * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class AdviceServiceTest extends TestCase implements DependentTestComponent +public class AdviceServiceTest implements DependentTestComponent { private AdviceService service; private DependentTestComponent advisedThis; private ServiceContainer container; - /** - * Constructor - * @param name the name of the test case - */ - public AdviceServiceTest( String name ) - { - super(name); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ + @BeforeEach protected void setUp() throws Exception { - super.setUp(); ServiceContainerConfiguration config = new ServiceContainerConfiguration(); config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); this.container = ServiceContainerFactory.create( config ); service = (AdviceService) this.container.lookup(AdviceService.class.getName()); } - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ + @AfterEach protected void tearDown() throws Exception { ServiceContainerFactory.dispose(this.container); - super.tearDown(); - } - - public static Test suite() - { - TestSuite suite= new TestSuite(); - - suite.addTest( new AdviceServiceTest("testSimpleObject") ); - suite.addTest( new AdviceServiceTest("testDefaultAdvice") ); - suite.addTest( new AdviceServiceTest("testChainedAdvices") ); - suite.addTest( new AdviceServiceTest("testMultipleProxies") ); - - - return suite; } /** * Advice a StringBuilder based on the CharSequence interface * @throws Exception generic exception */ + @Test public void testSimpleAdvice() throws Exception { String[] interceptorList = { LoggingInterceptorService.class.getName() }; @@ -107,6 +83,7 @@ public class AdviceServiceTest extends T * Advice a StringBuilder based on the CharSequence interface * @throws Exception generic exception */ + @Test public void testSimpleObject() throws Exception { String[] interceptorList = { LoggingInterceptorService.class.getName() }; @@ -123,6 +100,7 @@ public class AdviceServiceTest extends T * Advice a StringBuilder based on the CharSequenceInterface with default interceptors * @throws Exception generic exception */ + @Test public void testDefaultAdvice() throws Exception { StringBuilder unadvicedObject = new StringBuilder("foo"); @@ -137,6 +115,7 @@ public class AdviceServiceTest extends T * another advised component. * @throws Exception generic exception */ + @Test public void testChainedAdvices() throws Exception { String[] interceptorList = { LoggingInterceptorService.class.getName() }; @@ -148,6 +127,7 @@ public class AdviceServiceTest extends T * Advice a StringBuilder based on the CharSequenceInterface * @throws Exception generic exception */ + @Test public void testMultipleProxies() throws Exception { String[] interceptorList = { LoggingInterceptorService.class.getName() }; @@ -163,6 +143,7 @@ public class AdviceServiceTest extends T * Advice a StringBuilder based on the CharSequenceInterface * @see org.apache.fulcrum.yaafi.DependentTestComponent#test() */ + @Test public void test() { try Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/AdviceServiceTest.java ------------------------------------------------------------------------------ svn:keywords = Id 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=1887964&r1=1887963&r2=1887964&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 Mar 23 14:42:37 2021 @@ -1,5 +1,8 @@ package org.apache.fulcrum.yaafi.service; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,7 +22,6 @@ package org.apache.fulcrum.yaafi.service * under the License. */ -import junit.framework.TestCase; import org.apache.avalon.framework.service.ServiceManager; import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; @@ -27,6 +29,9 @@ import org.apache.fulcrum.yaafi.framewor import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory; import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService; import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test suite for the ServiceManagereService. @@ -34,43 +39,31 @@ import org.apache.fulcrum.yaafi.service. * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ServiceManagerServiceTest extends TestCase -{ +public class ServiceManagerServiceTest { + private ServiceContainer container = null; - /** - * Constructor - * @param name the name of the test case - */ - public ServiceManagerServiceTest( String name ) - { - super(name); - } - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ + + @BeforeEach protected void setUp() throws Exception { - super.setUp(); ServiceContainerConfiguration config = new ServiceContainerConfiguration(); config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" ); this.container = ServiceContainerFactory.create( config ); } - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ + @AfterEach protected void tearDown() throws Exception { ServiceContainerFactory.dispose(this.container); - super.tearDown(); } /** * Access the ServiceManagerService * @throws Exception if service manager not found */ + @Test public void testServiceManagerService() throws Exception { ServiceManagerService serviceManagerService = ServiceManagerServiceImpl.getInstance(); Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/service/ServiceManagerServiceTest.java ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords Tue Mar 23 14:42:37 2021 @@ -1 +1 @@ -Author Date Id Revision +Id Added: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnit5Test.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnit5Test.java?rev=1887964&view=auto ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnit5Test.java (added) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnit5Test.java Tue Mar 23 14:42:37 2021 @@ -0,0 +1,165 @@ +package org.apache.fulcrum.yaafi.testcontainer; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.avalon.framework.component.Component; +import org.apache.avalon.framework.component.ComponentException; +import org.apache.avalon.framework.service.ServiceException; +import org.junit.jupiter.api.AfterEach; + +import junit.framework.TestCase; + +/** + * Base class for unit tests for components. This version doesn't load the + * container until the first request for a component. This allows the tester to + * populate the configurationFileName and roleFileName, possible one per test. + * + * @author <a href="mailto:[email protected]">Eric Pugh</a> + * @author <a href="mailto:[email protected]">Quinton McCombs</a> + */ +public abstract class BaseUnit5Test { + + /** YaffiContainer for the components */ + private Container container; + + /** Setup our default configurationFileName */ + private String configurationFileName = "src/test/TestComponentConfig.xml"; + + /** Setup our default roleFileName */ + private String roleFileName = "src/test/TestRoleConfig.xml"; + + /** Setup our paramterFileName */ + private String parameterFileName = "src/test/TestParameters.properties"; + + /** + * Gets the configuration file name for the container should use for this test. + * By default it is src/test/TestComponentConfig. + * + * @param configurationFileName config file name + */ + protected void setConfigurationFileName(String configurationFileName) { + this.configurationFileName = configurationFileName; + } + + /** + * Override the role file name for the container should use for this test. By + * default it is src/test/TestRoleConfig. + * + * @param roleFileName role file name + */ + protected void setRoleFileName(String roleFileName) { + this.roleFileName = roleFileName; + } + + /** + * Override the parameter file name for the container should use for this test. + * By default it is src/test/TestRoleConfig. + * + * @param parameterFileName the name of the parameter file + */ + protected void setParameterFileName(String parameterFileName) { + this.parameterFileName = parameterFileName; + } + + @AfterEach + protected void tearDown() throws Exception { + if (this.container != null) { + this.container.dispose(); + } + this.container = null; + } + + /** + * Gets the configuration file name for the container should use for this test. + * + * @return The filename of the configuration file + */ + protected String getConfigurationFileName() { + return this.configurationFileName; + } + + /** + * Gets the role file name for the container should use for this test. + * + * @return The filename of the role configuration file + */ + protected String getRoleFileName() { + return this.roleFileName; + } + + /** + * Gets the parameter file name for the container should use for this test. + * + * @return The filename of the parameter file + */ + protected String getParameterFileName() { + return this.parameterFileName; + } + + /** + * Returns an instance of the named component. Starts the container if it hasn't + * been started. + * + * @param roleName Name of the role the component fills. + * @return Object representing the named component + * @throws ComponentException if the component is not found + */ + protected Object lookup(String roleName) throws ComponentException { + if (this.container == null) { + this.container = new Container(); + this.container.startup(getConfigurationFileName(), getRoleFileName(), getParameterFileName()); + } + return this.container.lookup(roleName); + } + + /** + * Releases the component + * + * @param component the component to be released + */ + protected void release(Component component) { + if (this.container != null) { + this.container.release(component); + } + } + + /** + * Releases the component + * + * @param component the component to be released + */ + protected void release(Object component) { + if (this.container != null) { + this.container.release(component); + } + } + + /** + * Decommision the service + * + * @param name the name of the service + * @throws ServiceException if the service is not found + */ + protected void decommision(String name) throws ServiceException { + if (this.container != null) { + this.container.decommission(name); + } + } +} Propchange: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnit5Test.java ------------------------------------------------------------------------------ svn:keywords = Id
