ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor DefaultEmbeddorTest.java
Date Wed, 20 Feb 2002 07:20:22 GMT
adammurdoch    02/02/19 23:20:22

  Modified:    proposal/myrmidon build.xml
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java ProjectListenerSupport.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon
                        AbstractMyrmidonTest.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        AbstractComponentTest.java
  Added:       proposal/myrmidon/etc/testcases/org/apache/myrmidon/components/embeddor
                        project-builder.ant
               proposal/myrmidon/src/testcases/org/apache/myrmidon
                        TrackingProjectListener.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddorTest.java
  Log:
  * Added test cases for DefaultEmbeddor.
  * Target start and finish events are now fired for a project's implicit target.
  * Unit tests now run against a dummy myrmidon install.
  * Tidy-up some error messages.
  
  Revision  Changes    Path
  1.59      +11 -2     jakarta-ant/proposal/myrmidon/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- build.xml	17 Feb 2002 10:06:25 -0000	1.58
  +++ build.xml	20 Feb 2002 07:20:21 -0000	1.59
  @@ -384,6 +384,7 @@
       <ant antfile="antlib.xml">
          <property name="antlib.name" value="sound"/>
       </ant>
  +
       <!--
       <ant antfile="antlib.xml">
         <property name="antlib.name" value="vfile"/>
  @@ -412,7 +413,7 @@
     </target>
   
     <!-- Compiles and runs the unit tests -->
  -  <target name="test" depends="compile" if="junit.present" description="Runs the unit
tests">
  +  <target name="test" depends="dist-lite" if="junit.present" description="Runs the unit
