avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test ComponentTestCase.java FullLifecycleComponent.java
Date Sun, 02 Dec 2001 15:15:36 GMT
donaldp     01/12/02 07:15:36

  Added:       src/scratchpad/org/apache/avalon/excalibur/util/test
                        ComponentTestCase.java FullLifecycleComponent.java
  Log:
  Add the ComponentStateValidator test case in.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/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 file.
   */
  package org.apache.avalon.excalibur.util.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.DefaultComponentManager;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.LogKitLogger;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.log.Hierarchy;
  
  /**
   * This class provides basic facilities for enforcing Avalon's contracts
   * within your own code.
   *
   * @author <a href="bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/02 15:15:36 $
   */
  public final class ComponentTestCase
      extends TestCase
  {
      public ComponentTestCase( String test )
      {
          super( test );
      }
  
      public void testCorrectLifecycle()
          throws Exception
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
          component.contextualize(new DefaultContext());
          component.parameterize(new Parameters());
          component.configure(new DefaultConfiguration("", ""));
          component.compose(new DefaultComponentManager());
          component.initialize();
          component.start();
          component.suspend();
          component.resume();
          component.stop();
          component.dispose();
      }
  
      public void testOutOfOrderInitialize()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.contextualize(new DefaultContext());
              component.initialize();
              component.parameterize(new Parameters());
          }
          catch ( Exception e )
          {
              return;
          }
          fail("Did not detect out of order initialization");
      }
  
      public void testOutOfOrderDispose()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.contextualize(new DefaultContext());
              component.parameterize(new Parameters());
              component.configure(new DefaultConfiguration("", ""));
              component.compose(new DefaultComponentManager());
              component.initialize();
              component.start();
              component.suspend();
              component.resume();
              component.dispose();
              component.stop();
          }
          catch ( Exception e )
          {
              return;
          }
          fail("Did not detect out of order disposal");
      }
  
      public void testDoubleAssignOfLogger()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
          }
          catch (Exception e)
          {
              // test successfull
              return;
          }
  
          fail("Did not detect double assignment of Logger");
      }
  
      public void testDoubleAssignOfContext()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              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()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.contextualize(new DefaultContext());
              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()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.contextualize(new DefaultContext());
              component.parameterize(new Parameters());
              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()
      {
          FullLifecycleComponent component = new FullLifecycleComponent();
  
          try
          {
              component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
              component.contextualize(new DefaultContext());
              component.parameterize(new Parameters());
              component.configure(new DefaultConfiguration("", ""));
              component.compose(new DefaultComponentManager());
              component.compose(new DefaultComponentManager());
          }
          catch (Exception e)
          {
              // test successfull
              return;
          }
  
          fail("Did not detect double assignment of ComponentManager");
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/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 file.
   */
  package org.apache.avalon.excalibur.util.test;
  
  import org.apache.avalon.excalibur.util.ComponentStateValidator;
  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.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  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.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * This test class is used to test the AbstractComponent facilities for you.
   *
   * @author <a href="bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/02 15:15:36 $
   */
  public final class FullLifecycleComponent
      implements LogEnabled, Contextualizable, Parameterizable, Configurable,
                 Composable, Initializable, Startable, Suspendable, Disposable,
                 ThreadSafe
  {
      private ComponentStateValidator m_validator = new ComponentStateValidator( this );
      private Logger m_logger;
      private Context m_context;
      private Parameters m_parameters;
      private Configuration m_configuration;
      private ComponentManager m_componentManager;
  
      public void enableLogging( Logger logger )
      {
          m_validator.checkNotAssigned( m_logger, "Logger already set!" );
          m_validator.checkLogEnabled( "Logger: Initialization out of order." );
  
          m_logger = logger;
      }
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_validator.checkNotAssigned( m_context, "Context already set!" );
          m_validator.checkContextualized( "Context: Initialization out of order." );
  
          m_context = context;
      }
  
      public void parameterize( Parameters params )
          throws ParameterException
      {
          m_validator.checkNotAssigned( m_parameters, "Parameters already set!" );
          m_validator.checkParameterized( "Parameters: Initialization out of order." );
  
          m_parameters = params;
      }
  
      public void configure( Configuration config )
          throws ConfigurationException
      {
          m_validator.checkNotAssigned( m_configuration, "Configuration already set!" );
          m_validator.checkConfigured( "Configuration: Initialization out of order."  );
  
          m_configuration = config;
      }
  
      public void compose( ComponentManager manager )
          throws ComponentException
      {
          m_validator.checkNotAssigned( m_componentManager, "Component Manager already set!"
);
          m_validator.checkComposed( "ComponentManager: Initialization out of order." );
      }
  
      public void initialize()
          throws Exception
      {
          m_validator.checkInitialized( "Initialize: Initialization out of order." );
      }
  
      public void start()
          throws Exception
      {
          m_validator.checkStarted( "Start: Initialization out of order." );
      }
  
      public void suspend()
      {
          m_validator.checkSuspended( "Suspend: Initialization out of order." );
      }
  
      public void resume()
      {
          m_validator.checkResumed( "Resume: Initialization out of order." );
      }
  
      public void stop()
          throws Exception
      {
          m_validator.checkStopped( "Stop: Initialization out of order." );
      }
  
      public void dispose()
      {
          m_validator.checkDisposed( "Dispose: Initialization out of order." );
  
          m_logger = null;
          m_context = null;
          m_parameters = null;
          m_configuration = null;
          m_componentManager = null;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message