* 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. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271443 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -384,6 +384,7 @@ Legal: | |||||
| <ant antfile="antlib.xml"> | <ant antfile="antlib.xml"> | ||||
| <property name="antlib.name" value="sound"/> | <property name="antlib.name" value="sound"/> | ||||
| </ant> | </ant> | ||||
| <!-- | <!-- | ||||
| <ant antfile="antlib.xml"> | <ant antfile="antlib.xml"> | ||||
| <property name="antlib.name" value="vfile"/> | <property name="antlib.name" value="vfile"/> | ||||
| @@ -412,7 +413,7 @@ Legal: | |||||
| </target> | </target> | ||||
| <!-- Compiles and runs the unit tests --> | <!-- 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 --> | <!-- Compile the unit tests --> | ||||
| <mkdir dir="${test.classes}"/> | <mkdir dir="${test.classes}"/> | ||||
| <javac srcdir="src/testcases" | <javac srcdir="src/testcases" | ||||
| @@ -429,6 +430,11 @@ Legal: | |||||
| <fileset dir="etc/testcases"/> | <fileset dir="etc/testcases"/> | ||||
| </copy> | </copy> | ||||
| <!-- Prepare a dummy installation --> | |||||
| <copy todir="${test.working.dir}/dist"> | |||||
| <fileset dir="${dist.dir}"/> | |||||
| </copy> | |||||
| <!-- Prepare the VFS tests --> | <!-- Prepare the VFS tests --> | ||||
| <property name="test.vfs.dir" location="${test.working.dir}/org/apache/aut/vfs"/> | <property name="test.vfs.dir" location="${test.working.dir}/org/apache/aut/vfs"/> | ||||
| <mkdir dir="${test.vfs.dir}/basedir/emptydir"/> | <mkdir dir="${test.vfs.dir}/basedir/emptydir"/> | ||||
| @@ -455,7 +461,10 @@ Legal: | |||||
| <junit printsummary="on" | <junit printsummary="on" | ||||
| fork="true"> | fork="true"> | ||||
| <formatter type="brief" usefile="false"/> | <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}"/> | <classpath location="${test.classes}"/> | ||||
| <!-- Pass config to the tests --> | <!-- Pass config to the tests --> | ||||
| @@ -0,0 +1,6 @@ | |||||
| <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> | |||||
| @@ -287,10 +287,10 @@ public class DefaultEmbeddor | |||||
| filepath = getParameter( "myrmidon.home" ); | filepath = getParameter( "myrmidon.home" ); | ||||
| m_homeDir = ( new File( filepath ) ).getAbsoluteFile(); | m_homeDir = ( new File( filepath ) ).getAbsoluteFile(); | ||||
| checkDirectory( m_homeDir, "home" ); | |||||
| checkDirectory( m_homeDir, "home-dir.name" ); | |||||
| filepath = getParameter( "myrmidon.lib.path" ); | filepath = getParameter( "myrmidon.lib.path" ); | ||||
| m_taskLibDir = resolveDirectory( filepath, "task-lib-dir" ); | |||||
| m_taskLibDir = resolveDirectory( filepath, "task-lib-dir.name" ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -339,12 +339,14 @@ public class DefaultEmbeddor | |||||
| { | { | ||||
| if( !file.exists() ) | 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 ); | throw new Exception( message ); | ||||
| } | } | ||||
| else if( !file.isDirectory() ) | 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 ); | throw new Exception( message ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -5,3 +5,5 @@ bad-ctor.error=Non-public constructor for {0} {1}. | |||||
| no-instantiate.error=Error instantiating class for {0} {1}. | no-instantiate.error=Error instantiating class for {0} {1}. | ||||
| no-class.error=Could not find the 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}. | bad-filename.error=Unable to retrieve filename for file {0}. | ||||
| home-dir.name=Myrmidon home directory | |||||
| task-lib-dir.name=Task library directory | |||||
| @@ -134,7 +134,7 @@ public class DefaultWorkspace | |||||
| m_listenerSupport.projectStarted( project.getProjectName() ); | m_listenerSupport.projectStarted( project.getProjectName() ); | ||||
| executeTarget( "<init>", project.getImplicitTarget(), entry.getFrame() ); | |||||
| executeTarget( project, "<init>", project.getImplicitTarget(), entry.getFrame() ); | |||||
| execute( project, target, entry ); | execute( project, target, entry ); | ||||
| @@ -370,13 +370,7 @@ public class DefaultWorkspace | |||||
| } | } | ||||
| } | } | ||||
| //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 @@ public class DefaultWorkspace | |||||
| * @param frame the frame in which to execute | * @param frame the frame in which to execute | ||||
| * @exception TaskException if an error occurs | * @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 Target target, | ||||
| final ExecutionFrame frame ) | final ExecutionFrame frame ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| //notify listeners | |||||
| m_listenerSupport.targetStarted( project.getProjectName(), name ); | |||||
| //check the condition associated with target. | //check the condition associated with target. | ||||
| //if it is not satisfied then skip target | //if it is not satisfied then skip target | ||||
| final Condition condition = target.getCondition(); | final Condition condition = target.getCondition(); | ||||
| @@ -426,6 +424,9 @@ public class DefaultWorkspace | |||||
| { | { | ||||
| executeTask( tasks[ i ], frame ); | executeTask( tasks[ i ], frame ); | ||||
| } | } | ||||
| //notify listeners | |||||
| m_listenerSupport.targetFinished(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -110,7 +110,6 @@ public class ProjectListenerSupport | |||||
| { | { | ||||
| m_projectName = projectName; | m_projectName = projectName; | ||||
| m_targetName = targetName; | m_targetName = targetName; | ||||
| ; | |||||
| m_taskName = null; | m_taskName = null; | ||||
| for( int i = 0; i < m_listeners.length; i++ ) | for( int i = 0; i < m_listeners.length; i++ ) | ||||
| @@ -7,8 +7,16 @@ | |||||
| */ | */ | ||||
| package org.apache.myrmidon; | package org.apache.myrmidon; | ||||
| import junit.framework.TestCase; | |||||
| import java.io.File; | 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 | * A base class for Myrmidon tests. Provides utility methods for locating | ||||
| @@ -20,16 +28,20 @@ public abstract class AbstractMyrmidonTest | |||||
| extends TestCase | extends TestCase | ||||
| { | { | ||||
| private final File m_testBaseDir; | 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 ) | public AbstractMyrmidonTest( String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| final String baseDirProp = System.getProperty( "test.basedir" ); | final String baseDirProp = System.getProperty( "test.basedir" ); | ||||
| m_baseDir = new File( baseDirProp ); | |||||
| String packagePath = getClass().getName(); | String packagePath = getClass().getName(); | ||||
| int idx = packagePath.lastIndexOf('.'); | int idx = packagePath.lastIndexOf('.'); | ||||
| packagePath = packagePath.substring(0, idx); | packagePath = packagePath.substring(0, idx); | ||||
| packagePath = packagePath.replace('.', File.separatorChar); | packagePath = packagePath.replace('.', File.separatorChar); | ||||
| m_testBaseDir = new File( baseDirProp, packagePath ).getAbsoluteFile(); | |||||
| m_testBaseDir = new File( m_baseDir, packagePath ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -37,7 +49,49 @@ public abstract class AbstractMyrmidonTest | |||||
| */ | */ | ||||
| protected File getTestResource( final String name ) | 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 ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,145 @@ | |||||
| /* | |||||
| * 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$ $Date$ | |||||
| */ | |||||
| 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 ); | |||||
| } | |||||
| } | |||||
| @@ -10,42 +10,35 @@ package org.apache.myrmidon.components; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import junit.framework.TestCase; | |||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
| import org.apache.avalon.framework.component.ComponentManager; | import org.apache.avalon.framework.component.ComponentManager; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | import org.apache.avalon.framework.component.DefaultComponentManager; | ||||
| import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | 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.configurer.DefaultConfigurer; | ||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | ||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | 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.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.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | 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.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.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | 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.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. | * A base class for tests for the default components. | ||||
| @@ -58,8 +51,6 @@ public abstract class AbstractComponentTest | |||||
| private DefaultComponentManager m_componentManager; | private DefaultComponentManager m_componentManager; | ||||
| private Logger m_logger; | private Logger m_logger; | ||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public AbstractComponentTest( final String name ) | public AbstractComponentTest( final String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| @@ -87,16 +78,7 @@ public abstract class AbstractComponentTest | |||||
| protected void setUp() | protected void setUp() | ||||
| throws Exception | 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 | // Create the components | ||||
| m_componentManager = new DefaultComponentManager(); | m_componentManager = new DefaultComponentManager(); | ||||
| @@ -162,6 +144,7 @@ public abstract class AbstractComponentTest | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Utility method to register a Converter. | * Utility method to register a Converter. | ||||
| */ | */ | ||||
| @@ -0,0 +1,123 @@ | |||||
| /* | |||||
| * 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$ $Date$ | |||||
| */ | |||||
| 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(); | |||||
| } | |||||
| } | |||||
| @@ -7,8 +7,16 @@ | |||||
| */ | */ | ||||
| package org.apache.myrmidon; | package org.apache.myrmidon; | ||||
| import junit.framework.TestCase; | |||||
| import java.io.File; | 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 | * A base class for Myrmidon tests. Provides utility methods for locating | ||||
| @@ -20,16 +28,20 @@ public abstract class AbstractMyrmidonTest | |||||
| extends TestCase | extends TestCase | ||||
| { | { | ||||
| private final File m_testBaseDir; | 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 ) | public AbstractMyrmidonTest( String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| final String baseDirProp = System.getProperty( "test.basedir" ); | final String baseDirProp = System.getProperty( "test.basedir" ); | ||||
| m_baseDir = new File( baseDirProp ); | |||||
| String packagePath = getClass().getName(); | String packagePath = getClass().getName(); | ||||
| int idx = packagePath.lastIndexOf('.'); | int idx = packagePath.lastIndexOf('.'); | ||||
| packagePath = packagePath.substring(0, idx); | packagePath = packagePath.substring(0, idx); | ||||
| packagePath = packagePath.replace('.', File.separatorChar); | packagePath = packagePath.replace('.', File.separatorChar); | ||||
| m_testBaseDir = new File( baseDirProp, packagePath ).getAbsoluteFile(); | |||||
| m_testBaseDir = new File( m_baseDir, packagePath ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -37,7 +49,49 @@ public abstract class AbstractMyrmidonTest | |||||
| */ | */ | ||||
| protected File getTestResource( final String name ) | 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 ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,145 @@ | |||||
| /* | |||||
| * 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$ $Date$ | |||||
| */ | |||||
| 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 ); | |||||
| } | |||||
| } | |||||
| @@ -10,42 +10,35 @@ package org.apache.myrmidon.components; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import junit.framework.TestCase; | |||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
| import org.apache.avalon.framework.component.ComponentManager; | import org.apache.avalon.framework.component.ComponentManager; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | import org.apache.avalon.framework.component.DefaultComponentManager; | ||||
| import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | 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.configurer.DefaultConfigurer; | ||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | ||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | 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.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.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | 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.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.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | 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.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. | * A base class for tests for the default components. | ||||
| @@ -58,8 +51,6 @@ public abstract class AbstractComponentTest | |||||
| private DefaultComponentManager m_componentManager; | private DefaultComponentManager m_componentManager; | ||||
| private Logger m_logger; | private Logger m_logger; | ||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public AbstractComponentTest( final String name ) | public AbstractComponentTest( final String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| @@ -87,16 +78,7 @@ public abstract class AbstractComponentTest | |||||
| protected void setUp() | protected void setUp() | ||||
| throws Exception | 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 | // Create the components | ||||
| m_componentManager = new DefaultComponentManager(); | m_componentManager = new DefaultComponentManager(); | ||||
| @@ -162,6 +144,7 @@ public abstract class AbstractComponentTest | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Utility method to register a Converter. | * Utility method to register a Converter. | ||||
| */ | */ | ||||
| @@ -0,0 +1,123 @@ | |||||
| /* | |||||
| * 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$ $Date$ | |||||
| */ | |||||
| 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(); | |||||
| } | |||||
| } | |||||