You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/10/12 00:13:07 UTC

cvs commit: avalon/merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit HelloComponent.java StandardTestCase.java

mcconnell    2003/10/11 15:13:07

  Modified:    merlin/kernel/unit maven.xml project.xml
               merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit
                        AbstractMerlinTestCase.java
               merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit
                        HelloComponent.java StandardTestCase.java
  Log:
  Update static values to avoid Maven issue (file not found translates to class not found with details) and improve overall error handling.
  
  Revision  Changes    Path
  1.2       +1 -1      avalon/merlin/kernel/unit/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/unit/maven.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven.xml	7 Oct 2003 18:03:11 -0000	1.1
  +++ maven.xml	11 Oct 2003 22:13:07 -0000	1.2
  @@ -1,7 +1,7 @@
   <project default="jar:install" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util" xmlns:ant="jelly:ant">
   
     <ant:property name="maven.jar.manifest.extensions.add" value="false"/>
  -  <ant:property file="project.properties"/>
  +  <ant:property file="${basedir}/../../version.properties"/>
   
     <preGoal name="jar:jar">
       <maven:snapshot project="${pom}"/>
  
  
  
  1.4       +1 -1      avalon/merlin/kernel/unit/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/unit/project.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.xml	10 Oct 2003 00:21:57 -0000	1.3
  +++ project.xml	11 Oct 2003 22:13:07 -0000	1.4
  @@ -6,7 +6,7 @@
     <groupId>merlin</groupId>
     <id>merlin-unit</id>
     <name>Merlin Unit Test</name>
  -  <currentVersion>1.0</currentVersion>
  +  <currentVersion>dev-031012</currentVersion>
     <package>*</package>
   
     <inceptionYear>2003</inceptionYear>
  
  
  
  1.3       +61 -33    avalon/merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit/AbstractMerlinTestCase.java
  
  Index: AbstractMerlinTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit/AbstractMerlinTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractMerlinTestCase.java	7 Oct 2003 21:33:37 -0000	1.2
  +++ AbstractMerlinTestCase.java	11 Oct 2003 22:13:07 -0000	1.3
  @@ -90,11 +90,19 @@
       // static
       //-------------------------------------------------------------------
   
  -    private static boolean DEBUG = false;
  +    public static boolean MERLIN_DEBUG_OFF = false;
  +    public static boolean MERLIN_DEBUG_ON = true;
  +    public static boolean MERLIN_INFO_OFF = false;
  +    public static boolean MERLIN_INFO_ON = true;
   
  -    private static boolean INFO = false;
  +    public static final File MAVEN_TARGET_CLASSES_DIR = 
  +      getTargetClassesDirectory();
   
  -    private static URL BLOCK = getTargetClassesPath();
  +    public static final File MAVEN_TARGET_TEST_CLASSES_DIR = 
  +      getTargetTestClassesDirectory();
  +
  +    public static final File MERLIN_DEFAULT_CONFIG_FILE = 
  +      getProjectFile( "conf/config.xml" );
   
       //-------------------------------------------------------------------
       // state
  @@ -131,7 +139,7 @@
       */
       public AbstractMerlinTestCase( String name )
       {
  -        this( BLOCK, INFO, DEBUG, name );
  +        this( MAVEN_TARGET_CLASSES_DIR, null, MERLIN_INFO_OFF, MERLIN_DEBUG_OFF, name );
       }
   
      /**
  @@ -144,7 +152,7 @@
       */
       public AbstractMerlinTestCase( boolean info, boolean debug, String name )
       {
  -        this( BLOCK, info, debug, name );
  +        this( MAVEN_TARGET_CLASSES_DIR, null, info, debug, name );
       }
   
      /**
  @@ -157,10 +165,32 @@
       * @param name the name of the test case
       */
       public AbstractMerlinTestCase( 
  -      URL url, boolean info, boolean debug, String name )
  +      File block, File targets, boolean info, boolean debug, String name )
       {
           super( name );
   
  +        if( block == null )
  +        {
  +            throw new NullPointerException( "block" );
  +        }
  +
  +        if( !block.exists() )
  +        {
  +            final String error = 
  +              "Containment block [" + block + "] does not exist.";
  +            throw new IllegalStateException( error );
  +        }
  +
  +        if( ( targets != null ) && !targets.exists() )
  +        {
  +            final String error = 
  +              "Configuration targets [" + targets + "] does not exist.";
  +            throw new IllegalStateException( error );
  +        }
  +
  +        URL url = convertToURL( block );
  +        URL conf = convertToURL( targets );
  +
           File base = 
             new File( 
               System.getProperty( 
  @@ -205,7 +235,7 @@
           try
           {
               ContainmentModel root = m_kernel.getContainmentModel();
  -            m_test = (ContainmentModel) root.addModel( url );
  +            m_test = root.addContainmentModel( url, conf );
           }
           catch( Throwable e )
           {
  @@ -416,54 +446,52 @@
       }
   
      /**
  -    * Convinience method to get the ${basedir}/target/classes directory
  -    * as a deployment url.
  -    * @return the deployment url
  +    * Convinience method to get the ${basedir}/target/classes directory.
  +    * @return the deployment directory
       */
  -    public static URL getTargetClassesPath()
  +    public static File getTargetClassesDirectory()
       {
  -        return getBlockPath( "target/classes" );
  +        return getProjectFile( "target/classes" );
       }
   
      /**
  -    * Convinience method to get the ${basedir}/target/test-classes directory
  -    * as a deployment url.
  +    * Convinience method to get the ${basedir}/target/test-classes directory.
       * @return the deployment url
       */
  -    public static URL getTargetTestClassesPath()
  +    public static File getTargetTestClassesDirectory()
       {
  -        return getBlockPath( "target/test-classes" );
  +        return getProjectFile( "target/test-classes" );
       }
   
      /**
  -    * Convinience method to get the ${basedir}/[path] directory
  -    * as a deployment url.
  +    * Convinience method to get the ${basedir}/[path] directory.
       * @return the deployment url
       */
  -    public static URL getBlockPath( String path )
  +    public static File getProjectFile( String path )
       {
           File base = getBaseDirectory();
  -        File inf = new File( base, path );
  +        return new File( base, path );
  +    }
  +
  +    private static File getBaseDirectory()
  +    {
  +        String basedir = System.getProperty( "basedir" );
  +        return new File( basedir );
  +    }
  +
  +    private URL convertToURL( File file )
  +    {
  +        if( file == null ) return null;
           try
           {
  -            if( inf.exists() ) return inf.toURL();
  +            return file.toURL();
           }
           catch( Throwable e )
           {
               final String error = 
  -              "Unexpected error while constructing block path: " + inf;
  +              "Unable to convert file [" + file + "] to a url.";
               throw new UnitRuntimeException( error, e );
           }
  -
  -        final String error = 
  -          "Test path ${basedir}/[" + path + "] does not exist.";
  -        throw new UnitRuntimeException( error );
  -    }
  -
  -    private static File getBaseDirectory()
  -    {
  -        String basedir = System.getProperty( "basedir" );
  -        return new File( basedir );
       }
   }
   
  
  
  
  1.2       +16 -2     avalon/merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit/HelloComponent.java
  
  Index: HelloComponent.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit/HelloComponent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HelloComponent.java	7 Oct 2003 18:03:11 -0000	1.1
  +++ HelloComponent.java	11 Oct 2003 22:13:07 -0000	1.2
  @@ -55,6 +55,9 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Executable;
   import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.Configuration;
   
   /**
    * A sample component.  This component implements a number 
  @@ -69,7 +72,7 @@
    * @avalon.component version="1.0" name="hello"
    */
   public class HelloComponent 
  -  implements LogEnabled, Initializable, Disposable, Hello
  +  implements LogEnabled, Configurable, Initializable, Disposable, Hello
   {
   
      //------------------------------------------------------------
  @@ -82,6 +85,7 @@
       */
       private Logger m_logger;
   
  +    private String m_message;
   
      //------------------------------------------------------------
      // Hello
  @@ -93,7 +97,7 @@
       */
       public String getMessage()
       {
  -        return "Hello";
  +        return m_message;
       }
   
      //------------------------------------------------------------
  @@ -109,6 +113,16 @@
       {
           m_logger = logger;
           getLogger().info( "logging" );
  +    }
  +
  +   /**
  +    * Configuration of the component by the container.
  +    * @exception Exception if a configuration error occurs
  +    */
  +    public void configure( Configuration config ) throws ConfigurationException
  +    {
  +        getLogger().info( "configuration" );
  +        m_message = config.getChild( "message" ).getValue( "unknown" );
       }
   
      /**
  
  
  
  1.2       +6 -19     avalon/merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit/StandardTestCase.java
  
  Index: StandardTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/unit/src/test/org/apache/avalon/merlin/unit/StandardTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardTestCase.java	7 Oct 2003 18:03:11 -0000	1.1
  +++ StandardTestCase.java	11 Oct 2003 22:13:07 -0000	1.2
  @@ -61,15 +61,6 @@
    */
   public class StandardTestCase extends AbstractMerlinTestCase
   {
  -    //--------------------------------------------------------
  -    // static
  -    //--------------------------------------------------------
  -
  -    private static boolean DEBUG = false;
  -
  -    private static boolean INFO = false;
  -
  -    private static URL BLOCK = getTargetTestClassesPath();
   
       //--------------------------------------------------------
       // constructors
  @@ -79,18 +70,14 @@
       * @param name the name of the test case
       * @param root the merlin system install directory
       */
  -    public StandardTestCase( )
  -    {
  -        this( "standard" );
  -    }
  -
  -   /**
  -    * @param name the name of the test case
  -    * @param root the merlin system install directory
  -    */
       public StandardTestCase( String name )
       {
  -        super( BLOCK, INFO, DEBUG, name );
  +        super( 
  +          MAVEN_TARGET_TEST_CLASSES_DIR, 
  +          MERLIN_DEFAULT_CONFIG_FILE, 
  +          MERLIN_DEBUG_OFF, 
  +          MERLIN_INFO_OFF, 
  +          name );
       }
   
       //--------------------------------------------------------
  
  
  

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