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-phoenix/src/java/org/apache/avalon/phoenix/tools/punit PUnitBlockEntry.java PUnitBlockContext.java PUnitLogger.java PUnitResourceProvider.java PUnitTestCase.java PUnitBlock.java PUnitComponentManager.java PUnitServiceManager.java
Date Tue, 12 Nov 2002 20:40:25 GMT
donaldp     2002/11/12 12:40:25

  Modified:    src/java/org/apache/avalon/phoenix/tools/punit
                        PUnitBlockContext.java PUnitLogger.java
                        PUnitResourceProvider.java PUnitTestCase.java
  Added:       src/java/org/apache/avalon/phoenix/tools/punit
                        PUnitBlockEntry.java
  Removed:     src/java/org/apache/avalon/phoenix/tools/punit
                        PUnitBlock.java PUnitComponentManager.java
                        PUnitServiceManager.java
  Log:
  Rework slightly to reuse other parts of avalon framework
  such as WrapperComponentManager/DefaultContext etc
  
  Revision  Changes    Path
  1.2       +22 -19    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitBlockContext.java
  
  Index: PUnitBlockContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitBlockContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PUnitBlockContext.java	9 Nov 2002 19:23:21 -0000	1.1
  +++ PUnitBlockContext.java	12 Nov 2002 20:40:25 -0000	1.2
  @@ -9,6 +9,7 @@
   
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.phoenix.BlockContext;
   
   import java.io.File;
  @@ -19,49 +20,51 @@
    * @author Paul Hammant
    */
   public class PUnitBlockContext
  +    extends DefaultContext
       implements BlockContext
   {
   
       public File getBaseDirectory()
       {
  -        // TODO
  -        return null;
  +        try
  +        {
  +            return (File)get( BlockContext.APP_HOME_DIR );
  +        }
  +        catch( ContextException e )
  +        {
  +            return new File( "." );
  +        }
       }
   
       public String getName()
       {
  -        // TODO
  -        return null;
  +        try
  +        {
  +            return (String)get( BlockContext.APP_NAME );
  +        }
  +        catch( ContextException e )
  +        {
  +            return "myBlock";
  +        }
       }
   
  -
       public void requestShutdown()
       {
  -        //TODO
       }
   
  -    // TODO
  -    public InputStream getResourceAsStream(String name)
  +    public InputStream getResourceAsStream( String name )
       {
           return null;
       }
   
  -    public Logger getLogger(String name)
  +    public Logger getLogger( String name )
       {
           throw new UnsupportedOperationException();
       }
   
  -    public ClassLoader getClassLoader(String name)
  -            throws Exception
  -    {
  -        // TODO
  -        return null;
  -    }
  -
  -    public Object get(Object o) throws ContextException
  +    public ClassLoader getClassLoader( String name )
  +        throws Exception
       {
  -        //TODO
           return null;
       }
  -
   }
  
  
  
  1.2       +51 -43    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitLogger.java
  
  Index: PUnitLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PUnitLogger.java	11 Nov 2002 01:35:19 -0000	1.1
  +++ PUnitLogger.java	12 Nov 2002 20:40:25 -0000	1.2
  @@ -13,26 +13,28 @@
   
   /**
    * PunitLogger
  + *
    * @author Paul Hammant
    */
  -public class PUnitLogger implements Logger
  +public class PUnitLogger
  +    implements Logger
   {
  -
  -    private ArrayList m_log = new ArrayList();
  +    private ArrayList m_messages = new ArrayList();
   
       /**
        * Get a logged entry.
        * @param startsWith This term
        * @return The full term
        */
  -    public String get(String startsWith)
  +    public String get( String startsWith )
       {
  -        for (int i = 0; i < m_log.size(); i++)
  +        final int size = m_messages.size();
  +        for( int i = 0; i < size; i++ )
           {
  -            String s = (String) m_log.get(i);
  -            if (s.startsWith(startsWith))
  +            final String message = (String)m_messages.get( i );
  +            if( message.startsWith( startsWith ) )
               {
  -                return s;
  +                return message;
               }
           }
           return null;
  @@ -40,31 +42,34 @@
   
       /**
        * Contains a logged entry
  -     * @param s The term
  +     *
  +     * @param message The term
        * @return true or not.
        */
  -    public boolean contains(String s)
  +    public boolean contains( final String message )
       {
  -        return get(s) != null;
  +        return get( message ) != null;
       }
   
       /**
        * Debug an entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        */
  -    public void debug(String s)
  +    public void debug( final String message )
       {
  -        m_log.add("D:" + s);
  +        m_messages.add( "D:" + message );
       }
   
       /**
        * Debug an entry as per Loggable
  -     * @param s the term
  +     *
  +     * @param message the term
        * @param throwable An exception
        */
  -    public void debug(String s, Throwable throwable)
  +    public void debug( final String message,
  +                       final Throwable throwable )
       {
  -        m_log.add("D:" + s + ":" + throwable != null ? throwable.getMessage() : "");
  +        m_messages.add( "D:" + message + ":" + throwable != null ? throwable.getMessage()
: "" );
       }
   
       public boolean isDebugEnabled()
  @@ -74,21 +79,21 @@
   
       /**
        * Info an entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        */
  -    public void info(String s)
  +    public void info( final String message )
       {
  -        m_log.add("I:" + s);
  +        m_messages.add( "I:" + message );
       }
   
       /**
        * Info an entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        * @param throwable An exception
        */
  -    public void info(String s, Throwable throwable)
  +    public void info( final String message, final Throwable throwable )
       {
  -        m_log.add("I:" + s + ":" + throwable != null ? throwable.getMessage() : "");
  +        m_messages.add( "I:" + message + ":" + throwable != null ? throwable.getMessage()
: "" );
       }
   
       /**
  @@ -102,21 +107,22 @@
   
       /**
        * Warn an entry as per Loggable
  -     * @param s the term
  +     *
  +     * @param message the term
        */
  -    public void warn(String s)
  +    public void warn( final String message )
       {
  -        m_log.add("W:" + s);
  +        m_messages.add( "W:" + message );
       }
   
       /**
        * Warn an entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        * @param throwable An exception
        */
  -    public void warn(String s, Throwable throwable)
  +    public void warn( final String message, final Throwable throwable )
       {
  -        m_log.add("W:" + s + ":" + throwable != null ? throwable.getMessage() : "");
  +        m_messages.add( "W:" + message + ":" + throwable != null ? throwable.getMessage()
: "" );
       }
   
       /**
  @@ -130,21 +136,22 @@
   
       /**
        * Error an entry as per Loggable
  -     * @param s the term
  +     *
  +     * @param message the term
        */
  -    public void error(String s)
  +    public void error( final String message )
       {
  -        m_log.add("E:" + s);
  +        m_messages.add( "E:" + message );
       }
   
       /**
        * Error an entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        * @param throwable An exception
        */
  -    public void error(String s, Throwable throwable)
  +    public void error( final String message, final Throwable throwable )
       {
  -        m_log.add("E:" + s + ":" + throwable != null ? throwable.getMessage() : "");
  +        m_messages.add( "E:" + message + ":" + throwable != null ? throwable.getMessage()
: "" );
       }
   
       /**
  @@ -158,21 +165,21 @@
   
       /**
        * Log a fatal error as per Loggable
  -     * @param s the term
  +     * @param message the term
        */
  -    public void fatalError(String s)
  +    public void fatalError( final String message )
       {
  -        m_log.add("F:" + s);
  +        m_messages.add( "F:" + message );
       }
   
       /**
        * Log a fatal error entry as per Loggable
  -     * @param s the term
  +     * @param message the term
        * @param throwable An exception
        */
  -    public void fatalError(String s, Throwable throwable)
  +    public void fatalError( final String message, final Throwable throwable )
       {
  -        m_log.add("F:" + s + ":" + throwable != null ? throwable.getMessage() : "");
  +        m_messages.add( "F:" + message + ":" + throwable != null ? throwable.getMessage()
: "" );
       }
   
       /**
  @@ -186,10 +193,11 @@
   
       /**
        * Gtet the child logger
  -     * @param s The hint to use (ignored)
  +     *
  +     * @param name The hint to use (ignored)
        * @return The child logger.
        */
  -    public Logger getChildLogger(String s)
  +    public Logger getChildLogger( final String name )
       {
           return this;
       }
  
  
  
  1.7       +26 -19    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitResourceProvider.java
  
  Index: PUnitResourceProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitResourceProvider.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PUnitResourceProvider.java	11 Nov 2002 01:35:19 -0000	1.6
  +++ PUnitResourceProvider.java	12 Nov 2002 20:40:25 -0000	1.7
  @@ -7,24 +7,24 @@
    */
   package org.apache.avalon.phoenix.tools.punit;
   
  -import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.component.WrapperComponentManager;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
   
   /**
    * PUnitResourceProvider
  + *
    * @author Paul Hammant
    */
   public class PUnitResourceProvider
       implements ResourceProvider
   {
  -
       private ServiceManager m_serviceManager;
  -    private ComponentManager m_componentManager;
       private Configuration m_configuration;
       private Logger m_logger;
   
  @@ -33,22 +33,24 @@
        * @param serviceManager The service manager
        * @param configuration The configuration
        */
  -    public PUnitResourceProvider( ServiceManager serviceManager,
  -                                  Configuration configuration, Logger logger )
  +    public PUnitResourceProvider( final ServiceManager serviceManager,
  +                                  final Configuration configuration,
  +                                  final Logger logger )
       {
           m_serviceManager = serviceManager;
  -        m_componentManager = new PUnitComponentManager(serviceManager);
           m_configuration = configuration;
           m_logger = logger;
       }
   
       /**
        * Create an object
  +     *
        * @param object The object
        * @return The returned object
        * @throws Exception If a problm
        */
  -    public Object createObject(Object object) throws Exception
  +    public Object createObject( final Object object )
  +        throws Exception
       {
           return object;
       }
  @@ -59,7 +61,7 @@
        * @return The Logger
        * @throws Exception If a problem
        */
  -    public Logger createLogger(Object object) throws Exception
  +    public Logger createLogger( final Object object ) throws Exception
       {
           return m_logger;
       }
  @@ -70,7 +72,8 @@
        * @return the context
        * @throws Exception If a problem
        */
  -    public Context createContext(Object object) throws Exception
  +    public Context createContext( final Object object )
  +        throws Exception
       {
           return new PUnitBlockContext();
       }
  @@ -81,9 +84,9 @@
        * @return The comp mgr
        * @throws Exception If a problem
        */
  -    public ComponentManager createComponentManager(Object object) throws Exception
  +    public ComponentManager createComponentManager( Object object ) throws Exception
       {
  -        return m_componentManager;
  +        return new WrapperComponentManager( m_serviceManager );
       }
   
       /**
  @@ -92,18 +95,21 @@
        * @return The service manager
        * @throws Exception If a problem
        */
  -    public ServiceManager createServiceManager(Object object) throws Exception
  +    public ServiceManager createServiceManager( final Object object )
  +        throws Exception
       {
           return m_serviceManager;
       }
   
       /**
        * Create some Configuration
  +     *
        * @param object For this object
        * @return The configuration
        * @throws Exception If a problem
        */
  -    public Configuration createConfiguration(Object object) throws Exception
  +    public Configuration createConfiguration( final Object object )
  +        throws Exception
       {
           return m_configuration;
       }
  @@ -114,9 +120,10 @@
        * @return The parameters
        * @throws Exception If a problem
        */
  -    public Parameters createParameters(Object object) throws Exception
  +    public Parameters createParameters( final Object object )
  +        throws Exception
       {
  -        //TODO
  -        throw new UnsupportedOperationException();
  +        final Configuration configuration = createConfiguration( object );
  +        return Parameters.fromConfiguration( configuration );
       }
   }
  
  
  
  1.6       +24 -19    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitTestCase.java
  
  Index: PUnitTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PUnitTestCase.java	12 Nov 2002 00:08:01 -0000	1.5
  +++ PUnitTestCase.java	12 Nov 2002 20:40:25 -0000	1.6
  @@ -11,6 +11,7 @@
   import org.apache.excalibur.containerkit.lifecycle.LifecycleException;
   import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.service.DefaultServiceManager;
   import junit.framework.TestCase;
   import java.util.ArrayList;
   
  @@ -18,12 +19,13 @@
    * PUnitTestCase
    * @author Paul Hammant
    */
  -public abstract class PUnitTestCase extends TestCase
  +public abstract class PUnitTestCase
  +    extends TestCase
   {
       private LifecycleHelper m_lifecycleHelper;
       private ArrayList m_blocks;
  -    private PUnitServiceManager m_pUnitServiceManager;
  -    private PUnitLogger m_pUnitLogger = new PUnitLogger();
  +    private DefaultServiceManager m_serviceManager;
  +    private PUnitLogger m_logger = new PUnitLogger();
   
       /**
        * PUnitTestCase
  @@ -39,9 +41,9 @@
        * @param startsWith For an expression that starts with this
        * @return The logged entry.
        */
  -    public final String lookupInLog(String startsWith)
  +    public final String lookupInLog( String startsWith )
       {
  -        return m_pUnitLogger.get(startsWith);
  +        return m_logger.get( startsWith );
       }
   
       /**
  @@ -49,12 +51,11 @@
        * @param startsWith For an expression that starts with this
        * @return true or not
        */
  -    public final boolean logHasEntry(String startsWith)
  +    public final boolean logHasEntry( String startsWith )
       {
  -        return m_pUnitLogger.contains(startsWith);
  +        return m_logger.contains( startsWith );
       }
   
  -
       /**
        * Setup as per Junit
        * @throws Exception If a problem
  @@ -63,7 +64,7 @@
       {
           m_lifecycleHelper = new LifecycleHelper();
           m_lifecycleHelper.enableLogging( new ConsoleLogger() );
  -        m_pUnitServiceManager = new PUnitServiceManager();
  +        m_serviceManager = new DefaultServiceManager();
           m_blocks = new ArrayList();
       }
   
  @@ -74,15 +75,18 @@
        * @param serviceName The service name (for lookup)
        * @param configuration The configuration
        */
  -    protected void addBlock( String blockName, String serviceName,
  -                             Object block , Configuration configuration )
  -    {
  -        PUnitBlock pBlock = new PUnitBlock( blockName, block,
  -                new PUnitResourceProvider(m_pUnitServiceManager, configuration, m_pUnitLogger)
);
  +    protected void addBlock( final String blockName,
  +                             final String serviceName,
  +                             final Object block,
  +                             final Configuration configuration )
  +    {
  +        final PUnitResourceProvider resourceProvider =
  +            new PUnitResourceProvider( m_serviceManager, configuration, m_logger );
  +        final PUnitBlockEntry pBlock = new PUnitBlockEntry( blockName, block, resourceProvider
);
           m_blocks.add( pBlock );
  -        if (serviceName != null)
  +        if( serviceName != null )
           {
  -            m_pUnitServiceManager.addService(serviceName, block);
  +            m_serviceManager.put( serviceName, block );
           }
       }
   
  @@ -95,7 +99,7 @@
   
           for( int i = 0; i < m_blocks.size(); i++ )
           {
  -            final PUnitBlock block = (PUnitBlock) m_blocks.get( i );
  +            final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i );
               m_lifecycleHelper.startup( block.getBlockName(),
                                          block.getBlock(),
                                          block.getResourceProvider() );
  @@ -108,9 +112,10 @@
        */
       protected final void shutdown() throws LifecycleException
       {
  -        for( int i = 0; i < m_blocks.size(); i++ )
  +        final int size = m_blocks.size();
  +        for( int i = 0; i < size; i++ )
           {
  -            PUnitBlock block = (PUnitBlock) m_blocks.get( i );
  +            final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i );
               m_lifecycleHelper.shutdown( block.getBlockName(), block.getBlock() );
           }
       }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitBlockEntry.java
  
  Index: PUnitBlockEntry.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.phoenix.tools.punit;
  
  import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
  
  /**
   * PUnitBlockEntry contains the runtime state of a block.
   *
   * @author Paul Hammant
   */
  public class PUnitBlockEntry
  {
      private String m_blockName;
      private Object m_block;
      private ResourceProvider m_resourceProvider;
  
      /**
       * Construct a PUnitBlockEntry
       *
       * @param blockName The block name
       * @param block The block
       * @param resourceProvider The resource provider for the block
       */
      public PUnitBlockEntry( final String blockName,
                         final Object block,
                         final ResourceProvider resourceProvider )
      {
          m_blockName = blockName;
          m_block = block;
          m_resourceProvider = resourceProvider;
      }
  
      /**
       * Get the block name
       * @return The block name
       */
      public String getBlockName()
      {
          return m_blockName;
      }
  
      /**
       * Get The block
       * @return The block
       */
      public Object getBlock()
      {
          return m_block;
      }
  
      /**
       * Get the resource provider
       * @return The resource provider.
       */
      public ResourceProvider getResourceProvider()
      {
          return m_resourceProvider;
      }
  }
  
  
  

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