leosimons    2003/01/27 09:04:49

  Added:       fortress/src/test/org/apache/avalon/fortress/test
                        ContainerProfile.java ContainerProfile.roles
                        ContainerProfile.xconf ContainerProfile.xlog
                        HandlersTestCase.java
               fortress/src/test/org/apache/avalon/fortress/test/data
                        BaseRole.java Component1.java Component2.java
                        Component3.java Component4.java Role1.java
                        Role2.java Role3.java Role4.java test1.roles
                        test1.xconf test1.xlog
               fortress/src/test/org/apache/avalon/fortress/test/util
                        AbstractRoleManagerTestCase.java
                        ComponentClassLoaderTestCase.java
                        ComponentStateValidator.java ComponentTestCase.java
                        ConfigurableRoleManagerTestCase.java
                        FortressRoleManagerTestCase.java
                        FullLifecycleComponent.java empty.jar full.jar
  Log:
    Wholesale refactoring. Moved classes to org.apache.avalon.fortress, changed 
exception handling, removed inner class, documentation changes, removed some 
remnants from ECM copy-pasting. Seperated interfaces from implementation. 
Consider this a proposal. The excalibur.fortress tree can be removed if no-one 
objects to these changes.
  
  This updates the TestCases to reference the new classes.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/ContainerProfile.java
  
  Index: ContainerProfile.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software 
Foundation"
      must not be used to endorse or promote products derived from this  
