donaldp 02/04/14 02:33:14
Added: framework/src/test/org/apache/myrmidon
AbstractMyrmidonTest.java AbstractProjectTest.java
LogMessageTracker.java TrackingProjectListener.java
framework/src/test/org/apache/myrmidon/framework/conditions/test
AndConditionTestCase.java ConditionTestTask.java
IsSetConditionTestCase.java
IsTrueConditionTestCase.java
NotConditionTestCase.java OrConditionTestCase.java
TestCondition.java and.ant isset.ant istrue.ant
not.ant or.ant
framework/src/test/org/apache/myrmidon/framework/file/test
PathTestCase.java TestFileList.java path.ant
Log:
Add the unit tests now.
Revision Changes Path
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/AbstractMyrmidonTest.java
Index: AbstractMyrmidonTest.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.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.avalon.framework.logger.Logger;
import org.apache.myrmidon.interfaces.BasicLogger;
/**
* A base class for Myrmidon tests. Provides utility methods for locating
* test resources.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
*/
public abstract class AbstractMyrmidonTest
extends TestCase
{
private final File m_testBaseDir;
private final File m_baseDir;
private Logger m_logger;
public AbstractMyrmidonTest( final String name )
{
super( name );
final String baseDirProp = System.getProperty( "test.basedir" );
m_baseDir = getCanonicalFile( new File( baseDirProp ) );
final String packagePath = getPackageName( getClass() ).replace( '.',
File.separatorChar );
m_testBaseDir = getCanonicalFile( new File( m_baseDir, packagePath )
);
}
/**
* Locates the error message resources for a class.
*/
protected static final Resources getResourcesForTested( final Class clazz
)
{
String baseName = getPackageName( clazz );
if( baseName.endsWith( ".test" ) )
{
baseName = baseName.substring( 0, baseName.length() - 5 );
}
return ResourceManager.getBaseResources( baseName + ".Resources",
AbstractMyrmidonTest.class.getClassLoader() );
}
/**
* Returns the name of the package containing a class.
*
* @return The . delimited package name, or an empty string if the class
* is in the default package.
*/
protected static String getPackageName( final Class clazz )
{
final Package pkg = clazz.getPackage();
if( null != pkg )
{
return pkg.getName();
}
final String name = clazz.getName();
if( -1 == name.lastIndexOf( "." ) )
{
return "";
}
else
{
return name.substring( 0, name.lastIndexOf( "." ) );
}
}
/**
* Locates a test resource, and asserts that the resource exists
*
* @param name path of the resource, relative to this test's base
directory.
*/
protected File getTestResource( final String name )
{
return getTestResource( name, true );
}
/**
* Locates a test resource.
*
* @param name path of the resource, relative to this test's base
directory.
*/
protected File getTestResource( final String name, final boolean
mustExist )
{
File file = new File( m_testBaseDir, name );
file = getCanonicalFile( file );
if( mustExist )
{
assertTrue( "Test file \"" + file + "\" does not exist.",
file.exists() );
}
else
{
assertTrue( "Test file \"" + file + "\" should not exist.",
!file.exists() );
}
return file;
}
/**
* Locates the base directory for this test.
*/
protected File getTestDirectory()
{
return m_testBaseDir;
}
/**
* Locates a test directory, creating it if it does not exist.
*
* @param name path of the directory, relative to this test's base
directory.
*/
protected File getTestDirectory( final String name )
{
File file = new File( m_testBaseDir, name );
file = getCanonicalFile( file );
assertTrue( "Test directory \"" + file + "\" does not exist or is not
a directory.",
file.isDirectory() || file.mkdirs() );
return file;
}
/**
* Returns the directory containing a Myrmidon install.
*/
protected File getInstallDirectory()
{
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 getLogger()
{
if( m_logger == null )
{
m_logger = new BasicLogger( "[test]", BasicLogger.LEVEL_WARN );
}
return m_logger;
}
/**
* Asserts that an exception chain contains the expected messages.
*
* @param messages The messages, in order. A null entry in this array
* indicates that the message should be ignored.
*/
protected void assertSameMessage( final String[] messages, final
Throwable throwable )
{
Throwable current = throwable;
for( int i = 0; i < messages.length; i++ )
{
String message = messages[ i ];
assertNotNull( current );
if( message != null )
{
assertEquals( message, current.getMessage() );
}
// Get the next exception in the chain
current = ExceptionUtil.getCause( current, true );
}
}
/**
* Asserts that an exception contains the expected message.
*/
protected void assertSameMessage( final String message, final Throwable
throwable )
{
assertSameMessage( new String[]{message}, throwable );
}
/**
* Compares 2 objects for equality, nulls are equal. Used by the test
* classes' equals() methods.
*/
public static boolean equals( final Object o1, final Object o2 )
{
if( o1 == null && o2 == null )
{
return true;
}
if( o1 == null || o2 == null )
{
return false;
}
return o1.equals( o2 );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/AbstractProjectTest.java
Index: AbstractProjectTest.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.io.File;
import org.apache.myrmidon.interfaces.EmbeddedAnt;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.avalon.framework.ExceptionUtil;
/**
* A base class for test cases which need to execute projects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class AbstractProjectTest
extends AbstractMyrmidonTest
{
public AbstractProjectTest( final String name )
{
super( name );
}
/**
* Executes a target in a project, and asserts that it fails with the
* given error message.
*/
protected void executeTargetExpectError( final File projectFile,
final String targetName,
final String message )
{
executeTargetExpectError( projectFile, targetName, new
String[]{message} );
}
/**
* Executes a target in a project, and asserts that it fails with the
* given error messages.
*/
protected void executeTargetExpectError( final File projectFile,
final String targetName,
final String[] messages )
{
try
{
executeTarget( projectFile, targetName, null );
fail( "target execution did not fail" );
}
catch( Exception e )
{
assertSameMessage( messages, e );
}
}
/**
* Executes a target in a project, and asserts that it does not fail.
*/
protected void executeTarget( final File projectFile, final String
targetName )
throws Exception
{
executeTarget( projectFile, targetName, null );
}
/**
* Executes a target in a project, and asserts that it does not fail.
*/
protected void executeTarget( final File projectFile,
final String targetName,
final ProjectListener listener )
throws Exception
{
final EmbeddedAnt embeddor = new EmbeddedAnt();
final TrackingProjectListener tracker = new TrackingProjectListener();
try
{
// Configure embeddor
embeddor.setHomeDirectory( getInstallDirectory() );
embeddor.enableLogging( getLogger() );
embeddor.setSharedClassLoader( getClass().getClassLoader() );
embeddor.setProjectFile( projectFile.getAbsolutePath() );
embeddor.setProjectListener( null );
// Add a listener to make sure all is good
embeddor.addProjectListener( tracker );
// Add supplied listener
if( listener != null )
{
embeddor.addProjectListener( listener );
}
// Now execute the target
embeddor.executeTargets( new String[] { targetName } );
}
finally
{
embeddor.stop();
}
// Make sure all expected events were delivered
tracker.assertComplete();
if( listener instanceof TrackingProjectListener )
{
( (TrackingProjectListener)listener ).assertComplete();
}
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/LogMessageTracker.java
Index: LogMessageTracker.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.List;
import org.apache.myrmidon.listeners.LogEvent;
/**
* Asserts that log messages are delivered in the correct order.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class LogMessageTracker
extends TrackingProjectListener
{
private List m_targets = new ArrayList();
private List m_messages = new ArrayList();
/**
* Handles a log message.
*/
public void log( final LogEvent event )
{
super.log( event );
// Pop the next expected message off the list, and make sure it
// matches the message in the event
assertTrue( "Unexpected log message", m_targets.size() > 0 &&
m_messages.size() > 0 );
assertEquals( "Unexpected log message", m_targets.remove( 0 ),
event.getTargetName() );
assertEquals( "Unexpected log message", m_messages.remove( 0 ),
event.getMessage() );
}
/**
* Asserts that all the log messages were delivered.
*/
public void assertComplete()
{
super.assertComplete();
// Make sure that all log messages were delivered
assertTrue( "Log message not delivered", m_targets.size() == 0 &&
m_messages.size() == 0 );
}
/**
* Adds an expected log message.
*/
public void addExpectedMessage( String target, String message )
{
m_targets.add( target );
m_messages.add( message );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/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 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:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class TrackingProjectListener
extends Assert
implements ProjectListener
{
private String m_rootProject;
private String m_currentProject;
private String m_currentTarget;
private String m_currentTask;
/**
* 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();
}
/**
* 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;
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() );
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 );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/AndConditionTestCase.java
Index: AndConditionTestCase.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.framework.conditions.test;
import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
/**
* Test cases for the <and> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class AndConditionTestCase
extends AbstractProjectTest
{
public AndConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of the <and> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "and.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/ConditionTestTask.java
Index: ConditionTestTask.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.framework.conditions.test;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.conditions.Condition;
/**
* A simple assert task, used for testing conditions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*
* @ant.task name="assert"
*/
public class ConditionTestTask
extends AbstractTask
{
private boolean m_expected = true;
private Condition m_condition;
public void setExpected( final boolean expected )
{
m_expected = expected;
}
public void add( final Condition condition )
{
m_condition = condition;
}
/**
* Execute task.
*/
public void execute()
throws TaskException
{
final boolean result = m_condition.evaluate( getContext() );
if( result != m_expected )
{
throw new TaskException( "Expected " + m_expected + ", got " +
result );
}
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/IsSetConditionTestCase.java
Index: IsSetConditionTestCase.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.framework.conditions.test;
import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsSetCondition;
/**
* Test cases for the <is-set> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class IsSetConditionTestCase
extends AbstractProjectTest
{
public IsSetConditionTestCase( final String name )
{
super( name );
}
/**
* Test cases for <is-set> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "isset.ant" );
executeTarget( projectFile, "set" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );
Resources res = getResourcesForTested( IsSetCondition.class );
final String[] messages = {
null,
res.getString( "isset.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/IsTrueConditionTestCase.java
Index: IsTrueConditionTestCase.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.framework.conditions.test;
import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsTrueCondition;
/**
* Test cases for the <is-true> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class IsTrueConditionTestCase
extends AbstractProjectTest
{
public IsTrueConditionTestCase( final String name )
{
super( name );
}
/**
* Test cases for <is-true> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "istrue.ant" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );
// TODO - check error message
String[] messages = {};
executeTargetExpectError( projectFile, "set", messages );
final Resources res = getResourcesForTested( IsTrueCondition.class );
messages = new String[] {
null,
res.getString( "istrue.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/NotConditionTestCase.java
Index: NotConditionTestCase.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.framework.conditions.test;
import org.apache.myrmidon.AbstractProjectTest;
import java.io.File;
/**
* Test cases for the <not> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class NotConditionTestCase
extends AbstractProjectTest
{
public NotConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of <not>.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "not.ant" );
executeTarget( projectFile, "truth-table" );
// TODO - check error messages
executeTargetExpectError( projectFile, "empty", new String[0] );
executeTargetExpectError( projectFile, "too-many-nested", new
String[0] );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/OrConditionTestCase.java
Index: OrConditionTestCase.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.framework.conditions.test;
import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
/**
* Test cases for the <or> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class OrConditionTestCase
extends AbstractProjectTest
{
public OrConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of the <or> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "or.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/TestCondition.java
Index: TestCondition.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.framework.conditions.test;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* A condition used for testing.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*
* @ant.type type="condition" name="true"
* @ant.type type="condition" name="false"
* @ant.type type="condition" name="fail"
*/
public class TestCondition
implements Condition, Configurable
{
private String m_action;
public void configure( final Configuration configuration )
throws ConfigurationException
{
m_action = configuration.getName();
}
/**
* Evaluates this condition.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
if( m_action.equalsIgnoreCase( "true" ) )
{
return true;
}
else if( m_action.equalsIgnoreCase( "false" ) )
{
return false;
}
else
{
throw new TaskException( "Fail." );
}
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/and.ant
Index: and.ant
===================================================================
<!-- Tests for the <and> condition. -->
<project version="2.0">
<!-- An empty <and> condition -->
<target name="empty">
<assert>
<and/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<and><false/></and>
</assert>
<assert>
<and><true/></and>
</assert>
<assert expected="false">
<and><false/><false/></and>
</assert>
<assert expected="false">
<and><true/><false/></and>
</assert>
<assert expected="false">
<and><false/><true/></and>
</assert>
<assert>
<and><true/><true/></and>
</assert>
</target>
<!-- Check lazy evaluation -->
<target name="lazy">
<assert expected="false">
<and><false/><fail/></and>
</assert>
</target>
</project>
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant
Index: isset.ant
===================================================================
<!-- Tests for the <is-set> condition. -->
<project version="2.0">
<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-set property="test-prop"/>
</assert>
</target>
<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-set/>
</assert>
</target>
</project>
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant
Index: istrue.ant
===================================================================
<!-- Tests for the <is-true> condition. -->
<project version="2.0">
<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-true property="test-prop"/>
</assert>
</target>
<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-true property="test-prop"/>
</assert>
</target>
<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>
<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>
<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-true/>
</assert>
</target>
</project>
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/not.ant
Index: not.ant
===================================================================
<!-- Tests for the <not> condition. -->
<project version="2.0">
<!-- An empty <or> condition -->
<target name="empty">
<assert>
<not/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<not><true/></not>
</assert>
<assert>
<not><false/></not>
</assert>
</target>
<!-- Too many nested conditions -->
<target name="too-many-nested">
<assert>
<not><true/><false/></not>
</assert>
</target>
</project>
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/conditions/test/or.ant
Index: or.ant
===================================================================
<!-- Tests for the <or> condition. -->
<project version="2.0">
<!-- An empty <or> condition -->
<target name="empty">
<assert>
<or/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<or><false/></or>
</assert>
<assert>
<or><true/></or>
</assert>
<assert expected="false">
<or><false/><false/></or>
</assert>
<assert>
<or><true/><false/></or>
</assert>
<assert>
<or><false/><true/></or>
</assert>
<assert>
<or><true/><true/></or>
</assert>
</target>
<!-- Check lazy evaluation -->
<target name="lazy">
<assert>
<or><true/><fail/></or>
</assert>
</target>
</project>
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/file/test/PathTestCase.java
Index: PathTestCase.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.framework.file.test;
import java.io.File;
import org.apache.aut.nativelib.PathUtil;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;
/**
* Test-cases for the <path> data type.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*/
public class PathTestCase
extends AbstractProjectTest
{
public PathTestCase( final String name )
{
super( name );
}
/**
* Tests setting the location attribute.
*/
public void testLocationAttribute() throws Exception
{
testPathContent( "set-location", new String[]{"location"} );
}
/**
* Tests setting the path attribute.
*/
public void testPathAttribute() throws Exception
{
// Test a path with a single file
testPathContent( "set-path", new String[]{"single-file"} );
// Test a path with several files, using ; separator
testPathContent( "set-multi-path", new String[]{"file1", "file2",
".."} );
// Test a path with several files, using : separator
testPathContent( "set-multi-path2", new String[]{"file1", "file2",
".."} );
}
/**
* Test using nested <path> elements.
*/
public void testPathElement() throws Exception
{
testPathContent( "nested-path", new String[]{"some-file"} );
testPathContent( "mixed-path", new String[]{"file1", "file2",
"file3", "file4", "file5"} );
}
/**
* Test using nested <fileset> elements.
*/
public void testFilesetElement() throws Exception
{
testPathContent( "set-fileset", new String[]{"path.ant"} );
}
/**
* Test using a nested custom file list implementation.
*/
public void testCustomFileList() throws Exception
{
testPathContent( "test-custom-file-list", new String[]{"file1"} );
}
/**
* Test converting between string and path.
*/
public void testConvert() throws Exception
{
testPathContent( "convert-string-to-path", new String[]{"file1",
"file2"} );
// Test conversion from path -> string
final File[] files = {
getTestResource( "file1", false ),
getTestResource( "file2", false )
};
final String path = PathUtil.formatPath( files );
final LogMessageTracker listener = new LogMessageTracker();
listener.addExpectedMessage( "convert-path-to-string", "test-path = "
+ path );
final File projectFile = getTestResource( "path.ant" );
executeTarget( projectFile, "convert-path-to-string", listener );
}
/**
* Executes a target, and asserts that a particular list of file names
* is logged.
*/
private void testPathContent( final String targetName,
final String[] files ) throws Exception
{
final File projectFile = getTestResource( "path.ant" );
final File baseDir = projectFile.getParentFile();
// Add each of the expected file names
final LogMessageTracker listener = new LogMessageTracker();
for( int i = 0; i < files.length; i++ )
{
final String fileName = files[ i ];
final File file = FileUtil.resolveFile( baseDir, fileName );
listener.addExpectedMessage( targetName, file.getAbsolutePath() );
}
// Execute the target
executeTarget( projectFile, targetName, listener );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/file/test/TestFileList.java
Index: TestFileList.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.framework.file.test;
import java.io.File;
import java.util.ArrayList;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.file.FileList;
import org.apache.myrmidon.framework.file.Path;
/**
* A test FileList implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/04/14 09:33:13 $
*
* @ant.type type="path" name="test-file-list"
*/
public class TestFileList
implements FileList
{
private String m_name;
private Path m_path;
public void setName( final String name )
{
m_name = name;
}
public void setPath( final Path path )
{
m_path = path;
}
/**
* Returns the files in this list.
*/
public String[] listFiles( final TaskContext context )
throws TaskException
{
final ArrayList files = new ArrayList();
if( m_name != null )
{
final File file = context.resolveFile( m_name );
files.add( file.getAbsolutePath() );
}
if( m_path != null )
{
final String[] fileNames = m_path.listFiles( context );
for( int i = 0; i < fileNames.length; i++ )
{
files.add( fileNames[ i ] );
}
}
return (String[])files.toArray( new String[ files.size() ] );
}
}
1.1
jakarta-ant-myrmidon/framework/src/test/org/apache/myrmidon/framework/file/test/path.ant
Index: path.ant
===================================================================
<project version="2.0">
<!-- Test setting the location attribute -->
<target name="set-location">
<list-path>
<path location="location"/>
</list-path>
</target>
<!-- Test setting the path attribute -->
<target name="set-path">
<list-path>
<path path="single-file"/>
</list-path>
</target>
<!-- Test setting the path attribute with ; delims -->
<target name="set-multi-path">
<list-path>
<path path="file1;file2;.."/>
</list-path>
</target>
<!-- Test setting the path attribute with : delims -->
<target name="set-multi-path2">
<list-path>
<path path="file1:file2:.."/>
</list-path>
</target>
<!-- Test using a nested <path> element -->
<target name="nested-path">
<list-path>
<path>
<path location="some-file"/>
</path>
</list-path>
</target>
<!-- Test using a mix of attributes and nested <path> elements -->
<target name="mixed-path">
<list-path>
<path location="file1" path="file2;file3">
<path location="file4"/>
<path location="file5"/>
</path>
</list-path>
</target>
<!-- Test using a nested fileset -->
<target name="set-fileset">
<list-path>
<path>
<fileset dir="." includes="**/path.ant"/>
</path>
</list-path>
</target>
<!-- Test using a custom file list implementation -->
<target name="test-custom-file-list">
<list-path>
<path>
<test-file-list name="file1"/>
</path>
</list-path>
</target>
<!-- Test converting a string to a path -->
<target name="convert-string-to-path">
<list-path>
<test-file-list path="file1;file2"/>
</list-path>
</target>
<!-- Test converting a path to a string -->
<target name="convert-path-to-string">
<path id="test-path" path="file1:file2"/>
<log>test-path = ${test-path}</log>
</target>
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>