You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sg...@apache.org on 2005/03/01 11:52:27 UTC

cvs commit: jakarta-turbine-fulcrum/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container ServiceLifecycleManagerTest.java

sgoeschl    2005/03/01 02:52:27

  Modified:    yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory
                        ServiceContainerFactoryTest.java
  Added:       yaafi/src/test/org/apache/fulcrum/yaafi/framework/container
                        ServiceLifecycleManagerTest.java
  Removed:     yaafi/src/test/org/apache/fulcrum/yaafi/framework/crypto
                        CryptoUtilTest.java
  Log:
  Synchronizing my development CVS with Fulrum
  
  Revision  Changes    Path
  1.2       +71 -23    jakarta-turbine-fulcrum/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java
  
  Index: ServiceContainerFactoryTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/src/test/org/apache/fulcrum/yaafi/framework/factory/ServiceContainerFactoryTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceContainerFactoryTest.java	16 Feb 2005 11:26:33 -0000	1.1
  +++ ServiceContainerFactoryTest.java	1 Mar 2005 10:52:27 -0000	1.2
  @@ -19,13 +19,17 @@
   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;
   import org.apache.avalon.framework.context.DefaultContext;
  +import org.apache.avalon.framework.service.ServiceException;
   import org.apache.fulcrum.yaafi.TestComponent;
   import org.apache.fulcrum.yaafi.TestComponentImpl;
   import org.apache.fulcrum.yaafi.framework.container.ServiceContainer;
   
  -import junit.framework.TestCase;
  -
   /**
    * Test suite for the ServiceContainerFactory.
    *
  @@ -51,20 +55,14 @@
        */
       protected void tearDown() throws Exception
       {
  -        if( this.container != null )
  -        {
  -            this.container.dispose();
  -        }
  -        
  +        ServiceContainerFactory.dispose(this.container);
           super.tearDown();
       }
       
  -    private void checkTectComponent()
  +    private void checkTestComponent()
       	throws Exception
       {
  -        TestComponent testComponent = (TestComponent) container.lookup( 
  -            TestComponent.ROLE 
  -            );
  +        TestComponent testComponent = this.getTestComponent();
           
           testComponent.test();  
           
  @@ -81,6 +79,16 @@
           assertTrue( ((TestComponentImpl) testComponent).urnAvalonClassLoader instanceof ClassLoader );
       }
       
  +    /** 
  +     * @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
  @@ -88,9 +96,9 @@
       public void testCreationWithContainerConfiguration() throws Exception
       {
           ServiceContainerConfiguration config = new ServiceContainerConfiguration();                
  -        config.setContainerConfiguration( "./src/test/TestMerlinContainerConfig.xml", false );        
  +        config.loadContainerConfiguration( "./src/test/TestMerlinContainerConfig.xml" );        
           this.container = ServiceContainerFactory.create( config );
  -        this.checkTectComponent();  
  +        this.checkTestComponent();  
       }
   
       /**
  @@ -103,7 +111,7 @@
           
           try
           {
  -            config.setContainerConfiguration( "./src/test/MissingTestContainerConfig.xml", false );
  +            config.loadContainerConfiguration( "./src/test/MissingTestContainerConfig.xml" );
               this.container = ServiceContainerFactory.create( config );
               fail("The creation of the YAAFI container must fail");
           }
  @@ -128,7 +136,7 @@
           config.setComponentConfigurationLocation( "./src/test/TestComponentConfig.xml" );                               
           config.setParametersLocation( "./src/test/TestParameters.properties" );
           this.container = ServiceContainerFactory.create( config );   
  -        this.checkTectComponent();        
  +        this.checkTestComponent();        
       }
   
       /**
  @@ -141,18 +149,22 @@
           DefaultContext context = new DefaultContext();
           
           // use an existing container configuration
  -        config.setContainerConfiguration( "./src/test/TestPhoenixContainerConfig.xml", false );
  +        
  +        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.checkTectComponent();        
  +        // execute the test component
  +        
  +        this.checkTestComponent();        
       }
       
       /**
  @@ -165,18 +177,54 @@
           DefaultContext context = new DefaultContext();
           
           // use an existing container configuration
  -        config.setContainerConfiguration( "./src/test/TestFortressContainerConfig.xml", false );
           
  -        // fill the context with Phoenix settings
  +        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.checkTectComponent();        
  +        // 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 );        
  +        
  +        // load a different configuration
  +
  +		DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +		Configuration configuration = builder.buildFromFile( "./src/test/TestReconfigurationConfig.xml" );
  +		this.checkTestComponent();
  +        System.out.println(ConfigurationUtil.toString(configuration));
  +        
  +		// reconfigure YAAFI
  +
  +        this.container.reconfigure( configuration );
  +        TestComponent testComponent = this.getTestComponent();
  +        testComponent.test();
  +        
  +        // the TestReconfigurationConfig.xml overwrites the
  +        // TestComponentImpl.foo and the SystemProperty.FOO
  +        
  +        assertEquals( ((TestComponentImpl) testComponent).foo, "YAAFI" );
  +        assertEquals( System.getProperty("FOO"), "YAAFI" );
       }    
  +     
   }
  
  
  
  1.1                  jakarta-turbine-fulcrum/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java
  
  Index: ServiceLifecycleManagerTest.java
  ===================================================================
  package org.apache.fulcrum.yaafi.framework.container;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed 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 java.io.File;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.fulcrum.yaafi.TestComponent;
  import org.apache.fulcrum.yaafi.TestComponentImpl;
  import org.apache.fulcrum.yaafi.framework.container.ServiceContainer;
  import org.apache.fulcrum.yaafi.framework.container.ServiceLifecycleManager;
  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:siegfried.goeschl@drei.com">Siegfried Goeschl</a>
   * @version $Id: ServiceLifecycleManagerTest.java,v 1.1 2005/03/01 10:52:27 sgoeschl Exp $
   */
  
  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();
      }
  
      /**
       * Check our TestComponent.
       * 
       * @throws Exception
       */
      private void checkTestComponent()
          throws Exception
      {
          TestComponent testComponent = (TestComponent) container.lookup(
              TestComponent.ROLE
              );
  
          testComponent.test();
  
          assertEquals( ((TestComponentImpl) testComponent).bar, "BAR" );
          assertEquals( ((TestComponentImpl) testComponent).foo, "FOO" );
          assertNotNull( ((TestComponentImpl) testComponent).urnAvalonClassLoader );
          assertNotNull( ((TestComponentImpl) testComponent).urnAvaloneHome );
          assertNotNull( ((TestComponentImpl) testComponent).urnAvaloneTemp );
          assertNotNull( ((TestComponentImpl) testComponent).urnAvalonName );
          assertNotNull( ((TestComponentImpl) testComponent).urnAvalonPartition );
  
          assertTrue( ((TestComponentImpl) testComponent).urnAvaloneHome instanceof File );
          assertTrue( ((TestComponentImpl) testComponent).urnAvaloneTemp instanceof File );
          assertTrue( ((TestComponentImpl) testComponent).urnAvalonClassLoader instanceof ClassLoader );
      }
  
      private RoleEntry getRoleEntry( String name )
      	throws ServiceException
      {
          RoleEntry result =  this.container.getRoleEntry(
              name
              );
          
          return result;
    	}
      
      /**
       * 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 + " ...");
              
              this.lifecycleManager.reconfigure(list[i].getName());
              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();
              System.out.println("Processing " + serviceName + " ...");
              
              // reconfigure/decommission/reconfigure the service                
              this.lifecycleManager.reconfigure(serviceName);
              this.lifecycleManager.decommision(serviceName);
              this.lifecycleManager.reconfigure(serviceName);
              
              // run a reconfiguration over all services            
              this.container.reconfigure(configuration);
              
              // reconfigure/decommission/reconfigure the service    
              this.container.lookup(serviceName);
              this.lifecycleManager.reconfigure(serviceName);
              this.lifecycleManager.decommision(serviceName);
              this.lifecycleManager.reconfigure(serviceName);            
          }
      }
      
  
      /**
       * 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() );
      }    
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org