software
      without  prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.fortress.test;
  
  import java.net.URL;
  import junit.framework.TestCase;
  import junit.textui.TestRunner;
  import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
  import org.apache.avalon.excalibur.logger.DefaultLogKitManager;
  import org.apache.avalon.excalibur.monitor.Monitor;
  import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
  import org.apache.excalibur.xml.dom.DOMParser;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.NullLogger;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.WrapperServiceManager;
  import org.apache.avalon.fortress.ContainerManager;
  import org.apache.avalon.fortress.impl.DefaultContainerManager;
  import org.apache.avalon.fortress.impl.DefaultContainer;
  import org.apache.avalon.fortress.util.FortressConfig;
  
  /**
   * Used as a basis for the PoolComparisonProfile Tests
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version $Id: ContainerProfile.java,v 1.1 2003/01/27 17:04:47 leosimons 
Exp $
   */
  public final class ContainerProfile
      extends TestCase
  {
      /**
       * The TEST_SIZE defines the overall size of the tests.  Decreasing this 
will
       *  decrease the time the test takes to run, but also decrease its 
efficiency.
       */
      protected static final int TEST_SIZE = 5000;
      protected static final int THREADS = 20;
  
      protected static Throwable m_throwable = null;
      protected static int m_getCount = 0;
  
      protected Logger m_logger;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ContainerProfile( String name )
      {
          super( name );
  
          // Set to debug to see more useful information.
          m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
      }
  
      /*---------------------------------------------------------------
       * ECM vs. ContainerManager StartTimes
       *-------------------------------------------------------------*/
      /**
       * Compare the ECM and ContainerManager start times.
       */
      public void testCompare_ECM_ContainerManager_UseageTime()
          throws Exception
      {
          resetMemory(); // Start clean
  
          long ecmStart = System.currentTimeMillis();
          org.apache.log.Logger logKitLogger =
              org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( 
"test" );
          logKitLogger.setPriority( org.apache.log.Priority.INFO );
          ExcaliburComponentManager manager = new ExcaliburComponentManager();
          Context context = new DefaultContext();
          manager.setLogger( logKitLogger );
          manager.contextualize( context );
          DefaultLogKitManager logmanager = new DefaultLogKitManager();
          logmanager.setLogger( logKitLogger );
          logmanager.contextualize( context );
          logmanager.configure( getLogKitConfig() );
          manager.setLogKitManager( logmanager );
          manager.configure( getContainerConfig() );
          manager.initialize();
          long ecmStop = System.currentTimeMillis();
          long ecmDuration = ecmStop - ecmStart;
  
          resetMemory(); // Start clean
  
          long cmStart = System.currentTimeMillis();
          final FortressConfig config = new FortressConfig();
          config.setContextDirectory( "./" );
          config.setWorkDirectory( "./tmp" );
          config.setContainerClass( DefaultContainer.class );
          config.setContainerConfiguration( 
"resource://org/apache/excalibur/fortress/test/ContainerProfile.xconf" );
          config.setLoggerManagerConfiguration( 
"resource://org/apache/excalibur/fortress/test/ContainerProfile.xlog" );
          config.setRoleManagerConfiguration( 
"resource://org/apache/excalibur/fortress/test/ContainerProfile.roles" );
  
  
          final ContainerManager cm = new DefaultContainerManager( 
config.getContext(), new NullLogger() );
          ContainerUtil.initialize( cm );
          DefaultContainer container = (DefaultContainer)cm.getContainer();
          assertNotNull( container );
          long cmStop = System.currentTimeMillis();
          long cmDuration = cmStop - cmStart;
  
          // Show a summary
          if( m_logger.isInfoEnabled() )
          {
              m_logger.info( "Test Case: ECM_ContainerManager_StartTime" );
              m_logger.info( "     ECM time = " + ecmDuration + "ms." );
              m_logger.info( "     ContainerManager time = " + cmDuration + 
"ms." );
  
              double mult;
              mult = ( cmDuration > 0 ? ( ecmDuration * 100 / cmDuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => ContainerManager is " + mult + " X as fast 
as ExcaliburComponentManager on init." );
              mult = ( ecmDuration > 0 ? ( cmDuration * 100 / ecmDuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => ExcaliburComponentManager is " + mult + " X 
as fast as ContainerManager on init." );
          }
  
          resetMemory();
  
          lookupTest( "Test Case: ECM_ContainerManager_UseageTime", 
container.getServiceManager(), new WrapperServiceManager( manager ) );
  
          resetMemory();
  
          ecmStart = System.currentTimeMillis();
          ContainerUtil.dispose( manager );
          ecmStop = System.currentTimeMillis();
          ecmDuration = ecmStop - ecmStart;
  
          resetMemory();
  
          cmStart = System.currentTimeMillis();
          ContainerUtil.dispose( cm );
          cmStop = System.currentTimeMillis();
          cmDuration = cmStop - cmStart;
  
          // Show a summary
          if( m_logger.isInfoEnabled() )
          {
              m_logger.info( "Test Case: ECM_ContainerManager_KillTime" );
              m_logger.info( "     ECM time = " + ecmDuration + "ms." );
              m_logger.info( "     ContainerManager time = " + cmDuration + 
"ms." );
  
              double mult;
              mult = ( cmDuration > 0 ? ( ecmDuration * 100 / cmDuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => ContainerManager is " + mult + " X as fast 
as ExcaliburComponentManager on dispose." );
              mult = ( ecmDuration > 0 ? ( cmDuration * 100 / ecmDuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => ExcaliburComponentManager is " + mult + " X 
as fast as ContainerManager on dispose." );
          }
      }
  
      /*---------------------------------------------------------------
       * Utility Methods
       *-------------------------------------------------------------*/
      protected void resetMemory()
      {
          System.gc();
          System.gc();
  
          // Let the system settle down.
          try
          {
              Thread.sleep( 50 );
          }
          catch( InterruptedException e )
          {
          }
          Runtime runtime = Runtime.getRuntime();
          m_logger.debug( "Memory: " + ( runtime.totalMemory() - 
runtime.freeMemory() ) );
      }
  
      /**
       * Get the LogKitManager Config file
       */
      protected Configuration getLogKitConfig()
          throws Exception
      {
          final String resourceName = this.getClass().getName().replace( '.', 
'/' ) + ".xlog";
          java.net.URL resource = this.getClass().getClassLoader().getResource( 
resourceName );
          return loadConfig( resource );
      }
  
      /**
       * Get the Container Config file
       */
      protected Configuration getContainerConfig()
          throws Exception
      {
          final String resourceName = this.getClass().getName().replace( '.', 
'/' ) + ".xconf";
          java.net.URL resource = this.getClass().getClassLoader().getResource( 
resourceName );
          return loadConfig( resource );
      }
  
      /**
       * Load Config
       */
      protected Configuration loadConfig( java.net.URL path )
          throws Exception
      {
          final DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
          return builder.build( path.openStream() );
      }
  
      /**
       * Get the short class name
       */
      protected String getShortClassName( Object o )
      {
          String name = o.getClass().getName();
          int pos = name.lastIndexOf( '.' );
          if( pos > 0 )
          {
              name = name.substring( pos + 1 );
          }
          return name;
      }
  
      /**
       * The guts of the various test cases.  Will dispose the pools
       */
      protected void lookupTest( String name, ServiceManager cmA, 
ServiceManager cmB )
          throws Exception
      {
          m_logger.info( "Test Case: " + name );
  
          // Get the short class names
          final String cmAName = getShortClassName( cmA );
          final String cmBName = getShortClassName( cmB );
  
          // Start clean
          resetMemory();
  
  
          // Get the time for ecm
          final long cmADuration = getLookupRunTime( cmA );
          m_logger.info( "     " + cmAName + " time = " + cmADuration + "ms. to 
use " + TEST_SIZE + " calls on 3 components." );
          resetMemory();
  
  
          // Get the time for manager
          final long cmBDuration = getLookupRunTime( cmB );
          m_logger.info( "     " + cmBName + " time = " + cmBDuration + "ms. to 
use " + TEST_SIZE + " calls on 3 components." );
          resetMemory();
  
          // Show a summary
          if( m_logger.isInfoEnabled() )
          {
              double mult;
              mult = ( cmADuration > 0 ? ( cmBDuration * 100 / cmADuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => " + cmAName + " is " + mult + " X as fast as 
" + cmBName + "." );
  
              mult = ( cmBDuration > 0 ? ( cmADuration * 100 / cmBDuration ) / 
100.0 : Float.POSITIVE_INFINITY );
              m_logger.info( "  => " + cmBName + " is " + mult + " X as fast as 
" + cmAName + "." );
          }
      }
  
      protected long getLookupRunTime( ServiceManager manager )
      {
          // Create the runnable
          org.apache.avalon.fortress.test.ContainerProfile.LookupRunner 
runnable = new org.apache.avalon.fortress.test.ContainerProfile.LookupRunner( 
manager, m_logger );
  
          LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS 
);
          group.enableLogging( m_logger );
  
          long duration;
          try
          {
              duration = group.go();
          }
          catch( Throwable t )
          {
              // Throwable could have been thrown by one of the tests.
              if( m_throwable == null )
              {
                  m_throwable = t;
              }
              duration = 0;
          }
  
          if( m_throwable != null )
          {
              throw new CascadingAssertionFailedError( "Exception in test 
thread.", m_throwable );
          }
  
          assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  
          return duration;
      }
  
      private static class LookupRunner implements Runnable
      {
          private Logger m_logger;
          private ServiceManager m_manager;
          private int m_getCount = 0;
          private Throwable m_throwable = null;
  
          public LookupRunner( ServiceManager manager, Logger logger )
          {
              m_manager = manager;
              m_logger = logger;
          }
  
          public int getCount()
          {
              return m_getCount;
          }
  
          public Throwable getThrowable()
          {
              return m_throwable;
          }
  
          public void run()
          {
              // Perform this threads part of the test.
              final int loops = ( TEST_SIZE / THREADS );
              for( int i = 0; i < loops; i++ )
              {
                  DOMParser parser = null;
  
                  try
                  {
                      parser = (DOMParser)m_manager.lookup( DOMParser.ROLE );
  
                      // Make the loops hold the components longer than they 
are released, but only slightly.
                      Thread.yield();
                  }
                  catch( Throwable t )
                  {
                      m_logger.error( "Unexpected error after " + m_getCount +
                                      " iterations retrieved for DOMParser", t 
);
  
                      if( m_throwable == null )
                      {
                          m_throwable = t;
                      }
                      return;
                  }
                  finally
                  {
                      if( null != parser )
                      {
                          m_manager.release( parser );
                      }
                  }
                  /*
                  DataSourceComponent datasource = null;
  
                  try
                  {
                      datasource = (DataSourceComponent) 
m_manager.lookup(DataSourceComponent.ROLE);
  
                      // Make the loops hold the components longer than they 
are released, but only slightly.
                      Thread.yield();
                  }
                  catch (Throwable t)
                  {
                      m_logger.error( "Unexpected error after " + m_getCount +
                          " iterations retrieved for DataSourceComponent", t );
  
                      if (m_throwable == null) {
                          m_throwable = t;
                      }
                      return;
                  }
                  finally
                  {
                      if ( null != datasource )
                      {
                          m_manager.release( datasource );
                      }
                  }
                  */
                  Monitor monitor = null;
  
                  try
                  {
                      monitor = (Monitor)m_manager.lookup( Monitor.ROLE );
  
                      // Make the loops hold the components longer than they 
are released, but only slightly.
                      Thread.yield();
                  }
                  catch( Throwable t )
                  {
                      m_logger.error( "Unexpected error after " + m_getCount +
                                      " iterations retrieved for 
DataSourceComponent", t );
  
                      if( m_throwable == null )
                      {
                          m_throwable = t;
                      }
                      return;
                  }
                  finally
                  {
                      if( null != monitor )
                      {
                          m_manager.release( monitor );
                      }
                  }
              }
          }
      }
  
      public static final void main( String[] args )
      {
          TestRunner.run( ContainerProfile.class );
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/ContainerProfile.roles
  
  Index: ContainerProfile.roles
  ===================================================================
  <test>
    <role name="org.apache.avalon.excalibur.datasource.DataSourceComponent">
      <component shorthand="datasource"
                 class="org.apache.avalon.excalibur.datasource.JdbcDataSource"
                 
handler="org.apache.avalon.fortress.impl.handler.ThreadSafeComponentHandler"/>
    </role>
    <role name="org.apache.avalon.excalibur.monitor.Monitor">
      <component shorthand="monitor"
                 class="org.apache.avalon.excalibur.monitor.ActiveMonitor"
                 
handler="org.apache.avalon.fortress.impl.handler.ThreadSafeComponentHandler"/>
    </role>
    <role name="org.apache.excalibur.xml.dom.DOMParser">
      <component shorthand="parser"
                 class="org.apache.excalibur.xml.impl.JaxpParser"
                 
handler="org.apache.avalon.fortress.impl.handler.PoolableComponentHandler"/>
    </role>
  </test>
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/ContainerProfile.xconf
  
  Index: ContainerProfile.xconf
  ===================================================================
  <test>
    <component id="test2"
          class="org.apache.avalon.excalibur.monitor.ActiveMonitor"
            logger="test"
          activation="startup">
      <thread priority="10" frequency="1"/>
    </component>
    <component id="test3"
               class="org.apache.excalibur.xml.impl.JaxpParser"
                 logger="test"
               activation="startup">
      <parameter name="validate" value="false"/>
      <parameter name="namespace-prefixes" value="false"/>
      <parameter name="reuse-parsers" value="true"/>
      <parameter name="stop-on-warning" value="false"/>
      <parameter name="stop-on-recoverable-error" value="true"/>
    </component>
  </test>
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/ContainerProfile.xlog
  
  Index: ContainerProfile.xlog
  ===================================================================
  <logkit>
      <factories>
        <factory type="file" 
class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
      </factories>
  
      <targets>
         <file id="root">
          <filename>container-test.log</filename>
          <format type="extended">
            %7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): 
%{message}\n%{throwable}
          </format>
         </file>
       </targets>
  
       <categories>
         <category name="test" log-level="INFO">
           <log-target id-ref="root"/>
         </category>
         <category name="" log-level="INFO">
           <log-target id-ref="root"/>
         </category>
       </categories>
  </logkit>
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/HandlersTestCase.java
  
  Index: HandlersTestCase.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  
  package org.apache.avalon.fortress.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.fortress.ContainerManager;
  import org.apache.avalon.fortress.impl.DefaultContainerManager;
  import org.apache.avalon.fortress.impl.DefaultContainer;
  import org.apache.avalon.fortress.test.data.BaseRole;
  import org.apache.avalon.fortress.test.data.Role1;
  import org.apache.avalon.fortress.test.data.Role2;
  import org.apache.avalon.fortress.test.data.Role3;
  import org.apache.avalon.fortress.test.data.Role4;
  import org.apache.avalon.fortress.util.FortressConfig;
  
  /**
   * A testcase for the different handlers.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:47 $
   */
  public class HandlersTestCase extends TestCase
  {
      private Exception m_exception;
  
      public HandlersTestCase( final String name )
      {
          super( name );
      }
  
      public void testThreadsafe()
          throws Exception
      {
          final ServiceManager serviceManager = getServiceManager();
          final String key = org.apache.avalon.fortress.test.data.Role1.ROLE;
          final org.apache.avalon.fortress.test.data.BaseRole object1 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
          final org.apache.avalon.fortress.test.data.BaseRole object2 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
  
          assertEquals( "Threadsafe object IDs (1 vs 2)", object1.getID(), 
object2.getID() );
  
          final Thread thread = new Thread()
          {
              public void run()
              {
                  try
                  {
                      final org.apache.avalon.fortress.test.data.BaseRole 
object3 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
                      final org.apache.avalon.fortress.test.data.BaseRole 
object4 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
  
                      assertEquals( "Threadsafe object IDs (1 vs 3)", 
object1.getID(), object3.getID() );
                      assertEquals( "Threadsafe object IDs (2 vs 4)", 
object2.getID(), object4.getID() );
                      assertEquals( "Threadsafe object IDs (3 vs 4)", 
object3.getID(), object4.getID() );
                  }
                  catch( final Exception e )
                  {
                      m_exception = e;
                  }
              }
          };
          thread.start();
          thread.join();
  
          checkException();
      }
  
      public void testPerThread()
          throws Exception
      {
          final String key = org.apache.avalon.fortress.test.data.Role3.ROLE;
          final String type = "PerThread";
  
          final ServiceManager serviceManager = getServiceManager();
          final org.apache.avalon.fortress.test.data.BaseRole object1 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
          final org.apache.avalon.fortress.test.data.BaseRole object2 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
  
          assertEquals( type + " object IDs (1 vs 2)", object1.getID(), 
object2.getID() );
  
          final Thread thread = new Thread()
          {
              public void run()
              {
                  try
                  {
                      final org.apache.avalon.fortress.test.data.BaseRole 
object3 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
                      final org.apache.avalon.fortress.test.data.BaseRole 
object4 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
  
                      assertTrue( type + " object IDs (1 vs 3)", 
object1.getID() != object3.getID() );
                      assertTrue( type + " object IDs (2 vs 4)", 
object2.getID() != object4.getID() );
                      assertEquals( type + " object IDs (3 vs 4)", 
object3.getID(), object4.getID() );
                  }
                  catch( final Exception e )
                  {
                      m_exception = e;
                  }
              }
          };
          thread.start();
          thread.join();
  
          checkException();
      }
  
      public void testFactory()
          throws Exception
      {
          final String key = org.apache.avalon.fortress.test.data.Role4.ROLE;
          final String type = "Factory";
  
          final ServiceManager serviceManager = getServiceManager();
          final org.apache.avalon.fortress.test.data.BaseRole object1 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
          final org.apache.avalon.fortress.test.data.BaseRole object2 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
  
          assertTrue( type + " object IDs (1 vs 2)", object1.getID() != 
object2.getID() );
  
          final Thread thread = new Thread()
          {
              public void run()
              {
                  try
                  {
                      final org.apache.avalon.fortress.test.data.BaseRole 
object3 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
                      final org.apache.avalon.fortress.test.data.BaseRole 
object4 = (org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( 
key );
  
                      assertTrue( type + " object IDs (1 vs 3)", 
object1.getID() != object3.getID() );
                      assertTrue( type + " object IDs (2 vs 4)", 
object2.getID() != object4.getID() );
                      assertTrue( type + " object IDs (3 vs 4)", 
object3.getID() != object4.getID() );
                  }
                  catch( final Exception e )
                  {
                      m_exception = e;
                  }
              }
          };
          thread.start();
          thread.join();
  
          checkException();
      }
  
      private void checkException() throws Exception
      {
          if( null != m_exception )
          {
              final Exception exception = m_exception;
              m_exception = null;
              throw exception;
          }
      }
  
      public void testPoolable()
          throws Exception
      {
          final ServiceManager serviceManager = getServiceManager();
          final String key = org.apache.avalon.fortress.test.data.Role2.ROLE;
          final org.apache.avalon.fortress.test.data.BaseRole object1 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
          final org.apache.avalon.fortress.test.data.BaseRole object2 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
          final org.apache.avalon.fortress.test.data.BaseRole object3 = 
(org.apache.avalon.fortress.test.data.BaseRole)serviceManager.lookup( key );
  
  
          serviceManager.release( object1 );
          serviceManager.release( object2 );
          serviceManager.release( object3 );
      }
  
      private ServiceManager getServiceManager() throws Exception
      {
          final FortressConfig config = new FortressConfig();
          config.setContextDirectory( "./" );
          config.setWorkDirectory( "./" );
          final String BASE = 
"resource://org/apache/excalibur/fortress/test/data/";
          config.setContainerConfiguration( BASE + "test1.xconf" );
          config.setLoggerManagerConfiguration( BASE + "test1.xlog" );
          config.setRoleManagerConfiguration( BASE + "test1.roles" );
  
          final ContainerManager cm = new DefaultContainerManager( 
config.getContext() );
          ContainerUtil.initialize( cm );
  
          final DefaultContainer container = 
(DefaultContainer)cm.getContainer();
          final ServiceManager serviceManager = container.getServiceManager();
          return serviceManager;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/BaseRole.java
  
  Index: BaseRole.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public interface BaseRole
  {
      long getID();
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component1.java
  
  Index: Component1.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public class Component1
      implements Role1
  {
      public long getID()
      {
          return hashCode();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component2.java
  
  Index: Component2.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public class Component2
      implements Role2
  {
      public long getID()
      {
          return hashCode();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component3.java
  
  Index: Component3.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public class Component3
      implements Role3
  {
      public long getID()
      {
          return hashCode();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Component4.java
  
  Index: Component4.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public class Component4
      implements Role4
  {
      public long getID()
      {
          return hashCode();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role1.java
  
  Index: Role1.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public interface Role1
      extends org.apache.avalon.fortress.test.data.BaseRole
  {
      String ROLE = Role1.class.getName();
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role2.java
  
  Index: Role2.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public interface Role2
      extends org.apache.avalon.fortress.test.data.BaseRole
  {
      String ROLE = Role2.class.getName();
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role3.java
  
  Index: Role3.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public interface Role3
      extends org.apache.avalon.fortress.test.data.BaseRole
  {
      String ROLE = Role3.class.getName();
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/Role4.java
  
  Index: Role4.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.data;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:48 $
   */
  public interface Role4
      extends org.apache.avalon.fortress.test.data.BaseRole
  {
      String ROLE = Role4.class.getName();
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.roles
  
  Index: test1.roles
  ===================================================================
  <test>
      <role name="org.apache.avalon.fortress.test.data.Role1">
          <component shorthand="component1"
              class="org.apache.avalon.fortress.test.data.Component1"
              
handler="org.apache.avalon.fortress.impl.handler.ThreadSafeComponentHandler"/>
      </role>
      <role name="org.apache.avalon.fortress.test.data.Role2">
          <component shorthand="component2"
              class="org.apache.avalon.fortress.test.data.Component2"
              
handler="org.apache.avalon.fortress.impl.handler.PoolableComponentHandler"/>
      </role>
      <role name="org.apache.avalon.fortress.test.data.Role3">
          <component shorthand="component3"
              class="org.apache.avalon.fortress.test.data.Component3"
              
handler="org.apache.avalon.fortress.impl.handler.PerThreadComponentHandler"/>
      </role>
      <role name="org.apache.avalon.fortress.test.data.Role4">
          <component shorthand="component4"
              class="org.apache.avalon.fortress.test.data.Component4"
              
handler="org.apache.avalon.fortress.impl.handler.FactoryComponentHandler"/>
      </role>
  </test>
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xconf
  
  Index: test1.xconf
  ===================================================================
  <test>
      <component id="component1"
          class="org.apache.avalon.fortress.test.data.Component1"
          logger="component1"
          activation="startup"/>
      <component id="component2"
          class="org.apache.avalon.fortress.test.data.Component2"
          logger="component2"
          pool-min="2"
          activation="startup"/>
      <component id="component3"
          class="org.apache.avalon.fortress.test.data.Component3"
          logger="component3"
          activation="startup"/>
      <component id="component4"
          class="org.apache.avalon.fortress.test.data.Component4"
          logger="component4"
          activation="startup"/>
  </test>
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/data/test1.xlog
  
  Index: test1.xlog
  ===================================================================
  <logkit>
      <factories>
          <factory type="file" 
class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
      </factories>
  
      <targets>
          <file id="root">
              <filename>container-test.log</filename>
              <format type="extended">
              %7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): 
%{message}\n%{throwable}
          </format>
          </file>
      </targets>
  
      <categories>
          <category name="test" log-level="INFO">
              <log-target id-ref="root"/>
          </category>
          <category name="" log-level="INFO">
              <log-target id-ref="root"/>
          </category>
      </categories>
  </logkit>
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/AbstractRoleManagerTestCase.java
  
  Index: AbstractRoleManagerTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.util;
  
  import junit.framework.TestCase;
  import org.apache.avalon.fortress.RoleEntry;
  import org.apache.avalon.fortress.RoleManager;
  
  /**
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   */
  public class AbstractRoleManagerTestCase extends TestCase
  {
      private boolean m_informixClassExists = false;
  
      public AbstractRoleManagerTestCase( final String key )
      {
          super( key );
  
          try
          {
              Class.forName( 
"org.apache.avalon.excalibur.datasource.InformixDataSource" );
              m_informixClassExists = true;
          }
          catch( Exception e )
          {
              m_informixClassExists = false;
          }
      }
  
      protected boolean isInformixClassExists()
      {
          return m_informixClassExists;
      }
  
      protected void checkRole( final RoleManager roles,
                                final String shortname,
                                final String role,
                                final String className,
                                final String handlerClassname )
          throws ClassNotFoundException
      {
          final RoleEntry roleEntry = roles.getRoleForShortName( shortname );
          assertNotNull( "RoleEntry", roleEntry );
  
          assertEquals( "componentClass:",
                        roleEntry.getComponentClass(), Class.forName( className 
) );
          assertEquals( "Role:", roleEntry.getRole(), role );
          assertEquals( "Handler:",
                        roleEntry.getHandlerClass(), Class.forName( 
handlerClassname ) );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/ComponentClassLoaderTestCase.java
  
  Index: ComponentClassLoaderTestCase.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  
  package org.apache.avalon.fortress.test.util;
  
  import java.net.URL;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  import junit.framework.TestCase;
  import org.apache.excalibur.fortress.util.classloader.ComponentClassLoader;
  import org.apache.excalibur.fortress.util.classloader.JarEntries;
  import org.apache.excalibur.fortress.util.classloader.JarScanner;
  
  /**
  * A testcase for the @link{ComponentClassLoader}.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   */
  public class ComponentClassLoaderTestCase extends TestCase
  {
      private java.util.Set m_blocks;
      private java.util.Set m_services;
      private java.util.Set m_types;
  
      public ComponentClassLoaderTestCase( String name )
      {
          super( name );
          m_blocks = new java.util.HashSet();
          m_blocks.add("org.apache.avalon.test.EphemeralComponent");
          m_blocks.add("org.apache.avalon.test.AnotherTest");
  
          m_types = new java.util.HashSet();
          m_types.add("org.apache.avalon.test.YetAnotherTest");
          m_types.add("org.apache.avalon.test.HooHa");
  
          m_services = new java.util.HashSet();
          m_services.add("org.apache.avalon.test.EphemeralComponent");
          m_services.add("org.apache.avalon.test.Nothing");
      }
  
      public void testEmptyManifest()
      {
          java.net.URL jar = getClass().getResource( "empty.jar" );
          assertTrue( jar != null );
  
          org.apache.excalibur.fortress.util.classloader.ComponentClassLoader 
loader = new 
org.apache.excalibur.fortress.util.classloader.ComponentClassLoader( new 
java.net.URL[] { jar } );
  
          assertEquals( loader.getServiceEntries().length, 0 );
          assertEquals( loader.getBlockEntries().length, 0 );
          assertEquals( loader.getTypeEntries().length, 0 );
      }
  
      public void testEmptyManifestJarScanner()
      {
          java.net.URL jar = this.getClass().getResource( "empty.jar" );
          assertTrue( jar != null );
  
          org.apache.excalibur.fortress.util.classloader.JarEntries entries = 
org.apache.excalibur.fortress.util.classloader.JarScanner.scan( jar );
  
          assertEquals( entries.getServiceEntries().size(), 0 );
          assertEquals( entries.getBlockEntries().size(), 0 );
          assertEquals( entries.getTypeEntries().size(), 0 );
      }
  
      public void testBlocksManifest()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.ComponentClassLoader 
loader = new 
org.apache.excalibur.fortress.util.classloader.ComponentClassLoader( new 
java.net.URL[] { jar } );
  
          String[] blocks = loader.getBlockEntries();
          assertEquals( m_blocks.size(), blocks.length );
  
          for ( int i = 0; i < blocks.length; i++ )
          {
              assertTrue( m_blocks.contains( blocks[i] ) );
          }
      }
  
      public void testBlocksManifestJarScanner()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.JarEntries entries = 
org.apache.excalibur.fortress.util.classloader.JarScanner.scan( jar );
  
          java.util.Set blocks = entries.getBlockEntries();
          assertEquals( m_blocks.size(), blocks.size() );
  
          java.util.Iterator it = blocks.iterator();
          while( it.hasNext() )
          {
              assertTrue( m_blocks.contains( it.next() ) );
          }
      }
  
      public void testServicesManifest()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.ComponentClassLoader 
loader = new 
org.apache.excalibur.fortress.util.classloader.ComponentClassLoader( new 
java.net.URL[] { jar } );
  
          String[] services = loader.getServiceEntries();
          assertEquals( m_services.size(), services.length );
  
          for ( int i = 0; i < services.length; i++ )
          {
              assertTrue( m_services.contains( services[i] ) );
          }
      }
  
      public void testServicesManifestJarScanner()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.JarEntries entries = 
org.apache.excalibur.fortress.util.classloader.JarScanner.scan( jar );
  
          java.util.Set services = entries.getServiceEntries();
          assertEquals( m_services.size(), services.size() );
  
          java.util.Iterator it = services.iterator();
          while( it.hasNext() )
          {
              assertTrue( m_services.contains( it.next() ) );
          }
      }
  
      public void testTypesManifest()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.ComponentClassLoader 
loader = new 
org.apache.excalibur.fortress.util.classloader.ComponentClassLoader( new 
java.net.URL[] { jar } );
  
          String[] types = loader.getTypeEntries();
          assertEquals( m_types.size(), types.length );
  
          for ( int i = 0; i < types.length; i++ )
          {
              assertTrue( m_types.contains( types[i] ) );
          }
      }
  
      public void testTypesManifestJarScanner()
      {
          java.net.URL jar = this.getClass().getResource( "full.jar" );
          assertTrue( jar != null );
          org.apache.excalibur.fortress.util.classloader.JarEntries entries = 
org.apache.excalibur.fortress.util.classloader.JarScanner.scan( jar );
  
          java.util.Set types = entries.getTypeEntries();
          assertEquals( m_types.size(), types.size() );
  
          java.util.Iterator it = types.iterator();
          while( it.hasNext() )
          {
              assertTrue( m_types.contains( it.next() ) );
          }
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/ComponentStateValidator.java
  
  Index: ComponentStateValidator.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.util;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.activity.Suspendable;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.Recomposable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Reconfigurable;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Recontextualizable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.service.Serviceable;
  
  /**
   * This class provides basic facilities for enforcing Avalon's contracts
   * within your own code.
   *
   * Based on Avalon version from Sandbox.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Michael McKibben</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   */
  public final class ComponentStateValidator
  {
      private static final String WRITE_FAIL = "Value is already bound";
  
      // Interfaces
      private static final long LOG_ENABLED = 0x00000001;
      private static final long LOGGABLE = 0x00000002;
      private static final long CONTEXTUALIZABLE = 0x00000004;
      private static final long COMPOSABLE = 0x00000008;
      private static final long SERVICEABLE = 0x00000010;
      private static final long CONFIGURABLE = 0x00000020;
      private static final long PARAMETERIZABLE = 0x00000040;
      private static final long INITIALIZABLE = 0x00000080;
      private static final long STARTABLE = 0x00000100;
      private static final long SUSPENDABLE = 0x00001000;
      private static final long RECONTEXTUALIZABLE = 0x00002000;
      private static final long RECOMPOSABLE = 0x00004000;
      private static final long RECONFIGURABLE = 0x00008000;
      private static final long DISPOSABLE = 0x00100000;
  
      // Initialization Methods.
      private static final long ENABLE_LOGGING = 0x00000001;
      private static final long SET_LOGGER = 0x00000002;
      private static final long CONTEXTUALIZE = 0x00000004;
      private static final long SERVICE = 0x00000008;
      private static final long COMPOSE = 0x00000010;
      private static final long CONFIGURE = 0x00000020;
      private static final long PARAMETERIZE = 0x00000040;
      private static final long INITIALIZE = 0x00000080;
      private static final long START = 0x00000100;
      private static final long INIT_COMPLETE = 0x00000400;
  
      // Active Service Methods
      private static final long SUSPEND = 0x00001000;
      private static final long RECONTEXTUALIZE = 0x00002000;
      private static final long RECOMPOSE = 0x00004000;
      private static final long RECONFIGURE = 0x00008000;
      private static final long RESUME = 0x00010000;
  
      // Destruction Methods
      private static final long STOP = 0x00100000;
      private static final long DISPOSE = 0x00200000;
  
      // Masks
      private static final long INIT_MASK = ENABLE_LOGGING | SET_LOGGER |
          CONTEXTUALIZE | COMPOSE | SERVICE | CONFIGURE | PARAMETERIZE | 
INITIALIZE |
          START;
  
      private final long m_interfaces;
      private final long m_methods;
      private long m_state;
      private boolean m_active;
      private final Object m_object;
  
      /**
       * Create state validator from object (this can be used for more than just
       * components).
       */
      public ComponentStateValidator( final Object object )
      {
          m_object = object;
  
          long methods = 0;
          long interfaces = 0;
  
          if( object instanceof LogEnabled )
          {
              interfaces |= LOG_ENABLED;
              methods |= ENABLE_LOGGING;
          }
  
          if( object instanceof Loggable )
          {
              interfaces |= LOGGABLE;
              methods |= SET_LOGGER;
          }
  
          if( object instanceof Contextualizable )
          {
              interfaces |= CONTEXTUALIZABLE;
              methods |= CONTEXTUALIZE;
          }
  
          if( object instanceof Serviceable )
          {
              interfaces |= SERVICEABLE;
              methods |= SERVICE;
          }
  
          if( object instanceof Composable )
          {
              if( ( interfaces & SERVICEABLE ) > 0 )
              {
                  throw new IllegalStateException( "Cannot implement Composable 
and Serviceable together" );
              }
  
              interfaces |= COMPOSABLE;
              methods |= COMPOSE;
          }
  
          if( object instanceof Configurable )
          {
              interfaces |= CONFIGURABLE;
              methods |= CONFIGURE;
          }
  
          if( object instanceof Parameterizable )
          {
              interfaces |= PARAMETERIZABLE;
              methods |= PARAMETERIZE;
          }
  
          if( object instanceof Initializable )
          {
              interfaces |= INITIALIZABLE;
              methods |= INITIALIZE;
          }
  
          if( object instanceof Startable )
          {
              interfaces |= STARTABLE;
              methods |= START | STOP;
          }
  
          if( object instanceof Suspendable )
          {
              interfaces |= SUSPENDABLE;
              methods |= SUSPEND | RESUME;
          }
  
          if( object instanceof Recontextualizable )
          {
              interfaces |= RECONTEXTUALIZABLE;
              methods |= RECONTEXTUALIZE;
          }
  
          if( object instanceof Recomposable )
          {
              interfaces |= RECOMPOSABLE;
              methods |= RECOMPOSE;
          }
  
          if( object instanceof Reconfigurable )
          {
              interfaces |= RECONFIGURABLE;
              methods |= RECONFIGURE;
          }
  
          if( object instanceof Disposable )
          {
              interfaces |= DISPOSABLE;
              methods |= DISPOSE;
          }
  
          m_methods = methods;
          m_interfaces = interfaces;
  
          generalCheckInitComplete();
      }
  
      private String getInterfaceName( long interfaceId )
      {
          if( interfaceId == LOG_ENABLED )
          {
              return LogEnabled.class.getName();
          }
          else if( interfaceId == LOGGABLE )
          {
              return Loggable.class.getName();
          }
          else if( interfaceId == CONTEXTUALIZABLE )
          {
              return Contextualizable.class.getName();
          }
          else if( interfaceId == SERVICEABLE )
          {
              return Serviceable.class.getName();
          }
          else if( interfaceId == COMPOSABLE )
          {
              return Composable.class.getName();
          }
          else if( interfaceId == CONFIGURABLE )
          {
              return Configurable.class.getName();
          }
          else if( interfaceId == PARAMETERIZABLE )
          {
              return Parameterizable.class.getName();
          }
          else if( interfaceId == INITIALIZABLE )
          {
              return Initializable.class.getName();
          }
          else if( interfaceId == STARTABLE )
          {
              return Startable.class.getName();
          }
          else if( interfaceId == SUSPENDABLE )
          {
              return Suspendable.class.getName();
          }
          else if( interfaceId == RECONTEXTUALIZABLE )
          {
              return Recontextualizable.class.getName();
          }
          else if( interfaceId == RECOMPOSABLE )
          {
              return Recomposable.class.getName();
          }
          else if( interfaceId == RECONFIGURABLE )
          {
              return Reconfigurable.class.getName();
          }
          else if( interfaceId == DISPOSABLE )
          {
              return Disposable.class.getName();
          }
          else
          {
              throw new IllegalStateException( "Unknown Interface Id " + 
interfaceId );
          }
      }
  
      private String getMethodName( long methodId )
      {
          if( methodId == ENABLE_LOGGING )
          {
              return "enableLogging()";
          }
          else if( methodId == SET_LOGGER )
          {
              return "setLogger()";
          }
          else if( methodId == CONTEXTUALIZE )
          {
              return "contextualize()";
          }
          else if( methodId == SERVICE )
          {
              return "service()";
          }
          else if( methodId == COMPOSE )
          {
              return "compose()";
          }
          else if( methodId == CONFIGURE )
          {
              return "configure()";
          }
          else if( methodId == PARAMETERIZE )
          {
              return "parameterize()";
          }
          else if( methodId == INITIALIZE )
          {
              return "initialize()";
          }
          else if( methodId == START )
          {
              return "start()";
          }
          else if( methodId == SUSPEND )
          {
              return "suspend()";
          }
          else if( methodId == RECONTEXTUALIZE )
          {
              return "recontextualize()";
          }
          else if( methodId == RECOMPOSE )
          {
              return "recompose()";
          }
          else if( methodId == RECONFIGURE )
          {
              return "reconfigure()";
          }
          else if( methodId == RESUME )
          {
              return "resume()";
          }
          else if( methodId == STOP )
          {
              return "stop()";
          }
          else if( methodId == DISPOSE )
          {
              return "dispose()";
          }
          else
          {
              throw new IllegalStateException( "Unknown Method Id " + methodId 
);
          }
      }
  
      private String getLastMethod( long state )
      {
          for( int i = 31; i >= 0; i-- )
          {
              long methodId = 0x1 << i;
              if( ( state & methodId ) != 0 )
              {
                  return getMethodName( methodId );
              }
          }
          throw new IllegalStateException( "No last state method found for 
state " + state );
      }
  
      /**
       * Test to see if this was the last initialization method.
       */
      private void generalCheckInitComplete()
      {
          if( m_state == ( m_methods & INIT_MASK ) )
          {
              // All init methods called
              m_active = true;
          }
      }
  
      /**
       * Initialization methods must be called in order, must all be called, may
       *  not be called more than once, and may not be called once any of the
       *  Descruction methods have been called.
       */
      private void generalCheckInit( final String message, final long 
interfaceId, final long methodId )
      {
          if( ( m_interfaces & interfaceId ) == 0 )
          {
              // Interface not implemented
              if( message == null )
              {
                  throw new IllegalStateException( 
m_object.getClass().getName() +
                                                   " does not implement " + 
getInterfaceName( interfaceId ) + "." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else if( ( m_state & methodId ) > 0 )
          {
              // Method already called.
              if( message == null )
              {
                  throw new IllegalStateException( getMethodName( methodId ) + 
" already called." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else if( m_state > methodId )
          {
              // Method called after a descruction method was called.
              if( message == null )
              {
                  throw new IllegalStateException( getMethodName( methodId ) +
                                                   " can not be called after " 
+ getLastMethod( m_state ) + "." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else if( ( m_state & ( methodId - 1 ) ) != ( m_methods & ( methodId - 
1 ) ) )
          {
              // One or more of the methods that should have been called before
              //  this method was not.
              if( message == null )
              {
                  throw new IllegalStateException( getMethodName( methodId ) +
                                                   " called out of order. " + 
getLastMethod( m_methods & ( methodId - 1 ) ) +
                                                   " must be called first." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
  
          // Add this method to the state
          m_state |= methodId;
  
          // See if the initialization is complete.
          generalCheckInitComplete();
      }
  
      /**
       * Active Service methods may only be called after all of the
       *  Initialization methods have been called, any before any of the
       *  Descruction methods have been called.  While in the active state,
       *  the contracts of the methods allow the active state methods to be
       *  called any number of times, in any order.
       * The resume() method should do nothing if suspend() has not yet been
       *  called for example.
       */
      private void generalCheckActive( final String message, final long 
interfaceId, final long methodId )
      {
          if( ( m_interfaces & interfaceId ) == 0 )
          {
              // Interface not implemented
              if( message == null )
              {
                  throw new IllegalStateException( 
m_object.getClass().getName() +
                                                   " does not implement " + 
getInterfaceName( interfaceId ) + "." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else if( !m_active )
          {
              // Component not in the active state.
              if( m_state < INIT_COMPLETE )
              {
                  // Still expecting initialization methods.
                  if( message == null )
                  {
                      throw new IllegalStateException( getMethodName( methodId 
) +
                                                       " called before 
component was made active. " +
                                                       getLastMethod( m_methods 
& ( INIT_COMPLETE - 1 ) ) +
                                                       " must be called first." 
);
                  }
                  else
                  {
                      throw new IllegalStateException( message );
                  }
              }
              else
              {
                  // One or more destruction methods have been called.
                  if( message == null )
                  {
                      throw new IllegalStateException( getMethodName( methodId 
) +
                                                       " called after component 
was made inactive.  Cannot call after " +
                                                       getLastMethod( m_state ) 
+ "." );
                  }
                  else
                  {
                      throw new IllegalStateException( message );
                  }
              }
          }
      }
  
      /**
       * Descruction Methods must be called in order.  They may be called before
       *  all of the Initialization methods have been called if there was an
       *  error.
       */
      private void generalCheckDest( final String message, final long 
interfaceId, final long methodId )
      {
          if( ( m_interfaces & interfaceId ) == 0 )
          {
              // Interface not implemented
              if( message == null )
              {
                  throw new IllegalStateException( 
m_object.getClass().getName() +
                                                   " does not implement " + 
getInterfaceName( interfaceId ) + "." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else if( m_state > methodId )
          {
              // Method called after a later descruction method was called.
              if( message == null )
              {
                  throw new IllegalStateException( getMethodName( methodId ) +
                                                   " can not be called after " 
+ getLastMethod( m_state ) + "." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
  
          // Add this method to the state
          m_state |= methodId;
  
          // Deactivate
          m_active = false;
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the ENABLE_LOGGING state has already been set, if the component 
implements
       * LogEnabled, and if the state has progressed beyond the Logger stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkLogEnabled()
      {
          checkLogEnabled( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the ENABLE_LOGGING state has already been set, if the component 
implements
       * LogEnabled, and if the state has progressed beyond the Logger stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkLogEnabled( final String message )
      {
          generalCheckInit( message, LOG_ENABLED, ENABLE_LOGGING );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SET_LOGGER state has already been set, if the component 
implements
       * Loggable, and if the state has progressed beyond the Logger stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkLoggable()
      {
          checkLogEnabled( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SET_LOGGER state has already been set, if the component 
implements
       * Loggable, and if the state has progressed beyond the Logger stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkLoggable( final String message )
      {
          generalCheckInit( message, LOGGABLE, SET_LOGGER );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the CONTEXTUALIZED state has already been set, if the component 
implements
       * Contextualizable, and if the state has progressed beyond the Context 
stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkContextualized()
      {
          checkContextualized( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the CONTEXTUALIZED state has already been set, if the component 
implements
       * Contextualizable, and if the state has progressed beyond the Context 
stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkContextualized( final String message )
      {
          generalCheckInit( message, CONTEXTUALIZABLE, CONTEXTUALIZE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SERVICE state has already been set, if the component implements
       * Composable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkServiced()
      {
          checkServiced( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SERVICE state has already been set, if the component implements
       * Composable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkServiced( final String message )
      {
          generalCheckInit( message, SERVICEABLE, SERVICE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the COMPOSED state has already been set, if the component implements
       * Composable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkComposed()
      {
          checkComposed( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the COMPOSED state has already been set, if the component implements
       * Composable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkComposed( final String message )
      {
          generalCheckInit( message, COMPOSABLE, COMPOSE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the CONFIGURED state has already been set, if the component 
implements
       * Configurable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkConfigured()
      {
          checkConfigured( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the CONFIGURED state has already been set, if the component 
implements
       * Configurable, and if the state has progressed beyond the Configuration 
stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkConfigured( final String message )
      {
          generalCheckInit( message, CONFIGURABLE, CONFIGURE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the PARAMETERIZED state has already been set, if the component 
implements
       * Parameterizable, and if the state has progressed beyond the Parameters 
stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkParameterized()
      {
          checkParameterized( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the PARAMETERIZED state has already been set, if the component 
implements
       * Parameterizable, and if the state has progressed beyond the Parameters 
stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkParameterized( final String message )
      {
          generalCheckInit( message, PARAMETERIZABLE, PARAMETERIZE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the INITIALIZED state has already been set, if the component 
implements
       * Initializable, and if the state has progressed beyond the 
<code>initialize</code> stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkInitialized()
      {
          checkInitialized( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the INITIALIZED state has already been set, if the component 
implements
       * Initializable, and if the state has progressed beyond the 
<code>initialize</code> stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkInitialized( final String message )
      {
          generalCheckInit( message, INITIALIZABLE, INITIALIZE );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the STARTED state has already been set, if the component implements
       * Startable, and if the state has progressed beyond the 
<code>start</code> stage.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkStarted()
      {
          checkStarted( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the STARTED state has already been set, if the component implements
       * Startable, and if the state has progressed beyond the 
<code>start</code> stage.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkStarted( final String message )
      {
          generalCheckInit( message, STARTABLE, START );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SUSPENDED state has already been set, if the component 
implements
       * Suspendable, and if the Component is active.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkSuspended()
      {
          checkSuspended( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SUSPENDED state has already been set, if the component 
implements
       * Suspendable, and if the Component is active.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkSuspended( final String message )
      {
          generalCheckActive( message, SUSPENDABLE, SUSPEND );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SUSPENDED state has not been set, if the component implements
       * Suspendable, and if the Component is active.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkResumed()
      {
          checkResumed( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the SUSPENDED state has not been set, if the component implements
       * Suspendable, and if the Component is active.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkResumed( final String message )
      {
          generalCheckActive( message, SUSPENDABLE, RESUME );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the STOPPED state has not been set, if the component implements
       * Startable, and if the Component is active.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkStopped()
      {
          checkStopped( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the STOPPED state has not been set, if the component implements
       * Startable, and if the Component is active.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkStopped( final String message )
      {
          generalCheckDest( message, STARTABLE, STOP );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the DISPOSED state has not been set, if the component implements
       * Disposable.
       *
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkDisposed()
      {
          checkDisposed( null );
      }
  
      /**
       * Throw an exception if the initialization is out of order.  It tests to 
see
       * if the DISPOSED state has not been set, if the component implements
       * Disposable.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkDisposed( final String message )
      {
          generalCheckDest( message, DISPOSABLE, DISPOSE );
      }
  
      /**
       * Checks to see if the state is active.
       *
       * @throws java.lang.IllegalStateException if the component is not active
       */
      public void checkActive()
      {
          checkActive( null );
      }
  
      /**
       * Checks to see if the state is active.
       *
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the component is not active
       */
      public void checkActive( final String message )
      {
          if( isActive() )
          {
              return;
          }
  
          // Component not in the active state.
          if( m_state < INIT_COMPLETE )
          {
              // Still expecting initialization methods.
              if( message == null )
              {
                  throw new IllegalStateException( "Component not in the active 
state. " +
                                                   getLastMethod( m_methods & ( 
INIT_COMPLETE - 1 ) ) +
                                                   " was not called." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
          else
          {
              // One or more destruction methods have been called.
              if( message == null )
              {
                  throw new IllegalStateException( "Component not in the active 
state because " +
                                                   getLastMethod( m_state ) + " 
was called." );
              }
              else
              {
                  throw new IllegalStateException( message );
              }
          }
      }
  
      /**
       * Checks to see if the state is active, and returns true or false.
       *
       * @return <code>true</code> if active, <code>false</code> if not
       */
      public boolean isActive()
      {
          return m_active;
      }
  
      /**
       * Make sure object has not been assigned yet.
       *
       * @param object to test
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkNotAssigned( final Object object )
      {
          checkNotAssigned( object, WRITE_FAIL );
      }
  
      /**
       * Make sure object has not been assigned yet.
       *
       * @param object to test
       * @param message the message to include in the thrown exception
       * @throws java.lang.IllegalStateException if the state is manage out of 
order
       */
      public void checkNotAssigned( final Object object, final String message )
      {
          if( null != object )
          {
              throw new IllegalStateException( message );
          }
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/ComponentTestCase.java
  
  Index: ComponentTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.util;
  
  import junit.framework.TestCase;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.NullLogger;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.service.DefaultServiceManager;
  
  /**
   * This class provides basic facilities for enforcing Avalon's contracts
   * within your own code.
   *
   * @author <a href="[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   */
  public final class ComponentTestCase
      extends TestCase
  {
      public ComponentTestCase( String test )
      {
          super( test );
      }
  
      public void testCorrectLifecycle()
          throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          component.service( new DefaultServiceManager() );
          component.configure( new DefaultConfiguration( "", "" ) );
          component.parameterize( new Parameters() );
          component.initialize();
          component.start();
          component.suspend();
          component.resume();
          component.stop();
          component.dispose();
      }
  
      public void testMissingLogger()
          throws Exception
      {
          org.apache.avalon.fortress.test.util.FullLifecycleComponent component 
= new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
  
          try
          {
              component.contextualize( new DefaultContext() );
          }
          catch( Exception e )
          {
              return;
          }
          fail( "Did not detect missing logger" );
      }
  
      public void testOutOfOrderInitialize()
          throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          component.service( new DefaultServiceManager() );
          try
          {
              component.initialize();
              component.parameterize( new Parameters() );
          }
          catch( Exception e )
          {
              return;
          }
          fail( "Did not detect out of order initialization" );
      }
  
      public void testOutOfOrderDispose()
          throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          component.service( new DefaultServiceManager() );
          component.configure( new DefaultConfiguration( "", "" ) );
          component.parameterize( new Parameters() );
          component.initialize();
          component.start();
          component.suspend();
          component.resume();
  
          try
          {
              component.dispose();
              component.stop();
          }
          catch( Exception e )
          {
              return;
          }
          fail( "Did not detect out of order disposal" );
      }
  
      public void testDoubleAssignOfLogger()
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          try
          {
              component.enableLogging( new NullLogger() );
              component.enableLogging( new NullLogger() );
          }
          catch( Exception e )
          {
              // test successfull
              return;
          }
  
          fail( "Did not detect double assignment of Logger" );
      }
  
      public void testDoubleAssignOfContext()
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          try
          {
              component.contextualize( new DefaultContext() );
              component.contextualize( new DefaultContext() );
          }
          catch( Exception e )
          {
              // test successfull
              return;
          }
  
          fail( "Did not detect double assignment of Context" );
      }
  
      public void testDoubleAssignOfParameters()
          throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          component.service( new DefaultServiceManager() );
          component.configure( new DefaultConfiguration( "", "" ) );
  
          try
          {
              component.parameterize( new Parameters() );
              component.parameterize( new Parameters() );
          }
          catch( Exception e )
          {
              // test successfull
              return;
          }
  
          fail( "Did not detect double assignment of Parameters" );
      }
  
      public void testDoubleAssignOfConfiguration() throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          component.service( new DefaultServiceManager() );
          try
          {
              component.configure( new DefaultConfiguration( "", "" ) );
              component.configure( new DefaultConfiguration( "", "" ) );
          }
          catch( Exception e )
          {
              // test successfull
              return;
          }
  
          fail( "Did not detect double assignment of Configuration" );
      }
  
      public void testDoubleAssignOfComponentManger()
          throws Exception
      {
          final org.apache.avalon.fortress.test.util.FullLifecycleComponent 
component = new org.apache.avalon.fortress.test.util.FullLifecycleComponent();
          component.enableLogging( new NullLogger() );
          component.contextualize( new DefaultContext() );
          try
          {
              component.service( new DefaultServiceManager() );
              component.service( new DefaultServiceManager() );
          }
          catch( Exception e )
          {
              // test successfull
              return;
          }
  
          fail( "Did not detect double assignment of ComponentLocator" );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/ConfigurableRoleManagerTestCase.java
  
  Index: ConfigurableRoleManagerTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software 
Foundation"
      must not be used to endorse or promote products derived from this  
software
      without  prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.fortress.test.util;
  
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.fortress.impl.role.ConfigurableRoleManager;
  
  /**
   * Configurable RoleManager implementation.  It populates the RoleManager
   * from a configuration hierarchy.  This is based on the DefaultRoleManager
   * in the org.apache.avalon.component package.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   * @since 4.1
   */
  public class ConfigurableRoleManagerTestCase
      extends AbstractRoleManagerTestCase
  {
      public ConfigurableRoleManagerTestCase( String name )
      {
          super( name );
      }
  
      public void testShorthandReturnValues()
          throws Exception
      {
          DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
          ConfigurableRoleManager roles = new ConfigurableRoleManager( null, 
this.getClass().getClassLoader() );
          roles.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) );
          roles.configure( builder.build( this.getClass().getClassLoader()
                                          .getResourceAsStream( 
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
  
          checkRole( roles,
                     "datasource",
                     
"org.apache.avalon.excalibur.datasource.DataSourceComponent",
                     "org.apache.avalon.excalibur.datasource.JdbcDataSource",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "monitor",
                     "org.apache.avalon.excalibur.monitor.Monitor",
                     "org.apache.avalon.excalibur.monitor.ActiveMonitor",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "parser",
                     "org.apache.excalibur.xml.dom.DOMParser",
                     "org.apache.excalibur.xml.impl.JaxpParser",
                     
"org.apache.excalibur.fortress.handler.PoolableComponentHandler" );
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/FortressRoleManagerTestCase.java
  
  Index: FortressRoleManagerTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software 
Foundation"
      must not be used to endorse or promote products derived from this  
software
      without  prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.fortress.test.util;
  
  import junit.framework.TestCase;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.fortress.impl.role.FortressRoleManager;
  import org.apache.avalon.fortress.RoleEntry;
  
  /**
   * Configurable RoleManager implementation.  It populates the RoleManager
   * from a configuration hierarchy.  This is based on the DefaultRoleManager
   * in the org.apache.avalon.component package.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   * @since 4.1
   */
  public class FortressRoleManagerTestCase
      extends AbstractRoleManagerTestCase
  {
      public FortressRoleManagerTestCase( String name )
      {
          super( name );
      }
  
      /**
       * Test the shorthand return values.
       */
      public void testShorthandReturnValues()
          throws Exception
      {
          FortressRoleManager roles = new FortressRoleManager( null, 
this.getClass().getClassLoader() );
          roles.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) );
          roles.initialize();
  
          checkRole( roles,
                     "cache",
                     "org.apache.excalibur.cache.Cache",
                     "org.apache.excalibur.cache.impl.DefaultCache",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "lru-cache",
                     "org.apache.excalibur.cache.Cache",
                     "org.apache.excalibur.cache.impl.LRUCache",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "jdbc-datasource",
                     
"org.apache.avalon.excalibur.datasource.DataSourceComponent",
                     "org.apache.avalon.excalibur.datasource.JdbcDataSource",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "j2ee-datasource",
                     
"org.apache.avalon.excalibur.datasource.DataSourceComponent",
                     "org.apache.avalon.excalibur.datasource.J2eeDataSource",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          if( isInformixClassExists() )
          {
              checkRole( roles,
                         "informix-datasource",
                         
"org.apache.avalon.excalibur.datasource.DataSourceComponent",
                         
"org.apache.avalon.excalibur.datasource.InformixDataSource",
                         
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          }
          checkRole( roles,
                     "monitor",
                     "org.apache.avalon.excalibur.monitor.Monitor",
                     "org.apache.avalon.excalibur.monitor.ActiveMonitor",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "passive-monitor",
                     "org.apache.avalon.excalibur.monitor.Monitor",
                     "org.apache.avalon.excalibur.monitor.PassiveMonitor",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "xalan-xpath",
                     "org.apache.excalibur.xml.xpath.XPathProcessor",
                     "org.apache.excalibur.xml.xpath.XPathProcessorImpl",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "jaxpath",
                     "org.apache.excalibur.xml.xpath.XPathProcessor",
                     "org.apache.excalibur.xml.xpath.JaxenProcessorImpl",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "resolver",
                     "org.apache.excalibur.source.SourceResolver",
                     "org.apache.excalibur.source.impl.SourceResolverImpl",
                     
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
          checkRole( roles,
                     "parser",
                     "org.apache.excalibur.xml.dom.DOMParser",
                     "org.apache.excalibur.xml.impl.JaxpParser",
                     
"org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
          checkRole( roles,
                     "xerces-parser",
                     "org.apache.excalibur.xml.dom.DOMParser",
                     "org.apache.excalibur.xml.impl.XercesParser",
                     
"org.apache.excalibur.fortress.handler.FactoryComponentHandler" );
      }
  
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/FullLifecycleComponent.java
  
  Index: FullLifecycleComponent.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.fortress.test.util;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.activity.Suspendable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * This test class is used to test the AbstractComponent facilities for you.
   *
   * @author <a href="[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/27 17:04:49 $
   */
  public final class FullLifecycleComponent
      implements LogEnabled, Contextualizable, Parameterizable, Configurable,
      Serviceable, Initializable, Startable, Suspendable, Disposable,
      ThreadSafe
  {
      private org.apache.avalon.fortress.test.util.ComponentStateValidator 
m_validator = new org.apache.avalon.fortress.test.util.ComponentStateValidator( 
this );
      private Logger m_logger;
      private Context m_context;
      private Parameters m_parameters;
      private Configuration m_configuration;
      private ServiceManager m_componentManager;
  
      public void enableLogging( Logger logger )
      {
          m_validator.checkNotAssigned( m_logger );
          m_validator.checkLogEnabled();
  
          m_logger = logger;
      }
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_validator.checkNotAssigned( m_context );
          m_validator.checkContextualized();
  
          m_context = context;
      }
  
      public void parameterize( Parameters params )
          throws ParameterException
      {
          m_validator.checkNotAssigned( m_parameters );
          m_validator.checkParameterized();
  
          m_parameters = params;
      }
  
      public void configure( Configuration config )
          throws ConfigurationException
      {
          m_validator.checkNotAssigned( m_configuration );
          m_validator.checkConfigured();
  
          m_configuration = config;
      }
  
      public void service( final ServiceManager manager )
          throws ServiceException
      {
          m_validator.checkNotAssigned( m_componentManager );
          m_validator.checkServiced();
      }
  
      public void initialize()
          throws Exception
      {
          m_validator.checkInitialized();
      }
  
      public void start()
          throws Exception
      {
          m_validator.checkStarted();
      }
  
      public void suspend()
      {
          m_validator.checkSuspended();
      }
  
      public void resume()
      {
          m_validator.checkResumed();
      }
  
      public void stop()
          throws Exception
      {
          m_validator.checkStopped();
      }
  
      public void dispose()
      {
          m_validator.checkDisposed();
  
          m_logger = null;
          m_context = null;
          m_parameters = null;
          m_configuration = null;
          m_componentManager = null;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/empty.jar
  
        <<Binary file>>
  
  
  1.1                  
jakarta-avalon-excalibur/fortress/src/test/org/apache/avalon/fortress/test/util/full.jar
  
        <<Binary file>>
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to