targets from project files. * AbstractMyrmidonTest.getTestResource() now asserts that the resource exists. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271458 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -45,12 +45,14 @@ public abstract class AbstractMyrmidonTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Locates a test resource. | |||||
| * Locates a test resource, and asserts that the resource exists | |||||
| */ | */ | ||||
| protected File getTestResource( final String name ) | protected File getTestResource( final String name ) | ||||
| { | { | ||||
| final File file = new File( m_testBaseDir, name ); | |||||
| return getCanonicalFile( file ); | |||||
| File file = new File( m_testBaseDir, name ); | |||||
| file = getCanonicalFile( file ); | |||||
| assertTrue( "Test file \"" + file + "\" does not exist.", file.exists() ); | |||||
| return file; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,80 @@ | |||||
| /* | |||||
| * 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.io.File; | |||||
| import org.apache.myrmidon.components.embeddor.DefaultEmbeddor; | |||||
| import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||||
| import org.apache.myrmidon.interfaces.model.Project; | |||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.avalon.framework.parameters.Parameters; | |||||
| /** | |||||
| * A base class for test cases which need to execute projects. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class AbstractProjectTest | |||||
| extends AbstractMyrmidonTest | |||||
| { | |||||
| private DefaultEmbeddor m_embeddor; | |||||
| public AbstractProjectTest( final String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| /** | |||||
| * Tear-down the test. | |||||
| */ | |||||
| protected void tearDown() throws Exception | |||||
| { | |||||
| if( m_embeddor != null ) | |||||
| { | |||||
| m_embeddor.dispose(); | |||||
| m_embeddor = null; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns an embeddor which can be used to build and execute projects. | |||||
| */ | |||||
| protected Embeddor getEmbeddor() throws Exception | |||||
| { | |||||
| if( m_embeddor == null ) | |||||
| { | |||||
| 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(); | |||||
| } | |||||
| return m_embeddor; | |||||
| } | |||||
| /** | |||||
| * Executes a target in a project, and asserts that it does not fail | |||||
| */ | |||||
| protected void executeTarget( final File projectFile, final String targetName ) | |||||
| throws Exception | |||||
| { | |||||
| final Embeddor embeddor = getEmbeddor(); | |||||
| final Project project = embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final Workspace workspace = embeddor.createWorkspace( new Parameters() ); | |||||
| workspace.executeProject( project, targetName ); | |||||
| } | |||||
| } | |||||
| @@ -119,8 +119,6 @@ public class DefaultDeployerTest | |||||
| public void testLibDescriptor() throws Exception | public void testLibDescriptor() throws Exception | ||||
| { | { | ||||
| final File typelib = getTestResource( "test.atl" ); | final File typelib = getTestResource( "test.atl" ); | ||||
| assertTrue( "File " + typelib + " does not exist", typelib.exists() ); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( typelib ); | final TypeDeployer typeDeployer = m_deployer.createDeployer( typelib ); | ||||
| // Make sure the test types have not been deployed | // Make sure the test types have not been deployed | ||||
| @@ -12,9 +12,11 @@ import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.avalon.framework.parameters.Parameters; | import org.apache.avalon.framework.parameters.Parameters; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| import org.apache.myrmidon.TrackingProjectListener; | import org.apache.myrmidon.TrackingProjectListener; | ||||
| import org.apache.myrmidon.AbstractProjectTest; | |||||
| import org.apache.myrmidon.interfaces.model.Project; | import org.apache.myrmidon.interfaces.model.Project; | ||||
| import org.apache.myrmidon.interfaces.model.Target; | import org.apache.myrmidon.interfaces.model.Target; | ||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | import org.apache.myrmidon.interfaces.workspace.Workspace; | ||||
| import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||||
| import org.apache.myrmidon.listeners.ProjectListener; | import org.apache.myrmidon.listeners.ProjectListener; | ||||
| /** | /** | ||||
| @@ -24,51 +26,21 @@ import org.apache.myrmidon.listeners.ProjectListener; | |||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| public class DefaultEmbeddorTest | public class DefaultEmbeddorTest | ||||
| extends AbstractMyrmidonTest | |||||
| extends AbstractProjectTest | |||||
| { | { | ||||
| private DefaultEmbeddor m_embeddor; | |||||
| public DefaultEmbeddorTest( String name ) | public DefaultEmbeddorTest( String name ) | ||||
| { | { | ||||
| super( 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. | * Tests that a project is successfully built from a file. | ||||
| */ | */ | ||||
| public void testProjectBuilder() throws Exception | public void testProjectBuilder() throws Exception | ||||
| { | { | ||||
| final File projectFile = getTestResource( "project-builder.ant" ); | |||||
| assertTrue( "Project file \"" + projectFile + "\" does not exist.", projectFile.exists() ); | |||||
| // Build the project | // Build the project | ||||
| final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final File projectFile = getTestResource( "project-builder.ant" ); | |||||
| final Project project = getEmbeddor().createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| // Verify the project. | // Verify the project. | ||||
| assertEquals( "test-project", project.getProjectName() ); | assertEquals( "test-project", project.getProjectName() ); | ||||
| @@ -92,7 +64,7 @@ public class DefaultEmbeddorTest | |||||
| */ | */ | ||||
| public void testCreateListener() throws Exception | public void testCreateListener() throws Exception | ||||
| { | { | ||||
| final ProjectListener listener = m_embeddor.createListener( "default" ); | |||||
| final ProjectListener listener = getEmbeddor().createListener( "default" ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -102,10 +74,11 @@ public class DefaultEmbeddorTest | |||||
| { | { | ||||
| // Build the project | // Build the project | ||||
| final File projectFile = getTestResource( "project-builder.ant" ); | final File projectFile = getTestResource( "project-builder.ant" ); | ||||
| final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final Embeddor embeddor = getEmbeddor(); | |||||
| final Project project = embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| // Build the workspace | // Build the workspace | ||||
| final Workspace workspace = m_embeddor.createWorkspace( new Parameters() ); | |||||
| final Workspace workspace = embeddor.createWorkspace( new Parameters() ); | |||||
| // Install a listener | // Install a listener | ||||
| final TrackingProjectListener listener = new TrackingProjectListener(); | final TrackingProjectListener listener = new TrackingProjectListener(); | ||||
| @@ -63,7 +63,6 @@ public class TypeFactoryTest | |||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| final File file = getTestResource( "types.jar" ); | final File file = getTestResource( "types.jar" ); | ||||
| assertTrue( "Support Jar " + file + " exists", file.exists() ); | |||||
| final URL[] classpath = new URL[]{file.toURL()}; | final URL[] classpath = new URL[]{file.toURL()}; | ||||
| final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null ); | final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null ); | ||||
| @@ -45,12 +45,14 @@ public abstract class AbstractMyrmidonTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Locates a test resource. | |||||
| * Locates a test resource, and asserts that the resource exists | |||||
| */ | */ | ||||
| protected File getTestResource( final String name ) | protected File getTestResource( final String name ) | ||||
| { | { | ||||
| final File file = new File( m_testBaseDir, name ); | |||||
| return getCanonicalFile( file ); | |||||
| File file = new File( m_testBaseDir, name ); | |||||
| file = getCanonicalFile( file ); | |||||
| assertTrue( "Test file \"" + file + "\" does not exist.", file.exists() ); | |||||
| return file; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,80 @@ | |||||
| /* | |||||
| * 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.io.File; | |||||
| import org.apache.myrmidon.components.embeddor.DefaultEmbeddor; | |||||
| import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||||
| import org.apache.myrmidon.interfaces.model.Project; | |||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.avalon.framework.parameters.Parameters; | |||||
| /** | |||||
| * A base class for test cases which need to execute projects. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class AbstractProjectTest | |||||
| extends AbstractMyrmidonTest | |||||
| { | |||||
| private DefaultEmbeddor m_embeddor; | |||||
| public AbstractProjectTest( final String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| /** | |||||
| * Tear-down the test. | |||||
| */ | |||||
| protected void tearDown() throws Exception | |||||
| { | |||||
| if( m_embeddor != null ) | |||||
| { | |||||
| m_embeddor.dispose(); | |||||
| m_embeddor = null; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Returns an embeddor which can be used to build and execute projects. | |||||
| */ | |||||
| protected Embeddor getEmbeddor() throws Exception | |||||
| { | |||||
| if( m_embeddor == null ) | |||||
| { | |||||
| 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(); | |||||
| } | |||||
| return m_embeddor; | |||||
| } | |||||
| /** | |||||
| * Executes a target in a project, and asserts that it does not fail | |||||
| */ | |||||
| protected void executeTarget( final File projectFile, final String targetName ) | |||||
| throws Exception | |||||
| { | |||||
| final Embeddor embeddor = getEmbeddor(); | |||||
| final Project project = embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final Workspace workspace = embeddor.createWorkspace( new Parameters() ); | |||||
| workspace.executeProject( project, targetName ); | |||||
| } | |||||
| } | |||||
| @@ -119,8 +119,6 @@ public class DefaultDeployerTest | |||||
| public void testLibDescriptor() throws Exception | public void testLibDescriptor() throws Exception | ||||
| { | { | ||||
| final File typelib = getTestResource( "test.atl" ); | final File typelib = getTestResource( "test.atl" ); | ||||
| assertTrue( "File " + typelib + " does not exist", typelib.exists() ); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( typelib ); | final TypeDeployer typeDeployer = m_deployer.createDeployer( typelib ); | ||||
| // Make sure the test types have not been deployed | // Make sure the test types have not been deployed | ||||
| @@ -12,9 +12,11 @@ import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.avalon.framework.parameters.Parameters; | import org.apache.avalon.framework.parameters.Parameters; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| import org.apache.myrmidon.TrackingProjectListener; | import org.apache.myrmidon.TrackingProjectListener; | ||||
| import org.apache.myrmidon.AbstractProjectTest; | |||||
| import org.apache.myrmidon.interfaces.model.Project; | import org.apache.myrmidon.interfaces.model.Project; | ||||
| import org.apache.myrmidon.interfaces.model.Target; | import org.apache.myrmidon.interfaces.model.Target; | ||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | import org.apache.myrmidon.interfaces.workspace.Workspace; | ||||
| import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||||
| import org.apache.myrmidon.listeners.ProjectListener; | import org.apache.myrmidon.listeners.ProjectListener; | ||||
| /** | /** | ||||
| @@ -24,51 +26,21 @@ import org.apache.myrmidon.listeners.ProjectListener; | |||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| public class DefaultEmbeddorTest | public class DefaultEmbeddorTest | ||||
| extends AbstractMyrmidonTest | |||||
| extends AbstractProjectTest | |||||
| { | { | ||||
| private DefaultEmbeddor m_embeddor; | |||||
| public DefaultEmbeddorTest( String name ) | public DefaultEmbeddorTest( String name ) | ||||
| { | { | ||||
| super( 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. | * Tests that a project is successfully built from a file. | ||||
| */ | */ | ||||
| public void testProjectBuilder() throws Exception | public void testProjectBuilder() throws Exception | ||||
| { | { | ||||
| final File projectFile = getTestResource( "project-builder.ant" ); | |||||
| assertTrue( "Project file \"" + projectFile + "\" does not exist.", projectFile.exists() ); | |||||
| // Build the project | // Build the project | ||||
| final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final File projectFile = getTestResource( "project-builder.ant" ); | |||||
| final Project project = getEmbeddor().createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| // Verify the project. | // Verify the project. | ||||
| assertEquals( "test-project", project.getProjectName() ); | assertEquals( "test-project", project.getProjectName() ); | ||||
| @@ -92,7 +64,7 @@ public class DefaultEmbeddorTest | |||||
| */ | */ | ||||
| public void testCreateListener() throws Exception | public void testCreateListener() throws Exception | ||||
| { | { | ||||
| final ProjectListener listener = m_embeddor.createListener( "default" ); | |||||
| final ProjectListener listener = getEmbeddor().createListener( "default" ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -102,10 +74,11 @@ public class DefaultEmbeddorTest | |||||
| { | { | ||||
| // Build the project | // Build the project | ||||
| final File projectFile = getTestResource( "project-builder.ant" ); | final File projectFile = getTestResource( "project-builder.ant" ); | ||||
| final Project project = m_embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| final Embeddor embeddor = getEmbeddor(); | |||||
| final Project project = embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
| // Build the workspace | // Build the workspace | ||||
| final Workspace workspace = m_embeddor.createWorkspace( new Parameters() ); | |||||
| final Workspace workspace = embeddor.createWorkspace( new Parameters() ); | |||||
| // Install a listener | // Install a listener | ||||
| final TrackingProjectListener listener = new TrackingProjectListener(); | final TrackingProjectListener listener = new TrackingProjectListener(); | ||||
| @@ -63,7 +63,6 @@ public class TypeFactoryTest | |||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| final File file = getTestResource( "types.jar" ); | final File file = getTestResource( "types.jar" ); | ||||
| assertTrue( "Support Jar " + file + " exists", file.exists() ); | |||||
| final URL[] classpath = new URL[]{file.toURL()}; | final URL[] classpath = new URL[]{file.toURL()}; | ||||
| final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null ); | final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null ); | ||||