tests">
       <!-- Compile the unit tests -->
       <mkdir dir="${test.classes}"/>
       <javac srcdir="src/testcases"
  @@ -429,6 +430,11 @@
           <fileset dir="etc/testcases"/>
       </copy>
   
  +    <!-- Prepare a dummy installation -->
  +    <copy todir="${test.working.dir}/dist">
  +        <fileset dir="${dist.dir}"/>
  +    </copy>
  +
       <!-- Prepare the VFS tests -->
       <property name="test.vfs.dir" location="${test.working.dir}/org/apache/aut/vfs"/>
       <mkdir dir="${test.vfs.dir}/basedir/emptydir"/>
  @@ -455,7 +461,10 @@
       <junit printsummary="on"
              fork="true">
         <formatter type="brief" usefile="false"/>
  -      <classpath refid="project.class.path"/>
  +      <classpath>
  +          <fileset dir="${test.working.dir}/dist/bin/lib" includes="**/*.jar"/>
  +          <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl"/>
  +      </classpath>
         <classpath location="${test.classes}"/>
   
         <!-- Pass config to the tests -->
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/myrmidon/components/embeddor/project-builder.ant
  
  Index: project-builder.ant
  ===================================================================
  <project version="2.0" name="test-project" default="main-target">
      <property name="some-prop" value="some-value"/>
      <target name="main-target">
          <log>A log message</log>
      </target>
  </project>
  
  
  1.27      +7 -5      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DefaultEmbeddor.java	18 Feb 2002 08:38:09 -0000	1.26
  +++ DefaultEmbeddor.java	20 Feb 2002 07:20:21 -0000	1.27
  @@ -49,7 +49,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.26 $ $Date: 2002/02/18 08:38:09 $
  + * @version $Revision: 1.27 $ $Date: 2002/02/20 07:20:21 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -287,10 +287,10 @@
   
           filepath = getParameter( "myrmidon.home" );
           m_homeDir = ( new File( filepath ) ).getAbsoluteFile();
  -        checkDirectory( m_homeDir, "home" );
  +        checkDirectory( m_homeDir, "home-dir.name" );
   
           filepath = getParameter( "myrmidon.lib.path" );
  -        m_taskLibDir = resolveDirectory( filepath, "task-lib-dir" );
  +        m_taskLibDir = resolveDirectory( filepath, "task-lib-dir.name" );
       }
   
       /**
  @@ -339,12 +339,14 @@
       {
           if( !file.exists() )
           {
  -            final String message = REZ.getString( "file-no-exist.error", name, file );
  +            final String nameStr = REZ.getString( name );
  +            final String message = REZ.getString( "file-no-exist.error", nameStr, file
);
               throw new Exception( message );
           }
           else if( !file.isDirectory() )
           {
  -            final String message = REZ.getString( "file-not-dir.error", name, file );
  +            final String nameStr = REZ.getString( name );
  +            final String message = REZ.getString( "file-not-dir.error", nameStr, file );
               throw new Exception( message );
           }
       }
  
  
  
  1.3       +2 -0      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	19 Nov 2001 12:37:25 -0000	1.2
  +++ Resources.properties	20 Feb 2002 07:20:21 -0000	1.3
  @@ -5,3 +5,5 @@
   no-instantiate.error=Error instantiating class for {0} {1}.
   no-class.error=Could not find the class for {0} ({1}).
   bad-filename.error=Unable to retrieve filename for file {0}.
  +home-dir.name=Myrmidon home directory
  +task-lib-dir.name=Task library directory
  \ No newline at end of file
  
  
  
  1.24      +11 -10    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  
  Index: DefaultWorkspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- DefaultWorkspace.java	14 Feb 2002 10:26:36 -0000	1.23
  +++ DefaultWorkspace.java	20 Feb 2002 07:20:21 -0000	1.24
  @@ -47,7 +47,7 @@
    * This is the default implementation of Workspace.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.23 $ $Date: 2002/02/14 10:26:36 $
  + * @version $Revision: 1.24 $ $Date: 2002/02/20 07:20:21 $
    */
   public class DefaultWorkspace
       extends AbstractLogEnabled
  @@ -134,7 +134,7 @@
   
           m_listenerSupport.projectStarted( project.getProjectName() );
   
  -        executeTarget( "<init>", project.getImplicitTarget(), entry.getFrame() );
  +        executeTarget( project, "<init>", project.getImplicitTarget(), entry.getFrame()
);
   
           execute( project, target, entry );
   
  @@ -370,13 +370,7 @@
               }
           }
   
  -        //notify listeners
  -        m_listenerSupport.targetStarted( project.getProjectName(), targetName );
  -
  -        executeTarget( targetName, target, entry.getFrame() );
  -
  -        //notify listeners
  -        m_listenerSupport.targetFinished();
  +        executeTarget( project, targetName, target, entry.getFrame() );
       }
   
       /**
  @@ -387,11 +381,15 @@
        * @param frame the frame in which to execute
        * @exception TaskException if an error occurs
        */
  -    private void executeTarget( final String name,
  +    private void executeTarget( final Project project,
  +                                final String name,
                                   final Target target,
                                   final ExecutionFrame frame )
           throws TaskException
       {
  +        //notify listeners
  +        m_listenerSupport.targetStarted( project.getProjectName(), name );
  +
           //check the condition associated with target.
           //if it is not satisfied then skip target
           final Condition condition = target.getCondition();
  @@ -426,6 +424,9 @@
           {
               executeTask( tasks[ i ], frame );
           }
  +
  +        //notify listeners
  +        m_listenerSupport.targetFinished();
       }
   
       /**
  
  
  
  1.10      +1 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java
  
  Index: ProjectListenerSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/ProjectListenerSupport.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ProjectListenerSupport.java	14 Feb 2002 10:53:54 -0000	1.9
  +++ ProjectListenerSupport.java	20 Feb 2002 07:20:21 -0000	1.10
  @@ -14,7 +14,7 @@
    * Support for the project listener event dispatching.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.9 $ $Date: 2002/02/14 10:53:54 $
  + * @version $Revision: 1.10 $ $Date: 2002/02/20 07:20:21 $
    */
   public class ProjectListenerSupport
       implements LogEvent
  @@ -110,7 +110,6 @@
       {
           m_projectName = projectName;
           m_targetName = targetName;
  -        ;
           m_taskName = null;
   
           for( int i = 0; i < m_listeners.length; i++ )
  
  
  
  1.2       +57 -3     jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractMyrmidonTest.java
  
  Index: AbstractMyrmidonTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractMyrmidonTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractMyrmidonTest.java	10 Feb 2002 02:34:14 -0000	1.1
  +++ AbstractMyrmidonTest.java	20 Feb 2002 07:20:22 -0000	1.2
  @@ -7,8 +7,16 @@
    */
   package org.apache.myrmidon;
   
  -import junit.framework.TestCase;
   import java.io.File;
  +import java.io.IOException;
  +import junit.framework.TestCase;
  +import org.apache.avalon.framework.logger.LogKitLogger;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.log.Hierarchy;
  +import org.apache.log.LogTarget;
  +import org.apache.log.Priority;
  +import org.apache.log.format.PatternFormatter;
  +import org.apache.log.output.io.StreamTarget;
   
   /**
    * A base class for Myrmidon tests.  Provides utility methods for locating
  @@ -20,16 +28,20 @@
       extends TestCase
   {
       private final File m_testBaseDir;
  +    private final File m_baseDir;
  +
  +    private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}";
   
       public AbstractMyrmidonTest( String name )
       {
           super( name );
           final String baseDirProp = System.getProperty( "test.basedir" );
  +        m_baseDir = new File( baseDirProp );
           String packagePath = getClass().getName();
           int idx = packagePath.lastIndexOf('.');
           packagePath = packagePath.substring(0, idx);
           packagePath = packagePath.replace('.', File.separatorChar);
  -        m_testBaseDir = new File( baseDirProp, packagePath ).getAbsoluteFile();
  +        m_testBaseDir = new File( m_baseDir, packagePath );
       }
   
       /**
  @@ -37,7 +49,49 @@
        */
       protected File getTestResource( final String name )
       {
  -        return new File( m_testBaseDir, name );
  +        final File file = new File( m_testBaseDir, name );
  +        return getCanonicalFile( file );
  +    }
  +
  +    /**
  +     * Returns the directory containing a Myrmidon install.
  +     */
  +    protected File getHomeDirectory()
  +    {
  +        final File file = new File( m_baseDir, "dist" );
  +        return getCanonicalFile( file );
  +    }
  +
  +    /**
  +     * Makes a file canonical
  +     */
  +    private File getCanonicalFile( final File file )
  +    {
  +        try
  +        {
  +            return file.getCanonicalFile();
  +        }
  +        catch( IOException e )
  +        {
  +            return file.getAbsoluteFile();
  +        }
  +    }
  +
  +    /**
  +     * Creates a logger.
  +     */
  +    protected Logger createLogger()
  +    {
  +        // Setup a logger
  +        final Priority priority = Priority.WARN;
  +        final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor(
"myrmidon" );
  +
  +        final PatternFormatter formatter = new PatternFormatter( PATTERN );
  +        final StreamTarget target = new StreamTarget( System.out, formatter );
  +        targetLogger.setLogTargets( new LogTarget[]{target} );
  +        targetLogger.setPriority( priority );
  +
  +        return new LogKitLogger( targetLogger );
       }
   
       /**
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/TrackingProjectListener.java
  
  Index: TrackingProjectListener.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.myrmidon;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Map;
  import junit.framework.Assert;
  import org.apache.myrmidon.listeners.LogEvent;
  import org.apache.myrmidon.listeners.ProjectEvent;
  import org.apache.myrmidon.listeners.ProjectListener;
  import org.apache.myrmidon.listeners.TargetEvent;
  import org.apache.myrmidon.listeners.TaskEvent;
  
  /**
   * A project listener that asserts that it receives a particular sequence of
   * events.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/20 07:20:22 $
   */
  public class TrackingProjectListener
      extends Assert
      implements ProjectListener
  {
      private String m_rootProject;
      private String m_currentProject;
      private String m_currentTarget;
      private String m_currentTask;
      private Map m_messages = new HashMap();
      private ArrayList m_currentMsgs;
  
      /**
       * Notify the listener that a project is about to start.
       */
      public void projectStarted( final ProjectEvent event )
      {
          assertNull( "Project already started", m_rootProject );
          m_rootProject = event.getProjectName();
      }
  
      /**
       * Notify the listener that a project has finished.
       */
      public void projectFinished( final ProjectEvent event )
      {
          assertEquals( "Mismatched project name", m_rootProject, event.getProjectName() );
          m_rootProject = null;
  
          assertNull( "Target not started", m_currentTarget );
      }
  
      /**
       * Notify the listener that a target is about to start.
       */
      public void targetStarted( final TargetEvent event )
      {
          assertNotNull( "Project not started", m_rootProject );
          assertNull( "Target already started", m_currentTarget );
          m_currentProject = event.getProjectName();
          m_currentTarget = event.getTargetName();
          m_currentMsgs = (ArrayList)m_messages.get( m_currentTarget );
      }
  
      /**
       * Notify the listener that a target has finished.
       */
      public void targetFinished( final TargetEvent event )
      {
          assertEquals( "Mismatched project name", m_currentProject, event.getProjectName()
);
          assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
          m_currentProject = null;
          m_currentTarget = null;
          assertTrue( "Missing log messages for target", m_currentMsgs == null || m_currentMsgs.size()
== 0 );
  
          assertNull( "Task not finished", m_currentTask );
      }
  
      /**
       * Notify the listener that a task is about to start.
       */
      public void taskStarted( final TaskEvent event )
      {
          assertEquals( "Mismatched project name", m_currentProject, event.getProjectName()
);
          assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
  
          assertNull( "Task already started", m_currentTask );
          m_currentTask = event.getTaskName();
      }
  
      /**
       * Notify the listener that a task has finished.
       */
      public void taskFinished( final TaskEvent event )
      {
          assertEquals( "Mismatched project name", m_currentProject, event.getProjectName()
);
          assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
          assertEquals( "Mismatched task name", m_currentTask, event.getTaskName() );
          m_currentTask = null;
      }
  
      /**
       * Notify listener of log message event.
       */
      public void log( final LogEvent event )
      {
          assertEquals( "Mismatched project name", m_currentProject, event.getProjectName()
);
          assertEquals( "Mismatched target name", m_currentTarget, event.getTargetName() );
          assertEquals( "Mismatched task name", m_currentTask, event.getTaskName() );
          assertNotNull( "Unexpected log message", m_currentMsgs );
          assertTrue( "Unexpected log message", m_currentMsgs.size() > 0 );
          assertEquals( "Unexpected log message", m_currentMsgs.remove( 0 ), event.getMessage()
);
          assertNull( "Unexpected build error", event.getThrowable() );
      }
  
      /**
       * Asserts that the listener has finished.
       */
      public void assertComplete()
      {
          assertNull( "Task not finished", m_currentTask );
          assertNull( "Target not finished", m_currentTarget );
          assertNull( "Target not finished", m_currentProject );
          assertNull( "Project not finished", m_rootProject );
      }
  
      /**
       * Adds an expected log message.
       */
      public void addExpectedMessage( String target, String message )
      {
          ArrayList targetMsgs = (ArrayList)m_messages.get( target );
          if( targetMsgs == null )
          {
              targetMsgs = new ArrayList();
              m_messages.put( target, targetMsgs );
          }
          targetMsgs.add( message );
      }
  }
  
  
  
  1.5       +10 -27    jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractComponentTest.java	14 Feb 2002 02:12:23 -0000	1.4
  +++ AbstractComponentTest.java	20 Feb 2002 07:20:22 -0000	1.5
  @@ -10,42 +10,35 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  -import junit.framework.TestCase;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.component.DefaultComponentManager;
   import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.log.Hierarchy;
  -import org.apache.log.LogTarget;
  -import org.apache.log.Priority;
  -import org.apache.log.format.PatternFormatter;
  -import org.apache.log.output.io.StreamTarget;
  +import org.apache.myrmidon.AbstractMyrmidonTest;
   import org.apache.myrmidon.components.configurer.DefaultConfigurer;
   import org.apache.myrmidon.components.converter.DefaultConverterRegistry;
   import org.apache.myrmidon.components.converter.DefaultMasterConverter;
  -import org.apache.myrmidon.components.deployer.DefaultDeployer;
  -import org.apache.myrmidon.components.deployer.DefaultClassLoaderManager;
   import org.apache.myrmidon.components.deployer.ClassLoaderManager;
  +import org.apache.myrmidon.components.deployer.DefaultClassLoaderManager;
  +import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.components.extensions.DefaultExtensionManager;
   import org.apache.myrmidon.components.role.DefaultRoleManager;
  -import org.apache.myrmidon.components.type.DefaultTypeManager;
   import org.apache.myrmidon.components.service.DefaultServiceManager;
  +import org.apache.myrmidon.components.type.DefaultTypeManager;
  +import org.apache.myrmidon.converter.Converter;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.converter.MasterConverter;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  -import org.apache.myrmidon.interfaces.type.TypeManager;
  -import org.apache.myrmidon.interfaces.type.TypeException;
  -import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.service.ServiceManager;
  -import org.apache.myrmidon.converter.Converter;
  -import org.apache.myrmidon.AbstractMyrmidonTest;
  +import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  +import org.apache.myrmidon.interfaces.type.TypeException;
  +import org.apache.myrmidon.interfaces.type.TypeManager;
   
   /**
    * A base class for tests for the default components.
  @@ -58,8 +51,6 @@
       private DefaultComponentManager m_componentManager;
       private Logger m_logger;
   
  -    private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}";
  -
       public AbstractComponentTest( final String name )
       {
           super( name );
  @@ -87,16 +78,7 @@
       protected void setUp()
           throws Exception
       {
  -        // Setup a logger
  -        final Priority priority = Priority.DEBUG;
  -        final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor(
"myrmidon" );
  -
  -        final PatternFormatter formatter = new PatternFormatter( PATTERN );
  -        final StreamTarget target = new StreamTarget( System.out, formatter );
  -        targetLogger.setLogTargets( new LogTarget[]{target} );
  -        targetLogger.setPriority( priority );
  -
  -        m_logger = new LogKitLogger( targetLogger );
  +        m_logger = createLogger();
   
           // Create the components
           m_componentManager = new DefaultComponentManager();
  @@ -161,6 +143,7 @@
               }
           }
       }
  +
   
       /**
        * Utility method to register a Converter.
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor/DefaultEmbeddorTest.java
  
  Index: DefaultEmbeddorTest.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.myrmidon.components.embeddor;
  
  import java.io.File;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.myrmidon.AbstractMyrmidonTest;
  import org.apache.myrmidon.TrackingProjectListener;
  import org.apache.myrmidon.interfaces.model.Project;
  import org.apache.myrmidon.interfaces.model.Target;
  import org.apache.myrmidon.interfaces.workspace.Workspace;
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * Test cases for the default embeddor.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/20 07:20:22 $
   */
  public class DefaultEmbeddorTest
      extends AbstractMyrmidonTest
  {
      private DefaultEmbeddor m_embeddor;
  
      public DefaultEmbeddorTest( String name )
      {
          super( name );
      }
  
      /**
       * Setup the test, by creating and initialising the embeddor.
       */
      protected void setUp() throws Exception
      {
          final Logger logger = createLogger();
          m_embeddor = new DefaultEmbeddor();
          m_embeddor.enableLogging( logger );
  
          final Parameters params = new Parameters();
          final File instDir = getHomeDirectory();
          params.setParameter( "myrmidon.home", instDir.getAbsolutePath() );
          m_embeddor.parameterize( params );
          m_embeddor.initialize();
          m_embeddor.start();
      }
  
      /**
       * Tear-down the test.
       */
      protected void tearDown() throws Exception
      {
          m_embeddor.dispose();
          m_embeddor = null;
      }
  
      /**
       * Tests that a project is successfully built from a file.
       */
      public void testProjectBuilder() throws Exception
      {
          final File projectFile = getTestResource( "project-builder.ant" );
          assertTrue( "Project file \"" + projectFile + "\" does not exist.", projectFile.exists()
);
  
          // Build the project
          final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(),
null, null );
  
          // Verify the project.
          assertEquals( "test-project", project.getProjectName() );
          assertEquals( "main-target", project.getDefaultTargetName() );
          assertEquals( projectFile.getParentFile(), project.getBaseDirectory() );
          assertEquals( 0, project.getProjectNames().length );
          assertEquals( 0, project.getTypeLibs().length );
          assertEquals( 1, project.getTargetNames().length );
  
          final Target implicitTarget = project.getImplicitTarget();
          assertEquals( 1, implicitTarget.getTasks().length );
          assertEquals( "property", implicitTarget.getTasks()[0].getName() );
  
          final Target target = project.getTarget( "main-target" );
          assertEquals( 1, target.getTasks().length );
          assertEquals( "log", target.getTasks()[0].getName() );
      }
  
      /**
       * Tests that a listener can be created.
       */
      public void testCreateListener() throws Exception
      {
          final ProjectListener listener = m_embeddor.createListener( "default" );
      }
  
      /**
       * Tests that a workspace can execute a project file.
       */
      public void testWorkspaceCreate() throws Exception
      {
          // Build the project
          final File projectFile = getTestResource( "project-builder.ant" );
          final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(),
null, null );
  
          // Build the workspace
          final Workspace workspace = m_embeddor.createWorkspace( new Parameters() );
  
          // Install a listener
          final TrackingProjectListener listener = new TrackingProjectListener();
          workspace.addProjectListener( listener );
  
          listener.addExpectedMessage( "main-target", "A log message" );
  
          // Execute the default target
          final String target = project.getDefaultTargetName();
          workspace.executeProject( project, target );
  
          // Cleanup
          listener.assertComplete();
      }
  }
  
  
  

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


Mime
View raw message