avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test ComponentTestCase.java
Date Thu, 17 Jan 2002 15:02:01 GMT
bloritsch    02/01/17 07:02:01

  Modified:    src/scratchpad/org/apache/avalon/excalibur/util
                        ComponentStateValidator.java
               src/scratchpad/org/apache/avalon/excalibur/util/test
                        ComponentTestCase.java
  Log:
  fix test for missing lifecycle step
  
  Revision  Changes    Path
  1.7       +88 -36    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/ComponentStateValidator.java
  
  Index: ComponentStateValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/ComponentStateValidator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ComponentStateValidator.java	17 Jan 2002 08:02:38 -0000	1.6
  +++ ComponentStateValidator.java	17 Jan 2002 15:02:01 -0000	1.7
  @@ -24,7 +24,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:mike@hihat.net">Michael McKibben</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2002/01/17 08:02:38 $
  + * @version CVS $Revision: 1.7 $ $Date: 2002/01/17 15:02:01 $
    */
   public final class ComponentStateValidator
   {
  @@ -45,17 +45,25 @@
   
       private static final long LOG_ENABLED    = 0x00000001;
       private static final long CONTEXTUALIZED = 0x00000002;
  -    private static final long PARAMETERIZED  = 0x00000004;
  -    private static final long COMPOSED       = 0x00000008;
  -    private static final long CONFIGURED     = 0x00000010;
  -    private static final long ACTIVE         = 0x10000000;
  +    private static final long COMPOSED       = 0x00000004;
  +    private static final long CONFIGURED     = 0x00000008;
  +    private static final long PARAMETERIZED  = 0x00000010;
       private static final long INITIALIZED    = 0x00000020;
       private static final long STARTED        = 0x00000040;
  +    private static final long ACTIVE         = 0x10000000;
       private static final long SUSPENDED      = 0x01000000;
       private static final long STOPPED        = 0x00000080;
       private static final long DISPOSED       = 0x00000100;
  -    private static final long INIT_MASK      = LOG_ENABLED | CONTEXTUALIZED |
  -        PARAMETERIZED | CONFIGURED | COMPOSED | INITIALIZED | STARTED;
  +
  +    private static final long LOG_MASK       = LOG_ENABLED;
  +    private static final long CONTEXT_MASK   = LOG_MASK | CONTEXTUALIZED;
  +    private static final long COMPOSE_MASK   = CONTEXT_MASK | COMPOSED;
  +    private static final long CONFIGURE_MASK = COMPOSE_MASK | CONFIGURED;
  +    private static final long PARAMETER_MASK = CONFIGURE_MASK | PARAMETERIZED;
  +    private static final long INIT_MASK      = PARAMETER_MASK | INITIALIZED;
  +    private static final long START_MASK     = INIT_MASK | STARTED;
  +    private static final long STOP_MASK      = START_MASK | STOPPED;
  +    private static final long DISPOSE_MASK   = STOP_MASK | DISPOSED;
   
       private final long m_mask;
       private long m_state;
  @@ -141,14 +149,18 @@
        */
       public void checkLogEnabled( final String message )
       {
  -        if ( ( (m_state & m_mask & LOG_ENABLED) > 0 ) ||
  -             ( (m_mask & LOG_ENABLED) == 0 ) || ( m_state > LOG_ENABLED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & LOG_ENABLED) == 0;
  +        isValid = isValid && ((m_mask & LOG_MASK) | LOG_ENABLED) ==
  +                             ((m_state & DISPOSE_MASK) | LOG_ENABLED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= LOG_ENABLED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -176,14 +188,18 @@
        */
       public void checkContextualized( final String message )
       {
  -        if ( ( (m_state & m_mask & CONTEXTUALIZED) > 0 ) ||
  -             ( (m_mask & CONTEXTUALIZED) == 0 ) || ( m_state > CONTEXTUALIZED )
)
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & CONTEXTUALIZED) == 0;
  +        isValid = isValid && ((m_mask & CONTEXT_MASK) | CONTEXTUALIZED) ==
  +                             ((m_state & DISPOSE_MASK) | CONTEXTUALIZED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= CONTEXTUALIZED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -211,14 +227,18 @@
        */
       public void checkParameterized( final String message )
       {
  -        if ( ( (m_state & m_mask & PARAMETERIZED) > 0 ) ||
  -             ( (m_mask & PARAMETERIZED) == 0 ) || ( m_state > PARAMETERIZED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & PARAMETERIZED) == 0;
  +        isValid = isValid && ((m_mask & PARAMETER_MASK) | PARAMETERIZED) ==
  +                             ((m_state & DISPOSE_MASK) | PARAMETERIZED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= PARAMETERIZED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -246,14 +266,18 @@
        */
       public void checkConfigured( final String message )
       {
  -        if ( ( (m_state & m_mask & CONFIGURED) > 0 ) ||
  -             ( (m_mask & CONFIGURED) == 0 ) || ( m_state > CONFIGURED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & CONFIGURED) == 0;
  +        isValid = isValid && ((m_mask & CONFIGURE_MASK) | CONFIGURED) ==
  +                             ((m_state & DISPOSE_MASK) | CONFIGURED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= CONFIGURED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -281,14 +305,18 @@
        */
       public void checkComposed( final String message )
       {
  -        if ( ( (m_state & m_mask & COMPOSED) > 0 ) ||
  -             ( (m_mask & COMPOSED) == 0 ) || ( m_state > COMPOSED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & COMPOSED) == 0;
  +        isValid = isValid && ((m_mask & COMPOSE_MASK) | COMPOSED) ==
  +                             ((m_state & DISPOSE_MASK) | COMPOSED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= COMPOSED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -316,14 +344,18 @@
        */
       public void checkInitialized( final String message )
       {
  -        if ( ( (m_state & m_mask & INITIALIZED) > 0 ) ||
  -             ( (m_mask & INITIALIZED) == 0 ) || ( m_state > INITIALIZED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & INITIALIZED) == 0;
  +        isValid = isValid && ((m_mask & INIT_MASK) | INITIALIZED) ==
  +                             ((m_state & DISPOSE_MASK) | INITIALIZED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= INITIALIZED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -351,14 +383,18 @@
        */
       public void checkStarted( final String message )
       {
  -        if ( ( (m_state & m_mask & STARTED) > 0 ) ||
  -             ( (m_mask & STARTED) == 0 ) || ( m_state > STARTED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & STARTED) == 0;
  +        isValid = isValid && ((m_mask & START_MASK) | STARTED) ==
  +                             ((m_state & DISPOSE_MASK) | STARTED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
   
           m_state |= STARTED;
  -        if ( (m_state & INIT_MASK) == (m_mask & INIT_MASK) )
  +        if ( (m_state & START_MASK) == (m_mask & START_MASK) )
           {
               m_state |= ACTIVE;
           }
  @@ -387,8 +423,12 @@
       public void checkSuspended( final String message )
       {
           checkActive( message );
  -        if ( ( (m_state & m_mask & SUSPENDED) > 0 ) ||
  -             ( (m_mask & SUSPENDED) == 0 ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & SUSPENDED) == 0;
  +        isValid = isValid && ((m_mask & START_MASK) & ~SUSPENDED) ==
  +                             ((m_state & DISPOSE_MASK) & ~SUSPENDED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
  @@ -419,8 +459,12 @@
       public void checkResumed( final String message )
       {
           checkActive( message );
  -        if ( ( (m_state & m_mask & SUSPENDED) == 0 ) ||
  -             ( (m_mask & SUSPENDED) == 0 ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & SUSPENDED) > 0;
  +        isValid = isValid && ((m_mask & START_MASK) | SUSPENDED) ==
  +                             ((m_state & DISPOSE_MASK) | SUSPENDED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
  @@ -450,9 +494,12 @@
        */
       public void checkStopped( final String message )
       {
  -        if ( ( (m_state & m_mask & STOPPED) > 0 ) ||
  -             ( (m_mask & STOPPED) == 0 ) ||
  -             ( (m_state & m_mask) > STOPPED ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & STOPPED) == 0;
  +        isValid = isValid && ((m_mask & STOP_MASK) | STOPPED) ==
  +                             ((m_state & DISPOSE_MASK) | STOPPED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
  @@ -483,7 +530,12 @@
        */
       public void checkDisposed( final String message )
       {
  -        if ( ( (m_state & m_mask & DISPOSED) > 0 ) || ( (m_mask & DISPOSED)
== 0 ) )
  +        boolean isValid = false;
  +        isValid = (m_state & m_mask & DISPOSED) == 0;
  +        isValid = isValid && ((m_mask & DISPOSE_MASK) | DISPOSED) ==
  +                             ((m_state & DISPOSE_MASK) | DISPOSED);
  +
  +        if ( ! isValid )
           {
               throw new IllegalStateException( message );
           }
  
  
  
  1.3       +48 -25    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/ComponentTestCase.java
  
  Index: ComponentTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/ComponentTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentTestCase.java	11 Dec 2001 09:53:37 -0000	1.2
  +++ ComponentTestCase.java	17 Jan 2002 15:02:01 -0000	1.3
  @@ -24,7 +24,7 @@
    * within your own code.
    *
    * @author <a href="bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/12/11 09:53:37 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/01/17 15:02:01 $
    */
   public final class ComponentTestCase
       extends TestCase
  @@ -41,9 +41,9 @@
   
           component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
           component.contextualize(new DefaultContext());
  -        component.parameterize(new Parameters());
  -        component.configure(new DefaultConfiguration("", ""));
           component.compose(new DefaultComponentManager());
  +        component.configure(new DefaultConfiguration("", ""));
  +        component.parameterize(new Parameters());
           component.initialize();
           component.start();
           component.suspend();
  @@ -52,14 +52,32 @@
           component.dispose();
       }
   
  -    public void testOutOfOrderInitialize()
  +    public void testMissingLogger()
  +        throws Exception
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
           try
           {
  -            component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
               component.contextualize(new DefaultContext());
  +        }
  +        catch ( Exception e )
  +        {
  +            return;
  +        }
  +        fail("Did not detect missing logger");
  +    }
  +
  +    public void testOutOfOrderInitialize()
  +        throws Exception
  +    {
  +        FullLifecycleComponent component = new FullLifecycleComponent();
  +
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  +        component.contextualize(new DefaultContext());
  +        component.compose(new DefaultComponentManager());
  +        try
  +        {
               component.initialize();
               component.parameterize(new Parameters());
           }
  @@ -71,20 +89,22 @@
       }
   
       public void testOutOfOrderDispose()
  +        throws Exception
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  +        component.contextualize(new DefaultContext());
  +        component.compose(new DefaultComponentManager());
  +        component.configure(new DefaultConfiguration("", ""));
  +        component.parameterize(new Parameters());
  +        component.initialize();
  +        component.start();
  +        component.suspend();
  +        component.resume();
  +
           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();
           }
  @@ -117,9 +137,9 @@
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
           try
           {
  -            component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
               component.contextualize(new DefaultContext());
               component.contextualize(new DefaultContext());
           }
  @@ -133,13 +153,17 @@
       }
   
       public void testDoubleAssignOfParameters()
  +        throws Exception
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  +        component.contextualize(new DefaultContext());
  +        component.compose(new DefaultComponentManager());
  +        component.configure(new DefaultConfiguration("", ""));
  +
           try
           {
  -            component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  -            component.contextualize(new DefaultContext());
               component.parameterize(new Parameters());
               component.parameterize(new Parameters());
           }
  @@ -152,15 +176,15 @@
           fail("Did not detect double assignment of Parameters");
       }
   
  -    public void testDoubleAssignOfConfiguration()
  +    public void testDoubleAssignOfConfiguration() throws Exception
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  +        component.contextualize(new DefaultContext());
  +        component.compose(new DefaultComponentManager());
           try
           {
  -            component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  -            component.contextualize(new DefaultContext());
  -            component.parameterize(new Parameters());
               component.configure(new DefaultConfiguration("", ""));
               component.configure(new DefaultConfiguration("", ""));
           }
  @@ -174,15 +198,14 @@
       }
   
       public void testDoubleAssignOfComponentManger()
  +        throws Exception
       {
           FullLifecycleComponent component = new FullLifecycleComponent();
   
  +        component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
  +        component.contextualize(new DefaultContext());
           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());
           }
  
  
  

--
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