git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272459 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,124 +0,0 @@ | |||||
| /* | |||||
| * 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.test; | |||||
| import java.io.File; | |||||
| import org.apache.avalon.excalibur.i18n.Resources; | |||||
| import org.apache.myrmidon.AbstractProjectTest; | |||||
| import org.apache.myrmidon.LogMessageTracker; | |||||
| /** | |||||
| * Test cases for the <if> task. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class IfTestCase | |||||
| extends AbstractProjectTest | |||||
| { | |||||
| private final static Resources REZ = getResourcesForTested( IfTestCase.class ); | |||||
| public IfTestCase( String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| /** | |||||
| * Test checking whether a property is set and not 'false'. | |||||
| */ | |||||
| public void testConditions() | |||||
| throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "if.ant" ); | |||||
| // Test when property is set to 'true' | |||||
| LogMessageTracker listener = new LogMessageTracker(); | |||||
| listener.addExpectedMessage( "true-prop", "test-prop is set" ); | |||||
| executeTarget( projectFile, "true-prop", listener ); | |||||
| // Test when property is set to a value other than 'true' or 'false' | |||||
| executeTargetExpectError( projectFile, "set-prop", new String[ 0 ] ); | |||||
| // Test when property is set to 'false' | |||||
| listener = new LogMessageTracker(); | |||||
| listener.addExpectedMessage( "false-prop", "test-prop is not set" ); | |||||
| executeTarget( projectFile, "false-prop", listener ); | |||||
| // Test when property is not set | |||||
| listener = new LogMessageTracker(); | |||||
| listener.addExpectedMessage( "not-set-prop", "test-prop is not set" ); | |||||
| executeTarget( projectFile, "not-set-prop", listener ); | |||||
| } | |||||
| /** | |||||
| * Test nested <condition> elements. | |||||
| */ | |||||
| public void testNestedConditions() | |||||
| throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "if.ant" ); | |||||
| // Test when property is set to 'true' | |||||
| LogMessageTracker listener = new LogMessageTracker(); | |||||
| listener.addExpectedMessage( "nested-conditions", "prop-true is set" ); | |||||
| listener.addExpectedMessage( "nested-conditions", "prop-false is set" ); | |||||
| listener.addExpectedMessage( "nested-conditions", "prop-true is true" ); | |||||
| listener.addExpectedMessage( "nested-conditions", | |||||
| "prop-true is true and prop-false is not true" ); | |||||
| executeTarget( projectFile, "nested-conditions", listener ); | |||||
| } | |||||
| /** | |||||
| * Tests that the <if> task can handle multiple nested tasks. | |||||
| */ | |||||
| public void testMultipleTasks() throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "if.ant" ); | |||||
| // Test when property is not set | |||||
| LogMessageTracker listener = new LogMessageTracker(); | |||||
| listener.addExpectedMessage( "multiple-nested-tasks", "task 1" ); | |||||
| listener.addExpectedMessage( "multiple-nested-tasks", "task 2" ); | |||||
| listener.addExpectedMessage( "multiple-nested-tasks", "task 3" ); | |||||
| listener.addExpectedMessage( "multiple-nested-tasks", "task 4" ); | |||||
| executeTarget( projectFile, "multiple-nested-tasks", listener ); | |||||
| } | |||||
| /** | |||||
| * Tests validation. | |||||
| */ | |||||
| public void testValidation() throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "if.ant" ); | |||||
| // Check for missing condition | |||||
| String[] messages = { | |||||
| null, | |||||
| REZ.getString( "if.no-condition.error" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "no-condition", messages ); | |||||
| // Check for too many conditions | |||||
| messages = new String[] | |||||
| { | |||||
| null, | |||||
| null, | |||||
| REZ.getString( "if.ifelse-duplicate.error" ) | |||||
| }; | |||||
| // 2 condition attributes. | |||||
| executeTargetExpectError( projectFile, "too-many-conditions", messages ); | |||||
| // attribute condition + nested condition | |||||
| executeTargetExpectError( projectFile, "attribute-plus-nested-condition", | |||||
| messages ); | |||||
| // 2 nested conditions | |||||
| executeTargetExpectError( projectFile, "2-nested-conditions", messages ); | |||||
| } | |||||
| } | |||||
| @@ -1,128 +0,0 @@ | |||||
| /* | |||||
| * 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.test; | |||||
| 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.workspace.DefaultTaskContext; | |||||
| import org.apache.myrmidon.components.store.DefaultPropertyStore; | |||||
| /** | |||||
| * Test cases for <property> task. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class PropertyTestCase | |||||
| extends AbstractProjectTest | |||||
| { | |||||
| private final static Resources REZ = getResourcesForTested( PropertyTestCase.class ); | |||||
| public PropertyTestCase( 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[] messages = | |||||
| { | |||||
| null, | |||||
| REZ.getString( "property.no-name.error" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "missing-name", messages ); | |||||
| // Missing value | |||||
| messages = new String[] | |||||
| { | |||||
| null, | |||||
| REZ.getString( "property.no-value.error" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "missing-value", messages ); | |||||
| // Too many values | |||||
| messages = new String[] | |||||
| { | |||||
| null, | |||||
| null, | |||||
| REZ.getString( "property.multi-set.error" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "too-many-values1", messages ); | |||||
| executeTargetExpectError( projectFile, "too-many-values2", messages ); | |||||
| executeTargetExpectError( projectFile, "too-many-values3", messages ); | |||||
| } | |||||
| /** | |||||
| * Tests basic validation of property names. | |||||
| */ | |||||
| public void testNameValidation() throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "property.ant" ); | |||||
| final Resources rez | |||||
| = ResourceManager.getPackageResources( DefaultPropertyStore.class ); | |||||
| // Invalid names | |||||
| String[] messages = new String[] | |||||
| { | |||||
| null, | |||||
| rez.getString( "bad-property-name.error", "badname!" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "bad-prop-name1", messages ); | |||||
| messages = new String[] | |||||
| { | |||||
| null, | |||||
| rez.getString( "bad-property-name.error", "bad name" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "bad-prop-name2", messages ); | |||||
| messages = new String[] | |||||
| { | |||||
| null, | |||||
| rez.getString( "bad-property-name.error", "" ) | |||||
| }; | |||||
| executeTargetExpectError( projectFile, "bad-prop-name3", messages ); | |||||
| } | |||||
| } | |||||
| @@ -1,37 +0,0 @@ | |||||
| /* | |||||
| * 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.test; | |||||
| import org.apache.myrmidon.framework.DataType; | |||||
| /** | |||||
| * A test data-type used by the property tests. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| * | |||||
| * @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,137 +0,0 @@ | |||||
| <project version="2.0"> | |||||
| <target name="true-prop"> | |||||
| <property name="test-prop" value="true"/> | |||||
| <if test="test-prop"> | |||||
| <log>test-prop is set</log> | |||||
| </if> | |||||
| <if not-test="test-prop"> | |||||
| <log>test-prop is not set</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="set-prop"> | |||||
| <property name="test-prop" value="some value"/> | |||||
| <if test="test-prop"> | |||||
| <log>test-prop is set</log> | |||||
| </if> | |||||
| <if not-test="test-prop"> | |||||
| <log>test-prop is not set</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="not-set-prop"> | |||||
| <if test="test-prop"> | |||||
| <log>test-prop is set</log> | |||||
| </if> | |||||
| <if not-test="test-prop"> | |||||
| <log>test-prop is not set</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="false-prop"> | |||||
| <property name="test-prop" value="false"/> | |||||
| <if test="test-prop"> | |||||
| <log>test-prop is set</log> | |||||
| </if> | |||||
| <if not-test="test-prop"> | |||||
| <log>test-prop is not set</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="nested-conditions"> | |||||
| <property name="prop-true" value="true"/> | |||||
| <property name="prop-false" value="false"/> | |||||
| <if> | |||||
| <condition> | |||||
| <is-set property="prop-true"/> | |||||
| </condition> | |||||
| <log message="prop-true is set"/> | |||||
| </if> | |||||
| <if> | |||||
| <condition> | |||||
| <is-set property="prop-false"/> | |||||
| </condition> | |||||
| <log message="prop-false is set"/> | |||||
| </if> | |||||
| <if> | |||||
| <condition> | |||||
| <is-set property="prop-unset"/> | |||||
| </condition> | |||||
| <log message="prop-unset is set (shouldn't be here)"/> | |||||
| </if> | |||||
| <if> | |||||
| <condition> | |||||
| <is-true property="prop-true"/> | |||||
| </condition> | |||||
| <log message="prop-true is true"/> | |||||
| </if> | |||||
| <if> | |||||
| <condition> | |||||
| <is-true property="prop-false"/> | |||||
| </condition> | |||||
| <log message="prop-false is true (shouldn't be here)"/> | |||||
| </if> | |||||
| <!-- Compound condition --> | |||||
| <if> | |||||
| <condition> | |||||
| <is-true property="prop-true"/> | |||||
| <not> | |||||
| <is-true property="prop-false"/> | |||||
| </not> | |||||
| </condition> | |||||
| <log message="prop-true is true and prop-false is not true"/> | |||||
| </if> | |||||
| </target> | |||||
| <target name="multiple-nested-tasks"> | |||||
| <property name="test-prop" value="true"/> | |||||
| <if test="test-prop"> | |||||
| <log>task 1</log> | |||||
| <log>task 2</log> | |||||
| <log>task 3</log> | |||||
| <log>task 4</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="no-condition"> | |||||
| <if> | |||||
| <log>no go</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="too-many-conditions"> | |||||
| <if test="test-prop" not-test="test-prop"> | |||||
| <log>no go</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="attribute-plus-nested-condition"> | |||||
| <property name="test-prop" value="true"/> | |||||
| <if test="test-prop"> | |||||
| <condition> | |||||
| <is-set property="test-prop"/> | |||||
| </condition> | |||||
| <log>Double trouble.</log> | |||||
| </if> | |||||
| </target> | |||||
| <target name="2-nested-conditions"> | |||||
| <property name="test-prop" value="true"/> | |||||
| <if> | |||||
| <condition> | |||||
| <is-set property="test-prop"/> | |||||
| </condition> | |||||
| <condition> | |||||
| <is-true property="test-prop"/> | |||||
| </condition> | |||||
| <log>2 conditions not permitted.</log> | |||||
| </if> | |||||
| </target> | |||||
| </project> | |||||
| @@ -1,65 +0,0 @@ | |||||
| <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> | |||||
| <!-- Test setting the value more than once --> | |||||
| <target name="too-many-values3"> | |||||
| <property name="some-prop"> | |||||
| <property-test-type value="value 1"/> | |||||
| <property-test-type value="value 2"/> | |||||
| <property-test-type value="value 3"/> | |||||
| </property> | |||||
| </target> | |||||
| <!-- Test properties with invalid names --> | |||||
| <target name="bad-prop-name1"> | |||||
| <property name="badname!" value="value"/> | |||||
| </target> | |||||
| <target name="bad-prop-name2"> | |||||
| <property name="bad name" value="value"/> | |||||
| </target> | |||||
| <target name="bad-prop-name3"> | |||||
| <property name="" value="value"/> | |||||
| </target> | |||||
| </project> | |||||
| @@ -1,35 +0,0 @@ | |||||
| /* | |||||
| * 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.vfile.test; | |||||
| import java.io.File; | |||||
| import org.apache.myrmidon.AbstractProjectTest; | |||||
| /** | |||||
| * Test cases for the <v-copy> task. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class CopyFilesTaskTestCase | |||||
| extends AbstractProjectTest | |||||
| { | |||||
| public CopyFilesTaskTestCase( String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| /** | |||||
| * A simple smoke test. | |||||
| */ | |||||
| public void testCopy() throws Exception | |||||
| { | |||||
| final File projectFile = getTestResource( "copy.ant" ); | |||||
| executeTarget( projectFile, "copy" ); | |||||
| } | |||||
| } | |||||
| @@ -1,8 +0,0 @@ | |||||
| <project version="2.0"> | |||||
| <target name="copy"> | |||||
| <v-fileset id="src-files" dir="src"/> | |||||
| <v-copy destdir="dest"> | |||||
| <v-fileset-ref id="src-files"/> | |||||
| </v-copy> | |||||
| </target> | |||||
| </project> | |||||
| @@ -1 +0,0 @@ | |||||
| A test file. | |||||
| @@ -1,5 +0,0 @@ | |||||
| <html> | |||||
| <body> | |||||
| <p>Yo!</p> | |||||
| </body> | |||||
| </html> | |||||