adammurdoch 02/02/26 15:26:56
Modified: proposal/myrmidon build.xml
proposal/myrmidon/src/testcases/org/apache/myrmidon
AbstractMyrmidonTest.java AbstractProjectTest.java
TrackingProjectListener.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor
DefaultEmbeddorTest.java
proposal/myrmidon/src/java/org/apache/antlib/core
Property.java
Added: proposal/myrmidon/src/manifest testcases-ant-descriptor.xml
proposal/myrmidon/src/testcases/org/apache/antlib/core
PropertyTest.java PropertyTestType.java
proposal/myrmidon/src/testcases/org/apache/myrmidon
LogMessageTracker.java
proposal/myrmidon/etc/testcases/org/apache/antlib/core
property.ant
Log:
Changes to <property>:
* No longer implements Configurable, uses a set() method instead.
* The property value can be included as the text content of
the <property> element.
* Added test-cases.
* Added some alternative executeTarget() methods to
AbstractProjectTest, to expect a particular set of log messages,
or a particular failure.
Revision Changes Path
1.63 +4 -0 jakarta-ant/proposal/myrmidon/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- build.xml 25 Feb 2002 10:42:43 -0000 1.62
+++ build.xml 26 Feb 2002 23:26:55 -0000 1.63
@@ -454,6 +454,10 @@
<fileset dir="${test.classes}"
includes="org/apache/myrmidon/interfaces/type/MyType1.class"/>
</jar>
+ <!-- Prepare the project tests -->
+ <copy file="src/manifest/testcases-ant-descriptor.xml"
tofile="${test.classes}/META-INF/ant-descriptor.xml"/>
+
+ <!-- Run all the tests -->
<junit printsummary="on"
fork="false">
<formatter type="brief" usefile="false"/>
1.1
jakarta-ant/proposal/myrmidon/src/manifest/testcases-ant-descriptor.xml
Index: testcases-ant-descriptor.xml
===================================================================
<ant-lib version="1.0">
<types>
<data-type name="property-test-type"
classname="org.apache.antlib.core.PropertyTestType"/>
</types>
</ant-lib>
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/PropertyTest.java
Index: PropertyTest.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.antlib.core;
import java.io.File;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;
import org.apache.myrmidon.components.configurer.DefaultConfigurer;
/**
* Test cases for <property> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/26 23:26:55 $
*/
public class PropertyTest
extends AbstractProjectTest
{
private final static Resources REZ
= ResourceManager.getPackageResources( PropertyTest.class );
public PropertyTest( final String name )
{
super( name );
}
/**
* Tests setting a property, using an attribute, text content, and
* nested element.
*/
public void testSetProperty()
throws Exception
{
final File projectFile = getTestResource( "property.ant" );
// Set by attribute
LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "set-attr", "test-prop = [some value]");
executeTarget( projectFile, "set-attr", tracker );
// Set by text content
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "set-content", "test-prop2 = [some
value]");
executeTarget( projectFile, "set-content", tracker );
// Set by nested element
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "set-element", "test-prop3 = [value=[some
value]]");
executeTarget( projectFile, "set-element", tracker );
}
/**
* Tests the validation performed by the propery task.
*/
public void testValidation()
throws Exception
{
final File projectFile = getTestResource( "property.ant" );
// Missing name
String message = REZ.getString( "property.no-name.error" );
executeTargetExpectError( projectFile, "missing-name", message );
// Missing value
message = REZ.getString( "property.no-value.error" );
executeTargetExpectError( projectFile, "missing-value", message );
// Too many values
String[] messages = {
null,
null,
REZ.getString( "property.multi-set.error" )
};
executeTargetExpectError( projectFile, "too-many-values1", messages );
executeTargetExpectError( projectFile, "too-many-values2", messages );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/PropertyTestType.java
Index: PropertyTestType.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.antlib.core;
import org.apache.myrmidon.framework.DataType;
/**
* A test data-type used by the property tests.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/26 23:26:55 $
*
* @ant:data-type name="property-test-type"
*/
public class PropertyTestType
implements DataType
{
private String m_value;
public void setValue( final String value )
{
m_value = value;
}
/**
* Used in the test project file to check the value has been set.
*/
public String toString()
{
return "value=[" + m_value + "]";
}
}
1.5 +7 -1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractMyrmidonTest.java
Index: AbstractMyrmidonTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractMyrmidonTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractMyrmidonTest.java 24 Feb 2002 07:43:38 -0000 1.4
+++ AbstractMyrmidonTest.java 26 Feb 2002 23:26:55 -0000 1.5
@@ -99,6 +99,9 @@
/**
* 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 )
{
@@ -107,7 +110,10 @@
{
String message = messages[ i ];
assertNotNull( current );
- assertEquals( message, current.getMessage() );
+ if( message != null )
+ {
+ assertEquals( message, current.getMessage() );
+ }
if( current instanceof CascadingThrowable )
{
1.3 +65 -4
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java
Index: AbstractProjectTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractProjectTest.java 25 Feb 2002 10:42:44 -0000 1.2
+++ AbstractProjectTest.java 26 Feb 2002 23:26:55 -0000 1.3
@@ -8,18 +8,19 @@
package org.apache.myrmidon;
import java.io.File;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.parameters.Parameters;
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;
+import org.apache.myrmidon.listeners.ProjectListener;
/**
* A base class for test cases which need to execute projects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.2 $ $Date: 2002/02/25 10:42:44 $
+ * @version $Revision: 1.3 $ $Date: 2002/02/26 23:26:55 $
*/
public class AbstractProjectTest
extends AbstractMyrmidonTest
@@ -69,15 +70,75 @@
}
/**
- * Executes a target in a project, and asserts that it does not fail
+ * 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
+ {
+ // Create the project and workspace
final Embeddor embeddor = getEmbeddor();
final Project project = embeddor.createProject(
projectFile.getAbsolutePath(), null, null );
final Workspace workspace = embeddor.createWorkspace( new
Parameters() );
+ // Add a listener to make sure all is good
+ final TrackingProjectListener tracker = new
TrackingProjectListener();
+ workspace.addProjectListener( tracker );
+
+ // Add supplied listener
+ if( listener != null )
+ {
+ workspace.addProjectListener( listener );
+ }
+
+ // Now execute the target
workspace.executeProject( project, targetName );
+
+ // Make sure all expected events were delivered
+ tracker.assertComplete();
+ if( listener instanceof TrackingProjectListener )
+ {
+ ( (TrackingProjectListener)listener ).assertComplete();
+ }
}
}
1.2 +1 -25
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/TrackingProjectListener.java
Index: TrackingProjectListener.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/TrackingProjectListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TrackingProjectListener.java 20 Feb 2002 07:20:22 -0000 1.1
+++ TrackingProjectListener.java 26 Feb 2002 23:26:55 -0000 1.2
@@ -7,9 +7,6 @@
*/
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;
@@ -22,7 +19,7 @@
* events.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.1 $ $Date: 2002/02/20 07:20:22 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/26 23:26:55 $
*/
public class TrackingProjectListener
extends Assert
@@ -32,8 +29,6 @@
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.
@@ -64,7 +59,6 @@
assertNull( "Target already started", m_currentTarget );
m_currentProject = event.getProjectName();
m_currentTarget = event.getTargetName();
- m_currentMsgs = (ArrayList)m_messages.get( m_currentTarget );
}
/**
@@ -76,7 +70,6 @@
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 );
}
@@ -112,9 +105,6 @@
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() );
}
@@ -127,19 +117,5 @@
assertNull( "Target not finished", m_currentTarget );
assertNull( "Target not finished", m_currentProject );
assertNull( "Project not finished", m_rootProject );
- }
-
- /**
- * Adds an expected log message.
- */
- public void addExpectedMessage( String target, String message )
- {
- ArrayList targetMsgs = (ArrayList)m_messages.get( target );
- if( targetMsgs == null )
- {
- targetMsgs = new ArrayList();
- m_messages.put( target, targetMsgs );
- }
- targetMsgs.add( message );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/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/02/26 23:26:55 $
*/
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.3 +4 -6
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor/DefaultEmbeddorTest.java
Index: DefaultEmbeddorTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/embeddor/DefaultEmbeddorTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultEmbeddorTest.java 21 Feb 2002 03:23:38 -0000 1.2
+++ DefaultEmbeddorTest.java 26 Feb 2002 23:26:56 -0000 1.3
@@ -8,22 +8,20 @@
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.AbstractProjectTest;
+import org.apache.myrmidon.LogMessageTracker;
+import org.apache.myrmidon.interfaces.embeddor.Embeddor;
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.interfaces.embeddor.Embeddor;
import org.apache.myrmidon.listeners.ProjectListener;
/**
* Test cases for the default embeddor.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.2 $ $Date: 2002/02/21 03:23:38 $
+ * @version $Revision: 1.3 $ $Date: 2002/02/26 23:26:56 $
*/
public class DefaultEmbeddorTest
extends AbstractProjectTest
@@ -81,7 +79,7 @@
final Workspace workspace = embeddor.createWorkspace( new
Parameters() );
// Install a listener
- final TrackingProjectListener listener = new
TrackingProjectListener();
+ final LogMessageTracker listener = new LogMessageTracker();
workspace.addProjectListener( listener );
listener.addExpectedMessage( "main-target", "A log message" );
1.11 +27 -39
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java
Index: Property.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Property.java 14 Feb 2002 10:53:53 -0000 1.10
+++ Property.java 26 Feb 2002 23:26:56 -0000 1.11
@@ -9,12 +9,9 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.framework.DataType;
/**
@@ -23,12 +20,11 @@
* TODO: Determine final format of property task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.10 $ $Date: 2002/02/14 10:53:53 $
+ * @version $Revision: 1.11 $ $Date: 2002/02/26 23:26:56 $
* @ant:task name="property"
*/
public class Property
- extends AbstractContainerTask
- implements Configurable
+ extends AbstractTask
{
private final static Resources REZ =
ResourceManager.getPackageResources( Property.class );
@@ -37,40 +33,37 @@
private Object m_value;
private boolean m_localScope = true;
- public void configure( final Configuration configuration )
- throws ConfigurationException
+ public void setName( final String name )
{
- final String[] attributes = configuration.getAttributeNames();
- for( int i = 0; i < attributes.length; i++ )
- {
- final String name = attributes[ i ];
- final String value = configuration.getAttribute( name );
- configure( this, name, value );
- }
+ m_name = name;
+ }
- final Configuration[] children = configuration.getChildren();
- for( int i = 0; i < children.length; i++ )
- {
- try
- {
- final String typeName = children[ i ].getName();
- final DataType value = (DataType)newInstance(
DataType.class, typeName );
- configure( value, children[ i ] );
- setValue( value );
- }
- catch( final Exception e )
- {
- final String message = REZ.getString(
"property.no-set.error" );
- throw new ConfigurationException( message, e );
- }
- }
+ public void setLocalScope( final boolean localScope )
+ {
+ m_localScope = localScope;
}
- public void setName( final String name )
+ /**
+ * Sets the property value from a nested element.
+ */
+ public void set( final DataType value )
+ throws TaskException
{
- m_name = name;
+ setValue( value );
+ }
+
+ /**
+ * Sets the property value from text content.
+ */
+ public void addContent( final String value )
+ throws TaskException
+ {
+ setValue( value );
}
+ /**
+ * Sets the property value from an attribute.
+ */
public void setValue( final Object value )
throws TaskException
{
@@ -81,11 +74,6 @@
}
m_value = value;
- }
-
- public void setLocalScope( final boolean localScope )
- {
- m_localScope = localScope;
}
public void execute()
1.1
jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core/property.ant
Index: property.ant
===================================================================
<project version="2.0">
<!-- Test setting property via attribute -->
<target name="set-attr">
<property name="test-prop" value="some value"/>
<log>test-prop = [${test-prop}]</log>
</target>
<!-- Test setting property via content -->
<target name="set-content">
<property name="test-prop2">some value</property>
<log>test-prop2 = [${test-prop2}]</log>
</target>
<!-- Test setting property via a nested element -->
<target name="set-element">
<property name="test-prop3">
<property-test-type value="some value"/>
</property>
<log>test-prop3 = [${test-prop3}]</log>
</target>
<!-- Test missing property name -->
<target name="missing-name">
<property value="some value"/>
</target>
<!-- Test missing property value -->
<target name="missing-value">
<property name="some-prop"/>
</target>
<!-- Test setting the value more than once -->
<target name="too-many-values1">
<property name="some-prop" value="some value">another value</property>
</target>
<!-- Test setting the value more than once -->
<target name="too-many-values2">
<property name="some-prop" value="some value">
<property-test-type value="value 2"/>
</property>
</target>
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>