git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1588563 13f79535-47bb-0310-9956-ffa450edef68master
@@ -26,6 +26,16 @@ Changes that could break older environments: | |||
might lead to blocking or other undefined behavior. | |||
Bugzilla Report 56149 | |||
* BuildFileTest and BaseSelectorTest have both been deprecated in | |||
favour of BuildFileRule and BaseSelectorRule respectively, and the | |||
tests that previously extended these base tests have been converted to | |||
JUnit 4 tests using the new "rule"s. Any external test that sub-classed | |||
a test in the Ant workspace, rather than BuildFileTest, will need | |||
changed to either use JUnit4's annotations, or be modified to | |||
extend BuildFileTest directly. This will not affect any tests that are | |||
being executed by Ant's junit or batchtest tasks that are not specifically | |||
testing Ant's code. | |||
Fixed bugs: | |||
----------- | |||
@@ -140,78 +140,58 @@ | |||
<p>For a robust component (and selectors are (Project)Components) tests are | |||
necessary. For testing Tasks we use JUnit TestCases - more specific | |||
<tt>org.apache.tools.ant.BuildFileTest extends junit.framework.TestCase</tt>. | |||
<tt>org.apache.tools.ant.BuildFileRule extends org.junit.rules.ExternalResource</tt>. | |||
Some of its features like configure the (test) project by reading its buildfile and | |||
execute targets we need for selector tests also. Therefore we use that BuildFileTest. | |||
execute targets we need for selector tests also. Therefore we use that BuildFileRule. | |||
But testing selectors requires some more work: having a set of files, instantiate | |||
and configure the selector, check the selection work and more. Because we usually | |||
extend <tt>BaseExtendSelector</tt> its features have to be tested also (e.g. setError()). | |||
</p> | |||
<p>That's why we have a base class for doing our selector tests: | |||
<tt>org.apache.tools.ant.types.selectors.BaseSelectorTest</tt>.</p> | |||
<p>That's why we have a test rule for doing our selector tests: | |||
<tt>org.apache.tools.ant.types.selectors.BaseSelectorRule</tt>.</p> | |||
<p>This class extends TestCase and therefore can included in the set of Ant's | |||
unit tests. It holds an instance of preconfigured BuildFileTest. Configuration | |||
is done by parsing the src/etc/testcases/types/selectors.xml. BaseSelectorTest | |||
<p>This class extends ExternalResource and therefore can included in the set of Ant's | |||
unit tests. It holds an instance of preconfigured BuildFileRule. Configuration | |||
is done by parsing the src/etc/testcases/types/selectors.xml. BaseSelectorRule | |||
then gives us helper methods for handling multiple selections. </p> | |||
<p>Because the term "testcase" or "testenvironment" are so often used, this | |||
special testenvironment got a new name: <i>bed</i>. Like you initialize the | |||
test environment by calling setUp() and cleaning by calling tearDown() (<i>or like | |||
to make your bed before go sleeping</i>) you have to do that work with your | |||
<i>bed</i> by calling <tt>makeBed()</tt> respective <tt>cleanupBed()</tt>.</p> | |||
special testenvironment got a new name: <i>bed</i>. The setup and cleanup of | |||
the bed is all handled by the BaseSelectorRule so any test only has to handle | |||
the actual test scenarios</p> | |||
<p>A usual test scenario is<ol> | |||
<li>make the bed</li> | |||
<p>A usual test scenario is:</p> | |||
<ol> | |||
<li>instantiate the selector</li> | |||
<li>configure the selector</li> | |||
<li>let the selector do some work</li> | |||
<li>verify the work</li> | |||
<li>clean the bed</li> | |||
</ol> | |||
</p> | |||
</ol> | |||
<p>For common way of instantiation you have to override the <tt>getInstance()</tt> | |||
simply by returning a new object of your selector. For easier "selection and verification work" | |||
BaseSelectorTest provides the method <tt>performTests()</tt> which | |||
iterates over all files (and directories) in the String array <tt>filenames</tt> | |||
and checks whether the given selector returns the expected result. If an error | |||
occurred (especially the selector does not return the expected result) the test | |||
fails and the failing filenames are logged.</p> | |||
<p>An example test would be:<pre> | |||
package org.apache.tools.ant.types.selectors; | |||
public class MySelectorTest extends BaseSelectorTest { | |||
public MySelectorTest(String name) { | |||
super(name); | |||
} | |||
public class MySelectorTest { | |||
public BaseSelector getInstance() { | |||
return new MySelector(); | |||
} | |||
@Rule | |||
public final BaseSelectorRule selectorRule = new BaseSelectorRule(); | |||
@Test | |||
public void testCase1() { | |||
try { | |||
// initialize test environment 'bed' | |||
makeBed(); | |||
// Configure the selector | |||
MySelector s = (MySelector)getSelector(); | |||
s.addParam("key1", "value1"); | |||
s.addParam("key2", "value2"); | |||
s.setXX(true); | |||
s.setYY("a value"); | |||
// do the tests | |||
performTests(s, "FTTTTTTTTTTT"); // First is not selected - rest is | |||
} finally { | |||
// cleanup the environment | |||
cleanupBed(); | |||
} | |||
// Configure the selector | |||
MySelector s = new MySelector(); | |||
s.addParam("key1", "value1"); | |||
s.addParam("key2", "value2"); | |||
s.setXX(true); | |||
s.setYY("a value"); | |||
// do the tests | |||
assertEquals("FTTTTTTTT", selectorRule.selectionString(s)); | |||
} | |||
} | |||
</pre> | |||
@@ -135,20 +135,28 @@ to them, sorry :-)</p> | |||
we can call that from our testcase: | |||
<pre class="code"> | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.Before; | |||
import org.junit.Assert; | |||
import org.apache.tools.ant.BuildFileRule; | |||
public class FindTest extends BuildFileTest { | |||
public FindTest(String name) { | |||
super(name); | |||
} | |||
public class FindTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("build.xml"); | |||
} | |||
@Test | |||
public void testSimple() { | |||
<b>expectLog("use.simple", "test-value");</b> | |||
buildRule.executeTarget("useSimgle"); | |||
<b>Assert.assertEquals("test-value", buildRule.getLog());</b> | |||
} | |||
} | |||
</pre> | |||
@@ -211,10 +219,14 @@ Maybe you find some more testcases. But this is enough for now.<br> | |||
For each of these points we create a <tt>testXX</tt> method.</p> | |||
<pre class="code"> | |||
public class FindTest extends BuildFileTest { | |||
public class FindTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
... // constructor, setUp as above | |||
@Test | |||
public void testMissingFile() { | |||
<b>Find find = new Find();</b> | |||
try { | |||
@@ -227,6 +239,7 @@ public class FindTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testMissingLocation() { | |||
Find find = new Find(); | |||
<b>find.setFile("ant.jar");</b> | |||
@@ -238,6 +251,7 @@ public class FindTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testMissingFileset() { | |||
Find find = new Find(); | |||
find.setFile("ant.jar"); | |||
@@ -250,15 +264,17 @@ public class FindTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testFileNotPresent() { | |||
executeTarget("testFileNotPresent"); | |||
String result = getProject().getProperty("location.ant-jar"); | |||
buildRule.executeTarget("testFileNotPresent"); | |||
String result = buildRule.getProject().getProperty("location.ant-jar"); | |||
assertNull("Property set to wrong value.", result); | |||
} | |||
@Test | |||
public void testFilePresent() { | |||
executeTarget("testFilePresent"); | |||
String result = getProject().getProperty("location.ant-jar"); | |||
buildRule.executeTarget("testFilePresent"); | |||
String result = buildRule.getProject().getProperty("location.ant-jar"); | |||
assertNotNull("Property not set.", result); | |||
assertTrue("Wrong file found.", result.endsWith("ant.jar")); | |||
} | |||
@@ -906,7 +922,7 @@ entry. For both we need some information:</p> | |||
</tr> | |||
<tr> | |||
<th>attachments</th> | |||
<td><i>all files needed to apply the path</td> | |||
<td><i>all files needed to apply the path</i></td> | |||
<td>Archive containing a patch with the new and modified resources</td> | |||
</tr> | |||
</table> | |||
@@ -17,8 +17,7 @@ | |||
<html> | |||
<head> | |||
<title>Tutorial: Writing Tasks</title> | |||
<link rel="stylesheet" type="text/css" href="stylesheets/style.css"> | |||
</link> | |||
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" /> | |||
</head> | |||
<body> | |||
<h1>Tutorial: Writing Tasks</h1> | |||
@@ -596,12 +595,9 @@ Next step: test ... | |||
<h2>Test the Task</h2> | |||
<p>We have written a test already: the use.* tasks in the buildfile. But its | |||
difficult to test that automatically. Common (and in Ant) used is JUnit for | |||
that. For testing tasks Ant provides a baseclass <tt>org.apache.tools.ant.BuildFileTest</tt>. | |||
This class extends <tt>junit.framework.TestCase</tt> and can therefore be integrated | |||
into the unit tests. But this class provides some for testing tasks useful methods: | |||
initialize Ant, load a buildfile, execute targets, | |||
expecting BuildExceptions with a specified text, expect a special text | |||
in the output log ... </p> | |||
that. For testing tasks Ant provides a JUnit Rule <tt>org.apache.tools.ant.BuildFileRule</tt>. | |||
This class provides some for testing tasks useful methods: | |||
initialize Ant, load a buildfile, execute targets, capturing debug and run logs ...</p> | |||
<p>In Ant it is usual that the testcase has the same name as the task with a prepending | |||
<i>Test</i>, therefore we will create a file <i>HelloWorldTest.java</i>. Because we | |||
@@ -677,49 +673,68 @@ and <code><junitreport></code>. So we add to the buildfile:</p> | |||
... | |||
</pre> | |||
<p>Back to the <i>src/HelloWorldTest.java</i>. We create a class extending | |||
<i>BuildFileTest</i> with String-constructor (JUnit-standard), a <i>setUp()</i> | |||
method initializing Ant and for each testcase (targets use.*) a <i>testXX()</i> | |||
method invoking that target.</p> | |||
<p>Back to the <i>src/HelloWorldTest.java</i>. We create a class with a public | |||
<i>BuildFileRule</i> field annotated with JUnit's <i>@Rule</i> annotation. As per | |||
conventional JUnit4 tests, this class should have no constructors, or a default no-args | |||
constructor, setup methods should be annotated with <i>@Before</i>, tear down methods | |||
annotated with <i>@After</i> and any test method annotated with <i>@Test</i>. | |||
<pre class="code"> | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildException; | |||
public class HelloWorldTest extends BuildFileTest { | |||
public class HelloWorldTest { | |||
public HelloWorldTest(String s) { | |||
super(s); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
// initialize Ant | |||
configureProject("build.xml"); | |||
buildRule.configureProject("build.xml"); | |||
} | |||
@Test | |||
public void testWithout() { | |||
executeTarget("use.without"); | |||
assertEquals("Message was logged but should not.", getLog(), ""); | |||
buildRule.executeTarget("use.without"); | |||
assertEquals("Message was logged but should not.", buildRule.getLog(), ""); | |||
} | |||
public void testMessage() { | |||
// execute target 'use.nestedText' and expect a message | |||
// 'attribute-text' in the log | |||
expectLog("use.message", "attribute-text"); | |||
buildRule.executeTarget("use.message"); | |||
Assert.assertEquals("attribute-text", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testFail() { | |||
// execute target 'use.fail' and expect a BuildException | |||
// with text 'Fail requested.' | |||
expectBuildException("use.fail", "Fail requested."); | |||
try { | |||
buildRule.executeTarget("use.fail"); | |||
fail("BuildException should have been thrown as task was set to fail"); | |||
} catch (BuildException ex) { | |||
Assert.assertEquals("fail requested", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNestedText() { | |||
expectLog("use.nestedText", "nested-text"); | |||
buildRule.executeTarget("use.nestedText"); | |||
Assert.assertEquals("nested-text", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testNestedElement() { | |||
executeTarget("use.nestedElement"); | |||
assertLogContaining("Nested Element 1"); | |||
assertLogContaining("Nested Element 2"); | |||
buildRule.executeTarget("use.nestedElement"); | |||
AntAssert.assertContains("Nested Element 1", buildRule.getLog()); | |||
AntAssert.assertContains("Nested Element 2", buildRule.getLog()); | |||
} | |||
} | |||
</pre> | |||
@@ -790,14 +805,14 @@ The ZIP provided there contains</p><ul> | |||
<a href="tutorial-writing-tasks-src.zip">here [7]</a> inside the manual. | |||
</p> | |||
<p>Used Links:<br></br> | |||
[1] <a href="http://ant.apache.org/manual/properties.html#built-in-props">http://ant.apache.org/manual/properties.html#built-in-props</a><br></br> | |||
[2] <a href="http://ant.apache.org/manual/Tasks/taskdef.html">http://ant.apache.org/manual/Tasks/taskdef.html</a><br></br> | |||
[3] <a href="http://ant.apache.org/manual/develop.html#set-magic">http://ant.apache.org/manual/develop.html#set-magic</a><br></br> | |||
[4] <a href="http://ant.apache.org/manual/develop.html#nested-elements">http://ant.apache.org/manual/develop.html#nested-elements</a><br></br> | |||
[5] <a href="http://gump.covalent.net/jars/latest/ant/ant-testutil.jar">http://gump.covalent.net/jars/latest/ant/ant-testutil.jar</a><br></br> | |||
[6] <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=22570">http://issues.apache.org/bugzilla/show_bug.cgi?id=22570</a><br></br> | |||
[7] <a href="tutorial-writing-tasks-src.zip">tutorial-writing-tasks-src.zip</a><br></br> | |||
<p>Used Links:<br /> | |||
[1] <a href="http://ant.apache.org/manual/properties.html#built-in-props">http://ant.apache.org/manual/properties.html#built-in-props</a><br /> | |||
[2] <a href="http://ant.apache.org/manual/Tasks/taskdef.html">http://ant.apache.org/manual/Tasks/taskdef.html</a><br /> | |||
[3] <a href="http://ant.apache.org/manual/develop.html#set-magic">http://ant.apache.org/manual/develop.html#set-magic</a><br /> | |||
[4] <a href="http://ant.apache.org/manual/develop.html#nested-elements">http://ant.apache.org/manual/develop.html#nested-elements</a><br /> | |||
[5] <a href="http://gump.covalent.net/jars/latest/ant/ant-testutil.jar">http://gump.covalent.net/jars/latest/ant/ant-testutil.jar</a><br /> | |||
[6] <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=22570">http://issues.apache.org/bugzilla/show_bug.cgi?id=22570</a><br /> | |||
[7] <a href="tutorial-writing-tasks-src.zip">tutorial-writing-tasks-src.zip</a><br /> | |||
</p> | |||
</body> | |||
@@ -63,13 +63,10 @@ a=b= | |||
<target name="test3"> | |||
<!-- create an empty file --> | |||
<touch file="${output}/copytest3.tmp"/> | |||
<!--wait --> | |||
<sleep seconds="4"/> | |||
<!-- copy a different file to two places --> | |||
<copy file="copy.xml" tofile="${output}/copytest3a.tmp" overwrite="true"/> | |||
<copy file="copy.xml" tofile="${output}/copytest3b.tmp" overwrite="true"/> | |||
<!--wait --> | |||
<sleep seconds="4"/> | |||
</target><target name="test3Part2"> | |||
<!-- copy an old file onto a newer file (should not work) --> | |||
<copy file="${output}/copytest3.tmp" tofile="${output}/copytest3b.tmp" /> | |||
<!-- copy an older file onto a new one, should succeed --> | |||
@@ -66,7 +66,6 @@ | |||
</target> | |||
<target name="testRecreateNewerFileSetup" depends="test4"> | |||
<sleep seconds="3"/> | |||
<touch file="jar.xml"/> | |||
</target> | |||
@@ -111,7 +110,6 @@ | |||
</manifest> | |||
<jar destfile="${tmp.jar}" basedir="." includes="jar.xml" | |||
manifest="${tmp.dir}/manifest"/> | |||
<sleep seconds="3"/> | |||
<touch file="jar.xml"/> | |||
<jar destfile="${tmp.jar}" basedir="." includes="jar.xml" | |||
update="true"/> | |||
@@ -110,14 +110,12 @@ | |||
<!-- test9 will have been run before that --> | |||
<target name="normalRecompile"> | |||
<sleep seconds="2"/> | |||
<touch file="${output}/extended.calc.g"/> | |||
<antlr target="${output}/extended.calc.g" glib="${output}/antlr.g"/> | |||
</target> | |||
<!-- test9 will have been run before that --> | |||
<target name="supergrammarChangeRecompile"> | |||
<sleep seconds="2"/> | |||
<touch file="${output}/antlr.g"/> | |||
<antlr target="${output}/extended.calc.g" glib="${output}/antlr.g"/> | |||
</target> | |||
@@ -19,11 +19,13 @@ | |||
<project name="depend" basedir="." default="help"> | |||
<import file="../../../buildfiletest-base.xml"/> | |||
<target name="setUp"> | |||
<mkdir dir="${output}" /> | |||
<property name="tempsrc.dir" value="${output}/tempsrc.dir"/> | |||
<property name="cache.dir" value="${output}/tempsrc.dir"/> | |||
<property name="classes.dir" value="${output}/classes"/> | |||
<target name="setUp"> | |||
<mkdir dir="${output}" /> | |||
</target> | |||
<property name="src1.dir" value="src1"/> | |||
@@ -71,16 +73,14 @@ | |||
<javac srcdir="${tempsrc.dir}" destdir="${classes.dir}"/> | |||
</target> | |||
<target name="testdirect" depends="src1setup, compile"> | |||
<sleep seconds="3"/> | |||
<target name="testdirect"> | |||
<delete file="${tempsrc.dir}/C.java"/> | |||
<copy file="${src1.dir}/C.java" tofile="${tempsrc.dir}/C.java"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}"/> | |||
<fileset id="result" dir="${classes.dir}"/> | |||
</target> | |||
<target name="testclosure" depends="src1setup, compile"> | |||
<sleep seconds="3"/> | |||
<target name="testclosure"> | |||
<delete file="${tempsrc.dir}/C.java"/> | |||
<copy file="${src1.dir}/C.java" tofile="${tempsrc.dir}/C.java"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/> | |||
@@ -138,16 +138,14 @@ | |||
<classfileset id="result" dir="${classes.dir}" rootclass="E"/> | |||
</target> | |||
<target name="testinner" depends="src2setup, compile"> | |||
<sleep seconds="3"/> | |||
<target name="testinner"> | |||
<delete file="${tempsrc.dir}/B.java"/> | |||
<copy file="${src2.dir}/B.java" tofile="${tempsrc.dir}/B.java"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/> | |||
<fileset id="result" dir="${classes.dir}"/> | |||
</target> | |||
<target name="testinnerinner" depends="src3setup, compile"> | |||
<sleep seconds="3"/> | |||
<target name="testinnerinner"> | |||
<delete file="${tempsrc.dir}/B.java"/> | |||
<copy file="${src3.dir}/B.java" tofile="${tempsrc.dir}/B.java"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/> | |||
@@ -173,10 +171,9 @@ | |||
</path> | |||
<javac srcdir="${tempsrc.dir}" destdir="${classes.dir}" | |||
classpathref="path.compile"/> | |||
classpathref="path.compile" fork="false" /> | |||
<sleep seconds="3"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" | |||
closure="yes" dump="yes" | |||
classpathref="path.compile"/> | |||
@@ -190,8 +187,7 @@ | |||
destdir="${classes.dir}" closure="yes"/> | |||
</target> | |||
<target name="testnonpublic" depends="src5setup, compile"> | |||
<sleep seconds="3"/> | |||
<target name="testnonpublic"> | |||
<delete file="${tempsrc.dir}/B.java"/> | |||
<copy file="${src2.dir}/B.java" tofile="${tempsrc.dir}/B.java"/> | |||
<depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/> | |||
@@ -280,8 +280,7 @@ | |||
<!-- JUnit4 Ignore and Assume for skipping tests --> | |||
<target name="testSkippableTests"> | |||
<mkdir dir="${output}"/> | |||
<junit fork="true"> | |||
<classpath refid="test"/> | |||
<junit> | |||
<formatter type="xml"/> | |||
<classpath refid="test"/> | |||
<batchtest todir="${output}"> | |||
@@ -297,8 +296,7 @@ | |||
<!-- Skipping classes that are not tests --> | |||
<target name="testNonTests"> | |||
<mkdir dir="${output}"/> | |||
<junit fork="true"> | |||
<classpath refid="test"/> | |||
<junit> | |||
<formatter type="xml"/> | |||
<classpath refid="test"/> | |||
<batchtest todir="${output}" skipNonTests="true"> | |||
@@ -313,8 +311,7 @@ | |||
<!-- Not skipping classes that are not tests --> | |||
<target name="testNonTestsRun"> | |||
<mkdir dir="${output}"/> | |||
<junit fork="true"> | |||
<classpath refid="test"/> | |||
<junit> | |||
<formatter type="xml"/> | |||
<classpath refid="test"/> | |||
<batchtest todir="${output}" skipNonTests="false"> | |||
@@ -43,7 +43,7 @@ | |||
<!-- use in conjunction with testDirectoryDateDoesNotChange to make sure something will happen --> | |||
<target name="touchDirectory"> | |||
<copy file="replaceregexp.properties" tofile="${output}/test.properties" /> | |||
<sleep seconds="2"/> | |||
</target> | |||
<target name="testDirectoryDateDoesNotChange"> | |||
<replaceregexp file="${output}/test.properties" byline="true"> | |||
@@ -44,7 +44,7 @@ | |||
before they have finnished (hopefully). Tweak if needed. | |||
--> | |||
<property name="delay" value="3"/> | |||
<property name="delay" value="0"/> | |||
<import file="../../../buildfiletest-base.xml"/> | |||
@@ -19,7 +19,6 @@ | |||
<target name="setUp"> | |||
<touch file="source"/> | |||
<sleep seconds="3"/> | |||
<touch file="target"/> | |||
</target> | |||
@@ -28,19 +27,19 @@ | |||
<delete file="target"/> | |||
</target> | |||
<target name="testFilesetUpToDate" depends="setUp"> | |||
<target name="testFilesetUpToDate"> | |||
<uptodate property="foo" targetfile="target"> | |||
<srcfiles dir="." includes="source"/> | |||
</uptodate> | |||
</target> | |||
<target name="testFilesetOutOfDate" depends="setUp"> | |||
<target name="testFilesetOutOfDate"> | |||
<uptodate property="foo" targetfile="source"> | |||
<srcfiles dir="." includes="target"/> | |||
</uptodate> | |||
</target> | |||
<target name="testRCUpToDate" depends="setUp"> | |||
<target name="testRCUpToDate"> | |||
<uptodate property="foo" targetfile="target"> | |||
<srcresources> | |||
<fileset dir="." includes="source"/> | |||
@@ -48,7 +47,7 @@ | |||
</uptodate> | |||
</target> | |||
<target name="testRCOutOfDate" depends="setUp"> | |||
<target name="testRCOutOfDate"> | |||
<uptodate property="foo" targetfile="source"> | |||
<srcresources> | |||
<fileset dir="." includes="target"/> | |||
@@ -118,7 +118,6 @@ | |||
</target> | |||
<target name="testUpdateIsNecessary" depends="feather"> | |||
<sleep seconds="5" /> | |||
<touch file="${output}/dummyfile" /> | |||
<copy file="../asf-logo.gif" todir="${output}"/> | |||
<zip destFile="${output}/asf-logo.gif.zip" | |||
@@ -88,11 +88,8 @@ | |||
<mkdir dir="${mirror.dir}/tar/bz2" /> | |||
<touch file="${mirror.dir}/asf-logo.gif.md5"/> | |||
<touch file="${mirror.dir}/asf-logo.gif.bz2"/> | |||
<sleep seconds="2"/> | |||
<touch file="${mirror.dir}/zip/asf-logo.gif.zip"/> | |||
<sleep seconds="3"/> | |||
<touch file="${mirror.dir}/tar/asf-logo.gif.tar"/> | |||
<sleep seconds="2"/> | |||
<touch file="${mirror.dir}/tar/asf-logo-huge.tar.gz"/> | |||
<touch file="${mirror.dir}/tar/gz/asf-logo.gif.tar.gz"/> | |||
<touch file="${mirror.dir}/tar/bz2/asf-logo.gif.tar.bz2"/> | |||
@@ -0,0 +1,72 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Provides common assert functions for use across multiple tests, similar to the <tt>Assert</tt>s | |||
* within JUnit. | |||
*/ | |||
public class AntAssert { | |||
/** | |||
* Assert that a string contains the given substring. | |||
* @param message the message to fail with if the substring is not present in the target string. | |||
* @param needle the string to search for. | |||
* @param haystack the string to search in. | |||
*/ | |||
public static void assertContains(String message, String needle, String haystack) { | |||
String formattedMessage = (message == null ? "" : message + " "); | |||
assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||
} | |||
/** | |||
* Assert that a string contains the given substring. A default failure message will be used if the target string | |||
* is not found. | |||
* @param needle the target string to search for. | |||
* @param haystack the string to search in. | |||
*/ | |||
public static void assertContains(String needle, String haystack) { | |||
assertContains("", needle, haystack); | |||
} | |||
/** | |||
* Assert that a string does not contain the given substring. | |||
* @param message the message to fail with if the substring is present in the target string. | |||
* @param needle the string to search for. | |||
* @param haystack the string to search in. | |||
*/ | |||
public static void assertNotContains(String message, String needle, String haystack) { | |||
String formattedMessage = (message == null ? "" : message + " "); | |||
assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||
} | |||
/** | |||
* Assert that a string does not contain the given substring. A default failure message will be used if the target | |||
* string is found. | |||
* @param needle the target string to search for. | |||
* @param haystack the string to search in. | |||
*/ | |||
public static void assertNotContains(String needle, String haystack) { | |||
assertNotContains("", needle, haystack); | |||
} | |||
} |
@@ -25,26 +25,27 @@ import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.Enumeration; | |||
import java.util.List; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Test case for ant class loader | |||
* | |||
*/ | |||
public class AntClassLoaderDelegationTest extends TestCase { | |||
public class AntClassLoaderDelegationTest { | |||
/** Instance of a utility class to use for file operations. */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
private Project p; | |||
public AntClassLoaderDelegationTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
p = new Project(); | |||
p.init(); | |||
@@ -53,7 +54,8 @@ public class AntClassLoaderDelegationTest extends TestCase { | |||
/** Sample resource present in build/testcases/ */ | |||
private static final String TEST_RESOURCE | |||
= "apache/tools/ant/IncludeTest.class"; | |||
@Test | |||
public void testFindResources() throws Exception { | |||
// This path should contain the class files for these testcases: | |||
String buildTestcases = System.getProperty("build.tests"); | |||
@@ -79,6 +81,7 @@ public class AntClassLoaderDelegationTest extends TestCase { | |||
enum2List(acl.getResources(TEST_RESOURCE))); | |||
} | |||
@Test | |||
public void testFindIsolateResources() throws Exception { | |||
String buildTestcases = System.getProperty("build.tests"); | |||
assertNotNull("defined ${build.tests}", buildTestcases); | |||
@@ -19,15 +19,16 @@ | |||
package org.apache.tools.ant; | |||
import java.io.File; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Test; | |||
/** | |||
* Used to verify the performance effect of classloader changes. | |||
*/ | |||
public class AntClassLoaderPerformance extends TestCase { | |||
public class AntClassLoaderPerformance { | |||
@Test | |||
public void testFindClass() throws Exception { | |||
String testCaseURL = getClass() | |||
.getClassLoader().getResource("junit/framework/TestCase.class") | |||
@@ -18,63 +18,75 @@ | |||
package org.apache.tools.ant; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
import java.io.File; | |||
import java.io.PrintStream; | |||
import java.net.URL; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* Test case for ant class loader | |||
* | |||
*/ | |||
public class AntClassLoaderTest extends BuildFileTest { | |||
public class AntClassLoaderTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private AntClassLoader loader; | |||
public AntClassLoaderTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
super.configureProject("src/etc/testcases/core/antclassloader.xml"); | |||
getProject().executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/core/antclassloader.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@After | |||
public void tearDown() { | |||
if (loader != null) { | |||
loader.cleanup(); | |||
} | |||
try { | |||
super.tearDown(); | |||
} catch ( Exception e) { | |||
System.err.println(e.getMessage()); | |||
} | |||
} | |||
//test inspired by bug report 37085 | |||
@Test | |||
public void testJarWithManifestInDirWithSpace() { | |||
String mainjarstring = getProject().getProperty("main.jar"); | |||
String extjarstring = getProject().getProperty("ext.jar"); | |||
Path myPath = new Path(getProject()); | |||
String mainjarstring = buildRule.getProject().getProperty("main.jar"); | |||
String extjarstring = buildRule.getProject().getProperty("ext.jar"); | |||
Path myPath = new Path(buildRule.getProject()); | |||
myPath.setLocation(new File(mainjarstring)); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
String path = loader.getClasspath(); | |||
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | |||
} | |||
@Test | |||
public void testJarWithManifestInNonAsciiDir() { | |||
String mainjarstring = getProject().getProperty("main.jar.nonascii"); | |||
String extjarstring = getProject().getProperty("ext.jar.nonascii"); | |||
Path myPath = new Path(getProject()); | |||
String mainjarstring = buildRule.getProject().getProperty("main.jar.nonascii"); | |||
String extjarstring = buildRule.getProject().getProperty("ext.jar.nonascii"); | |||
Path myPath = new Path(buildRule.getProject()); | |||
myPath.setLocation(new File(mainjarstring)); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
String path = loader.getClasspath(); | |||
assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | |||
} | |||
@Test | |||
public void testCleanup() throws BuildException { | |||
Path path = new Path(project, "."); | |||
loader = project.createClassLoader(path); | |||
Path path = new Path(buildRule.getProject(), "."); | |||
loader = buildRule.getProject().createClassLoader(path); | |||
try { | |||
// we don't expect to find this | |||
loader.findClass("fubar"); | |||
@@ -95,7 +107,7 @@ public class AntClassLoaderTest extends BuildFileTest { | |||
} | |||
// tell the build it is finished | |||
project.fireBuildFinished(null); | |||
buildRule.getProject().fireBuildFinished(null); | |||
try { | |||
// we don't expect to find this | |||
loader.findClass("fubar"); | |||
@@ -107,40 +119,43 @@ public class AntClassLoaderTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testGetPackage() throws Exception { | |||
executeTarget("prepareGetPackageTest"); | |||
Path myPath = new Path(getProject()); | |||
myPath.setLocation(new File(getProject().getProperty("test.jar"))); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
buildRule.executeTarget("prepareGetPackageTest"); | |||
Path myPath = new Path(buildRule.getProject()); | |||
myPath.setLocation(new File(buildRule.getProject().getProperty("test.jar"))); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
assertNotNull("should find class", loader.findClass("org.example.Foo")); | |||
assertNotNull("should find package", | |||
new GetPackageWrapper(loader).getPackage("org.example")); | |||
} | |||
@Test | |||
public void testCodeSource() throws Exception { | |||
executeTarget("prepareGetPackageTest"); | |||
Path myPath = new Path(getProject()); | |||
File testJar = new File(getProject().getProperty("test.jar")); | |||
buildRule.executeTarget("prepareGetPackageTest"); | |||
Path myPath = new Path(buildRule.getProject()); | |||
File testJar = new File(buildRule.getProject().getProperty("test.jar")); | |||
myPath.setLocation(testJar); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
Class foo = loader.findClass("org.example.Foo"); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
Class<?> foo = loader.findClass("org.example.Foo"); | |||
URL codeSourceLocation = | |||
foo.getProtectionDomain().getCodeSource().getLocation(); | |||
assertEquals(codeSourceLocation + " should point to test.jar", | |||
FileUtils.getFileUtils().getFileURL(testJar), codeSourceLocation); | |||
} | |||
@Test | |||
public void testSignedJar() throws Exception { | |||
executeTarget("signTestJar"); | |||
File jar = new File(getProject().getProperty("test.jar")); | |||
buildRule.executeTarget("signTestJar"); | |||
File jar = new File(buildRule.getProject().getProperty("test.jar")); | |||
Path myPath = new Path(getProject()); | |||
Path myPath = new Path(buildRule.getProject()); | |||
myPath.setLocation(jar); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
Class foo = loader.findClass("org.example.Foo"); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
Class<?> foo = loader.findClass("org.example.Foo"); | |||
assertNotNull("should find class", foo); | |||
assertNotNull("should have certificates", | |||
@@ -154,23 +169,24 @@ public class AntClassLoaderTest extends BuildFileTest { | |||
* bug 47593, request to log the name of corrupt zip files from which | |||
* classes cannot be loaded</a> | |||
*/ | |||
@Test | |||
public void testInvalidZipException() throws Exception { | |||
executeTarget("createNonJar"); | |||
File jar = new File(getProject().getProperty("tmp.dir") | |||
buildRule.executeTarget("createNonJar"); | |||
File jar = new File(buildRule.getProject().getProperty("tmp.dir") | |||
+ "/foo.jar"); | |||
Path myPath = new Path(getProject()); | |||
Path myPath = new Path(buildRule.getProject()); | |||
myPath.setLocation(jar); | |||
getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = getProject().createClassLoader(myPath); | |||
buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); | |||
loader = buildRule.getProject().createClassLoader(myPath); | |||
PrintStream sysErr = System.err; | |||
try { | |||
StringBuffer errBuffer = new StringBuffer(); | |||
PrintStream err = | |||
new PrintStream(new BuildFileTest.AntOutputStream(errBuffer)); | |||
new PrintStream(new BuildFileRule.AntOutputStream(errBuffer)); | |||
System.setErr(err); | |||
loader.getResource("foo.txt"); | |||
String log = getLog(); | |||
String log = buildRule.getLog(); | |||
int startMessage = log.indexOf("CLASSPATH element "); | |||
assertTrue(startMessage >= 0); | |||
assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0); | |||
@@ -0,0 +1,318 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant; | |||
import java.io.File; | |||
import java.io.OutputStream; | |||
import java.io.PrintStream; | |||
import org.apache.tools.ant.util.ProcessUtil; | |||
import org.junit.rules.ExternalResource; | |||
/** | |||
* Provides access for JUnit tests to execute Ant targets and access execution details (i.e logs). | |||
* | |||
* Example usage: | |||
* <code> | |||
* public class MyTest { | |||
* | |||
* \@Rule | |||
* public BuildFileRule rule = new BuildFileRule(); | |||
* | |||
* \@Before | |||
* public void setUp() { | |||
* rule.configureProject("my/and/file.xml"); | |||
* } | |||
* | |||
* \@Test | |||
* public void testSuccess() { | |||
* rule.executeTarget("passingTaget"); | |||
* assertEquals("Incorrect log message", "[taskName] Action Complete", rule.getLog()); | |||
* } | |||
* | |||
* \@Test | |||
* public void testException() { | |||
* try { | |||
* rule.executeTarget("failingTarget"); | |||
* fail("Target should have thrown a BuildException"); | |||
* } catch (BuildException ex) { | |||
* assertContains("Exception did not contain correct text", "Could not find compiler on classpath", ex.getMessage()); | |||
* } | |||
* } | |||
* | |||
* } | |||
* </code> | |||
*/ | |||
public class BuildFileRule extends ExternalResource { | |||
private Project project; | |||
private StringBuffer logBuffer; | |||
private StringBuffer fullLogBuffer; | |||
private StringBuffer outputBuffer; | |||
private StringBuffer errorBuffer; | |||
/** | |||
* Tidies up following a test execution. If the currently configured | |||
* project has a <tt>tearDown</tt> target then this will automatically | |||
* be called, otherwise this method will not perform any actions. | |||
*/ | |||
@Override | |||
protected void after() { | |||
if (project == null) { | |||
// configureProject has not been called - nothing we can clean-up | |||
return; | |||
} | |||
final String tearDown = "tearDown"; | |||
if (project.getTargets().containsKey(tearDown)) { | |||
project.executeTarget(tearDown); | |||
} | |||
} | |||
/** | |||
* Gets the INFO, WARNING and ERROR message from the current execution, | |||
* unless the logging level is set above any of these level in which case | |||
* the message is excluded. | |||
* This is only valid if configureProject() has been called. | |||
* | |||
* @return The INFO, WARN and ERROR messages in the log. | |||
*/ | |||
public String getLog() { | |||
return logBuffer.toString(); | |||
} | |||
/** | |||
* Gets any messages that have been logged during the current execution, unless | |||
* the logging level has been set above the log level defined in the message. | |||
* | |||
* Only valid if configureProject() has been called. | |||
* @return the content of the log. | |||
*/ | |||
public String getFullLog() { | |||
return fullLogBuffer.toString(); | |||
} | |||
/** | |||
* Provides all output sent to the System.out stream during the current execution. | |||
* @return all output messages in a single string, normalised to have platform independent line breaks. | |||
*/ | |||
public String getOutput() { | |||
return cleanBuffer(outputBuffer); | |||
} | |||
/** | |||
* Provides all output sent to the System.err stream during the current execution. | |||
* @return all error messages in a single string, normalised to have platform independent line breaks. | |||
*/ | |||
public String getError() { | |||
return cleanBuffer(errorBuffer); | |||
} | |||
private String cleanBuffer(StringBuffer buffer) { | |||
StringBuilder cleanedBuffer = new StringBuilder(); | |||
for (int i = 0; i < buffer.length(); i++) { | |||
char ch = buffer.charAt(i); | |||
if (ch != '\r') { | |||
cleanedBuffer.append(ch); | |||
} | |||
} | |||
return cleanedBuffer.toString(); | |||
} | |||
/** | |||
* Sets up to run the named project | |||
* | |||
* @param filename name of project file to run | |||
*/ | |||
public void configureProject(String filename) throws BuildException { | |||
configureProject(filename, Project.MSG_DEBUG); | |||
} | |||
/** | |||
* Sets up to run the named project | |||
* | |||
* @param filename name of project file to run | |||
*/ | |||
public void configureProject(String filename, int logLevel) throws BuildException { | |||
logBuffer = new StringBuffer(); | |||
fullLogBuffer = new StringBuffer(); | |||
project = new Project(); | |||
project.init(); | |||
File antFile = new File(System.getProperty("root"), filename); | |||
project.setProperty("ant.processid", ProcessUtil.getProcessId("<Process>")); | |||
project.setProperty("ant.threadname", Thread.currentThread().getName()); | |||
project.setUserProperty("ant.file" , antFile.getAbsolutePath()); | |||
project.addBuildListener(new AntTestListener(logLevel)); | |||
ProjectHelper.configureProject(project, antFile); | |||
} | |||
/** | |||
* Executes a target in the configured Ant build file. Requires #configureProject() | |||
* to have been invoked before this call. | |||
* | |||
* @param targetName the target in the currently configured build file to run. | |||
*/ | |||
public void executeTarget(String targetName) { | |||
outputBuffer = new StringBuffer(); | |||
PrintStream out = new PrintStream(new AntOutputStream(outputBuffer)); | |||
errorBuffer = new StringBuffer(); | |||
PrintStream err = new PrintStream(new AntOutputStream(errorBuffer)); | |||
logBuffer = new StringBuffer(); | |||
fullLogBuffer = new StringBuffer(); | |||
/* we synchronize to protect our custom output streams from being overridden | |||
* by other tests executing targets concurrently. Ultimately this would only | |||
* happen if we ran a multi-threaded test executing multiple targets at once, and | |||
* this protection doesn't prevent a target from internally modifying the output | |||
* stream during a test - but at least this scenario is fairly deterministic so | |||
* easier to troubleshoot. | |||
*/ | |||
synchronized (System.out) { | |||
PrintStream sysOut = System.out; | |||
PrintStream sysErr = System.err; | |||
sysOut.flush(); | |||
sysErr.flush(); | |||
try { | |||
System.setOut(out); | |||
System.setErr(err); | |||
project.executeTarget(targetName); | |||
} finally { | |||
System.setOut(sysOut); | |||
System.setErr(sysErr); | |||
} | |||
} | |||
} | |||
/** | |||
* Get the project which has been configured for a test. | |||
* | |||
* @return the Project instance for this test. | |||
*/ | |||
public Project getProject() { | |||
return project; | |||
} | |||
/** | |||
* An output stream which saves contents to our buffer. | |||
*/ | |||
protected static class AntOutputStream extends OutputStream { | |||
private StringBuffer buffer; | |||
public AntOutputStream( StringBuffer buffer ) { | |||
this.buffer = buffer; | |||
} | |||
public void write(int b) { | |||
buffer.append((char)b); | |||
} | |||
} | |||
/** | |||
* Our own personal build listener. | |||
*/ | |||
private class AntTestListener implements BuildListener { | |||
private int logLevel; | |||
/** | |||
* Constructs a test listener which will ignore log events | |||
* above the given level. | |||
*/ | |||
public AntTestListener(int logLevel) { | |||
this.logLevel = logLevel; | |||
} | |||
/** | |||
* Fired before any targets are started. | |||
*/ | |||
public void buildStarted(BuildEvent event) { | |||
} | |||
/** | |||
* Fired after the last target has finished. This event | |||
* will still be thrown if an error occurred during the build. | |||
* | |||
* @see BuildEvent#getException() | |||
*/ | |||
public void buildFinished(BuildEvent event) { | |||
} | |||
/** | |||
* Fired when a target is started. | |||
* | |||
* @see BuildEvent#getTarget() | |||
*/ | |||
public void targetStarted(BuildEvent event) { | |||
} | |||
/** | |||
* Fired when a target has finished. This event will | |||
* still be thrown if an error occurred during the build. | |||
* | |||
* @see BuildEvent#getException() | |||
*/ | |||
public void targetFinished(BuildEvent event) { | |||
} | |||
/** | |||
* Fired when a task is started. | |||
* | |||
* @see BuildEvent#getTask() | |||
*/ | |||
public void taskStarted(BuildEvent event) { | |||
} | |||
/** | |||
* Fired when a task has finished. This event will still | |||
* be throw if an error occurred during the build. | |||
* | |||
* @see BuildEvent#getException() | |||
*/ | |||
public void taskFinished(BuildEvent event) { | |||
} | |||
/** | |||
* Fired whenever a message is logged. | |||
* | |||
* @see BuildEvent#getMessage() | |||
* @see BuildEvent#getPriority() | |||
*/ | |||
public void messageLogged(BuildEvent event) { | |||
if (event.getPriority() > logLevel) { | |||
// ignore event | |||
return; | |||
} | |||
if (event.getPriority() == Project.MSG_INFO || | |||
event.getPriority() == Project.MSG_WARN || | |||
event.getPriority() == Project.MSG_ERR) { | |||
logBuffer.append(event.getMessage()); | |||
} | |||
fullLogBuffer.append(event.getMessage()); | |||
} | |||
} | |||
public File getOutputDir() { | |||
return new File(getProject().getProperty("output")); | |||
} | |||
} | |||
@@ -32,7 +32,10 @@ import org.apache.tools.ant.util.ProcessUtil; | |||
* This class provides a number of utility methods for particular build file | |||
* tests which extend this class. | |||
* | |||
* @deprecated as of 1.9.4. Use BuildFileRule, Assert, AntAssert and JUnit4 annotations to drive tests instead | |||
* @see org.apache.tools.ant.BuildFileRule | |||
*/ | |||
@Deprecated | |||
public abstract class BuildFileTest extends TestCase { | |||
protected Project project; | |||
@@ -18,37 +18,47 @@ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Simple tests of build file processing | |||
*/ | |||
public class CaseTest extends BuildFileTest { | |||
public CaseTest(String name) { | |||
super(name); | |||
} | |||
public class CaseTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/case.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/case.xml"); | |||
} | |||
/** | |||
* Test whether the build file treats nested elements without | |||
* regard to case. This should not cause an exception. | |||
*/ | |||
@Test | |||
public void testCaseSensitivity() { | |||
executeTarget("case-sensitivity"); | |||
buildRule.executeTarget("case-sensitivity"); | |||
} | |||
/** | |||
* Test whether the build file uses case when determining | |||
* task names. | |||
*/ | |||
@Test | |||
public void testTaskCase() { | |||
expectBuildExceptionContaining("taskcase", | |||
"Task names are case sensitive", | |||
"Problem: failed to create task or type ecHO"); | |||
try { | |||
buildRule.executeTarget("taskcase"); | |||
fail("Build exception should have been thrown due to case sensitivity of name"); | |||
} catch(BuildException ex) { | |||
assertContains("Task names should be case sensitive", "Problem: failed to create task or type ecHO", ex.getMessage()); | |||
} | |||
} | |||
} | |||
@@ -18,15 +18,15 @@ | |||
package org.apache.tools.ant; | |||
import java.io.PrintWriter; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.junit.Test; | |||
public class DefaultLoggerTest extends TestCase { | |||
import java.io.PrintWriter; | |||
import static org.junit.Assert.assertEquals; | |||
public class DefaultLoggerTest { | |||
public DefaultLoggerTest(String n) { | |||
super(n); | |||
} | |||
private static String msg(Throwable error, boolean verbose) { | |||
StringBuffer m = new StringBuffer(); | |||
@@ -34,6 +34,7 @@ public class DefaultLoggerTest extends TestCase { | |||
return m.toString(); | |||
} | |||
@Test | |||
public void testThrowableMessage() throws Exception { // #43398 | |||
BuildException be = new BuildException("oops", new Location("build.xml", 1, 0)); | |||
assertEquals( | |||
@@ -18,9 +18,11 @@ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.apache.tools.ant.types.selectors.TokenizedPath; | |||
import org.apache.tools.ant.util.SymbolicLinkUtils; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assume.assumeTrue; | |||
import static org.junit.Assume.assumeFalse; | |||
import java.io.File; | |||
import java.io.IOException; | |||
@@ -30,34 +32,43 @@ import java.util.List; | |||
import java.util.Set; | |||
import java.util.TreeSet; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.apache.tools.ant.types.selectors.TokenizedPath; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* JUnit 3 testcases for org.apache.tools.ant.DirectoryScanner | |||
* JUnit testcases for org.apache.tools.ant.DirectoryScanner | |||
* | |||
*/ | |||
public class DirectoryScannerTest extends BuildFileTest { | |||
public DirectoryScannerTest(String name) {super(name);} | |||
public class DirectoryScannerTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
// keep track of what operating systems are supported here. | |||
private boolean supportsSymlinks = Os.isFamily("unix"); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/directoryscanner.xml"); | |||
getProject().executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/core/directoryscanner.xml"); | |||
buildRule.getProject().executeTarget("setUp"); | |||
} | |||
@Test | |||
public void test1() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {} ,new String[] {"alpha"}); | |||
} | |||
@Test | |||
public void test2() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/beta.xml", | |||
@@ -65,9 +76,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void test3() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/beta.xml", | |||
"alpha/beta/gamma/gamma.xml"}, | |||
@@ -75,27 +87,30 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
"alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testFullPathMatchesCaseSensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {}, new String[] {}); | |||
} | |||
@Test | |||
public void testFullPathMatchesCaseInsensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setCaseSensitive(false); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, | |||
new String[] {}); | |||
} | |||
@Test | |||
public void test2ButCaseInsensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"ALPHA/"}); | |||
ds.setCaseSensitive(false); | |||
ds.scan(); | |||
@@ -104,28 +119,28 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testAllowSymlinks() { | |||
if (!supportsSymlinks) { | |||
return; | |||
} | |||
assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||
getProject().executeTarget("symlink-setup"); | |||
buildRule.getProject().executeTarget("symlink-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/beta/gamma/"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, | |||
new String[] {"alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testProhibitSymlinks() { | |||
if (!supportsSymlinks) { | |||
return; | |||
} | |||
assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||
getProject().executeTarget("symlink-setup"); | |||
buildRule.getProject().executeTarget("symlink-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/beta/gamma/"}); | |||
ds.setFollowSymlinks(false); | |||
ds.scan(); | |||
@@ -133,26 +148,28 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
} | |||
// father and child pattern test | |||
@Test | |||
public void testOrderOfIncludePatternsIrrelevant() { | |||
String [] expectedFiles = {"alpha/beta/beta.xml", | |||
"alpha/beta/gamma/gamma.xml"}; | |||
String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" }; | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"}); | |||
ds.scan(); | |||
compareFiles(ds, expectedFiles, expectedDirectories); | |||
// redo the test, but the 2 include patterns are inverted | |||
ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"}); | |||
ds.scan(); | |||
compareFiles(ds, expectedFiles, expectedDirectories); | |||
} | |||
@Test | |||
public void testPatternsDifferInCaseScanningSensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/beta.xml", | |||
@@ -160,9 +177,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testPatternsDifferInCaseScanningInsensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); | |||
ds.setCaseSensitive(false); | |||
ds.scan(); | |||
@@ -171,9 +189,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testFullpathDiffersInCaseScanningSensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] { | |||
"alpha/beta/gamma/gamma.xml", | |||
"alpha/beta/gamma/GAMMA.XML" | |||
@@ -183,9 +202,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {}); | |||
} | |||
@Test | |||
public void testFullpathDiffersInCaseScanningInsensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] { | |||
"alpha/beta/gamma/gamma.xml", | |||
"alpha/beta/gamma/GAMMA.XML" | |||
@@ -196,9 +216,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {}); | |||
} | |||
@Test | |||
public void testParentDiffersInCaseScanningSensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); | |||
ds.scan(); | |||
compareFiles(ds, new String[] {"alpha/beta/beta.xml", | |||
@@ -206,9 +227,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testParentDiffersInCaseScanningInsensitive() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); | |||
ds.setCaseSensitive(false); | |||
ds.scan(); | |||
@@ -222,8 +244,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
* Only supports test on Linux at the moment because Java has | |||
* no real notion of symlinks built in, so an os-specfic call | |||
* to Runtime.exec() must be made to create a link to test against. | |||
* @throws InterruptedException | |||
*/ | |||
public void testSetFollowLinks() throws IOException { | |||
@Test | |||
public void testSetFollowLinks() throws IOException, InterruptedException { | |||
if (supportsSymlinks) { | |||
File linkFile = new File(System.getProperty("root"), "src/main/org/apache/tools/ThisIsALink"); | |||
System.err.println("link exists pre-test? " + linkFile.exists()); | |||
@@ -233,20 +257,11 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
String[] command = new String[] { | |||
"ln", "-s", "ant", linkFile.getAbsolutePath() | |||
}; | |||
try { | |||
Runtime.getRuntime().exec(command); | |||
// give ourselves some time for the system call | |||
// to execute... tweak if you have a really over | |||
// loaded system. | |||
Thread.sleep(1000); | |||
} catch (IOException ioe) { | |||
fail("IOException making link "+ioe); | |||
} catch (InterruptedException ie) { | |||
} | |||
Process process = Runtime.getRuntime().exec(command); | |||
assertEquals("0 return code expected for external process", 0, process.waitFor()); | |||
File dir = new File(System.getProperty("root"), "src/main/org/apache/tools"); | |||
System.err.println("link exists after exec? " + linkFile.exists()); | |||
System.err.println("Ant knows it is a link? " + SymbolicLinkUtils.getSymbolicLinkUtils().isSymbolicLink(dir, "ThisIsALink")); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
@@ -304,18 +319,19 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
!haveTaskdefsPackage); | |||
} finally { | |||
System.err.println("link exists pre-delete? " + linkFile.exists()); | |||
if (!linkFile.delete()) { | |||
throw new RuntimeException("Failed to delete " + linkFile); | |||
//TODO log this? | |||
//throw new RuntimeException("Failed to delete " + linkFile); | |||
} | |||
System.err.println("link exists post-delete? " + linkFile.exists()); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testExcludeOneFile() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] { | |||
"**/*.xml" | |||
}); | |||
@@ -327,9 +343,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {}); | |||
} | |||
@Test | |||
public void testExcludeHasPrecedence() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] { | |||
"alpha/**" | |||
}); | |||
@@ -342,9 +359,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
} | |||
@Test | |||
public void testAlternateIncludeExclude() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setIncludes(new String[] { | |||
"alpha/**", | |||
"alpha/beta/gamma/**" | |||
@@ -358,9 +376,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
} | |||
@Test | |||
public void testAlternateExcludeInclude() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setExcludes(new String[] { | |||
"alpha/**", | |||
"alpha/beta/gamma/**" | |||
@@ -377,10 +396,11 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
/** | |||
* Test inspired by Bug#1415. | |||
*/ | |||
@Test | |||
public void testChildrenOfExcludedDirectory() { | |||
getProject().executeTarget("children-of-excluded-dir-setup"); | |||
buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setExcludes(new String[] {"alpha/**"}); | |||
ds.setFollowSymlinks(false); | |||
ds.scan(); | |||
@@ -388,7 +408,7 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {"", "delta"}); | |||
ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setExcludes(new String[] {"alpha"}); | |||
ds.setFollowSymlinks(false); | |||
ds.scan(); | |||
@@ -399,35 +419,35 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
} | |||
@Test | |||
public void testIsExcludedDirectoryScanned() { | |||
String shareclassloader = getProject().getProperty("tests.and.ant.share.classloader"); | |||
String shareclassloader = buildRule.getProject().getProperty("tests.and.ant.share.classloader"); | |||
// when the test is started by the build.xml of ant | |||
// if the property tests.and.ant.share.classloader is not set in the build.xml | |||
// a sysproperty with name tests.and.ant.share.classloader and value | |||
// ${tests.and.ant.share.classloader} will be set | |||
// we are trying to catch this here. | |||
if (shareclassloader == null | |||
|| (shareclassloader != null && shareclassloader.startsWith("${"))) { | |||
System.out.println("cannot execute testIsExcludedDirectoryScanned when tests are forked, " + | |||
"package private method called"); | |||
return; | |||
} | |||
getProject().executeTarget("children-of-excluded-dir-setup"); | |||
assumeFalse("cannot execute testIsExcludedDirectoryScanned when tests are forked, " + | |||
"package private method called", shareclassloader == null | |||
|| (shareclassloader != null && shareclassloader.indexOf("${") == 0)); | |||
buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setExcludes(new String[] {"**/gamma/**"}); | |||
ds.setFollowSymlinks(false); | |||
ds.scan(); | |||
Set set = ds.getScannedDirs(); | |||
Set<String> set = ds.getScannedDirs(); | |||
assertFalse("empty set", set.isEmpty()); | |||
String s = "alpha/beta/gamma/".replace('/', File.separatorChar); | |||
assertFalse("scanned " + s, set.contains(s)); | |||
} | |||
@Test | |||
public void testAbsolute1() { | |||
getProject().executeTarget("extended-setup"); | |||
buildRule.getProject().executeTarget("extended-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
String tmpdir = getProject().getProperty("output").replace( | |||
String tmpdir = buildRule.getProject().getProperty("output").replace( | |||
File.separatorChar, '/'); | |||
ds.setIncludes(new String[] {tmpdir + "/**/*"}); | |||
ds.scan(); | |||
@@ -440,6 +460,7 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
tmpdir + "/delta"}); | |||
} | |||
@Test | |||
public void testAbsolute2() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setIncludes(new String[] {"alpha/**", "alpha/beta/gamma/**"}); | |||
@@ -448,10 +469,11 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
compareFiles(ds, mt, mt); | |||
} | |||
@Test | |||
public void testAbsolute3() { | |||
getProject().executeTarget("extended-setup"); | |||
buildRule.getProject().executeTarget("extended-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
String tmpdir = getProject().getProperty("output").replace( | |||
String tmpdir = buildRule.getProject().getProperty("output").replace( | |||
File.separatorChar, '/'); | |||
ds.setIncludes(new String[] {tmpdir + "/**/*"}); | |||
ds.setExcludes(new String[] {"**/alpha", | |||
@@ -464,11 +486,12 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
tmpdir + "/delta"}); | |||
} | |||
@Test | |||
public void testAbsolute4() { | |||
getProject().executeTarget("extended-setup"); | |||
buildRule.getProject().executeTarget("extended-setup"); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
String tmpdir = getProject().getProperty("output").replace( | |||
File.separatorChar, '/') ; | |||
String tmpdir = buildRule.getProject().getProperty("output").replace( | |||
File.separatorChar, '/') ; | |||
ds.setIncludes(new String[] {tmpdir + "/alpha/beta/**/*", | |||
tmpdir + "/delta/*"}); | |||
ds.setExcludes(new String[] {"**/beta.xml"}); | |||
@@ -478,11 +501,10 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
new String[] {tmpdir + "/alpha/beta/gamma"}); | |||
} | |||
@Test | |||
public void testAbsolute5() { | |||
//testing drive letter search from root: | |||
if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { | |||
return; | |||
} | |||
assumeTrue("Can't use drive letters on non DOS or Netware systems", (Os.isFamily("dos") || Os.isFamily("netware"))); | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
String pattern = new File(File.separator).getAbsolutePath().toUpperCase() + "*"; | |||
ds.setIncludes(new String[] {pattern}); | |||
@@ -501,18 +523,18 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
assertEquals("directories present: ", expectedDirectories.length, | |||
includedDirectories.length); | |||
TreeSet files = new TreeSet(); | |||
TreeSet<String> files = new TreeSet<String>(); | |||
for (int counter = 0; counter < includedFiles.length; counter++) { | |||
files.add(includedFiles[counter].replace(File.separatorChar, '/')); | |||
} | |||
TreeSet directories = new TreeSet(); | |||
TreeSet<String> directories = new TreeSet<String>(); | |||
for (int counter = 0; counter < includedDirectories.length; counter++) { | |||
directories.add(includedDirectories[counter] | |||
.replace(File.separatorChar, '/')); | |||
} | |||
String currentfile; | |||
Iterator i = files.iterator(); | |||
Iterator<String> i = files.iterator(); | |||
int counter = 0; | |||
while (i.hasNext()) { | |||
currentfile = (String) i.next(); | |||
@@ -520,7 +542,7 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
counter++; | |||
} | |||
String currentdirectory; | |||
Iterator dirit = directories.iterator(); | |||
Iterator<String> dirit = directories.iterator(); | |||
counter = 0; | |||
while (dirit.hasNext()) { | |||
currentdirectory = (String) dirit.next(); | |||
@@ -529,19 +551,20 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testRecursiveExcludes() throws Exception { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(getProject().getProperty("output"))); | |||
ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); | |||
ds.setExcludes(new String[] {"**/beta/**"}); | |||
ds.scan(); | |||
List dirs = Arrays.asList(ds.getExcludedDirectories()); | |||
List<String> dirs = Arrays.asList(ds.getExcludedDirectories()); | |||
assertEquals(2, dirs.size()); | |||
assertTrue("beta is excluded", | |||
dirs.contains("alpha/beta".replace('/', File.separatorChar))); | |||
assertTrue("gamma is excluded", | |||
dirs.contains("alpha/beta/gamma".replace('/', | |||
File.separatorChar))); | |||
List files = Arrays.asList(ds.getExcludedFiles()); | |||
List<String> files = Arrays.asList(ds.getExcludedFiles()); | |||
assertEquals(2, files.size()); | |||
assertTrue("beta.xml is excluded", | |||
files.contains("alpha/beta/beta.xml" | |||
@@ -551,6 +574,7 @@ public class DirectoryScannerTest extends BuildFileTest { | |||
.replace('/', File.separatorChar))); | |||
} | |||
@Test | |||
public void testContentsExcluded() { | |||
DirectoryScanner ds = new DirectoryScanner(); | |||
ds.setBasedir(new File(".")); | |||
@@ -18,19 +18,29 @@ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import static org.junit.Assert.fail; | |||
public class DispatchTaskTest extends BuildFileTest { | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public DispatchTaskTest(String name) { | |||
super(name); | |||
} | |||
public class DispatchTaskTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/dispatch/dispatch.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/dispatch/dispatch.xml"); | |||
} | |||
@Test | |||
public void testDisp() { | |||
expectBuildException("disp", "list"); | |||
try { | |||
buildRule.executeTarget("disp"); | |||
fail("BuildException should have been thrown"); | |||
} catch(BuildException ex) { | |||
//FIXME the previous method used here ignored the build exception - what are we trying to test | |||
} | |||
} | |||
} |
@@ -18,23 +18,35 @@ | |||
package org.apache.tools.ant; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
import java.util.Vector; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* Executor tests | |||
*/ | |||
public class ExecutorTest extends BuildFileTest implements BuildListener { | |||
private static final String SINGLE_CHECK | |||
public class ExecutorTest implements BuildListener { | |||
private static final String SINGLE_CHECK | |||
= "org.apache.tools.ant.helper.SingleCheckExecutor"; | |||
private static final String IGNORE_DEPS | |||
= "org.apache.tools.ant.helper.IgnoreDependenciesExecutor"; | |||
private static final Vector TARGET_NAMES; | |||
private static final Vector<String> TARGET_NAMES; | |||
static { | |||
TARGET_NAMES = new Vector(); | |||
TARGET_NAMES = new Vector<String>(); | |||
TARGET_NAMES.add("a"); | |||
TARGET_NAMES.add("b"); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private int targetCount; | |||
/* BuildListener stuff */ | |||
@@ -48,14 +60,11 @@ public class ExecutorTest extends BuildFileTest implements BuildListener { | |||
public void taskFinished(BuildEvent event) {} | |||
public void messageLogged(BuildEvent event) {} | |||
public ExecutorTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/executor.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/executor.xml"); | |||
targetCount = 0; | |||
getProject().addBuildListener(this); | |||
buildRule.getProject().addBuildListener(this); | |||
} | |||
private Project getProject(String e) { | |||
@@ -67,7 +76,7 @@ public class ExecutorTest extends BuildFileTest implements BuildListener { | |||
} | |||
private Project getProject(String e, boolean f, boolean k) { | |||
Project p = getProject(); | |||
Project p = buildRule.getProject(); | |||
p.setNewProperty("ant.executor.class", e); | |||
p.setKeepGoingMode(k); | |||
if (f) { | |||
@@ -76,75 +85,84 @@ public class ExecutorTest extends BuildFileTest implements BuildListener { | |||
return p; | |||
} | |||
@Test | |||
public void testDefaultExecutor() { | |||
getProject().executeTargets(TARGET_NAMES); | |||
buildRule.getProject().executeTargets(TARGET_NAMES); | |||
assertEquals(4, targetCount); | |||
} | |||
@Test | |||
public void testSingleCheckExecutor() { | |||
getProject(SINGLE_CHECK).executeTargets(TARGET_NAMES); | |||
assertEquals(3, targetCount); | |||
} | |||
@Test | |||
public void testIgnoreDependenciesExecutor() { | |||
getProject(IGNORE_DEPS).executeTargets(TARGET_NAMES); | |||
assertEquals(2, targetCount); | |||
} | |||
@Test | |||
public void testDefaultFailure() { | |||
try { | |||
getProject(null, true).executeTargets(TARGET_NAMES); | |||
fail("should fail"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage().equals("failfoo")); | |||
assertEquals("failfoo", e.getMessage()); | |||
assertEquals(1, targetCount); | |||
} | |||
} | |||
@Test | |||
public void testSingleCheckFailure() { | |||
try { | |||
getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES); | |||
fail("should fail"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage().equals("failfoo")); | |||
assertEquals("failfoo", e.getMessage()); | |||
assertEquals(1, targetCount); | |||
} | |||
} | |||
@Test | |||
public void testIgnoreDependenciesFailure() { | |||
//no foo failure; foo is never executed as dependencies are ignored! | |||
getProject(IGNORE_DEPS, true).executeTargets(TARGET_NAMES); | |||
} | |||
@Test | |||
public void testKeepGoingDefault() { | |||
try { | |||
getProject(null, true, true).executeTargets(TARGET_NAMES); | |||
fail("should fail"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage().equals("failfoo")); | |||
assertEquals("failfoo", e.getMessage()); | |||
assertEquals(2, targetCount); | |||
} | |||
} | |||
@Test | |||
public void testKeepGoingSingleCheck() { | |||
try { | |||
getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES); | |||
fail("should fail"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage().equals("failfoo")); | |||
assertEquals("failfoo", e.getMessage()); | |||
assertEquals(1, targetCount); | |||
} | |||
} | |||
@Test | |||
public void testKeepGoingIgnoreDependencies() { | |||
try { | |||
//explicitly add foo for failure | |||
Vector targetNames = new Vector(TARGET_NAMES); | |||
Vector<String> targetNames = new Vector<String>(TARGET_NAMES); | |||
targetNames.add(0, "foo"); | |||
getProject(IGNORE_DEPS, true, true).executeTargets(targetNames); | |||
fail("should fail"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage().equals("failfoo")); | |||
assertEquals("failfoo", e.getMessage()); | |||
assertEquals(3, targetCount); | |||
} | |||
} | |||
@@ -17,49 +17,52 @@ | |||
*/ | |||
package org.apache.tools.ant; | |||
import static org.junit.Assert.fail; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* created 16-Mar-2006 12:25:12 | |||
*/ | |||
public class ExtendedTaskdefTest extends BuildFileTest { | |||
/** | |||
* Constructor for the BuildFileTest object. | |||
* | |||
* @param name string to pass up to TestCase constructor | |||
*/ | |||
public ExtendedTaskdefTest(String name) { | |||
super(name); | |||
} | |||
public class ExtendedTaskdefTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/extended-taskdef.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/extended-taskdef.xml"); | |||
} | |||
/** | |||
* Automatically calls the target called "tearDown" | |||
* from the build file tested if it exits. | |||
* <p/> | |||
* This allows to use Ant tasks directly in the build file | |||
* to clean up after each test. Note that no "setUp" target | |||
* is automatically called, since it's trivial to have a | |||
* test target depend on it. | |||
*/ | |||
protected void tearDown() throws Exception { | |||
super.tearDown(); | |||
executeTarget("teardown"); | |||
@After | |||
public void tearDown() throws Exception { | |||
buildRule.executeTarget("teardown"); | |||
} | |||
@Test | |||
public void testRun() throws Exception { | |||
expectBuildExceptionContaining("testRun", | |||
"exception thrown by the subclass", | |||
"executing the Foo task"); | |||
try { | |||
buildRule.executeTarget("testRun"); | |||
fail("BuildException should have been thrown"); | |||
} catch(BuildException ex) { | |||
assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testRun2() throws Exception { | |||
expectBuildExceptionContaining("testRun2", | |||
"exception thrown by the subclass", | |||
"executing the Foo task"); | |||
try { | |||
buildRule.executeTarget("testRun2"); | |||
fail("BuildException should have been thrown"); | |||
} catch(BuildException ex) { | |||
assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,88 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import static org.junit.Assume.assumeTrue; | |||
public class FileUtilities { | |||
/** | |||
* Reads the contents of a file into a String. | |||
* @param project the project containing the base directory the file is in. | |||
* @param fileName the path to the file from the base directory. | |||
* @return the contents of the given file as a string. | |||
* @throws IOException on error reading the file (not existing, not readable etc) | |||
*/ | |||
public static String getFileContents(Project project, String fileName) throws IOException { | |||
return getFileContents(new File(project.getBaseDir(), fileName)); | |||
} | |||
/** | |||
* Reads the contents of a file into a String. | |||
* @param file the file to read. | |||
* @return the contents of the given file as a string. | |||
* @throws IOException on error reading the file (not existing, not readable etc) | |||
*/ | |||
public static String getFileContents(File file) throws IOException { | |||
FileReader rdr = null; | |||
try { | |||
rdr = new FileReader(file); | |||
return FileUtils.readFully(rdr); | |||
} | |||
finally { | |||
if (rdr != null) { | |||
rdr.close(); | |||
} | |||
} | |||
} | |||
/** | |||
* Modified the timestamp on a file so it's <tt>seconds</tt> earlier than it was before. Where <tt>file</tt> | |||
* is a directory, this function recurses into all child files (and directories) and reduces their modified | |||
* timestamps by the same range, rather than set all timestamps to the same time. | |||
* @param file the file to change, or the directory to change then recurse into | |||
* @param seconds how many seconds to roll the timestamp back by | |||
*/ | |||
public static void rollbackTimetamps(File file, long seconds) { | |||
if (null == file || !file.exists()) { | |||
return; | |||
} | |||
assumeTrue(file.setLastModified(file.lastModified() - (seconds * 1000))); | |||
if (file.isDirectory()) { | |||
File[] children = file.listFiles(); | |||
// only possible if exception occurs, or abstract path was not valid | |||
if (children == null) { | |||
return; | |||
} | |||
for (File child : children) { | |||
rollbackTimetamps(child, seconds); | |||
} | |||
} | |||
} | |||
} |
@@ -18,61 +18,73 @@ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
*/ | |||
public class ImmutableTest extends BuildFileTest { | |||
public class ImmutableTest { | |||
public ImmutableTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/immutable.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/immutable.xml"); | |||
} | |||
// override allowed on <available> | |||
@Test | |||
public void test1() { | |||
executeTarget("test1"); | |||
assertEquals("override", project.getProperty("test")); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("override",buildRule.getProject().getProperty("test")); | |||
} | |||
// ensure <tstamp>'s new prefix attribute is working | |||
@Test | |||
public void test2() { | |||
executeTarget("test2"); | |||
assertNotNull(project.getProperty("DSTAMP")); | |||
assertNotNull(project.getProperty("start.DSTAMP")); | |||
buildRule.executeTarget("test2"); | |||
assertNotNull(buildRule.getProject().getProperty("DSTAMP")); | |||
assertNotNull(buildRule.getProject().getProperty("start.DSTAMP")); | |||
} | |||
// ensure <tstamp> follows the immutability rule | |||
@Test | |||
public void test3() { | |||
executeTarget("test3"); | |||
assertEquals("original", project.getProperty("DSTAMP")); | |||
buildRule.executeTarget("test3"); | |||
assertEquals("original", buildRule.getProject().getProperty("DSTAMP")); | |||
} | |||
// ensure <condition> follows the immutability rule | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
assertEquals("original", project.getProperty("test")); | |||
buildRule.executeTarget("test4"); | |||
assertEquals("original", buildRule.getProject().getProperty("test")); | |||
} | |||
// ensure <checksum> follows the immutability rule | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
assertEquals("original", project.getProperty("test")); | |||
buildRule.executeTarget("test5"); | |||
assertEquals("original", buildRule.getProject().getProperty("test")); | |||
} | |||
// ensure <exec> follows the immutability rule | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
assertEquals("original", project.getProperty("test1")); | |||
assertEquals("original", project.getProperty("test2")); | |||
buildRule.executeTarget("test6"); | |||
assertEquals("original", buildRule.getProject().getProperty("test1")); | |||
assertEquals("original", buildRule.getProject().getProperty("test2")); | |||
} | |||
// ensure <pathconvert> follows the immutability rule | |||
@Test | |||
public void test7() { | |||
executeTarget("test7"); | |||
assertEquals("original", project.getProperty("test")); | |||
buildRule.executeTarget("test7"); | |||
assertEquals("original", buildRule.getProject().getProperty("test")); | |||
} | |||
} | |||
@@ -18,60 +18,75 @@ | |||
package org.apache.tools.ant; | |||
import junit.framework.AssertionFailedError; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* Test the build file inclusion using XML entities. | |||
* | |||
*/ | |||
public class IncludeTest extends BuildFileTest { | |||
public IncludeTest(String name) { | |||
super(name); | |||
} | |||
public class IncludeTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Test | |||
public void test1() { | |||
configureProject("src/etc/testcases/core/include/basic/include.xml"); | |||
expectLog("test1", "from included entity"); | |||
buildRule.configureProject("src/etc/testcases/core/include/basic/include.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity", buildRule.getLog()); | |||
} | |||
@Test | |||
public void test2() { | |||
configureProject("src/etc/testcases/core/include/frag#ment/include.xml"); | |||
expectLog("test1", "from included entity"); | |||
buildRule.configureProject("src/etc/testcases/core/include/frag#ment/include.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity", buildRule.getLog()); | |||
} | |||
@Test | |||
public void test3() { | |||
configureProject("src/etc/testcases/core/include/frag#ment/simple.xml"); | |||
expectLog("test1", "from simple buildfile"); | |||
buildRule.configureProject("src/etc/testcases/core/include/frag#ment/simple.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from simple buildfile", buildRule.getLog()); | |||
} | |||
@Test | |||
public void test4() { | |||
configureProject("src/etc/testcases/core/include/basic/relative.xml"); | |||
expectLog("test1", "from included entity"); | |||
buildRule.configureProject("src/etc/testcases/core/include/basic/relative.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity", buildRule.getLog()); | |||
} | |||
@Test | |||
public void test5() { | |||
configureProject("src/etc/testcases/core/include/frag#ment/relative.xml"); | |||
expectLog("test1", "from included entity"); | |||
buildRule.configureProject("src/etc/testcases/core/include/frag#ment/relative.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testParseErrorInIncluding() { | |||
try { | |||
configureProject("src/etc/testcases/core/include/including_file_parse_error/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/include/including_file_parse_error/build.xml"); | |||
fail("should have caused a parser exception"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getLocation().toString() | |||
assertContains(e.getLocation().toString() | |||
+ " should refer to build.xml", | |||
e.getLocation().toString().indexOf("build.xml:") > -1); | |||
"build.xml:", e.getLocation().toString()); | |||
} | |||
} | |||
@Test | |||
public void testTaskErrorInIncluding() { | |||
configureProject("src/etc/testcases/core/include/including_file_task_error/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/include/including_file_task_error/build.xml"); | |||
try { | |||
executeTarget("test"); | |||
buildRule.executeTarget("test"); | |||
fail("should have cause a build failure"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage() | |||
@@ -83,22 +98,24 @@ public class IncludeTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testParseErrorInIncluded() { | |||
try { | |||
configureProject("src/etc/testcases/core/include/included_file_parse_error/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/include/included_file_parse_error/build.xml"); | |||
fail("should have caused a parser exception"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getLocation().toString() | |||
assertContains(e.getLocation().toString() | |||
+ " should refer to included_file.xml", | |||
e.getLocation().toString() | |||
.indexOf("included_file.xml:") > -1); | |||
"included_file.xml:", | |||
e.getLocation().toString()); | |||
} | |||
} | |||
@Test | |||
public void testTaskErrorInIncluded() { | |||
configureProject("src/etc/testcases/core/include/included_file_task_error/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/include/included_file_task_error/build.xml"); | |||
try { | |||
executeTarget("test"); | |||
buildRule.executeTarget("test"); | |||
fail("should have cause a build failure"); | |||
} catch (BuildException e) { | |||
assertTrue(e.getMessage() | |||
@@ -110,24 +127,25 @@ public class IncludeTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testWithSpaceInclude() { | |||
configureProject("src/etc/testcases/core/include/with space/include.xml"); | |||
try { | |||
expectLog("test1", "from included entity in 'with space'"); | |||
} catch (Throwable t) { | |||
throw new AssertionFailedError( | |||
t.toString() + "; log=\n" + getFullLog()); | |||
} | |||
buildRule.configureProject("src/etc/testcases/core/include/with space/include.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity in 'with space'", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testWithSpaceSimple() { | |||
configureProject("src/etc/testcases/core/include/with space/simple.xml"); | |||
expectLog("test1", "from simple buildfile in 'with space'"); | |||
buildRule.configureProject("src/etc/testcases/core/include/with space/simple.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from simple buildfile in 'with space'", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testWithSpaceRelative() { | |||
configureProject("src/etc/testcases/core/include/with space/relative.xml"); | |||
expectLog("test1", "from included entity in 'with space'"); | |||
buildRule.configureProject("src/etc/testcases/core/include/with space/relative.xml"); | |||
buildRule.executeTarget("test1"); | |||
assertEquals("from included entity in 'with space'", buildRule.getLog()); | |||
} | |||
} |
@@ -18,8 +18,6 @@ | |||
package org.apache.tools.ant; | |||
import junit.framework.TestCase; | |||
import junit.framework.AssertionFailedError; | |||
import java.io.File; | |||
import java.lang.reflect.Method; | |||
import java.lang.reflect.InvocationTargetException; | |||
@@ -31,43 +29,53 @@ import java.util.List; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.junit.Before; | |||
import org.junit.ComparisonFailure; | |||
import org.junit.Ignore; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* JUnit 3 testcases for org.apache.tools.ant.IntrospectionHelper. | |||
* JUnit testcases for org.apache.tools.ant.IntrospectionHelper. | |||
* | |||
*/ | |||
public class IntrospectionHelperTest extends TestCase { | |||
public class IntrospectionHelperTest { | |||
private Project p; | |||
private IntrospectionHelper ih; | |||
private static final String projectBasedir = File.separator; | |||
public IntrospectionHelperTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
p = new Project(); | |||
p.setBasedir(projectBasedir); | |||
ih = IntrospectionHelper.getHelper(getClass()); | |||
} | |||
@Test | |||
public void testIsDynamic() { | |||
assertTrue("Not dynamic", false == ih.isDynamic()); | |||
assertFalse("Not dynamic", ih.isDynamic()); | |||
} | |||
@Test | |||
public void testIsContainer() { | |||
assertTrue("Not a container", false == ih.isContainer()); | |||
assertFalse("Not a container", ih.isContainer()); | |||
} | |||
@Test | |||
public void testAddText() throws BuildException { | |||
ih.addText(p, this, "test"); | |||
try { | |||
ih.addText(p, this, "test2"); | |||
fail("test2 shouldn\'t be equal to test"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof ComparisonFailure); | |||
} | |||
ih = IntrospectionHelper.getHelper(String.class); | |||
@@ -75,9 +83,12 @@ public class IntrospectionHelperTest extends TestCase { | |||
ih.addText(p, "", "test"); | |||
fail("String doesn\'t support addText"); | |||
} catch (BuildException be) { | |||
//TODO the value should be asserted | |||
} | |||
} | |||
@Test | |||
@Ignore("This silently ignores a build exception") | |||
public void testGetAddTextMethod() { | |||
Method m = ih.getAddTextMethod(); | |||
assertMethod(m, "addText", String.class, "test", "bing!"); | |||
@@ -88,6 +99,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
} catch (BuildException e) {} | |||
} | |||
@Test | |||
public void testSupportsCharacters() { | |||
assertTrue("IntrospectionHelperTest supports addText", | |||
ih.supportsCharacters()); | |||
@@ -100,31 +112,37 @@ public class IntrospectionHelperTest extends TestCase { | |||
assertEquals("test", text); | |||
} | |||
@Test | |||
public void testElementCreators() throws BuildException { | |||
try { | |||
ih.getElementType("one"); | |||
fail("don't have element type one"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("two"); | |||
fail("createTwo takes arguments"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("three"); | |||
fail("createThree returns void"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("four"); | |||
fail("createFour returns array"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("five"); | |||
fail("createFive returns primitive type"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
assertEquals(String.class, ih.getElementType("six")); | |||
assertEquals("test", ih.createElement(p, this, "six")); | |||
@@ -133,31 +151,37 @@ public class IntrospectionHelperTest extends TestCase { | |||
ih.getElementType("seven"); | |||
fail("addSeven takes two arguments"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("eight"); | |||
fail("addEight takes no arguments"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("nine"); | |||
fail("nine return non void"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("ten"); | |||
fail("addTen takes array argument"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("eleven"); | |||
fail("addEleven takes primitive argument"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.getElementType("twelve"); | |||
fail("no primitive constructor for java.lang.Class"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
assertEquals(StringBuffer.class, ih.getElementType("thirteen")); | |||
assertEquals("test", ih.createElement(p, this, "thirteen").toString()); | |||
@@ -186,6 +210,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
return elemMap; | |||
} | |||
@Test | |||
public void testGetNestedElements() { | |||
Map elemMap = getExpectedNestedElements(); | |||
Enumeration e = ih.getNestedElements(); | |||
@@ -200,6 +225,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
assertTrue("Found all", elemMap.isEmpty()); | |||
} | |||
@Test | |||
public void testGetNestedElementMap() { | |||
Map elemMap = getExpectedNestedElements(); | |||
Map actualMap = ih.getNestedElementMap(); | |||
@@ -217,9 +243,11 @@ public class IntrospectionHelperTest extends TestCase { | |||
// Check it's a read-only map. | |||
try { | |||
actualMap.clear(); | |||
//TODO we should be asserting a value somewhere in here | |||
} catch (UnsupportedOperationException e) {} | |||
} | |||
@Test | |||
public void testGetElementMethod() { | |||
assertElemMethod("six", "createSix", String.class, null); | |||
assertElemMethod("thirteen", "addThirteen", null, StringBuffer.class); | |||
@@ -286,85 +314,92 @@ public class IntrospectionHelperTest extends TestCase { | |||
throw new NullPointerException(); | |||
} | |||
@Test | |||
public void testAttributeSetters() throws BuildException { | |||
try { | |||
ih.setAttribute(p, this, "one", "test"); | |||
fail("setOne doesn't exist"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.setAttribute(p, this, "two", "test"); | |||
fail("setTwo returns non void"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.setAttribute(p, this, "three", "test"); | |||
fail("setThree takes no args"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.setAttribute(p, this, "four", "test"); | |||
fail("setFour takes two args"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.setAttribute(p, this, "five", "test"); | |||
fail("setFive takes array arg"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
try { | |||
ih.setAttribute(p, this, "six", "test"); | |||
fail("Project doesn't have a String constructor"); | |||
} catch (BuildException be) { | |||
//TODO we should be asserting a value in here | |||
} | |||
ih.setAttribute(p, this, "seven", "2"); | |||
try { | |||
ih.setAttribute(p, this, "seven", "3"); | |||
fail("2 shouldn't be equals to three"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof ComparisonFailure); | |||
} | |||
ih.setAttribute(p, this, "eight", "2"); | |||
try { | |||
ih.setAttribute(p, this, "eight", "3"); | |||
fail("2 shouldn't be equals to three - as int"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue("Cause of error: " + be.toString(), be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "nine", "2"); | |||
try { | |||
ih.setAttribute(p, this, "nine", "3"); | |||
fail("2 shouldn't be equals to three - as Integer"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "ten", "2"); | |||
try { | |||
ih.setAttribute(p, this, "ten", "3"); | |||
fail(projectBasedir+"2 shouldn't be equals to "+projectBasedir+"3"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "eleven", "2"); | |||
try { | |||
ih.setAttribute(p, this, "eleven", "on"); | |||
fail("on shouldn't be false"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "twelve", "2"); | |||
try { | |||
ih.setAttribute(p, this, "twelve", "on"); | |||
fail("on shouldn't be false"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project"); | |||
try { | |||
ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.ProjectHelper"); | |||
fail("org.apache.tools.ant.Project shouldn't be equal to org.apache.tools.ant.ProjectHelper"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
try { | |||
ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project2"); | |||
@@ -377,42 +412,42 @@ public class IntrospectionHelperTest extends TestCase { | |||
ih.setAttribute(p, this, "fourteen", "on"); | |||
fail("2 shouldn't be equals to three - as StringBuffer"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof ComparisonFailure); | |||
} | |||
ih.setAttribute(p, this, "fifteen", "abcd"); | |||
try { | |||
ih.setAttribute(p, this, "fifteen", "on"); | |||
fail("o shouldn't be equal to a"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "sixteen", "abcd"); | |||
try { | |||
ih.setAttribute(p, this, "sixteen", "on"); | |||
fail("o shouldn't be equal to a"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "seventeen", "17"); | |||
try { | |||
ih.setAttribute(p, this, "seventeen", "3"); | |||
fail("17 shouldn't be equals to three"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "eightteen", "18"); | |||
try { | |||
ih.setAttribute(p, this, "eightteen", "3"); | |||
fail("18 shouldn't be equals to three"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
ih.setAttribute(p, this, "nineteen", "19"); | |||
try { | |||
ih.setAttribute(p, this, "nineteen", "3"); | |||
fail("19 shouldn't be equals to three"); | |||
} catch (BuildException be) { | |||
assertTrue(be.getCause() instanceof AssertionFailedError); | |||
assertTrue(be.getCause() instanceof AssertionError); | |||
} | |||
} | |||
@@ -444,6 +479,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
return attrMap; | |||
} | |||
@Test | |||
public void testGetAttributes() { | |||
Map attrMap = getExpectedAttributes(); | |||
Enumeration e = ih.getAttributes(); | |||
@@ -459,6 +495,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
assertTrue("Found all", attrMap.isEmpty()); | |||
} | |||
@Test | |||
public void testGetAttributeMap() { | |||
Map attrMap = getExpectedAttributes(); | |||
Map actualMap = ih.getAttributeMap(); | |||
@@ -477,9 +514,11 @@ public class IntrospectionHelperTest extends TestCase { | |||
// Check it's a read-only map. | |||
try { | |||
actualMap.clear(); | |||
//TODO we should be asserting a value somewhere in here | |||
} catch (UnsupportedOperationException e) {} | |||
} | |||
@Test | |||
public void testGetAttributeMethod() { | |||
assertAttrMethod("seven", "setSeven", String.class, | |||
"2", "3"); | |||
@@ -511,7 +550,9 @@ public class IntrospectionHelperTest extends TestCase { | |||
try { | |||
assertAttrMethod("onehundred", null, null, null, null); | |||
fail("Should have raised a BuildException!"); | |||
} catch (BuildException e) {} | |||
} catch (BuildException e) { | |||
//TODO we should be asserting a value in here | |||
} | |||
} | |||
private void assertAttrMethod(String attrName, String methodName, | |||
@@ -593,6 +634,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
assertTrue("Expected 19, received " + d, diff > -1e-6 && diff < 1e-6); | |||
} | |||
@Test | |||
public void testGetExtensionPoints() { | |||
List extensions = ih.getExtensionPoints(); | |||
final int adders = 2; | |||
@@ -645,7 +687,7 @@ public class IntrospectionHelperTest extends TestCase { | |||
throw new BuildException(e); | |||
} catch (InvocationTargetException e) { | |||
Throwable t = e.getTargetException(); | |||
assertTrue(t instanceof junit.framework.AssertionFailedError); | |||
assertTrue(t.toString(), t instanceof AssertionError); | |||
} | |||
} | |||
@@ -18,25 +18,35 @@ | |||
package org.apache.tools.ant; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.fail; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class LoaderRefTest extends BuildFileTest { | |||
public LoaderRefTest(String name) { | |||
super(name); | |||
} | |||
public class LoaderRefTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/loaderref/loaderref.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/core/loaderref/loaderref.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
// override allowed on <available> | |||
public void testBadRef() { | |||
expectBuildExceptionContaining("testbadref", "Should fail due to ref " | |||
+ "not being a class loader", "does not reference a class loader"); | |||
@Test | |||
public void testBadRef() { | |||
try { | |||
buildRule.executeTarget("testbadref"); | |||
fail("BuildRule should have thrown an exception due to a bad classloader being specified"); | |||
} catch (BuildException ex) { | |||
assertContains("Should fail due to ref not being a class loader", "does not reference a class loader", ex.getMessage()); | |||
} | |||
} | |||
} | |||
@@ -21,49 +21,65 @@ package org.apache.tools.ant; | |||
import org.apache.tools.ant.taskdefs.ConditionTask; | |||
import org.apache.tools.ant.taskdefs.Echo; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public class LocationTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
public class LocationTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/location.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/location.xml"); | |||
} | |||
@Test | |||
public void testPlainTask() { | |||
executeTarget("testPlainTask"); | |||
Echo e = (Echo) getProject().getReference("echo"); | |||
buildRule.executeTarget("testPlainTask"); | |||
Echo e = (Echo) buildRule.getProject().getReference("echo"); | |||
assertFalse(e.getLocation() == Location.UNKNOWN_LOCATION); | |||
assertFalse(e.getLocation().getLineNumber() == 0); | |||
} | |||
@Test | |||
public void testStandaloneType() { | |||
executeTarget("testStandaloneType"); | |||
Echo e = (Echo) getProject().getReference("echo2"); | |||
FileSet f = (FileSet) getProject().getReference("fs"); | |||
buildRule.executeTarget("testStandaloneType"); | |||
Echo e = (Echo) buildRule.getProject().getReference("echo2"); | |||
FileSet f = (FileSet) buildRule.getProject().getReference("fs"); | |||
assertFalse(f.getLocation() == Location.UNKNOWN_LOCATION); | |||
assertEquals(e.getLocation().getLineNumber() + 1, | |||
f.getLocation().getLineNumber()); | |||
} | |||
@Test | |||
public void testConditionTask() { | |||
executeTarget("testConditionTask"); | |||
TaskAdapter ta = (TaskAdapter) getProject().getReference("cond"); | |||
buildRule.executeTarget("testConditionTask"); | |||
TaskAdapter ta = (TaskAdapter) buildRule.getProject().getReference("cond"); | |||
ConditionTask c = (ConditionTask) ta.getProxy(); | |||
assertFalse(c.getLocation() == Location.UNKNOWN_LOCATION); | |||
assertFalse(c.getLocation().getLineNumber() == 0); | |||
} | |||
@Test | |||
public void testMacrodefWrappedTask() { | |||
executeTarget("testMacrodefWrappedTask"); | |||
Echo e = (Echo) getProject().getReference("echo3"); | |||
assertTrue(getLog().indexOf("Line: " | |||
buildRule.executeTarget("testMacrodefWrappedTask"); | |||
Echo e = (Echo) buildRule.getProject().getReference("echo3"); | |||
assertTrue(buildRule.getLog().indexOf("Line: " | |||
+ (e.getLocation().getLineNumber() + 1)) | |||
> -1); | |||
} | |||
@Test | |||
public void testPresetdefWrappedTask() { | |||
executeTarget("testPresetdefWrappedTask"); | |||
Echo e = (Echo) getProject().getReference("echo4"); | |||
assertTrue(getLog().indexOf("Line: " | |||
buildRule.executeTarget("testPresetdefWrappedTask"); | |||
Echo e = (Echo) buildRule.getProject().getReference("echo4"); | |||
assertTrue(buildRule.getLog().indexOf("Line: " | |||
+ (e.getLocation().getLineNumber() + 1)) | |||
> -1); | |||
} | |||
@@ -18,13 +18,14 @@ | |||
package org.apache.tools.ant; | |||
import java.util.Vector; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.assertEquals; | |||
import junit.framework.Assert; | |||
import java.util.Vector; | |||
public class MockBuildListener extends Assert implements BuildListener { | |||
public class MockBuildListener implements BuildListener { | |||
private final Vector buffer = new Vector(); | |||
private final Vector<BuildEvent> buffer = new Vector<BuildEvent>(); | |||
private final Project project; | |||
public MockBuildListener(final Project project) { | |||
@@ -18,14 +18,14 @@ | |||
package org.apache.tools.ant; | |||
import junit.framework.TestCase; | |||
import org.junit.Test; | |||
public class ProjectComponentTest extends TestCase { | |||
import static org.junit.Assert.assertNotSame; | |||
import static org.junit.Assert.assertSame; | |||
public ProjectComponentTest(String name) { | |||
super(name); | |||
} | |||
public class ProjectComponentTest { | |||
@Test | |||
public void testClone() throws CloneNotSupportedException { | |||
Project expectedProject = new Project(); | |||
Location expectedLocation = new Location("foo"); | |||
@@ -19,17 +19,19 @@ package org.apache.tools.ant; | |||
import java.io.File; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.helper.ProjectHelper2; | |||
import org.apache.tools.ant.types.Resource; | |||
import org.apache.tools.ant.types.resources.FileResource; | |||
import org.apache.tools.ant.types.resources.StringResource; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Testing around the management of the project helpers | |||
*/ | |||
public class ProjectHelperRepositoryTest extends TestCase { | |||
public class ProjectHelperRepositoryTest { | |||
public static class SomeHelper extends ProjectHelper { | |||
public boolean canParseBuildFile(Resource buildFile) { | |||
@@ -42,6 +44,7 @@ public class ProjectHelperRepositoryTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFind() throws Exception { | |||
ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); | |||
repo.registerProjectHelper(SomeHelper.class); | |||
@@ -71,7 +74,9 @@ public class ProjectHelperRepositoryTest extends TestCase { | |||
assertTrue(helper instanceof ProjectHelper2); | |||
} | |||
public void testNoDefaultConstructor() throws Exception { | |||
@Test | |||
public void testNoDefaultContructor() throws Exception { | |||
class IncrrectHelper extends ProjectHelper { | |||
// the default constructor is not visible to ant here | |||
} | |||
@@ -82,9 +87,11 @@ public class ProjectHelperRepositoryTest extends TestCase { | |||
fail("Registring an helper with no default constructor should fail"); | |||
} catch (BuildException e) { | |||
// ok | |||
//TODO we should be asserting a value in here | |||
} | |||
} | |||
@Test | |||
public void testUnkwnowHelper() throws Exception { | |||
ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); | |||
try { | |||
@@ -92,6 +99,7 @@ public class ProjectHelperRepositoryTest extends TestCase { | |||
fail("Registring an unknwon helper should fail"); | |||
} catch (BuildException e) { | |||
// ok | |||
//TODO we should be asserting a value in here | |||
} | |||
} | |||
} |
@@ -22,26 +22,39 @@ import org.apache.tools.ant.input.DefaultInputHandler; | |||
import org.apache.tools.ant.input.InputHandler; | |||
import org.apache.tools.ant.input.PropertyFileInputHandler; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.apache.tools.ant.types.*; | |||
import java.io.File; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.types.PatternSet; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertSame; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Very limited test class for Project. Waiting to be extended. | |||
* | |||
*/ | |||
public class ProjectTest extends TestCase { | |||
public class ProjectTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private Project p; | |||
private String root; | |||
private MockBuildListener mbl; | |||
public ProjectTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
p = new Project(); | |||
p.init(); | |||
@@ -49,6 +62,7 @@ public class ProjectTest extends TestCase { | |||
mbl = new MockBuildListener(p); | |||
} | |||
@Test | |||
public void testDataTypes() throws BuildException { | |||
assertNull("dummy is not a known data type", | |||
p.createDataType("dummy")); | |||
@@ -63,6 +77,7 @@ public class ProjectTest extends TestCase { | |||
/** | |||
* This test has been a starting point for moving the code to FileUtils. | |||
*/ | |||
@Test | |||
public void testResolveFile() { | |||
if (Os.isFamily("netware") || Os.isFamily("dos")) { | |||
assertEqualsIgnoreDriveCase(localize(File.separator), | |||
@@ -178,6 +193,7 @@ public class ProjectTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testAddTaskDefinition() { | |||
p.addBuildListener(mbl); | |||
@@ -209,6 +225,7 @@ public class ProjectTest extends TestCase { | |||
assertEquals(DummyTaskWithNonVoidExecute.class, p.getTaskDefinitions().get("NonVoidExecute")); | |||
} | |||
@Test | |||
public void testInputHandler() { | |||
InputHandler ih = p.getInputHandler(); | |||
assertNotNull(ih); | |||
@@ -218,33 +235,38 @@ public class ProjectTest extends TestCase { | |||
assertSame(pfih, p.getInputHandler()); | |||
} | |||
@Test | |||
public void testTaskDefinitionContainsKey() { | |||
assertTrue(p.getTaskDefinitions().containsKey("echo")); | |||
} | |||
@Test | |||
public void testTaskDefinitionContains() { | |||
assertTrue(p.getTaskDefinitions().contains(org.apache.tools.ant.taskdefs.Echo.class)); | |||
} | |||
@Test | |||
public void testDuplicateTargets() { | |||
// fail, because buildfile contains two targets with the same name | |||
try { | |||
BFT bft = new BFT("", "core/duplicate-target.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/duplicate-target.xml"); | |||
fail("Should throw BuildException about duplicate target"); | |||
} catch (BuildException ex) { | |||
assertEquals("specific message", | |||
"Duplicate target 'twice'", | |||
ex.getMessage()); | |||
return; | |||
} | |||
fail("Should throw BuildException about duplicate target"); | |||
} | |||
@Test | |||
public void testDuplicateTargetsImport() { | |||
// overriding target from imported buildfile is allowed | |||
BFT bft = new BFT("", "core/duplicate-target2.xml"); | |||
bft.expectLog("once", "once from buildfile"); | |||
buildRule.configureProject("src/etc/testcases/core/duplicate-target2.xml"); | |||
buildRule.executeTarget("once"); | |||
assertContains("once from buildfile", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testOutputDuringMessageLoggedIsSwallowed() | |||
throws InterruptedException { | |||
final String FOO = "foo", BAR = "bar"; | |||
@@ -277,8 +299,10 @@ public class ProjectTest extends TestCase { | |||
} | |||
/** | |||
* @see https://issues.apache.org/bugzilla/show_bug.cgi?id=47623 | |||
* @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47623"> | |||
* https://issues.apache.org/bugzilla/show_bug.cgi?id=47623</a> | |||
*/ | |||
@Test | |||
public void testNullThrowableMessageLog() { | |||
p.log(new Task() {}, null, new Throwable(), Project.MSG_ERR); | |||
// be content if no exception has been thrown | |||
@@ -294,42 +318,10 @@ public class ProjectTest extends TestCase { | |||
public void execute() {} | |||
} | |||
private class BFT extends org.apache.tools.ant.BuildFileTest { | |||
BFT(String name, String buildfile) { | |||
super(name); | |||
this.buildfile = buildfile; | |||
setUp(); | |||
} | |||
// avoid multiple configurations | |||
boolean isConfigured = false; | |||
// the buildfile to use | |||
String buildfile = ""; | |||
public void setUp() { | |||
if (!isConfigured) { | |||
configureProject("src/etc/testcases/"+buildfile); | |||
isConfigured = true; | |||
} | |||
} | |||
public void tearDown() { } | |||
// call a target | |||
public void doTarget(String target) { | |||
if (!isConfigured) setUp(); | |||
executeTarget(target); | |||
} | |||
public org.apache.tools.ant.Project getProject() { | |||
return super.getProject(); | |||
} | |||
}//class-BFT | |||
} | |||
class DummyTaskPackage extends Task { | |||
public DummyTaskPackage() {} | |||
public void execute() {} | |||
} | |||
class DummyTaskPackage extends Task { | |||
public DummyTaskPackage() {} | |||
public void execute() {} | |||
} | |||
} |
@@ -19,33 +19,39 @@ | |||
package org.apache.tools.ant; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
* class to look at how we expand properties | |||
*/ | |||
public class PropertyExpansionTest extends BuildFileTest { | |||
public PropertyExpansionTest(String name) { | |||
super(name); | |||
} | |||
public class PropertyExpansionTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
/** | |||
* we bind to an existing test file because we are too lazy to write our | |||
* own, and we don't really care what it is | |||
*/ | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/immutable.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/immutable.xml"); | |||
} | |||
/** | |||
* run through the test cases of expansion | |||
*/ | |||
@Test | |||
public void testPropertyExpansion() { | |||
assertExpandsTo("",""); | |||
assertExpandsTo("$","$"); | |||
assertExpandsTo("$$-","$-"); | |||
assertExpandsTo("$$","$"); | |||
project.setProperty("expanded","EXPANDED"); | |||
buildRule.getProject().setProperty("expanded","EXPANDED"); | |||
assertExpandsTo("a${expanded}b","aEXPANDEDb"); | |||
assertExpandsTo("${expanded}${expanded}","EXPANDEDEXPANDED"); | |||
assertExpandsTo("$$$","$$"); | |||
@@ -57,6 +63,7 @@ public class PropertyExpansionTest extends BuildFileTest { | |||
/** | |||
* new things we want | |||
*/ | |||
@Test | |||
public void testDollarPassthru() { | |||
assertExpandsTo("$-","$-"); | |||
assertExpandsTo("Class$subclass","Class$subclass"); | |||
@@ -71,6 +78,8 @@ public class PropertyExpansionTest extends BuildFileTest { | |||
/** | |||
* old things we dont want; not a test no more | |||
*/ | |||
@Test | |||
@Ignore("Previously disabled through naming convention") | |||
public void oldtestQuirkyLegacyBehavior() { | |||
assertExpandsTo("Class$subclass","Classsubclass"); | |||
assertExpandsTo("$$$-","$-"); | |||
@@ -82,7 +91,7 @@ public class PropertyExpansionTest extends BuildFileTest { | |||
* little helper method to validate stuff | |||
*/ | |||
private void assertExpandsTo(String source,String expected) { | |||
String actual=project.replaceProperties(source); | |||
String actual = buildRule.getProject().replaceProperties(source); | |||
assertEquals(source,expected,actual); | |||
} | |||
@@ -21,11 +21,14 @@ package org.apache.tools.ant; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.FileWriter; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Test; | |||
public class PropertyFileCLITest extends TestCase { | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
public class PropertyFileCLITest { | |||
@Test | |||
public void testPropertyResolution() throws Exception { | |||
FileUtils fu = FileUtils.getFileUtils(); | |||
File props = fu.createTempFile("propertyfilecli", ".properties", | |||
@@ -51,8 +54,7 @@ public class PropertyFileCLITest extends TestCase { | |||
"-l", log.getAbsolutePath() | |||
}, null, null); | |||
String l = FileUtils.safeReadFully(fr = new FileReader(log)); | |||
assertTrue("expected log to contain 'Hello, world' but was " + l, | |||
l.indexOf("Hello, world") > -1); | |||
assertContains("Hello, world", l); | |||
} finally { | |||
FileUtils.close(fw); | |||
FileUtils.close(fr); | |||
@@ -18,40 +18,49 @@ | |||
package org.apache.tools.ant; | |||
public class TaskContainerTest extends BuildFileTest { | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public TaskContainerTest(String name) { | |||
super(name); | |||
} | |||
import static org.junit.Assert.assertTrue; | |||
public class TaskContainerTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/taskcontainer.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/taskcontainer.xml"); | |||
} | |||
@Test | |||
public void testPropertyExpansion() { | |||
executeTarget("testPropertyExpansion"); | |||
buildRule.executeTarget("testPropertyExpansion"); | |||
assertTrue("attribute worked", | |||
getLog().indexOf("As attribute: it worked") > -1); | |||
buildRule.getLog().indexOf("As attribute: it worked") > -1); | |||
assertTrue("nested text worked", | |||
getLog().indexOf("As nested text: it worked") > -1); | |||
buildRule.getLog().indexOf("As nested text: it worked") > -1); | |||
} | |||
@Test | |||
public void testTaskdef() { | |||
executeTarget("testTaskdef"); | |||
buildRule.executeTarget("testTaskdef"); | |||
assertTrue("attribute worked", | |||
getLog().indexOf("As attribute: it worked") > -1); | |||
buildRule.getLog().indexOf("As attribute: it worked") > -1); | |||
assertTrue("nested text worked", | |||
getLog().indexOf("As nested text: it worked") > -1); | |||
buildRule.getLog().indexOf("As nested text: it worked") > -1); | |||
assertTrue("nested text worked", | |||
getLog().indexOf("As nested task: it worked") > -1); | |||
buildRule.getLog().indexOf("As nested task: it worked") > -1); | |||
} | |||
@Test | |||
public void testCaseInsensitive() { | |||
executeTarget("testCaseInsensitive"); | |||
buildRule.executeTarget("testCaseInsensitive"); | |||
assertTrue("works outside of container", | |||
getLog().indexOf("hello ") > -1); | |||
buildRule.getLog().indexOf("hello ") > -1); | |||
assertTrue("works inside of container", | |||
getLog().indexOf("world") > -1); | |||
buildRule.getLog().indexOf("world") > -1); | |||
} | |||
} |
@@ -21,29 +21,39 @@ package org.apache.tools.ant; | |||
// This test will fail with embed, or if top-level is moved out of | |||
// dependency - as 'echo' happens as part of configureProject stage. | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
* Tests for builds with tasks at the top level | |||
* | |||
* @since Ant 1.6 | |||
*/ | |||
public class TopLevelTaskTest extends BuildFileTest { | |||
public class TopLevelTaskTest { | |||
public TopLevelTaskTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Test | |||
public void testNoTarget() { | |||
configureProject("src/etc/testcases/core/topleveltasks/notarget.xml"); | |||
expectLog("", "Called"); | |||
buildRule.configureProject("src/etc/testcases/core/topleveltasks/notarget.xml"); | |||
buildRule.executeTarget(""); | |||
assertEquals("Called", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testCalledFromTopLevelAnt() { | |||
configureProject("src/etc/testcases/core/topleveltasks/toplevelant.xml"); | |||
expectLog("", "Called"); | |||
buildRule.configureProject("src/etc/testcases/core/topleveltasks/toplevelant.xml"); | |||
buildRule.executeTarget(""); | |||
assertEquals("Called", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testCalledFromTargetLevelAnt() { | |||
configureProject("src/etc/testcases/core/topleveltasks/targetlevelant.xml"); | |||
expectLog("foo", "Called"); | |||
buildRule.configureProject("src/etc/testcases/core/topleveltasks/targetlevelant.xml"); | |||
buildRule.executeTarget("foo"); | |||
assertEquals("Called", buildRule.getLog()); | |||
} | |||
} |
@@ -18,26 +18,45 @@ | |||
package org.apache.tools.ant; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
public class UnknownElementTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.assertNotNull; | |||
public class UnknownElementTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/core/unknownelement.xml"); | |||
buildRule.configureProject("src/etc/testcases/core/unknownelement.xml"); | |||
} | |||
@Test | |||
public void testMaybeConfigure() { | |||
// make sure we do not get a NPE | |||
executeTarget("testMaybeConfigure"); | |||
buildRule.executeTarget("testMaybeConfigure"); | |||
} | |||
/** | |||
* Not really a UnknownElement test but rather one of "what | |||
* information is available in taskFinished". | |||
* @see https://issues.apache.org/bugzilla/show_bug.cgi?id=26197 | |||
* @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=26197"> | |||
* https://issues.apache.org/bugzilla/show_bug.cgi?id=26197</a> | |||
*/ | |||
@Test | |||
@Ignore("Previously disabled through naming convention") | |||
public void XtestTaskFinishedEvent() { | |||
getProject().addBuildListener(new BuildListener() { | |||
buildRule.getProject().addBuildListener(new BuildListener() { | |||
public void buildStarted(BuildEvent event) {} | |||
public void buildFinished(BuildEvent event) {} | |||
public void targetStarted(BuildEvent event) {} | |||
@@ -58,7 +77,7 @@ public class UnknownElementTest extends BuildFileTest { | |||
t.getClass().getName()); | |||
} | |||
}); | |||
executeTarget("echo"); | |||
buildRule.executeTarget("echo"); | |||
} | |||
public static class Child extends Task { | |||
@@ -21,16 +21,21 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* JUnit Testcases for ConcatReader | |||
*/ | |||
public class ConcatFilterTest extends BuildFileTest { | |||
public class ConcatFilterTest { | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
private static final String lSep = StringUtils.LINE_SEP; | |||
private static final String FILE_PREPEND_WITH = | |||
@@ -65,48 +70,55 @@ public class ConcatFilterTest extends BuildFileTest { | |||
+ "Line 60" + lSep | |||
; | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
public ConcatFilterTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/concat.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/concat.xml"); | |||
} | |||
@Test | |||
public void testFilterReaderNoArgs() throws IOException { | |||
executeTarget("testFilterReaderNoArgs"); | |||
File expected = new File(getProject().getProperty("output"), "concatfilter.test"); | |||
File result = new File(getProject().getProperty("output"), "concat.FilterReaderNoArgs.test"); | |||
assertTrue("testFilterReaderNoArgs: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testFilterReaderNoArgs"); | |||
File expected = new File(buildRule.getProject().getProperty("output"), "concatfilter.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"), "concat.FilterReaderNoArgs.test"); | |||
assertEquals("testFilterReaderNoArgs: Result not like expected", FileUtilities.getFileContents(expected), | |||
FileUtilities.getFileContents(result)); | |||
} | |||
public void testFilterReaderBefore() { | |||
@Test | |||
public void testFilterReaderBefore() throws IOException { | |||
doTest("testFilterReaderPrepend", FILE_PREPEND_WITH, FILE_APPEND); | |||
} | |||
public void testFilterReaderAfter() { | |||
@Test | |||
public void testFilterReaderAfter() throws IOException { | |||
doTest("testFilterReaderAppend", FILE_PREPEND, FILE_APPEND_WITH); | |||
} | |||
public void testFilterReaderBeforeAfter() { | |||
@Test | |||
public void testFilterReaderBeforeAfter() throws IOException { | |||
doTest("testFilterReaderPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); | |||
} | |||
public void testConcatFilter() { | |||
@Test | |||
public void testConcatFilter() throws IOException { | |||
doTest("testConcatFilter", FILE_PREPEND, FILE_APPEND); | |||
} | |||
public void testConcatFilterBefore() { | |||
@Test | |||
public void testConcatFilterBefore() throws IOException { | |||
doTest("testConcatFilterPrepend", FILE_PREPEND_WITH, FILE_APPEND); | |||
} | |||
public void testConcatFilterAfter() { | |||
@Test | |||
public void testConcatFilterAfter() throws IOException { | |||
doTest("testConcatFilterAppend", FILE_PREPEND, FILE_APPEND_WITH); | |||
} | |||
public void testConcatFilterBeforeAfter() { | |||
@Test | |||
public void testConcatFilterBeforeAfter() throws IOException { | |||
doTest("testConcatFilterPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); | |||
} | |||
@@ -119,33 +131,13 @@ public class ConcatFilterTest extends BuildFileTest { | |||
* @param expectedStart The string which should be at the beginning of the file | |||
* @param expectedEnd The string which should be at the end of the file | |||
*/ | |||
protected void doTest(String target, String expectedStart, String expectedEnd) { | |||
executeTarget(target); | |||
String resultContent = read(getProject().getProperty("output") + "/concat." + target.substring(4) + ".test"); | |||
protected void doTest(String target, String expectedStart, String expectedEnd) throws IOException { | |||
buildRule.executeTarget(target); | |||
String resultContent = FileUtilities.getFileContents( | |||
new File(buildRule.getProject().getProperty("output") + "/concat." + target.substring(4) + ".test")); | |||
assertTrue("First 5 lines differs.", resultContent.startsWith(expectedStart)); | |||
assertTrue("Last 5 lines differs.", resultContent.endsWith(expectedEnd)); | |||
} | |||
/** | |||
* Wrapper for FileUtils.readFully(). | |||
* Additionally it resolves the filename according the the projects basedir | |||
* and closes the used reader. | |||
* @param filename The name of the file to read | |||
* @return the content of the file or <i>null</i> if something goes wrong | |||
*/ | |||
protected String read(String filename) { | |||
String content = null; | |||
try { | |||
File file = FILE_UTILS.resolveFile(getProject().getBaseDir(), filename); | |||
java.io.FileReader rdr = new java.io.FileReader(file); | |||
content = FileUtils.readFully(rdr); | |||
rdr.close(); | |||
rdr = null; | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return content; | |||
} | |||
} |
@@ -18,67 +18,38 @@ | |||
package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.Reader; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class DynamicFilterTest extends BuildFileTest { | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public DynamicFilterTest(String name) { | |||
super(name); | |||
} | |||
public class DynamicFilterTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/dynamicfilter.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/filters/dynamicfilter.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@Test | |||
public void testCustomFilter() throws IOException { | |||
expectFileContains("dynamicfilter", getProject().getProperty("output") + "/dynamicfilter", | |||
"hellO wOrld"); | |||
buildRule.executeTarget("dynamicfilter"); | |||
String content = FileUtilities.getFileContents( | |||
new File(buildRule.getProject().getProperty("output") + "/dynamicfilter")); | |||
assertContains("hellO wOrld", content); | |||
} | |||
// ------------------------------------------------------ | |||
// Helper methods | |||
// ----------------------------------------------------- | |||
private String getFileString(String filename) | |||
throws IOException | |||
{ | |||
Reader r = null; | |||
try { | |||
r = new FileReader(FILE_UTILS.resolveFile(getProject().getBaseDir(), filename)); | |||
return FileUtils.readFully(r); | |||
} | |||
finally { | |||
FileUtils.close(r); | |||
} | |||
} | |||
private void expectFileContains(String name, String contains) | |||
throws IOException | |||
{ | |||
String content = getFileString(name); | |||
assertTrue( | |||
"expecting file " + name + " to contain " + contains + | |||
" but got " + content, content.indexOf(contains) > -1); | |||
} | |||
private void expectFileContains( | |||
String target, String name, String contains) | |||
throws IOException | |||
{ | |||
executeTarget(target); | |||
expectFileContains(name, contains); | |||
} | |||
public static class CustomFilter implements ChainableReader { | |||
char replace = 'x'; | |||
@@ -21,28 +21,30 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class EscapeUnicodeTest extends BuildFileTest { | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
import static org.junit.Assert.assertEquals; | |||
public EscapeUnicodeTest(String name) { | |||
super(name); | |||
} | |||
public class EscapeUnicodeTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/build.xml"); | |||
} | |||
@Test | |||
public void testEscapeUnicode() throws IOException { | |||
executeTarget("testEscapeUnicode"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(), "expected/escapeunicode.test"); | |||
File result = new File(getProject().getProperty("output"), "escapeunicode.test"); | |||
assertTrue(FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testEscapeUnicode"); | |||
File expected = buildRule.getProject().resolveFile("expected/escapeunicode.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"), "escapeunicode.test"); | |||
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
} |
@@ -21,105 +21,117 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** JUnit Testcases for TailFilter and HeadFilter | |||
*/ | |||
/* I wrote the testcases in one java file because I want also to test the | |||
* combined behaviour (see end of the class). | |||
*/ | |||
public class HeadTailTest extends BuildFileTest { | |||
public class HeadTailTest { | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
public HeadTailTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/head-tail.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/head-tail.xml"); | |||
} | |||
@Test | |||
public void testHead() throws IOException { | |||
executeTarget("testHead"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(), "expected/head-tail.head.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.head.test"); | |||
assertTrue("testHead: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testHead"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.head.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.head.test"); | |||
assertEquals("testHead: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testHeadLines() throws IOException { | |||
executeTarget("testHeadLines"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(), "expected/head-tail.headLines.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.headLines.test"); | |||
assertTrue("testHeadLines: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testHeadLines"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.headLines.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLines.test"); | |||
assertEquals("testHeadLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testHeadSkip() throws IOException { | |||
executeTarget("testHeadSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.headSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.headSkip.test"); | |||
assertTrue("testHeadSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testHeadSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.headSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headSkip.test"); | |||
assertEquals("testHeadSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testHeadLinesSkip() throws IOException { | |||
executeTarget("testHeadLinesSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.headLinesSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.headLinesSkip.test"); | |||
assertTrue("testHeadLinesSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testHeadLinesSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLinesSkip.test"); | |||
assertEquals("testHeadLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testFilterReaderHeadLinesSkip() throws IOException { | |||
executeTarget("testFilterReaderHeadLinesSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(), | |||
"expected/head-tail.headLinesSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.filterReaderHeadLinesSkip.test"); | |||
assertTrue("testFilterReaderHeadLinesSkip: Result not like expected", | |||
FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testFilterReaderHeadLinesSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.filterReaderHeadLinesSkip.test"); | |||
assertEquals("testFilterReaderHeadLinesSkip: Result not like expected", | |||
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testTail() throws IOException { | |||
executeTarget("testTail"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.tail.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.tail.test"); | |||
assertTrue("testTail: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testTail"); | |||
File expected =buildRule.getProject().resolveFile("expected/head-tail.tail.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tail.test"); | |||
assertEquals("testTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testTailLines() throws IOException { | |||
executeTarget("testTailLines"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.tailLines.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.tailLines.test"); | |||
assertTrue("testTailLines: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testTailLines"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLines.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLines.test"); | |||
assertEquals("testTailLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testTailSkip() throws IOException { | |||
executeTarget("testTailSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.tailSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.tailSkip.test"); | |||
assertTrue("testTailSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testTailSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailSkip.test"); | |||
assertEquals("testTailSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testTailLinesSkip() throws IOException { | |||
executeTarget("testTailLinesSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.tailLinesSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.tailLinesSkip.test"); | |||
assertTrue("testTailLinesSkip: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testTailLinesSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLinesSkip.test"); | |||
assertEquals("testTailLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testFilterReaderTailLinesSkip() throws IOException { | |||
executeTarget("testFilterReaderTailLinesSkip"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(), | |||
"expected/head-tail.tailLinesSkip.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.filterReaderTailLinesSkip.test"); | |||
assertTrue("testFilterReaderTailLinesSkip: Result not like expected", | |||
FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testFilterReaderTailLinesSkip"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.filterReaderTailLinesSkip.test"); | |||
assertEquals("testFilterReaderTailLinesSkip: Result not like expected", | |||
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testHeadTail() throws IOException { | |||
executeTarget("testHeadTail"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/head-tail.headtail.test"); | |||
File result = new File(getProject().getProperty("output") + "/head-tail.headtail.test"); | |||
assertTrue("testHeadTail: Result not like expected", FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testHeadTail"); | |||
File expected = buildRule.getProject().resolveFile("expected/head-tail.headtail.test"); | |||
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headtail.test"); | |||
assertEquals("testHeadTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
} |
@@ -21,32 +21,37 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class LineContainsTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public LineContainsTest(String name) { | |||
super(name); | |||
} | |||
public class LineContainsTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/build.xml"); | |||
} | |||
@Test | |||
public void testLineContains() throws IOException { | |||
executeTarget("testLineContains"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/linecontains.test"); | |||
File result = new File(getProject().getProperty("output"),"linecontains.test"); | |||
assertTrue(FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testLineContains"); | |||
File expected = buildRule.getProject().resolveFile("expected/linecontains.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"),"linecontains.test"); | |||
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testNegateLineContains() throws IOException { | |||
executeTarget("testNegateLineContains"); | |||
buildRule.executeTarget("testNegateLineContains"); | |||
} | |||
} |
@@ -20,24 +20,29 @@ package org.apache.tools.ant.filters; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** JUnit Testcases for No new line when filterchain used | |||
*/ | |||
public class NoNewLineTest extends BuildFileTest { | |||
public class NoNewLineTest { | |||
public NoNewLineTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/build.xml"); | |||
} | |||
@Test | |||
public void testNoAddNewLine() throws IOException { | |||
executeTarget("testNoAddNewLine"); | |||
buildRule.executeTarget("testNoAddNewLine"); | |||
} | |||
@@ -21,35 +21,39 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class ReplaceTokensTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public class ReplaceTokensTest { | |||
public ReplaceTokensTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/build.xml"); | |||
} | |||
@Test | |||
public void testReplaceTokens() throws IOException { | |||
executeTarget("testReplaceTokens"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/replacetokens.test"); | |||
File result = new File(getProject().getProperty("output"), "replacetokens.test"); | |||
assertTrue(FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testReplaceTokens"); | |||
File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.test"); | |||
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
@Test | |||
public void testReplaceTokensPropertyFile() throws IOException { | |||
executeTarget("testReplaceTokensPropertyFile"); | |||
File expected = FILE_UTILS.resolveFile(getProjectDir(), "expected/replacetokens.test"); | |||
File result = new File(getProject().getProperty("output"), "replacetokensPropertyFile.test"); | |||
assertTrue(FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testReplaceTokensPropertyFile"); | |||
File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"), "replacetokensPropertyFile.test"); | |||
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
} |
@@ -21,28 +21,31 @@ package org.apache.tools.ant.filters; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class StripJavaCommentsTest extends BuildFileTest { | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
import static org.junit.Assert.assertEquals; | |||
public StripJavaCommentsTest(String name) { | |||
super(name); | |||
} | |||
public class StripJavaCommentsTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/filters/build.xml"); | |||
} | |||
@Test | |||
public void testStripJavaComments() throws IOException { | |||
executeTarget("testStripJavaComments"); | |||
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/stripjavacomments.test"); | |||
File result = new File(getProject().getProperty("output"), "stripjavacomments.test"); | |||
assertTrue(FILE_UTILS.contentEquals(expected, result)); | |||
buildRule.executeTarget("testStripJavaComments"); | |||
File expected = buildRule.getProject().resolveFile("expected/stripjavacomments.test"); | |||
File result = new File(buildRule.getProject().getProperty("output"), "stripjavacomments.test"); | |||
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); | |||
} | |||
} |
@@ -18,265 +18,252 @@ | |||
package org.apache.tools.ant.filters; | |||
import java.io.Reader; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.apache.tools.ant.AntAssert.assertNotContains; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import java.io.Reader; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class TokenFilterTest extends BuildFileTest { | |||
public class TokenFilterTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public TokenFilterTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/filters/tokenfilter.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
/** make sure tokenfilter exists */ | |||
@Test | |||
public void testTokenfilter() throws IOException { | |||
executeTarget("tokenfilter"); | |||
buildRule.executeTarget("tokenfilter"); | |||
} | |||
@Test | |||
public void testTrimignore() throws IOException { | |||
expectLogContaining("trimignore", "Hello-World"); | |||
buildRule.executeTarget("trimignore"); | |||
assertContains("Hello-World", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testStringTokenizer() throws IOException { | |||
expectLogContaining( | |||
"stringtokenizer", "#This#is#a#number#of#words#"); | |||
buildRule.executeTarget("stringtokenizer"); | |||
assertContains("#This#is#a#number#of#words#", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testUnixLineOutput() throws IOException { | |||
expectFileContains( | |||
"unixlineoutput", getProject().getProperty("output") + "/unixlineoutput", | |||
"\nThis\nis\na\nnumber\nof\nwords\n"); | |||
buildRule.executeTarget("unixlineoutput"); | |||
assertContains("\nThis\nis\na\nnumber\nof\nwords\n", | |||
getFileString(buildRule.getProject().getProperty("output") + "/unixlineoutput")); | |||
} | |||
@Test | |||
public void testDosLineOutput() throws IOException { | |||
expectFileContains( | |||
"doslineoutput", getProject().getProperty("output") + "/doslineoutput", | |||
"\r\nThis\r\nis\r\na\r\nnumber\r\nof\r\nwords\r\n"); | |||
buildRule.executeTarget("doslineoutput"); | |||
assertContains("\r\nThis\r\nis\r\na\r\nnumber\r\nof\r\nwords\r\n", | |||
getFileString(buildRule.getProject().getProperty("output") + "/doslineoutput")); | |||
} | |||
@Test | |||
public void testFileTokenizer() throws IOException { | |||
String contents = getFileString( | |||
"filetokenizer", getProject().getProperty("output") + "/filetokenizer"); | |||
assertStringContains(contents, " of words"); | |||
assertStringNotContains(contents, " This is"); | |||
buildRule.executeTarget("filetokenizer"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/filetokenizer"); | |||
assertContains(" of words", contents); | |||
assertNotContains(" This is", contents); | |||
} | |||
@Test | |||
public void testReplaceString() throws IOException { | |||
expectFileContains( | |||
"replacestring", getProject().getProperty("output") + "/replacestring", | |||
"this is the moon"); | |||
buildRule.executeTarget("replacestring"); | |||
assertContains("this is the moon", | |||
getFileString(buildRule.getProject().getProperty("output") + "/replacestring")); | |||
} | |||
@Test | |||
public void testReplaceStrings() throws IOException { | |||
expectLogContaining("replacestrings", "bar bar bar"); | |||
buildRule.executeTarget("replacestrings"); | |||
assertContains("bar bar bar", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testContainsString() throws IOException { | |||
String contents = getFileString( | |||
"containsstring", getProject().getProperty("output") + "/containsstring"); | |||
assertStringContains(contents, "this is a line contains foo"); | |||
assertStringNotContains(contents, "this line does not"); | |||
buildRule.executeTarget("containsstring"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsstring"); | |||
assertContains("this is a line contains foo", contents); | |||
assertNotContains("this line does not", contents); | |||
} | |||
@Test | |||
public void testReplaceRegex() throws IOException { | |||
if (! hasRegex("testReplaceRegex")) | |||
return; | |||
String contents = getFileString( | |||
"replaceregex", getProject().getProperty("output") + "/replaceregex"); | |||
assertStringContains(contents, "world world world world"); | |||
assertStringContains(contents, "dog Cat dog"); | |||
assertStringContains(contents, "moon Sun Sun"); | |||
assertStringContains(contents, "found WhiteSpace"); | |||
assertStringContains(contents, "Found digits [1234]"); | |||
assertStringNotContains(contents, "This is a line with digits"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", | |||
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
buildRule.executeTarget("replaceregex"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/replaceregex"); | |||
assertContains("world world world world", contents); | |||
assertContains("dog Cat dog", contents); | |||
assertContains("moon Sun Sun", contents); | |||
assertContains("found WhiteSpace", contents); | |||
assertContains("Found digits [1234]", contents); | |||
assertNotContains("This is a line with digits", contents); | |||
} | |||
@Test | |||
public void testFilterReplaceRegex() throws IOException { | |||
if (! hasRegex("testFilterReplaceRegex")) | |||
return; | |||
String contents = getFileString( | |||
"filterreplaceregex", getProject().getProperty("output") + "/filterreplaceregex"); | |||
assertStringContains(contents, "world world world world"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", | |||
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
buildRule.executeTarget("filterreplaceregex"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplaceregex"); | |||
assertContains("world world world world", contents); | |||
} | |||
@Test | |||
public void testHandleDollerMatch() throws IOException { | |||
if (! hasRegex("testFilterReplaceRegex")) | |||
return; | |||
executeTarget("dollermatch"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
buildRule.executeTarget("dollermatch"); | |||
} | |||
@Test | |||
public void testTrimFile() throws IOException { | |||
String contents = getFileString( | |||
"trimfile", getProject().getProperty("output") + "/trimfile"); | |||
buildRule.executeTarget("trimfile"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfile"); | |||
assertTrue("no ws at start", contents.startsWith("This is th")); | |||
assertTrue("no ws at end", contents.endsWith("second line.")); | |||
assertStringContains(contents, " This is the second"); | |||
assertContains(" This is the second", contents); | |||
} | |||
@Test | |||
public void testTrimFileByLine() throws IOException { | |||
String contents = getFileString( | |||
"trimfilebyline", getProject().getProperty("output") + "/trimfilebyline"); | |||
buildRule.executeTarget("trimfilebyline"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfilebyline"); | |||
assertFalse("no ws at start", contents.startsWith("This is th")); | |||
assertFalse("no ws at end", contents.endsWith("second line.")); | |||
assertStringNotContains(contents, " This is the second"); | |||
assertStringContains(contents, "file.\nThis is the second"); | |||
assertNotContains(" This is the second", contents); | |||
assertContains("file.\nThis is the second", contents); | |||
} | |||
@Test | |||
public void testFilterReplaceString() throws IOException { | |||
String contents = getFileString( | |||
"filterreplacestring", getProject().getProperty("output") + "/filterreplacestring"); | |||
assertStringContains(contents, "This is the moon"); | |||
buildRule.executeTarget("filterreplacestring"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplacestring"); | |||
assertContains("This is the moon", contents); | |||
} | |||
@Test | |||
public void testFilterReplaceStrings() throws IOException { | |||
expectLogContaining("filterreplacestrings", "bar bar bar"); | |||
buildRule.executeTarget("filterreplacestrings"); | |||
assertContains("bar bar bar", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testContainsRegex() throws IOException { | |||
if (! hasRegex("testContainsRegex")) | |||
return; | |||
String contents = getFileString( | |||
"containsregex", getProject().getProperty("output") + "/containsregex"); | |||
assertStringContains(contents, "hello world"); | |||
assertStringNotContains(contents, "this is the moon"); | |||
assertStringContains(contents, "World here"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
//expectFileContains(buildRule.getProject().getProperty("output") + "/replaceregexp", "bye world"); | |||
buildRule.executeTarget("containsregex"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex"); | |||
assertContains("hello world", contents); | |||
assertNotContains("this is the moon", contents); | |||
assertContains("World here", contents); | |||
} | |||
@Test | |||
public void testFilterContainsRegex() throws IOException { | |||
if (! hasRegex("testFilterContainsRegex")) | |||
return; | |||
String contents = getFileString( | |||
"filtercontainsregex", getProject().getProperty("output") + "/filtercontainsregex"); | |||
assertStringContains(contents, "hello world"); | |||
assertStringNotContains(contents, "this is the moon"); | |||
assertStringContains(contents, "World here"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
buildRule.executeTarget("filtercontainsregex"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/filtercontainsregex"); | |||
assertContains("hello world", contents); | |||
assertNotContains("this is the moon", contents); | |||
assertContains("World here", contents); | |||
} | |||
@Test | |||
public void testContainsRegex2() throws IOException { | |||
if (! hasRegex("testContainsRegex2")) | |||
return; | |||
String contents = getFileString( | |||
"containsregex2", getProject().getProperty("output") + "/containsregex2"); | |||
assertStringContains(contents, "void register_bits();"); | |||
buildRule.executeTarget("hasregex"); | |||
Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | |||
buildRule.executeTarget("containsregex2"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"); | |||
assertContains("void register_bits();", contents); | |||
} | |||
@Test | |||
public void testDeleteCharacters() throws IOException { | |||
String contents = getFileString( | |||
"deletecharacters", getProject().getProperty("output") + "/deletechars"); | |||
assertStringNotContains(contents, "#"); | |||
assertStringNotContains(contents, "*"); | |||
assertStringContains(contents, "This is some "); | |||
buildRule.executeTarget("deletecharacters"); | |||
String contents = getFileString(buildRule.getProject().getProperty("output") + "/deletechars"); | |||
assertNotContains("#", contents); | |||
assertNotContains("*", contents); | |||
assertContains("This is some ", contents); | |||
} | |||
@Test | |||
public void testScriptFilter() throws IOException { | |||
if (! hasScript("testScriptFilter")) | |||
return; | |||
Assume.assumeTrue("Project does not have 'testScriptFilter' target", | |||
buildRule.getProject().getTargets().contains("testScriptFilter")); | |||
buildRule.executeTarget("scriptfilter"); | |||
assertContains("HELLO WORLD", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter")); | |||
expectFileContains("scriptfilter", getProject().getProperty("output") + "/scriptfilter", | |||
"HELLO WORLD"); | |||
} | |||
@Test | |||
public void testScriptFilter2() throws IOException { | |||
if (! hasScript("testScriptFilter")) | |||
return; | |||
expectFileContains("scriptfilter2", getProject().getProperty("output") + "/scriptfilter2", | |||
"HELLO MOON"); | |||
Assume.assumeTrue("Project does not have 'testScriptFilter' target", buildRule.getProject().getTargets().contains("testScriptFilter")); | |||
buildRule.executeTarget("scriptfilter2"); | |||
assertContains("HELLO MOON", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2")); | |||
} | |||
@Test | |||
public void testCustomTokenFilter() throws IOException { | |||
expectFileContains("customtokenfilter", getProject().getProperty("output") + "/custom", | |||
"Hello World"); | |||
buildRule.executeTarget("customtokenfilter"); | |||
assertContains("Hello World", getFileString(buildRule.getProject().getProperty("output") + "/custom")); | |||
} | |||
// ------------------------------------------------------ | |||
// Helper methods | |||
// ----------------------------------------------------- | |||
private boolean hasScript(String test) { | |||
try { | |||
executeTarget("hasscript"); | |||
} | |||
catch (Throwable ex) { | |||
System.out.println( | |||
test + ": skipped - script not present "); | |||
return false; | |||
} | |||
return true; | |||
} | |||
private boolean hasRegex(String test) { | |||
try { | |||
executeTarget("hasregex"); | |||
expectFileContains(getProject().getProperty("output") + "/replaceregexp", "bye world"); | |||
} | |||
catch (Throwable ex) { | |||
System.out.println(test + ": skipped - regex not present " | |||
+ ex); | |||
return false; | |||
} | |||
return true; | |||
} | |||
private void assertStringContains(String string, String contains) { | |||
assertTrue("[" + string + "] does not contain [" + contains +"]", | |||
string.indexOf(contains) > -1); | |||
} | |||
private void assertStringNotContains(String string, String contains) { | |||
assertTrue("[" + string + "] does contain [" + contains +"]", | |||
string.indexOf(contains) == -1); | |||
} | |||
private String getFileString(String filename) | |||
throws IOException | |||
{ | |||
Reader r = null; | |||
try { | |||
r = new FileReader(FILE_UTILS.resolveFile(getProject().getBaseDir(),filename)); | |||
r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename)); | |||
return FileUtils.readFully(r); | |||
} | |||
finally { | |||
FileUtils.close(r); | |||
} | |||
} | |||
private String getFileString(String target, String filename) | |||
throws IOException | |||
{ | |||
executeTarget(target); | |||
return getFileString(filename); | |||
} | |||
private void expectFileContains(String name, String contains) | |||
throws IOException | |||
{ | |||
String content = getFileString(name); | |||
assertTrue( | |||
"expecting file " + name + " to contain " + contains + | |||
" but got " + content, content.indexOf(contains) > -1); | |||
} | |||
private void expectFileContains( | |||
String target, String name, String contains) | |||
throws IOException | |||
{ | |||
executeTarget(target); | |||
expectFileContains(name, contains); | |||
} | |||
public static class Capitalize | |||
implements TokenFilter.Filter | |||
@@ -17,39 +17,27 @@ | |||
*/ | |||
package org.apache.tools.ant.launch; | |||
import junit.framework.TestCase; | |||
import java.io.File; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Test; | |||
import static junit.framework.Assert.assertEquals; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.fail; | |||
/** Test the locator in the ant-launch JAR */ | |||
public class LocatorTest extends TestCase { | |||
public class LocatorTest { | |||
private boolean windows; | |||
private boolean unix; | |||
private static final String LAUNCHER_JAR = "//morzine/slo/Java/Apache/ant/lib/ant-launcher.jar"; | |||
private static final String SHARED_JAR_URI = "jar:file:"+ LAUNCHER_JAR +"!/org/apache/tools/ant/launch/Launcher.class"; | |||
/** | |||
* No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling | |||
* setName(). | |||
*/ | |||
public LocatorTest() { | |||
} | |||
/** Constructs a test case with the given name. | |||
* @param name | |||
*/ | |||
public LocatorTest(String name) { | |||
super(name); | |||
} | |||
/** | |||
* Sets up the fixture, for example, open a network connection. | |||
* This method is called before a test is executed. | |||
*/ | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
@Before | |||
public void setUp() throws Exception { | |||
windows = Os.isFamily(Os.FAMILY_DOS); | |||
unix = Os.isFamily(Os.FAMILY_UNIX); | |||
} | |||
@@ -105,26 +93,27 @@ public class LocatorTest extends TestCase { | |||
"\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); | |||
} | |||
/** | |||
* This is not being tested as we don't appear to generate paths like this in the launcher | |||
* @throws Exception | |||
*/ | |||
public void NotestTripleForwardSlashNetworkURI() throws Exception { | |||
@Ignore("We don't appear to generate paths like this in the launcher") | |||
@Test | |||
public void testTripleForwardSlashNetworkURI() throws Exception { | |||
resolveTo("file:///PC03/jclasses/lib/ant-1.7.0.jar", | |||
"///PC03/jclasses/lib/ant-1.7.0.jar", | |||
"\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); | |||
} | |||
@Test | |||
public void testUnixNetworkPath() throws Exception { | |||
resolveTo("file://cluster/home/ant/lib", | |||
"//cluster/home/ant/lib", | |||
"\\\\cluster\\home\\ant\\lib"); | |||
} | |||
@Test | |||
public void testUnixPath() throws Exception { | |||
resolveTo("file:/home/ant/lib", "/home/ant/lib", null); | |||
} | |||
@Test | |||
public void testSpacedURI() throws Exception { | |||
resolveTo("file:C:\\Program Files\\Ant\\lib", | |||
"C:\\Program Files\\Ant\\lib", | |||
@@ -135,6 +124,7 @@ public class LocatorTest extends TestCase { | |||
* Bug 42275; Ant failing to run off a remote share | |||
* @throws Throwable if desired | |||
*/ | |||
@Test | |||
public void testAntOnRemoteShare() throws Throwable { | |||
String resolved=Locator.fromJarURI(SHARED_JAR_URI); | |||
assertResolved(SHARED_JAR_URI, LAUNCHER_JAR, resolved, unix); | |||
@@ -147,6 +137,7 @@ public class LocatorTest extends TestCase { | |||
* | |||
* @throws Throwable if desired | |||
*/ | |||
@Test | |||
public void testFileFromRemoteShare() throws Throwable { | |||
String resolved = Locator.fromJarURI(SHARED_JAR_URI); | |||
File f = new File(resolved); | |||
@@ -156,17 +147,20 @@ public class LocatorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testHttpURI() throws Exception { | |||
String url = "http://ant.apache.org"; | |||
try { | |||
Locator.fromURI(url); | |||
fail("Exception should have been thrown"); | |||
} catch (IllegalArgumentException e) { | |||
String message = e.getMessage(); | |||
assertTrue(message, message.indexOf(Locator.ERROR_NOT_FILE_URI) >= 0); | |||
assertTrue(message, message.indexOf(url) >= 0); | |||
assertContains(Locator.ERROR_NOT_FILE_URI, message); | |||
assertContains(url, message); | |||
} | |||
} | |||
@Test | |||
public void testInternationalURI() throws Exception { | |||
String result = assertResolves("L\u00f6wenbrau.aus.M\u00fcnchen"); | |||
char umlauted = result.charAt(1); | |||
@@ -178,6 +172,7 @@ public class LocatorTest extends TestCase { | |||
assertEquals("file:/tmp/hezky \u010Desky", Locator.decodeUri("file:/tmp/hezky%20\u010Desky")); // non-ISO-8859-1 variant | |||
} | |||
@Test | |||
public void testOddLowAsciiURI() throws Exception { | |||
assertResolves("hash# and percent%"); | |||
} | |||
@@ -21,19 +21,26 @@ package org.apache.tools.ant.loader; | |||
import java.io.IOException; | |||
import java.net.URL; | |||
import java.util.Enumeration; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.AntClassLoader; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.CollectionUtils; | |||
import org.junit.Test; | |||
public class AntClassLoader5Test extends TestCase { | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | |||
public class AntClassLoader5Test { | |||
/** | |||
* Asserts that getResources won't return resources that cannot be | |||
* seen by AntClassLoader but by ClassLoader.this.parent. | |||
* | |||
* @see https://issues.apache.org/bugzilla/show_bug.cgi?id=46752 | |||
* @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=46752"> | |||
* https://issues.apache.org/bugzilla/show_bug.cgi?id=46752</a> | |||
*/ | |||
@Test | |||
public void testGetResources() throws IOException { | |||
AntClassLoader acl = new AntClassLoader5(new EmptyLoader(), null, | |||
new Path(null), true); | |||
@@ -46,6 +53,7 @@ public class AntClassLoader5Test extends TestCase { | |||
assertTrue(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements()); | |||
} | |||
@Test | |||
public void testGetResourcesUsingFactory() throws IOException { | |||
AntClassLoader acl = | |||
AntClassLoader.newAntClassLoader(new EmptyLoader(), null, | |||
@@ -17,38 +17,55 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
*/ | |||
public class AbstractCvsTaskTest extends BuildFileTest { | |||
public class AbstractCvsTaskTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
public AbstractCvsTaskTest() { | |||
this( "AbstractCvsTaskTest" ); | |||
@Before | |||
public void setUp() { | |||
buildRule.configureProject("src/etc/testcases/taskdefs/abstractcvstask.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
public AbstractCvsTaskTest(String name) { | |||
super(name); | |||
@After | |||
public void tearDown() { | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/abstractcvstask.xml"); | |||
executeTarget("setUp"); | |||
@Test | |||
public void testAbstractCvsTask() { | |||
buildRule.executeTarget("all"); | |||
} | |||
@Test | |||
public void testPackageAttribute() { | |||
File f = new File(getProject().getProperty("output") + "/src/Makefile"); | |||
File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); | |||
assertTrue("starting empty", !f.exists()); | |||
expectLogContaining("package-attribute", "U src/Makefile"); | |||
buildRule.executeTarget("package-attribute"); | |||
AntAssert.assertContains("U src/Makefile", buildRule.getLog()); | |||
assertTrue("now it is there", f.exists()); | |||
} | |||
@Test | |||
public void testTagAttribute() { | |||
File f = new File(getProject().getProperty("output") + "/src/Makefile"); | |||
File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); | |||
assertTrue("starting empty", !f.exists()); | |||
expectLogContaining("tag-attribute", "OPENBSD_5_3"); | |||
buildRule.executeTarget("tag-attribute"); | |||
AntAssert.assertContains("OPENBSD_5_3", buildRule.getLog()); | |||
assertTrue("now it is there", f.exists()); | |||
} | |||
} |
@@ -19,19 +19,25 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* @since Ant 1.6 | |||
*/ | |||
public class AntLikeTasksAtTopLevelTest extends BuildFileTest { | |||
public AntLikeTasksAtTopLevelTest(String name) { | |||
super(name); | |||
} | |||
public class AntLikeTasksAtTopLevelTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Test | |||
public void testAnt() { | |||
try { | |||
configureProject("src/etc/testcases/taskdefs/toplevelant.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelant.xml"); | |||
fail("no exception thrown"); | |||
} catch (BuildException e) { | |||
assertEquals("ant task at the top level must not invoke its own" | |||
@@ -39,9 +45,10 @@ public class AntLikeTasksAtTopLevelTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testSubant() { | |||
try { | |||
configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml"); | |||
fail("no exception thrown"); | |||
} catch (BuildException e) { | |||
assertEquals("subant task at the top level must not invoke its own" | |||
@@ -49,9 +56,10 @@ public class AntLikeTasksAtTopLevelTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testAntcall() { | |||
try { | |||
configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml"); | |||
fail("no exception thrown"); | |||
} catch (BuildException e) { | |||
assertEquals("antcall must not be used at the top level.", | |||
@@ -18,40 +18,57 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.Project; | |||
import org.junit.After; | |||
import org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.PrintWriter; | |||
import java.util.Hashtable; | |||
import junit.framework.Assert; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.Project; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class AntStructureTest extends BuildFileTest { | |||
public class AntStructureTest { | |||
public AntStructureTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/antstructure.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/antstructure.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("tearDown"); | |||
buildRule.executeTarget("tearDown"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void testCustomPrinter() { | |||
executeTarget("testCustomPrinter"); | |||
buildRule.executeTarget("testCustomPrinter"); | |||
// can't access the booleans in MyPrinter here (even if they | |||
// were static) since the MyPrinter instance that was used in | |||
// the test has likely been loaded via a different classloader | |||
// than this class. Therefore we make the printer assert its | |||
// state and only check for the tail invocation. | |||
assertLogContaining(MyPrinter.TAIL_CALLED); | |||
AntAssert.assertContains(MyPrinter.TAIL_CALLED, buildRule.getLog()); | |||
} | |||
public static class MyPrinter implements AntStructure.StructurePrinter { | |||
@@ -22,94 +22,145 @@ import java.io.File; | |||
import junit.framework.AssertionFailedError; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildEvent; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.BuildListener; | |||
import org.apache.tools.ant.input.InputHandler; | |||
import org.apache.tools.ant.input.PropertyFileInputHandler; | |||
import org.apache.tools.ant.types.Path; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertSame; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class AntTest extends BuildFileTest { | |||
public AntTest(String name) { | |||
super(name); | |||
} | |||
public class AntTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/ant.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/ant.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "recursive call"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("recursive call"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// target must be specified | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("required argument not specified"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// Should fail since a recursion will occur... | |||
@Test | |||
public void test3() { | |||
expectBuildException("test1", "recursive call"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("recursive call"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
expectBuildException("test4", "target attribute must not be empty"); | |||
try { | |||
buildRule.executeTarget("test4"); | |||
fail("target attribute must not be empty"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test4b() { | |||
expectBuildException("test4b", "target doesn't exist"); | |||
try { | |||
buildRule.executeTarget("test4b"); | |||
fail("target doesn't exist"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
buildRule.executeTarget("test5"); | |||
} | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
buildRule.executeTarget("test6"); | |||
} | |||
@Test | |||
public void testExplicitBasedir1() { | |||
File dir1 = getProjectDir(); | |||
File dir2 = project.resolveFile(".."); | |||
File dir1 = buildRule.getProject().getBaseDir(); | |||
File dir2 = buildRule.getProject().resolveFile(".."); | |||
testBaseDirs("explicitBasedir1", | |||
new String[] {dir1.getAbsolutePath(), | |||
dir2.getAbsolutePath() | |||
}); | |||
} | |||
@Test | |||
public void testExplicitBasedir2() { | |||
File dir1 = getProjectDir(); | |||
File dir2 = project.resolveFile(".."); | |||
File dir1 = buildRule.getProject().getBaseDir(); | |||
File dir2 = buildRule.getProject().resolveFile(".."); | |||
testBaseDirs("explicitBasedir2", | |||
new String[] {dir1.getAbsolutePath(), | |||
dir2.getAbsolutePath() | |||
}); | |||
} | |||
@Test | |||
public void testInheritBasedir() { | |||
String basedir = getProjectDir().getAbsolutePath(); | |||
String basedir = buildRule.getProject().getBaseDir().getAbsolutePath(); | |||
testBaseDirs("inheritBasedir", new String[] {basedir, basedir}); | |||
} | |||
@Test | |||
public void testDoNotInheritBasedir() { | |||
File dir1 = getProjectDir(); | |||
File dir2 = project.resolveFile("ant"); | |||
File dir1 = buildRule.getProject().getBaseDir(); | |||
File dir2 = buildRule.getProject().resolveFile("ant"); | |||
testBaseDirs("doNotInheritBasedir", | |||
new String[] {dir1.getAbsolutePath(), | |||
dir2.getAbsolutePath() | |||
}); | |||
} | |||
@Test | |||
public void testBasedirTripleCall() { | |||
File dir1 = getProjectDir(); | |||
File dir2 = project.resolveFile("ant"); | |||
File dir1 = buildRule.getProject().getBaseDir(); | |||
File dir2 = buildRule.getProject().resolveFile("ant"); | |||
testBaseDirs("tripleCall", | |||
new String[] {dir1.getAbsolutePath(), | |||
dir2.getAbsolutePath(), | |||
@@ -119,20 +170,21 @@ public class AntTest extends BuildFileTest { | |||
protected void testBaseDirs(String target, String[] dirs) { | |||
BasedirChecker bc = new BasedirChecker(dirs); | |||
project.addBuildListener(bc); | |||
executeTarget(target); | |||
buildRule.getProject().addBuildListener(bc); | |||
buildRule.executeTarget(target); | |||
AssertionFailedError ae = bc.getError(); | |||
if (ae != null) { | |||
throw ae; | |||
} | |||
project.removeBuildListener(bc); | |||
buildRule.getProject().removeBuildListener(bc); | |||
} | |||
@Test | |||
public void testReferenceInheritance() { | |||
Path p = Path.systemClasspath; | |||
p.setProject(project); | |||
project.addReference("path", p); | |||
project.addReference("no-override", p); | |||
p.setProject(buildRule.getProject()); | |||
buildRule.getProject().addReference("path", p); | |||
buildRule.getProject().addReference("no-override", p); | |||
testReference("testInherit", new String[] {"path", "path"}, | |||
new boolean[] {true, true}, p); | |||
testReference("testInherit", | |||
@@ -143,11 +195,12 @@ public class AntTest extends BuildFileTest { | |||
new boolean[] {false, false}, null); | |||
} | |||
@Test | |||
public void testReferenceNoInheritance() { | |||
Path p = Path.systemClasspath; | |||
p.setProject(project); | |||
project.addReference("path", p); | |||
project.addReference("no-override", p); | |||
p.setProject(buildRule.getProject()); | |||
buildRule.getProject().addReference("path", p); | |||
buildRule.getProject().addReference("no-override", p); | |||
testReference("testNoInherit", new String[] {"path", "path"}, | |||
new boolean[] {true, false}, p); | |||
testReference("testNoInherit", new String[] {"path", "path"}, | |||
@@ -160,10 +213,11 @@ public class AntTest extends BuildFileTest { | |||
new boolean[] {false, false}, null); | |||
} | |||
@Test | |||
public void testReferenceRename() { | |||
Path p = Path.systemClasspath; | |||
p.setProject(project); | |||
project.addReference("path", p); | |||
p.setProject(buildRule.getProject()); | |||
buildRule.getProject().addReference("path", p); | |||
testReference("testRename", new String[] {"path", "path"}, | |||
new boolean[] {true, false}, p); | |||
testReference("testRename", new String[] {"path", "path"}, | |||
@@ -172,35 +226,37 @@ public class AntTest extends BuildFileTest { | |||
new boolean[] {false, true}, p); | |||
} | |||
@Test | |||
public void testInheritPath() { | |||
executeTarget("testInheritPath"); | |||
buildRule.executeTarget("testInheritPath"); | |||
} | |||
protected void testReference(String target, String[] keys, | |||
boolean[] expect, Object value) { | |||
ReferenceChecker rc = new ReferenceChecker(keys, expect, value); | |||
project.addBuildListener(rc); | |||
executeTarget(target); | |||
buildRule.getProject().addBuildListener(rc); | |||
buildRule.executeTarget(target); | |||
AssertionFailedError ae = rc.getError(); | |||
if (ae != null) { | |||
throw ae; | |||
} | |||
project.removeBuildListener(rc); | |||
buildRule.getProject().removeBuildListener(rc); | |||
} | |||
@Test | |||
public void testLogfilePlacement() { | |||
File[] logFiles = new File[] { | |||
getProject().resolveFile("test1.log"), | |||
getProject().resolveFile("test2.log"), | |||
getProject().resolveFile("ant/test3.log"), | |||
getProject().resolveFile("ant/test4.log") | |||
buildRule.getProject().resolveFile("test1.log"), | |||
buildRule.getProject().resolveFile("test2.log"), | |||
buildRule.getProject().resolveFile("ant/test3.log"), | |||
buildRule.getProject().resolveFile("ant/test4.log") | |||
}; | |||
for (int i=0; i<logFiles.length; i++) { | |||
assertTrue(logFiles[i].getName()+" doesn\'t exist", | |||
!logFiles[i].exists()); | |||
} | |||
executeTarget("testLogfilePlacement"); | |||
buildRule.executeTarget("testLogfilePlacement"); | |||
for (int i=0; i<logFiles.length; i++) { | |||
assertTrue(logFiles[i].getName()+" exists", | |||
@@ -208,84 +264,106 @@ public class AntTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testInputHandlerInheritance() { | |||
InputHandler ih = new PropertyFileInputHandler(); | |||
getProject().setInputHandler(ih); | |||
buildRule.getProject().setInputHandler(ih); | |||
InputHandlerChecker ic = new InputHandlerChecker(ih); | |||
getProject().addBuildListener(ic); | |||
executeTarget("tripleCall"); | |||
buildRule.getProject().addBuildListener(ic); | |||
buildRule.executeTarget("tripleCall"); | |||
AssertionFailedError ae = ic.getError(); | |||
if (ae != null) { | |||
throw ae; | |||
} | |||
getProject().removeBuildListener(ic); | |||
buildRule.getProject().removeBuildListener(ic); | |||
} | |||
@Test | |||
public void testRefId() { | |||
Path testPath = new Path(project); | |||
Path testPath = new Path(buildRule.getProject()); | |||
testPath.createPath().setPath(System.getProperty("java.class.path")); | |||
PropertyChecker pc = | |||
new PropertyChecker("testprop", | |||
new String[] {null, | |||
testPath.toString()}); | |||
project.addBuildListener(pc); | |||
executeTarget("testRefid"); | |||
buildRule.getProject().addBuildListener(pc); | |||
buildRule.executeTarget("testRefid"); | |||
AssertionFailedError ae = pc.getError(); | |||
if (ae != null) { | |||
throw ae; | |||
} | |||
project.removeBuildListener(pc); | |||
buildRule.getProject().removeBuildListener(pc); | |||
} | |||
@Test | |||
public void testUserPropertyWinsInheritAll() { | |||
getProject().setUserProperty("test", "7"); | |||
expectLogContaining("test-property-override-inheritall-start", | |||
"The value of test is 7"); | |||
buildRule.getProject().setUserProperty("test", "7"); | |||
buildRule.executeTarget("test-property-override-inheritall-start"); | |||
AntAssert.assertContains("The value of test is 7", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testUserPropertyWinsNoInheritAll() { | |||
getProject().setUserProperty("test", "7"); | |||
expectLogContaining("test-property-override-no-inheritall-start", | |||
"The value of test is 7"); | |||
buildRule.getProject().setUserProperty("test", "7"); | |||
buildRule.executeTarget("test-property-override-no-inheritall-start"); | |||
AntAssert.assertContains("The value of test is 7", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testOverrideWinsInheritAll() { | |||
expectLogContaining("test-property-override-inheritall-start", | |||
"The value of test is 4"); | |||
buildRule.executeTarget("test-property-override-inheritall-start"); | |||
AntAssert.assertContains("The value of test is 4", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testOverrideWinsNoInheritAll() { | |||
expectLogContaining("test-property-override-no-inheritall-start", | |||
"The value of test is 4"); | |||
buildRule.executeTarget("test-property-override-no-inheritall-start"); | |||
AntAssert.assertContains("The value of test is 4", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testPropertySet() { | |||
executeTarget("test-propertyset"); | |||
assertTrue(getLog().indexOf("test1 is ${test1}") > -1); | |||
assertTrue(getLog().indexOf("test2 is ${test2}") > -1); | |||
assertTrue(getLog().indexOf("test1.x is 1") > -1); | |||
buildRule.executeTarget("test-propertyset"); | |||
assertTrue(buildRule.getLog().indexOf("test1 is ${test1}") > -1); | |||
assertTrue(buildRule.getLog().indexOf("test2 is ${test2}") > -1); | |||
assertTrue(buildRule.getLog().indexOf("test1.x is 1") > -1); | |||
} | |||
@Test | |||
public void testInfiniteLoopViaDepends() { | |||
expectBuildException("infinite-loop-via-depends", "recursive call"); | |||
try { | |||
buildRule.executeTarget("infinite-loop-via-depends"); | |||
fail("recursive call"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void testMultiSameProperty() { | |||
expectLog("multi-same-property", "prop is two"); | |||
buildRule.executeTarget("multi-same-property"); | |||
assertEquals("prop is two", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testTopLevelTarget() { | |||
expectLog("topleveltarget", "Hello world"); | |||
buildRule.executeTarget("topleveltarget"); | |||
assertEquals("Hello world", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testMultiplePropertyFileChildren() { | |||
PropertyChecker pcBar = new PropertyChecker("bar", | |||
new String[] {null, "Bar"}); | |||
PropertyChecker pcFoo = new PropertyChecker("foo", | |||
new String[] {null, "Foo"}); | |||
project.addBuildListener(pcBar); | |||
project.addBuildListener(pcFoo); | |||
executeTarget("multiple-property-file-children"); | |||
buildRule.getProject().addBuildListener(pcBar); | |||
buildRule.getProject().addBuildListener(pcFoo); | |||
buildRule.executeTarget("multiple-property-file-children"); | |||
AssertionFailedError aeBar = pcBar.getError(); | |||
if (aeBar != null) { | |||
throw aeBar; | |||
@@ -294,26 +372,37 @@ public class AntTest extends BuildFileTest { | |||
if (aeFoo != null) { | |||
throw aeFoo; | |||
} | |||
project.removeBuildListener(pcBar); | |||
project.removeBuildListener(pcFoo); | |||
buildRule.getProject().removeBuildListener(pcBar); | |||
buildRule.getProject().removeBuildListener(pcFoo); | |||
} | |||
@Test | |||
public void testBlankTarget() { | |||
expectBuildException("blank-target", "target name must not be empty"); | |||
try { | |||
buildRule.executeTarget("blank-target"); | |||
fail("target name must not be empty"); | |||
} catch(BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void testMultipleTargets() { | |||
expectLog("multiple-targets", "tadadctbdbtc"); | |||
buildRule.executeTarget("multiple-targets"); | |||
assertEquals("tadadctbdbtc", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testMultipleTargets2() { | |||
expectLog("multiple-targets-2", "dadctb"); | |||
buildRule.executeTarget("multiple-targets-2"); | |||
assertEquals("dadctb", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testAntCoreLib() { | |||
// Cf. #42263 | |||
executeTarget("sub-show-ant.core.lib"); | |||
String realLog = getLog(); | |||
buildRule.executeTarget("sub-show-ant.core.lib"); | |||
String realLog = buildRule.getLog(); | |||
assertTrue("found ant.core.lib in: " + realLog, realLog.matches(".*(ant[.]jar|build.classes).*")); | |||
} | |||
@@ -18,19 +18,26 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.Project; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
*/ | |||
public class AntlibTest extends BuildFileTest { | |||
public AntlibTest(String name) { | |||
super(name); | |||
} | |||
public class AntlibTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/antlib.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/antlib.xml"); | |||
} | |||
/** | |||
@@ -42,8 +49,10 @@ public class AntlibTest extends BuildFileTest { | |||
return property!=null && Project.toBoolean(property); | |||
} | |||
@Test | |||
public void testAntlibFile() { | |||
expectLog("antlib.file", "MyTask called"); | |||
buildRule.executeTarget("antlib.file"); | |||
assertEquals("MyTask called", buildRule.getLog()); | |||
} | |||
/** | |||
@@ -51,31 +60,34 @@ public class AntlibTest extends BuildFileTest { | |||
* can collect several antlibs in one Definer call. | |||
* @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=24024" | |||
*/ | |||
@Test | |||
public void testAntlibResource() { | |||
expectLog("antlib.resource", "MyTask called-and-then-MyTask2 called"); | |||
buildRule.executeTarget("antlib.resource"); | |||
assertEquals("MyTask called-and-then-MyTask2 called", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testNsCurrent() { | |||
expectLog("ns.current", "Echo2 inside a macroHello from x:p"); | |||
buildRule.executeTarget("ns.current"); | |||
assertEquals("Echo2 inside a macroHello from x:p", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testAntlib_uri() { | |||
if (isSharedJVM()) { | |||
executeTarget("antlib_uri"); | |||
} | |||
Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); | |||
buildRule.executeTarget("antlib_uri"); | |||
} | |||
@Test | |||
public void testAntlib_uri_auto() { | |||
if (isSharedJVM()) { | |||
executeTarget("antlib_uri_auto"); | |||
} | |||
Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); | |||
buildRule.executeTarget("antlib_uri_auto"); | |||
} | |||
@Test | |||
public void testAntlib_uri_auto2() { | |||
if (isSharedJVM()) { | |||
executeTarget("antlib_uri_auto2"); | |||
} | |||
Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); | |||
buildRule.executeTarget("antlib_uri_auto2"); | |||
} | |||
public static class MyTask extends Task { | |||
@@ -18,102 +18,140 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* JUnit test for the Available task/condition. | |||
*/ | |||
public class AvailableTest extends BuildFileTest { | |||
public AvailableTest(String name) { | |||
super(name); | |||
} | |||
public class AvailableTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/available.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/available.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
// Nothing specified -> Fail | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// Only property specified -> Fail | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// Only file specified -> Fail | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// file doesn't exist -> property 'test' == null | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
assertTrue(project.getProperty("test") == null); | |||
buildRule.executeTarget("test4"); | |||
assertTrue(buildRule.getProject().getProperty("test") == null); | |||
} | |||
// file does exist -> property 'test' == 'true' | |||
public void test5() { | |||
executeTarget("test5"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test5"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// resource doesn't exist -> property 'test' == null | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
assertTrue(project.getProperty("test") == null); | |||
buildRule.executeTarget("test6"); | |||
assertTrue(buildRule.getProject().getProperty("test") == null); | |||
} | |||
// resource does exist -> property 'test' == 'true' | |||
@Test | |||
public void test7() { | |||
executeTarget("test7"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test7"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// class doesn't exist -> property 'test' == null | |||
@Test | |||
public void test8() { | |||
executeTarget("test8"); | |||
assertTrue(project.getProperty("test") == null); | |||
buildRule.executeTarget("test8"); | |||
assertTrue(buildRule.getProject().getProperty("test") == null); | |||
} | |||
// class does exist -> property 'test' == 'true' | |||
@Test | |||
public void test9() { | |||
executeTarget("test9"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test9"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// All three specified and all three exist -> true | |||
@Test | |||
public void test10() { | |||
executeTarget("test10"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test10"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// All three specified but class missing -> null | |||
@Test | |||
public void test11() { | |||
executeTarget("test11"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("test11"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified property-name is "" -> true | |||
@Test | |||
public void test12() { | |||
executeTarget("test12"); | |||
assertNull(project.getProperty("test")); | |||
assertEquals("true", project.getProperty("")); | |||
buildRule.executeTarget("test12"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
assertEquals("true", buildRule.getProject().getProperty("")); | |||
} | |||
// Specified file is "" -> invalid files do not exist | |||
@Test | |||
public void test13() { | |||
executeTarget("test13"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("test13"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified file is "" actually a directory, so it should pass | |||
@Test | |||
public void test13b() { | |||
executeTarget("test13b"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test13b"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified resource is "" -> can such a thing exist? | |||
@@ -121,94 +159,114 @@ public class AvailableTest extends BuildFileTest { | |||
* returns non null IBM JDK 1.3 Linux | |||
*/ | |||
// public void test14() { | |||
// executeTarget("test14"); | |||
// assertEquals(project.getProperty("test"), null); | |||
// buildRule.executeTarget("test14"); | |||
// assertEquals(buildRule.getProject().getProperty("test"), null); | |||
// } | |||
// Specified class is "" -> can not exist | |||
@Test | |||
public void test15() { | |||
executeTarget("test15"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("test15"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified dir is "" -> this is the current directory and should | |||
// always exist | |||
@Test | |||
public void test16() { | |||
executeTarget("test16"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test16"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified dir is "../taskdefs" -> should exist since it's the | |||
// location of the buildfile used... | |||
@Test | |||
public void test17() { | |||
executeTarget("test17"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test17"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Specified dir is "../this_dir_should_never_exist" -> null | |||
@Test | |||
public void test18() { | |||
executeTarget("test18"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("test18"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// Invalid type specified | |||
@Test | |||
public void test19() { | |||
expectBuildException("test19", "Invalid value for type attribute."); | |||
try { | |||
buildRule.executeTarget("test19"); | |||
fail("Invalid value for type attribute"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
// Core class that exists in system classpath is ignored | |||
@Test | |||
public void test20() { | |||
executeTarget("test20"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("test20"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// Core class that exists in system classpath is ignored, but found in specified classpath | |||
@Test | |||
public void test21() { | |||
executeTarget("test21"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test21"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Core class that exists in system classpath is not ignored with ignoresystemclass="false" | |||
@Test | |||
public void test22() { | |||
executeTarget("test22"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test22"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Core class that exists in system classpath is not ignored with default ignoresystemclasses value | |||
@Test | |||
public void test23() { | |||
executeTarget("test23"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test23"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// Class is found in specified classpath | |||
@Test | |||
public void test24() { | |||
executeTarget("test24"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("test24"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// File is not found in specified filepath | |||
@Test | |||
public void testSearchInPathNotThere() { | |||
executeTarget("searchInPathNotThere"); | |||
assertNull(project.getProperty("test")); | |||
buildRule.executeTarget("searchInPathNotThere"); | |||
assertNull(buildRule.getProject().getProperty("test")); | |||
} | |||
// File is not found in specified filepath | |||
@Test | |||
public void testSearchInPathIsThere() { | |||
executeTarget("searchInPathIsThere"); | |||
assertEquals("true", project.getProperty("test")); | |||
buildRule.executeTarget("searchInPathIsThere"); | |||
assertEquals("true", buildRule.getProject().getProperty("test")); | |||
} | |||
// test when file begins with basedir twice | |||
@Test | |||
public void testDoubleBasedir() { | |||
executeTarget("testDoubleBasedir"); | |||
buildRule.executeTarget("testDoubleBasedir"); | |||
} | |||
// test for searching parents | |||
@Test | |||
public void testSearchParents() { | |||
executeTarget("search-parents"); | |||
buildRule.executeTarget("search-parents"); | |||
} | |||
// test for not searching parents | |||
@Test | |||
public void testSearchParentsNot() { | |||
executeTarget("search-parents-not"); | |||
buildRule.executeTarget("search-parents-not"); | |||
} | |||
} |
@@ -18,45 +18,49 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
*/ | |||
public class BUnzip2Test extends BuildFileTest { | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public class BUnzip2Test { | |||
public BUnzip2Test(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/bunzip2.xml"); | |||
executeTarget("prepare"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/bunzip2.xml"); | |||
buildRule.executeTarget("prepare"); | |||
} | |||
@Test | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void testRealTest() throws java.io.IOException { | |||
testRealTest("realTest"); | |||
} | |||
@Test | |||
public void testRealTestWithResource() throws java.io.IOException { | |||
testRealTest("realTestWithResource"); | |||
} | |||
private void testRealTest(String target) throws java.io.IOException { | |||
executeTarget(target); | |||
assertTrue("File content mismatch after bunzip2", | |||
FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"), | |||
project.resolveFile("asf-logo-huge.tar"))); | |||
buildRule.executeTarget(target); | |||
assertEquals("File content mismatch after bunzip2", | |||
FileUtilities.getFileContents(buildRule.getProject().resolveFile("expected/asf-logo-huge.tar")), | |||
FileUtilities.getFileContents(buildRule.getProject().resolveFile("asf-logo-huge.tar"))); | |||
} | |||
@Test | |||
public void testDocumentationClaimsOnCopy() throws java.io.IOException { | |||
testRealTest("testDocumentationClaimsOnCopy"); | |||
} | |||
@@ -18,34 +18,44 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.bzip2.CBZip2InputStream; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.BufferedInputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.InputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class BZip2Test extends BuildFileTest { | |||
public class BZip2Test { | |||
public BZip2Test(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/bzip2.xml"); | |||
executeTarget("prepare"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/bzip2.xml"); | |||
buildRule.executeTarget("prepare"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void testRealTest() throws IOException { | |||
executeTarget("realTest"); | |||
buildRule.executeTarget("realTest"); | |||
// doesn't work: Depending on the compression engine used, | |||
// compressed bytes may differ. False errors would be | |||
@@ -57,8 +67,8 @@ public class BZip2Test extends BuildFileTest { | |||
// We have to compare the decompressed content instead: | |||
File originalFile = | |||
project.resolveFile("expected/asf-logo-huge.tar.bz2"); | |||
File actualFile = project.resolveFile("asf-logo-huge.tar.bz2"); | |||
buildRule.getProject().resolveFile("expected/asf-logo-huge.tar.bz2"); | |||
File actualFile = buildRule.getProject().resolveFile("asf-logo-huge.tar.bz2"); | |||
InputStream originalIn = | |||
new BufferedInputStream(new FileInputStream(originalFile)); | |||
@@ -92,13 +102,15 @@ public class BZip2Test extends BuildFileTest { | |||
actualIn.close(); | |||
} | |||
@Test | |||
public void testResource(){ | |||
executeTarget("realTestWithResource"); | |||
buildRule.executeTarget("realTestWithResource"); | |||
} | |||
@Test | |||
public void testDateCheck(){ | |||
executeTarget("testDateCheck"); | |||
String log = getLog(); | |||
buildRule.executeTarget("testDateCheck"); | |||
String log = buildRule.getLog(); | |||
assertTrue( | |||
"Expecting message ending with 'asf-logo.gif.bz2 is up to date.' but got '" + log + "'", | |||
log.endsWith("asf-logo.gif.bz2 is up to date.")); | |||
@@ -18,65 +18,96 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class BasenameTest extends BuildFileTest { | |||
public class BasenameTest { | |||
public BasenameTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/basename.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/basename.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required attribute missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("Required attribute missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required attribute missing"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("Required attribute missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required attribute missing"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("Required attribute missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception message | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
String checkprop = project.getProperty("file.w.suf"); | |||
buildRule.executeTarget("test4"); | |||
String checkprop = buildRule.getProject().getProperty("file.w.suf"); | |||
assertEquals("foo.txt", checkprop); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
String checkprop = project.getProperty("file.wo.suf"); | |||
buildRule.executeTarget("test5"); | |||
String checkprop = buildRule.getProject().getProperty("file.wo.suf"); | |||
assertEquals("foo", checkprop); | |||
} | |||
@Test | |||
public void testMultipleDots() { | |||
executeTarget("testMultipleDots"); | |||
String checkprop = project.getProperty("file.wo.suf"); | |||
buildRule.executeTarget("testMultipleDots"); | |||
String checkprop = buildRule.getProject().getProperty("file.wo.suf"); | |||
assertEquals("foo.bar", checkprop); | |||
} | |||
@Test | |||
public void testNoDots() { | |||
executeTarget("testNoDots"); | |||
String checkprop = project.getProperty("file.wo.suf"); | |||
buildRule.executeTarget("testNoDots"); | |||
String checkprop = buildRule.getProject().getProperty("file.wo.suf"); | |||
assertEquals("foo.bar", checkprop); | |||
} | |||
@Test | |||
public void testValueEqualsSuffixWithDot() { | |||
executeTarget("testValueEqualsSuffixWithDot"); | |||
String checkprop = project.getProperty("file.wo.suf"); | |||
buildRule.executeTarget("testValueEqualsSuffixWithDot"); | |||
String checkprop = buildRule.getProject().getProperty("file.wo.suf"); | |||
assertEquals("", checkprop); | |||
} | |||
@Test | |||
public void testValueEqualsSuffixWithoutDot() { | |||
executeTarget("testValueEqualsSuffixWithoutDot"); | |||
String checkprop = project.getProperty("file.wo.suf"); | |||
buildRule.executeTarget("testValueEqualsSuffixWithoutDot"); | |||
String checkprop = buildRule.getProject().getProperty("file.wo.suf"); | |||
assertEquals("", checkprop); | |||
} | |||
@@ -19,14 +19,24 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.*; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Tests CVSLogin task. | |||
* | |||
*/ | |||
public class CVSPassTest extends BuildFileTest { | |||
public class CVSPassTest { | |||
private final String EOL = System.getProperty("line.separator"); | |||
private static final String JAKARTA_URL = | |||
":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z"; | |||
@@ -34,63 +44,69 @@ public class CVSPassTest extends BuildFileTest { | |||
":pserver:anoncvs@xml.apache.org:/home/cvspublic Ay=0=h<Z"; | |||
private static final String TIGRIS_URL = | |||
":pserver:guest@cvs.tigris.org:/cvs AIbdZ,"; | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
public CVSPassTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/cvspass.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/cvspass.xml"); | |||
} | |||
@Test | |||
public void testNoCVSRoot() { | |||
try{ | |||
executeTarget("test1"); | |||
buildRule.executeTarget("test1"); | |||
fail("BuildException not thrown"); | |||
}catch(BuildException e){ | |||
assertEquals("cvsroot is required", e.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNoPassword() { | |||
try{ | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
fail("BuildException not thrown"); | |||
}catch(BuildException e){ | |||
assertEquals("password is required", e.getMessage()); | |||
} | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void testPassFile() throws Exception { | |||
executeTarget("test3"); | |||
File f = new File(getProjectDir(), "testpassfile.tmp"); | |||
buildRule.executeTarget("test3"); | |||
File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); | |||
assertTrue( "Passfile "+f+" not created", f.exists()); | |||
assertEquals(JAKARTA_URL+EOL, readFile(f)); | |||
assertEquals(JAKARTA_URL+EOL, FileUtilities.getFileContents(f)); | |||
} | |||
@Test | |||
public void testPassFileDuplicateEntry() throws Exception { | |||
executeTarget("test4"); | |||
File f = new File(getProjectDir(), "testpassfile.tmp"); | |||
buildRule.executeTarget("test4"); | |||
File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); | |||
assertTrue( "Passfile "+f+" not created", f.exists()); | |||
assertEquals( | |||
JAKARTA_URL+ EOL+ | |||
TIGRIS_URL+ EOL, | |||
readFile(f)); | |||
FileUtilities.getFileContents(f)); | |||
} | |||
@Test | |||
public void testPassFileMultipleEntry() throws Exception { | |||
executeTarget("test5"); | |||
File f = new File(getProjectDir(), "testpassfile.tmp"); | |||
buildRule.executeTarget("test5"); | |||
File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); | |||
assertTrue( "Passfile "+f+" not created", f.exists()); | |||
@@ -98,25 +114,6 @@ public class CVSPassTest extends BuildFileTest { | |||
JAKARTA_URL+ EOL+ | |||
XML_URL+ EOL+ | |||
TIGRIS_URL+ EOL, | |||
readFile(f)); | |||
} | |||
private String readFile(File f) throws Exception { | |||
BufferedReader reader = null; | |||
try { | |||
reader = new BufferedReader(new FileReader(f)); | |||
StringBuffer buf = new StringBuffer(); | |||
String line=null; | |||
while((line=reader.readLine())!=null){ | |||
buf.append(line + EOL); | |||
} | |||
return buf.toString(); | |||
} finally { | |||
if (reader != null) { | |||
reader.close(); | |||
} | |||
} | |||
FileUtilities.getFileContents(f)); | |||
} | |||
} |
@@ -18,53 +18,75 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.util.Vector; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class CallTargetTest extends BuildFileTest { | |||
public class CallTargetTest { | |||
public CallTargetTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/calltarget.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/calltarget.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
// see bugrep 21724 (references not passing through with antcall) | |||
@Test | |||
public void testInheritRefFileSet() { | |||
expectLogContaining("testinheritreffileset", "calltarget.xml"); | |||
buildRule.executeTarget("testinheritreffileset"); | |||
AntAssert.assertContains("calltarget.xml", buildRule.getLog()); | |||
} | |||
// see bugrep 21724 (references not passing through with antcall) | |||
@Test | |||
public void testInheritFilterset() { | |||
project.executeTarget("testinheritreffilterset"); | |||
buildRule.getProject().executeTarget("testinheritreffilterset"); | |||
} | |||
// see bugrep 11418 (In repeated calls to the same target, | |||
// params will not be passed in) | |||
@Test | |||
public void testMultiCall() { | |||
Vector v = new Vector(); | |||
Vector<String> v = new Vector<String>(); | |||
v.add("call-multi"); | |||
v.add("call-multi"); | |||
project.executeTargets(v); | |||
assertLogContaining("multi is SETmulti is SET"); | |||
buildRule.getProject().executeTargets(v); | |||
AntAssert.assertContains("multi is SETmulti is SET", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testBlankTarget() { | |||
expectBuildException("blank-target", "target name must not be empty"); | |||
try { | |||
buildRule.executeTarget("blank-target"); | |||
fail("target name must not be empty"); | |||
} catch (BuildException ex) { | |||
//TODO assert exception contents | |||
} | |||
} | |||
@Test | |||
public void testMultipleTargets() { | |||
expectLog("multiple-targets", "tadadctbdbtc"); | |||
buildRule.executeTarget("multiple-targets"); | |||
assertEquals("tadadctbdbtc", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testMultipleTargets2() { | |||
expectLog("multiple-targets-2", "dadctb"); | |||
buildRule.executeTarget("multiple-targets-2"); | |||
assertEquals("dadctb", buildRule.getLog()); | |||
} | |||
} |
@@ -18,76 +18,92 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.IOException; | |||
/** | |||
*/ | |||
public class ChecksumTest extends BuildFileTest { | |||
public ChecksumTest(String name) { | |||
super(name); | |||
} | |||
public class ChecksumTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/checksum.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/checksum.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void testCreateMd5() throws IOException { | |||
executeTarget("createMd5"); | |||
buildRule.executeTarget("createMd5"); | |||
} | |||
@Test | |||
public void testCreateMD5SUMformat() throws IOException { | |||
executeTarget("createMD5SUMformat"); | |||
buildRule.executeTarget("createMD5SUMformat"); | |||
} | |||
@Test | |||
public void testCreateSVFformat() throws IOException { | |||
executeTarget("createSVFformat"); | |||
buildRule.executeTarget("createSVFformat"); | |||
} | |||
@Test | |||
public void testCreatePattern() throws IOException { | |||
executeTarget("createPattern"); | |||
buildRule.executeTarget("createPattern"); | |||
} | |||
@Test | |||
public void testSetProperty() { | |||
executeTarget("setProperty"); | |||
buildRule.executeTarget("setProperty"); | |||
} | |||
@Test | |||
public void testVerifyTotal() { | |||
executeTarget("verifyTotal"); | |||
buildRule.executeTarget("verifyTotal"); | |||
} | |||
@Test | |||
public void testVerifyTotalRC() { | |||
executeTarget("verifyTotalRC"); | |||
buildRule.executeTarget("verifyTotalRC"); | |||
} | |||
@Test | |||
public void testVerifyChecksumdir() { | |||
executeTarget("verifyChecksumdir"); | |||
buildRule.executeTarget("verifyChecksumdir"); | |||
} | |||
@Test | |||
public void testVerifyAsTask() { | |||
executeTarget("verifyAsTask"); | |||
buildRule.executeTarget("verifyAsTask"); | |||
} | |||
@Test | |||
public void testVerifyMD5SUMAsTask() { | |||
executeTarget("verifyMD5SUMAsTask"); | |||
buildRule.executeTarget("verifyMD5SUMAsTask"); | |||
} | |||
@Test | |||
public void testVerifyAsCondition() { | |||
executeTarget("verifyAsCondition"); | |||
buildRule.executeTarget("verifyAsCondition"); | |||
} | |||
@Test | |||
public void testVerifyFromProperty() { | |||
executeTarget("verifyFromProperty"); | |||
buildRule.executeTarget("verifyFromProperty"); | |||
} | |||
@Test | |||
public void testVerifyChecksumdirNoTotal() { | |||
executeTarget("verifyChecksumdirNoTotal"); | |||
buildRule.executeTarget("verifyChecksumdirNoTotal"); | |||
} | |||
} |
@@ -18,21 +18,28 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import java.io.Reader; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* A test class for the 'concat' task, used to concatenate a series of | |||
* files into a single stream. | |||
* | |||
*/ | |||
public class ConcatTest | |||
extends BuildFileTest { | |||
public class ConcatTest { | |||
/** | |||
* The name of the temporary file. | |||
@@ -44,57 +51,68 @@ public class ConcatTest | |||
*/ | |||
private static final String tempFile2 = "concat.tmp.2"; | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
/** | |||
* Required constructor. | |||
*/ | |||
public ConcatTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
/** | |||
* Test set up, called by the unit test framework prior to each | |||
* test. | |||
*/ | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/concat.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/concat.xml"); | |||
} | |||
/** | |||
* Test tear down, called by the unit test framework prior to each | |||
* test. | |||
*/ | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
/** | |||
* Expect an exception when insufficient information is provided. | |||
*/ | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "Insufficient information."); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("BuildException should have been thrown - Insufficient information"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* Expect an exception when the destination file is invalid. | |||
*/ | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "Invalid destination file."); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("BuildException should have been thrown - Invalid destination file"); | |||
} catch(BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* Cats the string 'Hello, World!' to a temporary file. | |||
*/ | |||
@Test | |||
public void test3() { | |||
File file = new File(getProjectDir(), tempFile); | |||
File file = new File(buildRule.getProject().getBaseDir(), tempFile); | |||
if (file.exists()) { | |||
file.delete(); | |||
} | |||
executeTarget("test3"); | |||
buildRule.executeTarget("test3"); | |||
assertTrue(file.exists()); | |||
} | |||
@@ -102,15 +120,16 @@ public class ConcatTest | |||
/** | |||
* Cats the file created in test3 three times. | |||
*/ | |||
@Test | |||
public void test4() { | |||
test3(); | |||
File file = new File(getProjectDir(), tempFile); | |||
File file = new File(buildRule.getProject().getBaseDir(), tempFile); | |||
final long origSize = file.length(); | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
File file2 = new File(getProjectDir(), tempFile2); | |||
File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); | |||
final long newSize = file2.length(); | |||
assertEquals(origSize * 3, newSize); | |||
@@ -119,170 +138,178 @@ public class ConcatTest | |||
/** | |||
* Cats the string 'Hello, World!' to the console. | |||
*/ | |||
@Test | |||
public void test5() { | |||
expectLog("test5", "Hello, World!"); | |||
buildRule.executeTarget("test5"); | |||
assertEquals("Hello, World!", buildRule.getLog()); | |||
} | |||
@Test | |||
public void test6() { | |||
String filename = "src/etc/testcases/taskdefs/thisfiledoesnotexist" | |||
.replace('/', File.separatorChar); | |||
expectLogContaining("test6", filename +" does not exist."); | |||
buildRule.executeTarget("test6"); | |||
assertContains(filename + " does not exist", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testConcatNoNewline() { | |||
expectLog("testConcatNoNewline", "ab"); | |||
buildRule.executeTarget("testConcatNoNewline"); | |||
assertEquals("ab", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testConcatNoNewlineEncoding() { | |||
expectLog("testConcatNoNewlineEncoding", "ab"); | |||
buildRule.executeTarget("testConcatNoNewlineEncoding"); | |||
assertEquals("ab", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testPath() { | |||
test3(); | |||
File file = new File(getProjectDir(), tempFile); | |||
File file = new File(buildRule.getProject().getBaseDir(), tempFile); | |||
final long origSize = file.length(); | |||
executeTarget("testPath"); | |||
buildRule.executeTarget("testPath"); | |||
File file2 = new File(getProjectDir(), tempFile2); | |||
File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); | |||
final long newSize = file2.length(); | |||
assertEquals(origSize, newSize); | |||
} | |||
@Test | |||
public void testAppend() { | |||
test3(); | |||
File file = new File(getProjectDir(), tempFile); | |||
File file = new File(buildRule.getProject().getBaseDir(), tempFile); | |||
final long origSize = file.length(); | |||
executeTarget("testAppend"); | |||
buildRule.executeTarget("testAppend"); | |||
File file2 = new File(getProjectDir(), tempFile2); | |||
File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); | |||
final long newSize = file2.length(); | |||
assertEquals(origSize*2, newSize); | |||
} | |||
@Test | |||
public void testFilter() { | |||
executeTarget("testfilter"); | |||
assertTrue(getLog().indexOf("REPLACED") > -1); | |||
buildRule.executeTarget("testfilter"); | |||
assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); | |||
} | |||
@Test | |||
public void testNoOverwrite() { | |||
executeTarget("testnooverwrite"); | |||
File file2 = new File(getProjectDir(), tempFile2); | |||
buildRule.executeTarget("testnooverwrite"); | |||
File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); | |||
long size = file2.length(); | |||
assertEquals(size, 0); | |||
} | |||
@Test | |||
public void testOverwrite() { | |||
executeTarget("testoverwrite"); | |||
File file2 = new File(getProjectDir(), tempFile2); | |||
buildRule.executeTarget("testoverwrite"); | |||
File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); | |||
long size = file2.length(); | |||
assertTrue(size > 0); | |||
} | |||
@Test | |||
public void testheaderfooter() { | |||
test3(); | |||
expectLog("testheaderfooter", "headerHello, World!footer"); | |||
buildRule.executeTarget("testheaderfooter"); | |||
assertEquals("headerHello, World!footer", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testfileheader() { | |||
test3(); | |||
expectLog("testfileheader", "Hello, World!Hello, World!"); | |||
buildRule.executeTarget("testfileheader"); | |||
assertEquals("Hello, World!Hello, World!", buildRule.getLog()); | |||
} | |||
/** | |||
* Expect an exception when attempting to cat an file to itself | |||
*/ | |||
@Test | |||
public void testsame() { | |||
expectBuildException("samefile", "output file same as input"); | |||
try { | |||
buildRule.executeTarget("samefile"); | |||
fail("Build exception should have been thrown - output file same as input"); | |||
} catch(BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* Check if filter inline works | |||
*/ | |||
@Test | |||
public void testfilterinline() { | |||
executeTarget("testfilterinline"); | |||
assertTrue(getLog().indexOf("REPLACED") > -1); | |||
buildRule.executeTarget("testfilterinline"); | |||
assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); | |||
} | |||
/** | |||
* Check if multireader works | |||
*/ | |||
@Test | |||
public void testmultireader() { | |||
executeTarget("testmultireader"); | |||
assertTrue(getLog().indexOf("Bye") > -1); | |||
assertTrue(getLog().indexOf("Hello") == -1); | |||
buildRule.executeTarget("testmultireader"); | |||
assertTrue(buildRule.getLog().indexOf("Bye") > -1); | |||
assertTrue(buildRule.getLog().indexOf("Hello") == -1); | |||
} | |||
/** | |||
* Check if fixlastline works | |||
*/ | |||
@Test | |||
public void testfixlastline() | |||
throws IOException | |||
{ | |||
expectFileContains( | |||
"testfixlastline", "concat.line4", | |||
"end of line" + System.getProperty("line.separator") | |||
+ "This has"); | |||
buildRule.executeTarget("testfixlastline"); | |||
assertContains("end of line" + System.getProperty("line.separator") + "This has", | |||
FileUtilities.getFileContents(buildRule.getProject(), "concat.line4")); | |||
} | |||
/** | |||
* Check if fixlastline works with eol | |||
*/ | |||
@Test | |||
public void testfixlastlineeol() | |||
throws IOException | |||
{ | |||
expectFileContains( | |||
"testfixlastlineeol", "concat.linecr", | |||
"end of line\rThis has"); | |||
buildRule.executeTarget("testfixlastlineeol"); | |||
assertContains("end of line\rThis has", FileUtilities.getFileContents(buildRule.getProject(), "concat.linecr")); | |||
} | |||
// ------------------------------------------------------ | |||
// Helper methods - should be in BuildFileTest | |||
// ----------------------------------------------------- | |||
private String getFileString(String filename) | |||
throws IOException | |||
{ | |||
Reader r = null; | |||
try { | |||
r = new FileReader(getProject().resolveFile(filename)); | |||
return FileUtils.readFully(r); | |||
} | |||
finally { | |||
FileUtils.close(r); | |||
} | |||
} | |||
private String getFileString(String target, String filename) | |||
throws IOException | |||
{ | |||
executeTarget(target); | |||
return getFileString(filename); | |||
@Test | |||
public void testTranscoding() throws IOException { | |||
buildRule.executeTarget("testTranscoding"); | |||
File f1 = buildRule.getProject().resolveFile("copy/expected/utf-8"); | |||
File f2 = buildRule.getProject().resolveFile("concat.utf8"); | |||
assertEquals(f1.toString() + " differs from " + f2.toString(), | |||
FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); | |||
} | |||
private void expectFileContains( | |||
// ------------------------------------------------------ | |||
// Helper methods - should be in a utility class | |||
// ----------------------------------------------------- | |||
private void expectFileContainsx( | |||
String target, String filename, String contains) | |||
throws IOException | |||
{ | |||
String content = getFileString(target, filename); | |||
buildRule.executeTarget(target); | |||
String content = FileUtilities.getFileContents(buildRule.getProject(), filename); | |||
assertTrue( | |||
"expecting file " + filename + " to contain " + | |||
contains + | |||
" but got " + content, content.indexOf(contains) > -1); | |||
} | |||
public void testTranscoding() throws IOException { | |||
executeTarget("testTranscoding"); | |||
File f1 = getProject().resolveFile("copy/expected/utf-8"); | |||
File f2 = getProject().resolveFile("concat.utf8"); | |||
assertTrue(f1.toString() + " differs from " + f2.toString(), | |||
FILE_UTILS.contentEquals(f1, f2)); | |||
} | |||
} |
@@ -17,259 +17,363 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* @created 13 January 2002 | |||
*/ | |||
public class ConditionTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Constructor for the ConditionTest object | |||
* | |||
* @param name we dont know | |||
*/ | |||
public ConditionTest(String name) { | |||
super(name); | |||
} | |||
public class ConditionTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
/** | |||
* The JUnit setup method | |||
*/ | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/condition.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/condition.xml"); | |||
} | |||
/** | |||
* The teardown method for JUnit | |||
*/ | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void testBasic() { | |||
expectPropertySet("basic","basic"); | |||
buildRule.executeTarget("basic"); | |||
assertEquals("true", buildRule.getProject().getProperty("basic")); | |||
} | |||
@Test | |||
public void testConditionIncomplete() { | |||
expectSpecificBuildException("condition-incomplete", | |||
"property attribute has been omitted", | |||
"The property attribute is required."); | |||
try { | |||
buildRule.executeTarget("condition-incomplete"); | |||
fail("BuildException should have been thrown - property attribute has been omitted"); | |||
} catch (BuildException ex) { | |||
assertEquals("The property attribute is required.", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testConditionEmpty() { | |||
expectSpecificBuildException("condition-empty", | |||
"no conditions", | |||
"You must nest a condition into <condition>"); | |||
try { | |||
buildRule.executeTarget("condition-empty"); | |||
fail("BuildException should have been thrown - no conditions"); | |||
} catch(BuildException ex) { | |||
assertEquals("You must nest a condition into <condition>", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testShortcut() { | |||
expectPropertySet("shortcut","shortcut","set"); | |||
buildRule.executeTarget("shortcut"); | |||
assertEquals("set", buildRule.getProject().getProperty("shortcut")); | |||
} | |||
@Test | |||
public void testUnset() { | |||
expectPropertyUnset("dontset","dontset"); | |||
buildRule.executeTarget("dontset"); | |||
assertNull(buildRule.getProject().getProperty("dontset")); | |||
} | |||
@Test | |||
public void testSetValue() { | |||
expectPropertySet("setvalue","setvalue","woowoo"); | |||
buildRule.executeTarget("setvalue"); | |||
assertEquals("woowoo", buildRule.getProject().getProperty("setvalue")); | |||
} | |||
@Test | |||
public void testNegation() { | |||
expectPropertySet("negation","negation"); | |||
buildRule.executeTarget("negation"); | |||
assertEquals("true", buildRule.getProject().getProperty("negation")); | |||
} | |||
@Test | |||
public void testNegationFalse() { | |||
expectPropertyUnset("negationfalse","negationfalse"); | |||
buildRule.executeTarget("negationfalse"); | |||
assertNull(buildRule.getProject().getProperty("negationfalse")); | |||
} | |||
@Test | |||
public void testNegationIncomplete() { | |||
expectSpecificBuildException("negationincomplete", | |||
"no conditions in <not>", | |||
"You must nest a condition into <not>"); | |||
try { | |||
buildRule.executeTarget("negationincomplete"); | |||
fail("BuildException should have been thrown - no conditions in <not>"); | |||
} catch (BuildException ex) { | |||
assertEquals("You must nest a condition into <not>", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testAnd() { | |||
expectPropertySet("and","and"); | |||
buildRule.executeTarget("and"); | |||
assertEquals("true", buildRule.getProject().getProperty("and")); | |||
} | |||
@Test | |||
public void testAndFails() { | |||
expectPropertyUnset("andfails","andfails"); | |||
buildRule.executeTarget("andfails"); | |||
assertNull(buildRule.getProject().getProperty("andfails")); | |||
} | |||
@Test | |||
public void testAndIncomplete() { | |||
expectPropertyUnset("andincomplete","andincomplete"); | |||
buildRule.executeTarget("andincomplete"); | |||
assertNull(buildRule.getProject().getProperty("andincomplete")); | |||
} | |||
@Test | |||
public void testAndempty() { | |||
expectPropertySet("andempty","andempty"); | |||
buildRule.executeTarget("andempty"); | |||
assertEquals("true", buildRule.getProject().getProperty("andempty")); | |||
} | |||
@Test | |||
public void testOr() { | |||
expectPropertySet("or","or"); | |||
buildRule.executeTarget("or"); | |||
assertEquals("true", buildRule.getProject().getProperty("or")); | |||
} | |||
@Test | |||
public void testOrincomplete() { | |||
expectPropertySet("or","or"); | |||
buildRule.executeTarget("or"); | |||
assertEquals("true", buildRule.getProject().getProperty("or")); | |||
} | |||
@Test | |||
public void testOrFails() { | |||
expectPropertyUnset("orfails","orfails"); | |||
buildRule.executeTarget("orfails"); | |||
assertNull(buildRule.getProject().getProperty("orfails")); | |||
} | |||
@Test | |||
public void testOrboth() { | |||
expectPropertySet("orboth","orboth"); | |||
buildRule.executeTarget("orboth"); | |||
assertEquals("true", buildRule.getProject().getProperty("orboth")); | |||
} | |||
@Test | |||
public void testFilesmatchIdentical() { | |||
expectPropertySet("filesmatch-identical","filesmatch-identical"); | |||
buildRule.executeTarget("filesmatch-identical"); | |||
assertEquals("true", buildRule.getProject().getProperty("filesmatch-identical")); | |||
} | |||
@Test | |||
public void testFilesmatchIncomplete() { | |||
expectSpecificBuildException("filesmatch-incomplete", | |||
"Missing file2 attribute", | |||
"both file1 and file2 are required in filesmatch"); | |||
try { | |||
buildRule.executeTarget("filesmatch-incomplete"); | |||
fail("Build exception should have been thrown - Missing file2 attirbute"); | |||
} catch (BuildException ex) { | |||
assertEquals("both file1 and file2 are required in filesmatch", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testFilesmatchOddsizes() { | |||
expectPropertyUnset("filesmatch-oddsizes","filesmatch-oddsizes"); | |||
buildRule.executeTarget("filesmatch-oddsizes"); | |||
assertNull(buildRule.getProject().getProperty("filesmatch-oddsizes")); | |||
} | |||
@Test | |||
public void testFilesmatchExistence() { | |||
expectPropertyUnset("filesmatch-existence", "filesmatch-existence"); | |||
buildRule.executeTarget("filesmatch-existence"); | |||
assertNull(buildRule.getProject().getProperty("filesmatch-existence")); | |||
} | |||
@Test | |||
public void testFilesmatchDifferent() { | |||
expectPropertyUnset("filesmatch-different","filesmatch-different"); | |||
buildRule.executeTarget("filesmatch-different"); | |||
assertNull(buildRule.getProject().getProperty("filesmatch-different")); | |||
} | |||
@Test | |||
public void testFilesmatchMatch() { | |||
expectPropertySet("filesmatch-match","filesmatch-match"); | |||
buildRule.executeTarget("filesmatch-match"); | |||
assertEquals("true", buildRule.getProject().getProperty("filesmatch-match")); | |||
} | |||
@Test | |||
public void testFilesmatchDifferentSizes() { | |||
expectPropertyUnset("filesmatch-different-sizes", | |||
"filesmatch-different-sizes"); | |||
buildRule.executeTarget("filesmatch-different-sizes"); | |||
assertNull(buildRule.getProject().getProperty("filesmatch-different-sizes")); | |||
} | |||
@Test | |||
public void testFilesmatchDifferentOnemissing() { | |||
expectPropertyUnset("filesmatch-different-onemissing", | |||
"filesmatch-different-onemissing"); | |||
buildRule.executeTarget("filesmatch-different-onemissing"); | |||
assertNull(buildRule.getProject().getProperty("filesmatch-different-onemissing")); | |||
} | |||
@Test | |||
public void testFilesmatchDifferentEol() { | |||
executeTarget("filesmatch-different-eol"); | |||
buildRule.executeTarget("filesmatch-different-eol"); | |||
} | |||
@Test | |||
public void testFilesmatchSameEol() { | |||
executeTarget("filesmatch-same-eol"); | |||
buildRule.executeTarget("filesmatch-same-eol"); | |||
} | |||
@Test | |||
public void testFilesmatchNeitherExist() { | |||
executeTarget("filesmatch-neitherexist"); | |||
buildRule.executeTarget("filesmatch-neitherexist"); | |||
} | |||
@Test | |||
public void testContains() { | |||
expectPropertySet("contains","contains"); | |||
buildRule.executeTarget("contains"); | |||
assertEquals("true", buildRule.getProject().getProperty("contains")); | |||
} | |||
@Test | |||
public void testContainsDoesnt() { | |||
expectPropertyUnset("contains-doesnt","contains-doesnt"); | |||
buildRule.executeTarget("contains-doesnt"); | |||
assertNull(buildRule.getProject().getProperty("contains-doesnt")); | |||
} | |||
@Test | |||
public void testContainsAnycase() { | |||
expectPropertySet("contains-anycase","contains-anycase"); | |||
buildRule.executeTarget("contains-anycase"); | |||
assertEquals("true", buildRule.getProject().getProperty("contains-anycase")); | |||
} | |||
@Test | |||
public void testContainsIncomplete1() { | |||
expectSpecificBuildException("contains-incomplete1", | |||
"Missing contains attribute", | |||
"both string and substring are required in contains"); | |||
try { | |||
buildRule.executeTarget("contains-incomplete1"); | |||
fail("BuildException should have been thrown - Missing contains attribute"); | |||
} catch(BuildException ex) { | |||
assertEquals("both string and substring are required in contains", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testContainsIncomplete2() { | |||
expectSpecificBuildException("contains-incomplete2", | |||
"Missing contains attribute", | |||
"both string and substring are required in contains"); | |||
try { | |||
buildRule.executeTarget("contains-incomplete2"); | |||
fail("BuildException should have been thrown - Missing contains attribute"); | |||
} catch(BuildException ex) { | |||
assertEquals("both string and substring are required in contains", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testIstrue() { | |||
expectPropertySet("istrue","istrue"); | |||
buildRule.executeTarget("istrue"); | |||
assertEquals("true", buildRule.getProject().getProperty("istrue")); | |||
} | |||
@Test | |||
public void testIstrueNot() { | |||
expectPropertyUnset("istrue-not","istrue-not"); | |||
buildRule.executeTarget("istrue-not"); | |||
assertNull(buildRule.getProject().getProperty("istrue-not")); | |||
} | |||
@Test | |||
public void testIstrueFalse() { | |||
expectPropertyUnset("istrue-false","istrue-false"); | |||
buildRule.executeTarget("istrue-false"); | |||
assertNull(buildRule.getProject().getProperty("istrue-false")); | |||
} | |||
@Test | |||
public void testIstrueIncomplete1() { | |||
expectSpecificBuildException("istrue-incomplete", | |||
"Missing attribute", | |||
"Nothing to test for truth"); | |||
try { | |||
buildRule.executeTarget("istrue-incomplete"); | |||
fail("BuildException should have been thrown - Missing attribute"); | |||
} catch(BuildException ex) { | |||
assertEquals("Nothing to test for truth", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testIsfalseTrue() { | |||
expectPropertyUnset("isfalse-true","isfalse-true"); | |||
buildRule.executeTarget("isfalse-true"); | |||
assertNull(buildRule.getProject().getProperty("isfalse-true")); | |||
} | |||
@Test | |||
public void testIsfalseNot() { | |||
expectPropertySet("isfalse-not","isfalse-not"); | |||
buildRule.executeTarget("isfalse-not"); | |||
assertEquals("true", buildRule.getProject().getProperty("isfalse-not")); | |||
} | |||
@Test | |||
public void testIsfalseFalse() { | |||
expectPropertySet("isfalse-false","isfalse-false"); | |||
} | |||
buildRule.executeTarget("isfalse-false"); | |||
assertEquals("true", buildRule.getProject().getProperty("isfalse-false")); | |||
} | |||
@Test | |||
public void testIsfalseIncomplete1() { | |||
expectSpecificBuildException("isfalse-incomplete", | |||
"Missing attribute", | |||
"Nothing to test for falsehood"); | |||
try { | |||
buildRule.executeTarget("isfalse-incomplete"); | |||
fail("BuildException should have been thrown - Missing attribute"); | |||
} catch(BuildException ex) { | |||
assertEquals("Nothing to test for falsehood", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testElse() { | |||
executeTarget("testElse"); | |||
buildRule.executeTarget("testElse"); | |||
} | |||
@Test | |||
public void testResourcesmatchError() { | |||
expectBuildException("resourcesmatch-error", | |||
"should fail because no resources specified"); | |||
try { | |||
buildRule.executeTarget("resourcematch-error"); | |||
fail("BuildException should have been thrown - no resources specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testResourcesmatchEmpty() { | |||
executeTarget("resourcesmatch-match-empty"); | |||
buildRule.executeTarget("resourcesmatch-match-empty"); | |||
} | |||
@Test | |||
public void testResourcesmatchOne() { | |||
executeTarget("resourcesmatch-match-one"); | |||
buildRule.executeTarget("resourcesmatch-match-one"); | |||
} | |||
@Test | |||
public void testResourcesmatchBinary() { | |||
executeTarget("resourcesmatch-match-binary"); | |||
buildRule.executeTarget("resourcesmatch-match-binary"); | |||
} | |||
@Test | |||
public void testResourcesmatchMultipleBinary() { | |||
executeTarget("resourcesmatch-match-multiple-binary"); | |||
buildRule.executeTarget("resourcesmatch-match-multiple-binary"); | |||
} | |||
@Test | |||
public void testResourcesmatchDiffer() { | |||
executeTarget("resourcesmatch-differ"); | |||
buildRule.executeTarget("resourcesmatch-differ"); | |||
} | |||
@Test | |||
public void testResourcesmatchText() { | |||
executeTarget("resourcesmatch-match-text"); | |||
buildRule.executeTarget("resourcesmatch-match-text"); | |||
} | |||
@Test | |||
public void testResourcesmatchNoneExist() { | |||
executeTarget("resourcesmatch-noneexist"); | |||
buildRule.executeTarget("resourcesmatch-noneexist"); | |||
} | |||
} |
@@ -18,55 +18,72 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Tests FileSet using the Copy task. | |||
* | |||
*/ | |||
public class CopyTest extends BuildFileTest { | |||
public class CopyTest { | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
public CopyTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/copy.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/copy.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@Test | |||
public void test1() { | |||
executeTarget("test1"); | |||
File f = new File(getOutputDir(), "copytest1.tmp"); | |||
buildRule.executeTarget("test1"); | |||
File f = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); | |||
if ( !f.exists()) { | |||
fail("Copy failed"); | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
executeTarget("test2"); | |||
File f = new File(getOutputDir(), "copytest1dir/copy.xml"); | |||
buildRule.executeTarget("test2"); | |||
File f = new File(buildRule.getProject().getProperty("output"), "copytest1dir/copy.xml"); | |||
if ( !f.exists()) { | |||
fail("Copy failed"); | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
executeTarget("test3"); | |||
File file3 = new File(getOutputDir(), "copytest3.tmp"); | |||
buildRule.executeTarget("test3"); | |||
File file3 = new File(buildRule.getProject().getProperty("output"), "copytest3.tmp"); | |||
//rollback file timestamp instead of delaying test | |||
FileUtilities.rollbackTimetamps(file3, 3); | |||
buildRule.executeTarget("test3Part2"); | |||
assertTrue(file3.exists()); | |||
File file3a = new File(getOutputDir(), "copytest3a.tmp"); | |||
File file3a = new File(buildRule.getProject().getProperty("output"), "copytest3a.tmp"); | |||
assertTrue(file3a.exists()); | |||
File file3b = new File(getOutputDir(), "copytest3b.tmp"); | |||
File file3b = new File(buildRule.getProject().getProperty("output"), "copytest3b.tmp"); | |||
assertTrue(file3b.exists()); | |||
File file3c = new File(getOutputDir(), "copytest3c.tmp"); | |||
File file3c = new File(buildRule.getProject().getProperty("output"), "copytest3c.tmp"); | |||
assertTrue(file3c.exists()); | |||
//file length checks rely on touch generating a zero byte file | |||
@@ -86,96 +103,120 @@ public class CopyTest extends BuildFileTest { | |||
} | |||
@Test | |||
public void testFilterTest() { | |||
executeTarget("filtertest"); | |||
assertTrue(getOutput().indexOf("loop in tokens") == -1); | |||
buildRule.executeTarget("filtertest"); | |||
assertTrue(buildRule.getLog().indexOf("loop in tokens") == -1); | |||
} | |||
@Test | |||
public void testInfiniteFilter() { | |||
executeTarget("infinitetest"); | |||
assertTrue(getOutput().indexOf("loop in tokens") != -1); | |||
buildRule.executeTarget("infinitetest"); | |||
assertContains("loop in tokens", buildRule.getOutput()); | |||
} | |||
@Test | |||
public void testFilterSet() throws IOException { | |||
executeTarget("testFilterSet"); | |||
File tmp = new File(getOutputDir(), "copy.filterset.tmp"); | |||
File check = new File(getProjectDir(), "expected/copy.filterset.filtered"); | |||
buildRule.executeTarget("testFilterSet"); | |||
File tmp = new File(buildRule.getProject().getProperty("output"), "copy.filterset.tmp"); | |||
File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); | |||
assertTrue(tmp.exists()); | |||
assertTrue(FILE_UTILS.contentEquals(tmp, check)); | |||
assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); | |||
} | |||
@Test | |||
public void testFilterChain() throws IOException { | |||
executeTarget("testFilterChain"); | |||
File tmp = new File(getOutputDir(), "copy.filterchain.tmp"); | |||
File check = new File(getProjectDir(), "expected/copy.filterset.filtered"); | |||
buildRule.executeTarget("testFilterChain"); | |||
File tmp = new File(buildRule.getProject().getProperty("output"), "copy.filterchain.tmp"); | |||
File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); | |||
assertTrue(tmp.exists()); | |||
assertTrue(FILE_UTILS.contentEquals(tmp, check)); | |||
assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); | |||
} | |||
@Test | |||
public void testSingleFileFileset() { | |||
executeTarget("test_single_file_fileset"); | |||
File file = new File(getOutputDir(), | |||
buildRule.executeTarget("test_single_file_fileset"); | |||
File file = new File(buildRule.getProject().getProperty("output"), | |||
"copytest_single_file_fileset.tmp"); | |||
assertTrue(file.exists()); | |||
} | |||
@Test | |||
public void testSingleFilePath() { | |||
executeTarget("test_single_file_path"); | |||
File file = new File(getOutputDir(), | |||
buildRule.executeTarget("test_single_file_path"); | |||
File file = new File(buildRule.getProject().getProperty("output"), | |||
"copytest_single_file_path.tmp"); | |||
assertTrue(file.exists()); | |||
} | |||
@Test | |||
public void testTranscoding() throws IOException { | |||
executeTarget("testTranscoding"); | |||
File f1 = getProject().resolveFile("copy/expected/utf-8"); | |||
File f2 = new File(getOutputDir(), "copytest1.tmp"); | |||
assertTrue(FILE_UTILS.contentEquals(f1, f2)); | |||
buildRule.executeTarget("testTranscoding"); | |||
File f1 = buildRule.getProject().resolveFile("copy/expected/utf-8"); | |||
File f2 = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); | |||
assertEquals(FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); | |||
} | |||
@Test | |||
public void testMissingFileIgnore() { | |||
expectLogContaining("testMissingFileIgnore", | |||
"Warning: Could not find file "); | |||
buildRule.executeTarget("testMissingFileIgnore"); | |||
assertContains("Warning: Could not find file", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testMissingFileBail() { | |||
expectBuildException("testMissingFileBail", "not-there doesn't exist"); | |||
assertTrue(getBuildException().getMessage() | |||
.startsWith("Warning: Could not find file ")); | |||
try { | |||
buildRule.executeTarget("testMissingFileBail"); | |||
fail("not-there doesn't exist"); | |||
} catch (BuildException ex) { | |||
assertTrue(ex.getMessage() | |||
.startsWith("Warning: Could not find file ")); | |||
} | |||
} | |||
@Test | |||
public void testMissingDirIgnore() { | |||
expectLogContaining("testMissingDirIgnore", "Warning: "); | |||
buildRule.executeTarget("testMissingDirIgnore"); | |||
assertContains("Warning: ", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testMissingDirBail() { | |||
expectBuildException("testMissingDirBail", "not-there doesn't exist"); | |||
assertTrue(getBuildException().getMessage().endsWith(" does not exist.")); | |||
try { | |||
buildRule.executeTarget("testMissingDirBail"); | |||
fail("not-there doesn't exist"); | |||
} catch (BuildException ex) { | |||
assertTrue(ex.getMessage().endsWith(" does not exist.")); | |||
} | |||
} | |||
@Test | |||
public void testFileResourcePlain() { | |||
executeTarget("testFileResourcePlain"); | |||
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt"); | |||
buildRule.executeTarget("testFileResourcePlain"); | |||
File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
public void _testFileResourceWithMapper() { | |||
executeTarget("testFileResourceWithMapper"); | |||
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt.bak"); | |||
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt.bak"); | |||
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt.bak"); | |||
@Ignore("Previously ignored by naming convention") | |||
@Test | |||
public void testFileResourceWithMapper() { | |||
buildRule.executeTarget("testFileResourceWithMapper"); | |||
File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt.bak"); | |||
File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt.bak"); | |||
File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt.bak"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
@Test | |||
public void testFileResourceWithFilter() { | |||
executeTarget("testFileResourceWithFilter"); | |||
File file1 = new File(getProject().getProperty("to.dir")+"/fileNR.txt"); | |||
buildRule.executeTarget("testFileResourceWithFilter"); | |||
File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/fileNR.txt"); | |||
assertTrue(file1.exists()); | |||
try { | |||
String file1Content = FileUtils.readFully(new FileReader(file1)); | |||
@@ -185,44 +226,55 @@ public class CopyTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testPathAsResource() { | |||
executeTarget("testPathAsResource"); | |||
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt"); | |||
buildRule.executeTarget("testPathAsResource"); | |||
File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
@Test | |||
public void testZipfileset() { | |||
executeTarget("testZipfileset"); | |||
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt"); | |||
buildRule.executeTarget("testZipfileset"); | |||
File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
@Test | |||
public void testDirset() { | |||
executeTarget("testDirset"); | |||
buildRule.executeTarget("testDirset"); | |||
} | |||
public void _testResourcePlain() { | |||
executeTarget("testResourcePlain"); | |||
@Ignore("Previously ignored due to naming convention") | |||
@Test | |||
public void testResourcePlain() { | |||
buildRule.executeTarget("testResourcePlain"); | |||
} | |||
public void _testResourcePlainWithMapper() { | |||
executeTarget("testResourcePlainWithMapper"); | |||
@Ignore("Previously ignored due to naming convention") | |||
@Test | |||
public void testResourcePlainWithMapper() { | |||
buildRule.executeTarget("testResourcePlainWithMapper"); | |||
} | |||
public void _testResourcePlainWithFilter() { | |||
executeTarget("testResourcePlainWithFilter"); | |||
@Ignore("Previously ignored due to naming convention") | |||
@Test | |||
public void testResourcePlainWithFilter() { | |||
buildRule.executeTarget("testResourcePlainWithFilter"); | |||
} | |||
public void _testOnlineResources() { | |||
executeTarget("testOnlineResources"); | |||
@Ignore("Previously ignored due to naming convention") | |||
@Test | |||
public void testOnlineResources() { | |||
buildRule.executeTarget("testOnlineResources"); | |||
} | |||
} |
@@ -18,48 +18,83 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class CopydirTest extends BuildFileTest { | |||
import java.io.File; | |||
public CopydirTest(String name) { | |||
super(name); | |||
} | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
public class CopydirTest { | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/copydir.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/copydir.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
expectLog("test4", "DEPRECATED - The copydir task is deprecated. Use copy instead.Warning: src == dest"); | |||
buildRule.executeTarget("test4"); | |||
assertEquals("DEPRECATED - The copydir task is deprecated. Use copy instead.Warning: src == dest", | |||
buildRule.getLog()); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
java.io.File f = new java.io.File(getOutputDir(), "taskdefs.tmp"); | |||
buildRule.executeTarget("test5"); | |||
java.io.File f = new java.io.File(new File(buildRule.getProject().getProperty("output")), "taskdefs.tmp"); | |||
if (!f.exists() || !f.isDirectory()) { | |||
fail("Copy failed"); | |||
} | |||
// We keep this, so we have something to delete in later tests :-) | |||
} | |||
@Test | |||
public void test6() { | |||
expectBuildException("test6", "target is file"); | |||
try { | |||
buildRule.executeTarget("test6"); | |||
fail("target is file"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
} |
@@ -18,46 +18,83 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import java.io.File; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class CopyfileTest extends BuildFileTest { | |||
public class CopyfileTest { | |||
public void test6() { | |||
expectBuildException("test6", "target is directory"); | |||
} | |||
public CopyfileTest(String name) { | |||
super(name); | |||
} | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/copyfile.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/copyfile.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
expectLog("test4", "DEPRECATED - The copyfile task is deprecated. Use copy instead.Warning: src == dest"); | |||
buildRule.executeTarget("test4"); | |||
assertEquals("DEPRECATED - The copyfile task is deprecated. Use copy instead.Warning: src == dest", | |||
buildRule.getLog()); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
java.io.File f = new java.io.File(getOutputDir(), "copyfile.tmp"); | |||
if (!f.exists()) { | |||
buildRule.executeTarget("test5"); | |||
File f = new File(new File(buildRule.getProject().getProperty("output")), "copyfile.tmp"); | |||
if (f.exists()) { | |||
f.delete(); | |||
} else { | |||
fail("Copy failed"); | |||
} | |||
} | |||
@Test | |||
public void test6() { | |||
try { | |||
buildRule.executeTarget("test6"); | |||
fail("Required argument not specified"); | |||
} catch (BuildException ex) { | |||
// TODO assert value | |||
} | |||
} | |||
} |
@@ -18,26 +18,35 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
*/ | |||
public class DefaultExcludesTest extends BuildFileTest { | |||
public class DefaultExcludesTest { | |||
public DefaultExcludesTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
project.executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
// Output the default excludes | |||
@Test | |||
public void test1() { | |||
String[] expected = { | |||
"**/*~", | |||
@@ -68,11 +77,12 @@ public class DefaultExcludesTest extends BuildFileTest { | |||
"**/.bzr/**", | |||
"**/.bzrignore", | |||
"**/.DS_Store"}; | |||
project.executeTarget("test1"); | |||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
buildRule.getProject().executeTarget("test1"); | |||
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
} | |||
// adding something to the excludes' | |||
@Test | |||
public void test2() { | |||
String[] expected = { | |||
"**/*~", | |||
@@ -104,11 +114,12 @@ public class DefaultExcludesTest extends BuildFileTest { | |||
"**/.bzrignore", | |||
"**/.DS_Store", | |||
"foo"}; | |||
project.executeTarget("test2"); | |||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
buildRule.executeTarget("test2"); | |||
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
} | |||
// removing something from the defaults | |||
@Test | |||
public void test3() { | |||
String[] expected = { | |||
"**/*~", | |||
@@ -139,10 +150,11 @@ public class DefaultExcludesTest extends BuildFileTest { | |||
"**/.bzr/**", | |||
"**/.bzrignore", | |||
"**/.DS_Store"}; | |||
project.executeTarget("test3"); | |||
assertEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
buildRule.executeTarget("test3"); | |||
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); | |||
} | |||
private void assertEquals(String message, String[] expected, String[] actual) { | |||
private void assertArrayContentsEquals(String message, String[] expected, String[] actual) { | |||
// check that both arrays have the same size | |||
assertEquals(message + " : string array length match", expected.length, actual.length); | |||
for (int counter=0; counter < expected.length; counter++) { | |||
@@ -151,7 +163,7 @@ public class DefaultExcludesTest extends BuildFileTest { | |||
found |= expected[counter].equals(actual[i]); | |||
} | |||
assertTrue(message + " : didn't find element " | |||
+ expected[counter] + " in array match", found); | |||
+ expected[counter] + " in array match", found); | |||
} | |||
} | |||
@@ -18,68 +18,95 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class DeleteTest extends BuildFileTest { | |||
public class DeleteTest { | |||
public DeleteTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/delete.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
} | |||
//where oh where has my test case 3 gone? | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
buildRule.executeTarget("test5"); | |||
} | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
buildRule.executeTarget("test6"); | |||
} | |||
@Test | |||
public void test7() { | |||
executeTarget("test7"); | |||
buildRule.executeTarget("test7"); | |||
} | |||
@Test | |||
public void test8() { | |||
executeTarget("test8"); | |||
buildRule.executeTarget("test8"); | |||
} | |||
@Test | |||
public void test9() { | |||
executeTarget("test9"); | |||
buildRule.executeTarget("test9"); | |||
} | |||
@Test | |||
public void test10() { | |||
executeTarget("test10"); | |||
buildRule.executeTarget("test10"); | |||
} | |||
@Test | |||
public void test11() { | |||
executeTarget("test11"); | |||
buildRule.executeTarget("test11"); | |||
} | |||
@Test | |||
public void test12() { | |||
executeTarget("test12"); | |||
buildRule.executeTarget("test12"); | |||
} | |||
@Test | |||
public void test13() { | |||
executeTarget("test13"); | |||
buildRule.executeTarget("test13"); | |||
} | |||
@Test | |||
public void test14() { | |||
executeTarget("test14"); | |||
buildRule.executeTarget("test14"); | |||
} | |||
@Test | |||
public void test15() { | |||
executeTarget("test15"); | |||
buildRule.executeTarget("test15"); | |||
} | |||
@Test | |||
public void test16() { | |||
executeTarget("test16"); | |||
buildRule.executeTarget("test16"); | |||
} | |||
@Test | |||
public void test17() { | |||
executeTarget("test17"); | |||
buildRule.executeTarget("test17"); | |||
} | |||
} |
@@ -18,27 +18,38 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class DeltreeTest extends BuildFileTest { | |||
import static org.junit.Assert.fail; | |||
public DeltreeTest(String name) { | |||
super(name); | |||
} | |||
public class DeltreeTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/deltree.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
// We try to delete the directory created in CopydirTest | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
} | |||
} |
@@ -18,53 +18,75 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class DirnameTest extends BuildFileTest { | |||
public DirnameTest(String name) { | |||
super(name); | |||
} | |||
public class DirnameTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/dirname.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/dirname.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "property attribute required"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("Build exception should have been thrown as property attribute is required"); | |||
} catch(BuildException ex) { | |||
assertEquals("property attribute required", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "file attribute required"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("Build exception should have been thrown as file attribute is required"); | |||
} catch(BuildException ex) { | |||
assertEquals("file attribute required", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "property attribute required"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("Build exception should have been thrown as property attribute is required"); | |||
} catch(BuildException ex) { | |||
assertEquals("property attribute required", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
if (Os.isFamily("netware") || Os.isFamily("dos")) { | |||
return; | |||
} | |||
executeTarget("test4"); | |||
Assume.assumeFalse("Test not possible on DOS or Netware family OS", Os.isFamily("netware") || Os.isFamily("dos")); | |||
buildRule.executeTarget("test4"); | |||
String filesep = System.getProperty("file.separator"); | |||
String expected = filesep + "usr" + filesep + "local"; | |||
String checkprop = project.getProperty("local.dir"); | |||
if (!checkprop.equals(expected)) { | |||
fail("dirname failed"); | |||
} | |||
String checkprop = buildRule.getProject().getProperty("local.dir"); | |||
assertEquals("dirname failed", expected, checkprop); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
String expected = project.getProperty("basedir"); | |||
String checkprop = project.getProperty("base.dir"); | |||
if (!checkprop.equals(expected)) { | |||
fail("dirname failed"); | |||
} | |||
buildRule.executeTarget("test5"); | |||
String expected = buildRule.getProject().getProperty("basedir"); | |||
String checkprop = buildRule.getProject().getProperty("base.dir"); | |||
assertEquals("dirname failed", expected, checkprop); | |||
} | |||
} |
@@ -18,23 +18,29 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public class DynamicTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
public DynamicTest(String name) { | |||
super(name); | |||
} | |||
public class DynamicTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/dynamictask.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/dynamictask.xml"); | |||
} | |||
@Test | |||
public void testSimple() { | |||
executeTarget("simple"); | |||
assertEquals("1", project.getProperty("prop1")); | |||
assertEquals("2", project.getProperty("prop2")); | |||
assertEquals("3", project.getProperty("prop3")); | |||
assertEquals("4", project.getProperty("prop4")); | |||
buildRule.executeTarget("simple"); | |||
assertEquals("1", buildRule.getProject().getProperty("prop1")); | |||
assertEquals("2", buildRule.getProject().getProperty("prop2")); | |||
assertEquals("3", buildRule.getProject().getProperty("prop3")); | |||
assertEquals("4", buildRule.getProject().getProperty("prop4")); | |||
} | |||
} |
@@ -18,28 +18,29 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.*; | |||
import junit.framework.TestCase; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.IOException; | |||
import java.io.InputStreamReader; | |||
import java.io.PrintStream; | |||
import org.apache.tools.ant.DefaultLogger; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.After; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
* Test Java-dependent parts of the Echo task. | |||
*/ | |||
public class EchoTest extends TestCase { | |||
public class EchoTest { | |||
private File removeThis; | |||
/** | |||
* Create a new EchoTest. | |||
* @param name | |||
*/ | |||
public EchoTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testLogBlankEcho() { | |||
Project p = new Project(); | |||
p.init(); | |||
@@ -52,7 +53,8 @@ public class EchoTest extends TestCase { | |||
assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage ); | |||
} | |||
public void testLogUTF8Echo() { | |||
@Test | |||
public void testLogUTF8Echo() throws IOException { | |||
Project p = new Project(); | |||
p.init(); | |||
EchoTestLogger logger = new EchoTestLogger(); | |||
@@ -65,15 +67,11 @@ public class EchoTest extends TestCase { | |||
echo.setFile(removeThis); | |||
echo.setEncoding("UTF-8"); | |||
echo.execute(); | |||
FileUtils fu = FileUtils.getFileUtils(); | |||
try { | |||
String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8" )); | |||
assertEquals(x,"\u00e4\u00a9"); | |||
} catch (Exception exc) { | |||
} | |||
assertEquals(x,"\u00e4\u00a9"); | |||
} | |||
@After | |||
public void tearDown() { | |||
if (removeThis != null && removeThis.exists()) { | |||
if (!removeThis.delete()) | |||
@@ -18,32 +18,54 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public class EchoXMLTest extends BuildFileTest { | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.fail; | |||
public EchoXMLTest(String name) { | |||
super(name); | |||
} | |||
public class EchoXMLTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/echoxml.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("tearDown"); | |||
buildRule.executeTarget("tearDown"); | |||
} | |||
@Test | |||
public void testPass() { | |||
executeTarget("testPass"); | |||
buildRule.executeTarget("testPass"); | |||
} | |||
@Test | |||
public void testFail() { | |||
expectBuildExceptionContaining("testFail", "must fail", "${foo}=bar"); | |||
try { | |||
buildRule.executeTarget("testFail"); | |||
fail("BuildException expected: must fail"); | |||
} catch (BuildException ex) { | |||
assertContains("${foo}=bar", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testEmpty() { | |||
expectBuildExceptionContaining("testEmpty", "must fail", "No nested XML specified"); | |||
try { | |||
buildRule.executeTarget("testEmpty"); | |||
fail("BuildException expected: must fail"); | |||
} catch (BuildException ex) { | |||
assertContains("No nested XML specified", ex.getMessage()); | |||
} | |||
} | |||
} |
@@ -18,16 +18,31 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import static org.junit.Assert.assertTrue; | |||
import java.io.File; | |||
import java.util.GregorianCalendar; | |||
import org.apache.tools.ant.BuildEvent; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.BuildListener; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.ProjectHelper; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* Unit test for the <exec> task. | |||
*/ | |||
public class ExecTaskTest extends BuildFileTest { | |||
public class ExecTaskTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private static final String BUILD_PATH = "src/etc/testcases/taskdefs/exec/"; | |||
private static final String BUILD_FILE = BUILD_PATH + "exec.xml"; | |||
private static final int TIME_TO_WAIT = 1; | |||
@@ -44,21 +59,19 @@ public class ExecTaskTest extends BuildFileTest { | |||
private MonitoredBuild myBuild = null; | |||
volatile private boolean buildFinished = false; | |||
public ExecTaskTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject(BUILD_FILE); | |||
buildRule.configureProject(BUILD_FILE); | |||
} | |||
public void testspawn() { | |||
project.executeTarget("setUp"); | |||
if (project.getProperty("test.can.run") == null) { | |||
return; | |||
} | |||
@Test | |||
public void testspawn() throws InterruptedException { | |||
buildRule.getProject().executeTarget("setUp"); | |||
Assume.assumeNotNull(buildRule.getProject().getProperty("test.can.run")); | |||
myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn"); | |||
logFile = FILE_UTILS.createTempFile("spawn", "log", getOutputDir(), false, false); | |||
logFile = FILE_UTILS.createTempFile("spawn", "log", new File(buildRule.getProject().getProperty("output")), | |||
false, false); | |||
// this is guaranteed by FileUtils#createTempFile | |||
assertTrue("log file not existing", !logFile.exists()); | |||
// make the spawned process run 4 seconds | |||
@@ -69,11 +82,7 @@ public class ExecTaskTest extends BuildFileTest { | |||
GregorianCalendar startwait = new GregorianCalendar(); | |||
// this loop runs parallel to the build | |||
while (!buildFinished) { | |||
try { | |||
Thread.sleep(10); | |||
} catch (InterruptedException e) { | |||
System.out.println("my sleep was interrupted"); | |||
} | |||
Thread.sleep(10); | |||
GregorianCalendar now = new GregorianCalendar(); | |||
// security | |||
if (now.getTime().getTime() - startwait.getTime().getTime() > MAX_BUILD_TIME) { | |||
@@ -84,11 +93,7 @@ public class ExecTaskTest extends BuildFileTest { | |||
} | |||
} | |||
// now wait until the spawned process is finished | |||
try { | |||
Thread.sleep((TIME_TO_WAIT) * 1000 + SECURITY_MARGIN); | |||
} catch (InterruptedException e) { | |||
System.out.println("my sleep was interrupted"); | |||
} | |||
Thread.sleep((TIME_TO_WAIT) * 1000 + SECURITY_MARGIN); | |||
// time of the build in milli seconds | |||
long elapsed = myBuild.getTimeElapsed(); | |||
assertTrue("we waited more than the process lasted", | |||
@@ -97,29 +102,26 @@ public class ExecTaskTest extends BuildFileTest { | |||
assertTrue("log file found after spawn", logFile.exists()); | |||
} | |||
/* TODO #50507 - fails at least on Linux | |||
@Test | |||
@Ignore("#50507 - fails at least on Linux") | |||
/* TODO #50507 - fails at least on Linux */ | |||
public void testOutAndErr() { | |||
project.executeTarget("test-out-and-err"); | |||
buildRule.getProject().executeTarget("test-out-and-err"); | |||
} | |||
*/ | |||
private static class MonitoredBuild implements Runnable { | |||
private Thread worker; | |||
private File myBuildFile = null; | |||
private String target = null; | |||
private Project project = null; | |||
private int timeToWait = 0; | |||
private String logFile = null; | |||
private GregorianCalendar timeStarted = null; | |||
private GregorianCalendar timeFinished = null; | |||
public void setLogFile(String logFile) { | |||
this.logFile = logFile; | |||
project.setProperty("logFile", logFile); | |||
} | |||
public void setTimeToWait(int timeToWait) { | |||
this.timeToWait = timeToWait; | |||
project.setProperty("timeToWait", Long.toString(timeToWait)); | |||
} | |||
@@ -23,14 +23,17 @@ import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.types.Commandline; | |||
import junit.framework.TestCase; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Simple testcase for the ExecuteJava class - mostly stolen from | |||
* ExecuteWatchdogTest. | |||
* | |||
*/ | |||
public class ExecuteJavaTest extends TestCase { | |||
public class ExecuteJavaTest { | |||
private final static int TIME_OUT = 5000; | |||
@@ -41,13 +44,10 @@ public class ExecuteJavaTest extends TestCase { | |||
private Project project; | |||
private Path cp; | |||
public ExecuteJavaTest(String name) { | |||
super(name); | |||
} | |||
protected void setUp(){ | |||
@Before | |||
public void setUp(){ | |||
ej = new ExecuteJava(); | |||
ej.setTimeout(new Long(TIME_OUT)); | |||
ej.setTimeout((long)TIME_OUT); | |||
project = new Project(); | |||
project.setBasedir("."); | |||
project.setProperty(MagicNames.ANT_HOME, System.getProperty(MagicNames.ANT_HOME)); | |||
@@ -62,6 +62,7 @@ public class ExecuteJavaTest extends TestCase { | |||
return cmd; | |||
} | |||
@Test | |||
public void testNoTimeOut() throws Exception { | |||
Commandline cmd = getCommandline(TIME_OUT/2); | |||
ej.setJavaCommand(cmd); | |||
@@ -70,6 +71,7 @@ public class ExecuteJavaTest extends TestCase { | |||
} | |||
// test that the watchdog ends the process | |||
@Test | |||
public void testTimeOut() throws Exception { | |||
Commandline cmd = getCommandline(TIME_OUT*2); | |||
ej.setJavaCommand(cmd); | |||
@@ -86,7 +88,7 @@ public class ExecuteJavaTest extends TestCase { | |||
elapsed < TIME_OUT*2); | |||
} | |||
@Test | |||
public void testNoTimeOutForked() throws Exception { | |||
Commandline cmd = getCommandline(TIME_OUT/2); | |||
ej.setJavaCommand(cmd); | |||
@@ -95,6 +97,7 @@ public class ExecuteJavaTest extends TestCase { | |||
} | |||
// test that the watchdog ends the process | |||
@Test | |||
public void testTimeOutForked() throws Exception { | |||
Commandline cmd = getCommandline(TIME_OUT*2); | |||
ej.setJavaCommand(cmd); | |||
@@ -18,17 +18,25 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.BufferedReader; | |||
import java.io.InputStreamReader; | |||
import org.apache.tools.ant.util.JavaEnvUtils; | |||
import junit.framework.*; | |||
import java.io.*; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.junit.internal.AssumptionViolatedException; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Simple testcase for the ExecuteWatchdog class. | |||
* | |||
*/ | |||
public class ExecuteWatchdogTest extends TestCase { | |||
public class ExecuteWatchdogTest { | |||
private final static long TIME_OUT = 5000; | |||
private final static long TIME_OUT = 500; | |||
private final static String TEST_CLASSPATH = getTestClassPath(); | |||
@@ -37,17 +45,14 @@ public class ExecuteWatchdogTest extends TestCase { | |||
private ExecuteWatchdog watchdog; | |||
public ExecuteWatchdogTest(String name) { | |||
super(name); | |||
} | |||
protected void setUp(){ | |||
@Before | |||
public void setUp(){ | |||
watchdog = new ExecuteWatchdog(TIME_OUT); | |||
} | |||
/** | |||
* Dangerous method to obtain the classpath for the test. This is | |||
* severely tighted to the build.xml properties. | |||
* severely tied to the build.xml properties. | |||
*/ | |||
private static String getTestClassPath(){ | |||
String classpath = System.getProperty("build.tests"); | |||
@@ -90,6 +95,7 @@ public class ExecuteWatchdogTest extends TestCase { | |||
return retcode; | |||
} | |||
@Test | |||
public void testNoTimeOut() throws Exception { | |||
Process process = getProcess(TIME_OUT/2); | |||
watchdog.start(process); | |||
@@ -99,6 +105,7 @@ public class ExecuteWatchdogTest extends TestCase { | |||
} | |||
// test that the watchdog ends the process | |||
@Test | |||
public void testTimeOut() throws Exception { | |||
Process process = getProcess(TIME_OUT*2); | |||
long now = System.currentTimeMillis(); | |||
@@ -112,6 +119,7 @@ public class ExecuteWatchdogTest extends TestCase { | |||
} | |||
// test a process that runs and failed | |||
@Test | |||
public void testFailed() throws Exception { | |||
Process process = getProcess(-1); // process should abort | |||
watchdog.start(process); | |||
@@ -120,6 +128,7 @@ public class ExecuteWatchdogTest extends TestCase { | |||
assertTrue("return code is invalid: " + retCode, retCode!=0); | |||
} | |||
@Test | |||
public void testManualStop() throws Exception { | |||
final Process process = getProcess(TIME_OUT*2); | |||
watchdog.start(process); | |||
@@ -131,7 +140,7 @@ public class ExecuteWatchdogTest extends TestCase { | |||
process.waitFor(); | |||
} catch(InterruptedException e){ | |||
// not very nice but will do the job | |||
fail("process interrupted in thread"); | |||
throw new AssumptionViolatedException("process interrupted in thread", e); | |||
} | |||
} | |||
}; | |||
@@ -19,57 +19,79 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class FailTest extends BuildFileTest { | |||
public class FailTest { | |||
public FailTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/fail.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/fail.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildExceptionContaining("test1", | |||
"it is required to fail :-)", | |||
"No message"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("No message", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectSpecificBuildException("test2", | |||
"it is required to fail :-)", | |||
"test2"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("test2", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testText() { | |||
expectSpecificBuildException("testText", | |||
"it is required to fail :-)", | |||
"testText"); | |||
try { | |||
buildRule.executeTarget("testText"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("testText", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testIf() { | |||
buildRule.executeTarget("testIf"); | |||
buildRule.getProject().setProperty("foo", ""); | |||
try { | |||
executeTarget("testIf"); | |||
} catch (BuildException be) { | |||
fail("foo has not been defined, testIf must not fail"); | |||
buildRule.executeTarget("testIf"); | |||
fail("testIf must fail if foo has been set") ; | |||
} catch (BuildException ex) { | |||
//TODO assert result | |||
} | |||
project.setProperty("foo", ""); | |||
expectBuildException("testIf", "testIf must fail if foo has been set"); | |||
} | |||
@Test | |||
public void testUnless() { | |||
expectBuildException("testUnless", | |||
"testUnless must fail unless foo has been set"); | |||
project.setProperty("foo", ""); | |||
try { | |||
executeTarget("testUnless"); | |||
} catch (BuildException be) { | |||
fail("foo has been defined, testUnless must not fail"); | |||
buildRule.executeTarget("testUnless"); | |||
fail("testUnless must fail unless foo has been set") ; | |||
} catch (BuildException ex) { | |||
//TODO assert rules | |||
} | |||
buildRule.getProject().setProperty("foo", ""); | |||
buildRule.executeTarget("testUnless"); | |||
} | |||
/** | |||
@@ -77,51 +99,58 @@ public class FailTest extends BuildFileTest { | |||
* that the autogenerated text contains information | |||
* about which condition was not met | |||
*/ | |||
@Test | |||
public void testIfAndUnless() { | |||
//neither | |||
executeTarget("testIfAndUnless"); | |||
project.setProperty("if", ""); | |||
expectBuildExceptionContaining("testIfAndUnless", | |||
"expect fail on defined(if)", | |||
"if=if and unless=unless"); | |||
project.setProperty("unless", ""); | |||
buildRule.executeTarget("testIfAndUnless"); | |||
buildRule.getProject().setProperty("if", ""); | |||
try { | |||
buildRule.executeTarget("testIfAndUnless"); | |||
fail("expect fail on defined(if)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("if=if and unless=unless", ex.getMessage()); | |||
} | |||
buildRule.getProject().setProperty("unless", ""); | |||
//this call should succeed as unless overrides if | |||
executeTarget("testIfAndUnless"); | |||
buildRule.executeTarget("testIfAndUnless"); | |||
} | |||
/** | |||
* see that the different combinations work, and | |||
* that the autogenerated text contains information | |||
* about which condition was not met | |||
*/ | |||
@Test | |||
public void testIfAndUnless2() { | |||
project.setProperty("unless", ""); | |||
try { | |||
executeTarget("testIfAndUnless"); | |||
} catch (BuildException be) { | |||
fail("defined(if) && !defined(unless); testIfAndUnless must not fail"); | |||
} | |||
buildRule.getProject().setProperty("unless", ""); | |||
buildRule.executeTarget("testIfAndUnless"); | |||
} | |||
@Test | |||
public void testNested1() { | |||
expectSpecificBuildException("testNested1", | |||
"it is required to fail :-)", | |||
"condition satisfied"); | |||
try { | |||
buildRule.executeTarget("testNested1"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("condition satisfied", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNested2() { | |||
try { | |||
executeTarget("testNested2"); | |||
} catch (BuildException be) { | |||
fail("condition not satisfied; testNested2 must not fail"); | |||
} | |||
buildRule.executeTarget("testNested2"); | |||
} | |||
@Test | |||
public void testNested3() { | |||
expectSpecificBuildException("testNested3", | |||
"it is required to fail :-)", | |||
"testNested3"); | |||
try { | |||
buildRule.executeTarget("testNested3"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("testNested3", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNested4() { | |||
String specificMessage = "Nested conditions " | |||
+ "not permitted in conjunction with if/unless attributes"; | |||
@@ -131,23 +160,36 @@ public class FailTest extends BuildFileTest { | |||
for (int i = 0; i < c.length; i++) { | |||
target.setCharAt(target.length() - 1, c[i]); | |||
expectSpecificBuildException(target.toString(), | |||
"it is required to fail :-)", specificMessage); | |||
try { | |||
buildRule.executeTarget(target.toString()); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals(specificMessage, ex.getMessage()); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testNested5() { | |||
expectSpecificBuildException("testNested5", | |||
"it is required to fail :-)", | |||
"Only one nested condition is allowed."); | |||
try { | |||
buildRule.executeTarget("testNested5"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("Only one nested condition is allowed.", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNested6() { | |||
expectSpecificBuildException("testNested6", | |||
"it is required to fail :-)", | |||
"testNested6\ntestNested6\ntestNested6"); | |||
try { | |||
buildRule.executeTarget("testNested6"); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals("testNested6\ntestNested6\ntestNested6", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNested7() { | |||
String specificMessage = "A single nested condition is required."; | |||
@@ -156,8 +198,12 @@ public class FailTest extends BuildFileTest { | |||
for (int i = 0; i < c.length; i++) { | |||
target.setCharAt(target.length() - 1, c[i]); | |||
expectSpecificBuildException(target.toString(), | |||
"it is required to fail :-)", specificMessage); | |||
try { | |||
buildRule.executeTarget(target.toString()); | |||
fail("it is required to fail :-)") ; | |||
} catch (BuildException ex) { | |||
assertEquals(specificMessage, ex.getMessage()); | |||
} | |||
} | |||
} | |||
@@ -23,67 +23,100 @@ import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
/** | |||
*/ | |||
public class FilterTest extends BuildFileTest { | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public FilterTest(String name) { | |||
super(name); | |||
} | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
public class FilterTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/filter.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/filter.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
buildRule.executeTarget("test5"); | |||
assertEquals("2000", | |||
getFilteredFile("5", "filtered.tmp")); | |||
} | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
buildRule.executeTarget("test6"); | |||
assertEquals("2000", | |||
getFilteredFile("6", "taskdefs.tmp/filter1.txt")); | |||
} | |||
@Test | |||
public void test7() { | |||
executeTarget("test7"); | |||
buildRule.executeTarget("test7"); | |||
assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | |||
getFilteredFile("7", "filtered.tmp")); | |||
} | |||
@Test | |||
public void test8() { | |||
executeTarget("test8"); | |||
buildRule.executeTarget("test8"); | |||
assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | |||
getFilteredFile("8", "taskdefs.tmp/filter2.txt")); | |||
} | |||
@Test | |||
public void test9() { | |||
executeTarget("test9"); | |||
buildRule.executeTarget("test9"); | |||
assertEquals("included", | |||
getFilteredFile("9", "taskdefs.tmp/filter3.txt")); | |||
} | |||
@@ -91,7 +124,7 @@ public class FilterTest extends BuildFileTest { | |||
private String getFilteredFile(String testNumber, String filteredFile) { | |||
String line = null; | |||
File f = new File(getProjectDir(), filteredFile); | |||
File f = new File(buildRule.getProject().getBaseDir(), filteredFile); | |||
if (!f.exists()) { | |||
fail("filter test"+testNumber+" failed"); | |||
} else { | |||
@@ -26,103 +26,136 @@ import java.io.InputStream; | |||
import junit.framework.AssertionFailedError; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.AntAssert; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class FixCrLfTest extends BuildFileTest { | |||
public class FixCrLfTest { | |||
public FixCrLfTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml"); | |||
} | |||
@Test | |||
public void test1() throws IOException { | |||
executeTarget("test1"); | |||
buildRule.executeTarget("test1"); | |||
} | |||
@Test | |||
public void test2() throws IOException { | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
} | |||
@Test | |||
public void test3() throws IOException { | |||
executeTarget("test3"); | |||
buildRule.executeTarget("test3"); | |||
} | |||
@Test | |||
public void test4() throws IOException { | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
} | |||
@Test | |||
public void test5() throws IOException { | |||
executeTarget("test5"); | |||
buildRule.executeTarget("test5"); | |||
} | |||
@Test | |||
public void test6() throws IOException { | |||
executeTarget("test6"); | |||
buildRule.executeTarget("test6"); | |||
} | |||
@Test | |||
public void test7() throws IOException { | |||
executeTarget("test7"); | |||
buildRule.executeTarget("test7"); | |||
} | |||
@Test | |||
public void test8() throws IOException { | |||
executeTarget("test8"); | |||
buildRule.executeTarget("test8"); | |||
} | |||
@Test | |||
public void test9() throws IOException { | |||
executeTarget("test9"); | |||
buildRule.executeTarget("test9"); | |||
} | |||
@Test | |||
public void testMacLines() throws IOException { | |||
executeTarget("testMacLines"); | |||
buildRule.executeTarget("testMacLines"); | |||
} | |||
@Test | |||
public void testNoOverwrite() throws IOException { | |||
executeTarget("testNoOverwrite"); | |||
buildRule.executeTarget("testNoOverwrite"); | |||
} | |||
@Test | |||
public void testEncoding() throws IOException { | |||
executeTarget("testEncoding"); | |||
buildRule.executeTarget("testEncoding"); | |||
} | |||
@Test | |||
public void testOutputEncoding() throws IOException { | |||
executeTarget("testOutputEncoding"); | |||
buildRule.executeTarget("testOutputEncoding"); | |||
} | |||
@Test | |||
public void testLongLines() throws IOException { | |||
executeTarget("testLongLines"); | |||
buildRule.executeTarget("testLongLines"); | |||
} | |||
@Test | |||
public void testCrCrLfSequenceUnix() throws IOException { | |||
executeTarget("testCrCrLfSequence-unix"); | |||
buildRule.executeTarget("testCrCrLfSequence-unix"); | |||
} | |||
@Test | |||
public void testCrCrLfSequenceDos() throws IOException { | |||
executeTarget("testCrCrLfSequence-dos"); | |||
buildRule.executeTarget("testCrCrLfSequence-dos"); | |||
} | |||
@Test | |||
public void testCrCrLfSequenceMac() throws IOException { | |||
executeTarget("testCrCrLfSequence-mac"); | |||
buildRule.executeTarget("testCrCrLfSequence-mac"); | |||
} | |||
@Test | |||
public void testFixlastDos() throws IOException { | |||
executeTarget("testFixlastDos"); | |||
buildRule.executeTarget("testFixlastDos"); | |||
} | |||
@Test | |||
public void testFixlastFalseMac() throws IOException { | |||
executeTarget("testFixlastFalseMac"); | |||
buildRule.executeTarget("testFixlastFalseMac"); | |||
} | |||
@Test | |||
public void testFixFile() throws Exception { | |||
executeTarget("testFixFile"); | |||
buildRule.executeTarget("testFixFile"); | |||
} | |||
@Test | |||
public void testFixFileExclusive() throws Exception { | |||
expectBuildExceptionContaining("testFixFileExclusive", | |||
FixCRLF.ERROR_FILE_AND_SRCDIR, FixCRLF.ERROR_FILE_AND_SRCDIR); | |||
try { | |||
buildRule.executeTarget("testFixFileExclusive"); | |||
fail(FixCRLF.ERROR_FILE_AND_SRCDIR); | |||
} catch (BuildException ex) { | |||
AntAssert.assertContains(FixCRLF.ERROR_FILE_AND_SRCDIR, ex.getMessage()); | |||
} | |||
} | |||
/** | |||
@@ -131,59 +164,73 @@ public class FixCrLfTest extends BuildFileTest { | |||
* Will fail with an exception if the parent directories do not | |||
* get created. | |||
*/ | |||
@Test | |||
public void testCreateParentDirs() { | |||
executeTarget("createParentDirs"); | |||
buildRule.executeTarget("createParentDirs"); | |||
} | |||
@Test | |||
public void testPreserveLastModified() { | |||
executeTarget("testPreserveLastModified"); | |||
buildRule.executeTarget("testPreserveLastModified"); | |||
} | |||
@Test | |||
public void testFilter1() { | |||
executeTarget("testFilter1"); | |||
buildRule.executeTarget("testFilter1"); | |||
} | |||
@Test | |||
public void testFilter2() { | |||
executeTarget("testFilter2"); | |||
buildRule.executeTarget("testFilter2"); | |||
} | |||
@Test | |||
public void testFilter3() { | |||
executeTarget("testFilter3"); | |||
buildRule.executeTarget("testFilter3"); | |||
} | |||
@Test | |||
public void testFilter4() { | |||
executeTarget("testFilter4"); | |||
buildRule.executeTarget("testFilter4"); | |||
} | |||
@Test | |||
public void testFilter5() { | |||
executeTarget("testFilter5"); | |||
buildRule.executeTarget("testFilter5"); | |||
} | |||
@Test | |||
public void testFilter6() { | |||
executeTarget("testFilter6"); | |||
buildRule.executeTarget("testFilter6"); | |||
} | |||
@Test | |||
public void testFilter7() { | |||
executeTarget("testFilter7"); | |||
buildRule.executeTarget("testFilter7"); | |||
} | |||
@Test | |||
public void testFilter8() { | |||
executeTarget("testFilter8"); | |||
buildRule.executeTarget("testFilter8"); | |||
} | |||
@Test | |||
public void testFilter9() { | |||
executeTarget("testFilter9"); | |||
buildRule.executeTarget("testFilter9"); | |||
} | |||
@Test | |||
public void testCannotDoubleEof() { | |||
executeTarget("testCannotDoubleEof"); | |||
buildRule.executeTarget("testCannotDoubleEof"); | |||
} | |||
@Test | |||
public void testTabInLiteralInComment() { | |||
executeTarget("testTabInLiteralInComment"); | |||
buildRule.executeTarget("testTabInLiteralInComment"); | |||
} | |||
// not used, but public so theoretically must remain for BC? | |||
@Deprecated | |||
public void assertEqualContent(File expect, File result) | |||
throws AssertionFailedError, IOException { | |||
if (!result.exists()) { | |||
@@ -17,54 +17,74 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class GUnzipTest extends BuildFileTest { | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public class GUnzipTest { | |||
public GUnzipTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/gunzip.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/gunzip.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "attribute src invalid"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("attribute src invalid"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testRealTest() throws java.io.IOException { | |||
testRealTest("realTest"); | |||
} | |||
@Test | |||
public void testRealTestWithResource() throws java.io.IOException { | |||
testRealTest("realTestWithResource"); | |||
} | |||
private void testRealTest(String target) throws java.io.IOException { | |||
executeTarget(target); | |||
assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"), | |||
project.resolveFile("asf-logo.gif"))); | |||
buildRule.executeTarget(target); | |||
assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), | |||
FileUtilities.getFileContents(buildRule.getProject().resolveFile("asf-logo.gif"))); | |||
} | |||
@Test | |||
public void testTestGzipTask() throws java.io.IOException { | |||
testRealTest("testGzipTask"); | |||
} | |||
@Test | |||
public void testDocumentationClaimsOnCopy() throws java.io.IOException { | |||
testRealTest("testDocumentationClaimsOnCopy"); | |||
} | |||
@@ -18,58 +18,105 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class GetTest extends BuildFileTest { | |||
public class GetTest { | |||
public GetTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/get.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/get.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
expectBuildException("test4", "src invalid"); | |||
try { | |||
buildRule.executeTarget("test4"); | |||
fail("src invalid"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test5() { | |||
expectBuildException("test5", "dest invalid (or no http-server on local machine)"); | |||
try { | |||
buildRule.executeTarget("test5"); | |||
fail("dest invalid (or no http-server on local machine"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
buildRule.executeTarget("test6"); | |||
} | |||
@Test | |||
public void test7() { | |||
expectBuildException("test7", "userAgent may not be null or empty"); | |||
try { | |||
buildRule.executeTarget("test7"); | |||
fail("userAgent may not be null or empty"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testUseTimestamp() { | |||
executeTarget("testUseTimestamp"); | |||
buildRule.executeTarget("testUseTimestamp"); | |||
} | |||
@Test | |||
public void testUseTomorrow() { | |||
executeTarget("testUseTomorrow"); | |||
buildRule.executeTarget("testUseTomorrow"); | |||
} | |||
} |
@@ -18,59 +18,96 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class GzipTest extends BuildFileTest { | |||
public class GzipTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
public GzipTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/gzip.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/gzip.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("BuildException expected: required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("BuildException expected: required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("BuildException expected: required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test4() { | |||
expectBuildException("test4", "zipfile must not point to a directory"); | |||
try { | |||
buildRule.executeTarget("test4"); | |||
fail("BuildException expected: zipfile must not point to a directory"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testGZip(){ | |||
executeTarget("realTest"); | |||
String log = getLog(); | |||
buildRule.executeTarget("realTest"); | |||
String log = buildRule.getLog(); | |||
assertTrue("Expecting message starting with 'Building:' but got '" | |||
+ log + "'", log.startsWith("Building:")); | |||
assertTrue("Expecting message ending with 'asf-logo.gif.gz' but got '" | |||
+ log + "'", log.endsWith("asf-logo.gif.gz")); | |||
} | |||
@Test | |||
public void testResource(){ | |||
executeTarget("realTestWithResource"); | |||
buildRule.executeTarget("realTestWithResource"); | |||
} | |||
@Test | |||
public void testDateCheck(){ | |||
executeTarget("testDateCheck"); | |||
String log = getLog(); | |||
buildRule.executeTarget("testDateCheck"); | |||
String log = buildRule.getLog(); | |||
assertTrue( | |||
"Expecting message ending with 'asf-logo.gif.gz is up to date.' but got '" + log + "'", | |||
log.endsWith("asf-logo.gif.gz is up to date.")); | |||
} | |||
@After | |||
public void tearDown(){ | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
} |
@@ -18,141 +18,141 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.Location; | |||
import org.apache.tools.ant.Project; | |||
import org.junit.Assume; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class ImportTest extends BuildFileTest { | |||
public ImportTest(String name) { | |||
super(name); | |||
} | |||
public void setUp() { | |||
} | |||
public void tearDown() { | |||
} | |||
public class ImportTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Test | |||
public void testSimpleImport() { | |||
configureProject("src/etc/testcases/taskdefs/import/import.xml"); | |||
assertLogContaining("Before importIn imported topAfter import"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/import.xml"); | |||
assertContains("Before importIn imported topAfter import", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testUnnamedNesting() { | |||
configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", | |||
Project.MSG_WARN); | |||
String log = getLog(); | |||
String log = buildRule.getLog(); | |||
assertTrue("Warnings logged when not expected: " + log, | |||
log.length() == 0); | |||
} | |||
@Test | |||
public void testSerial() { | |||
configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); | |||
assertLogContaining("Unnamed2.xmlUnnamed1.xml"); | |||
String fullLog = getFullLog(); | |||
String substring = "Skipped already imported file"; | |||
assertTrue("expecting full log to contain \"" + substring | |||
+ "\" full log was \"" + fullLog + "\"", | |||
fullLog.indexOf(substring) >= 0); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); | |||
assertContains("Unnamed2.xmlUnnamed1.xml", buildRule.getLog()); | |||
assertContains("Expected string was not found in log", | |||
"Skipped already imported file", buildRule.getFullLog()); | |||
} | |||
// allow this as imported in targets are only tested when a target is run | |||
public void testImportInTargetNoEffect() { | |||
configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | |||
expectPropertyUnset("no-import", "foo"); | |||
assertTrue(null == getProject().getReference("baz")); | |||
@Test | |||
public void testImportInTargetNoEffect() { | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | |||
buildRule.executeTarget("no-import"); | |||
assertNull(buildRule.getProject().getProperty("foo")); | |||
assertNull(buildRule.getProject().getReference("baz")); | |||
} | |||
// deactivate this test as imports within targets are not allowed | |||
@Ignore("deactivate this test as imports within targets are not allowed") | |||
@Test | |||
public void notTestImportInTargetWithEffect() { | |||
configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | |||
expectPropertySet("do-import", "foo", "bar"); | |||
assertNotNull(getProject().getReference("baz")); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | |||
buildRule.executeTarget("do-import"); | |||
assertEquals(buildRule.getProject().getProperty("foo"), "bar"); | |||
assertNotNull(buildRule.getProject().getReference("baz")); | |||
} | |||
@Test | |||
public void testImportInTargetNotAllowed() { | |||
configureProject( | |||
buildRule.configureProject( | |||
"src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | |||
expectBuildExceptionContaining( | |||
"do-import", "not a top level task", | |||
"import only allowed as a top-level task"); | |||
try { | |||
buildRule.executeTarget("do-import"); | |||
fail("Build exception should have been thrown as import only allowed in top level task"); | |||
} catch(BuildException ex) { | |||
assertContains( "not a top level task", "import only allowed as a top-level task", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testImportInSequential() { | |||
configureProject( | |||
buildRule.configureProject( | |||
"src/etc/testcases/taskdefs/import/subdir/importinsequential.xml"); | |||
expectPropertySet("within-imported", "foo", "bar"); | |||
assertNotNull(getProject().getReference("baz")); | |||
buildRule.executeTarget("within-imported"); | |||
assertEquals(buildRule.getProject().getProperty("foo"), "bar"); | |||
assertNotNull(buildRule.getProject().getReference("baz")); | |||
} | |||
@Test | |||
public void testImportSameTargets() { | |||
try { | |||
configureProject( | |||
buildRule.configureProject( | |||
"src/etc/testcases/taskdefs/import/same_target.xml"); | |||
fail("Expected build exception"); | |||
} catch (BuildException ex) { | |||
String message = ex.getMessage(); | |||
if (message.indexOf("Duplicate target") == -1) { | |||
assertTrue("Did not see 'Duplicate target' in '" + message +"'", false); | |||
} | |||
return; | |||
assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); | |||
} | |||
assertTrue( | |||
"Did not see build exception", | |||
false); | |||
} | |||
@Test | |||
public void testImportError() { | |||
try { | |||
configureProject( | |||
buildRule.configureProject( | |||
"src/etc/testcases/taskdefs/import/import_bad_import.xml"); | |||
fail("Build exception should have been thrown"); | |||
} catch (BuildException ex) { | |||
Location lo = ex.getLocation(); | |||
assertTrue( | |||
"expected location of build exception to be set", | |||
(lo != null)); | |||
assertTrue( | |||
"expected location to contain calling file", | |||
lo.getFileName().indexOf("import_bad_import.xml") != -1); | |||
assertTrue( | |||
"expected message of ex to contain called file", | |||
ex.getMessage().indexOf("bad.xml") != -1); | |||
return; | |||
assertNotNull( | |||
"expected location of build exception to be set", lo); | |||
assertContains( | |||
"expected location to contain calling file", "import_bad_import.xml", lo.getFileName()); | |||
assertContains( | |||
"expected message of ex to contain called file", "bad.xml", ex.getMessage()); | |||
} | |||
assertTrue( | |||
"Did not see build exception", | |||
false); | |||
} | |||
@Test | |||
public void testSymlinkedImports() throws Exception { | |||
String ln = "/usr/bin/ln"; | |||
if (!new File(ln).exists()) { | |||
ln = "/bin/ln"; | |||
} | |||
if (!new File(ln).exists()) { | |||
// Running on Windows or something, so skip it. | |||
return; | |||
} | |||
Assume.assumeTrue("Current system does not support Symlinks", new File(ln).exists()); | |||
String symlink = "src/etc/testcases/taskdefs/import/symlinks/d3b"; | |||
File symlinkFile = new File(System.getProperty("root"), symlink); | |||
if (Runtime.getRuntime().exec(new String[] {ln, "-s", "d3a", symlinkFile.getAbsolutePath()}).waitFor() != 0) { | |||
throw new IOException("'" + ln + " -s d3a " + symlink + "' failed"); | |||
} | |||
try { | |||
configureProject( | |||
buildRule.configureProject( | |||
"src/etc/testcases/taskdefs/import/symlinks/d1/p1.xml"); | |||
assertPropertyEquals( | |||
"ant.file.p2", | |||
assertEquals( | |||
buildRule.getProject().getProperty("ant.file.p2"), | |||
new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d2/p2.xml") | |||
.getAbsolutePath()); | |||
assertPropertyEquals( | |||
"ant.file.p3", | |||
assertEquals( | |||
buildRule.getProject().getProperty("ant.file.p3"), | |||
new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d3b/p3.xml") | |||
.getAbsolutePath()); | |||
} finally { | |||
@@ -160,13 +160,15 @@ public class ImportTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testTargetFirst() { | |||
configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); | |||
assertLogContaining("Importing targetfirstAfter target firstAfter importing"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); | |||
assertContains("Importing targetfirstAfter target firstAfter importing", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testTargetName() { | |||
configureProject("src/etc/testcases/taskdefs/import/c.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/import/c.xml"); | |||
} | |||
} |
@@ -22,41 +22,54 @@ import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.PrintStream; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
/** | |||
* Test to see if static initializers are invoked the same way | |||
* when <java> is invoked in forked and unforked modes. | |||
* | |||
*/ | |||
public class InitializeClassTest extends BuildFileTest { | |||
public class InitializeClassTest { | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
private File f1 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/forkedout"); | |||
private File f2 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/unforkedout"); | |||
public InitializeClassTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/initializeclass.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/initializeclass.xml"); | |||
} | |||
@Test | |||
public void testAll() throws IOException { | |||
executeTarget("forked"); | |||
PrintStream ps = System.out; | |||
PrintStream newps = new PrintStream(new FileOutputStream(f2)); | |||
System.setOut(newps); | |||
project.executeTarget("unforked"); | |||
System.setOut(ps); | |||
newps.close(); | |||
assertTrue("Forked - non-forked mismatch", FILE_UTILS.contentEquals(f1, f2)); | |||
buildRule.executeTarget("forked"); | |||
synchronized (System.out) { | |||
PrintStream ps = System.out; | |||
PrintStream newps = new PrintStream(new FileOutputStream(f2)); | |||
try { | |||
System.setOut(newps); | |||
buildRule.getProject().executeTarget("unforked"); | |||
} finally { | |||
System.setOut(ps); | |||
newps.close(); | |||
} | |||
} | |||
assertEquals(FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); | |||
} | |||
@After | |||
public void tearDown() { | |||
f1.delete(); | |||
f2.delete(); | |||
@@ -19,88 +19,108 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.FileInputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.input.PropertyFileInputHandler; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
public class InputTest extends BuildFileTest { | |||
public InputTest(String name) { | |||
super(name); | |||
} | |||
public class InputTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
private InputStream originalStdIn; | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/input.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/input.xml"); | |||
System.getProperties() | |||
.put(PropertyFileInputHandler.FILE_NAME_KEY, | |||
getProject().resolveFile("input.properties") | |||
buildRule.getProject().resolveFile("input.properties") | |||
.getAbsolutePath()); | |||
getProject().setInputHandler(new PropertyFileInputHandler()); | |||
buildRule.getProject().setInputHandler(new PropertyFileInputHandler()); | |||
originalStdIn = System.in; | |||
} | |||
@After | |||
public void tearDown() { | |||
System.setIn(originalStdIn); | |||
} | |||
@Test | |||
public void test1() { | |||
executeTarget("test1"); | |||
buildRule.executeTarget("test1"); | |||
} | |||
@Test | |||
public void test2() { | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
} | |||
@Test | |||
public void test3() { | |||
expectSpecificBuildException("test3", "invalid input", | |||
"Found invalid input test for \'" | |||
+ getKey("All data is" | |||
+ " going to be deleted from DB" | |||
+ " continue?") | |||
+ "\'"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("BuildException expected: invalid input"); | |||
} catch (BuildException ex) { | |||
assertEquals("Found invalid input test for 'All data is going to be deleted from DB continue?'", | |||
ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
buildRule.executeTarget("test5"); | |||
} | |||
@Test | |||
public void test6() { | |||
executeTarget("test6"); | |||
assertEquals("scott", project.getProperty("db.user")); | |||
buildRule.executeTarget("test6"); | |||
assertEquals("scott", buildRule.getProject().getProperty("db.user")); | |||
} | |||
@Test | |||
public void testPropertyFileInlineHandler() { | |||
executeTarget("testPropertyFileInlineHandler"); | |||
buildRule.executeTarget("testPropertyFileInlineHandler"); | |||
} | |||
public void testDefaultInlineHandler() { | |||
@Test | |||
public void testDefaultInlineHandler() throws IOException { | |||
stdin(); | |||
executeTarget("testDefaultInlineHandler"); | |||
buildRule.executeTarget("testDefaultInlineHandler"); | |||
} | |||
public void testGreedyInlineHandler() { | |||
@Test | |||
public void testGreedyInlineHandler() throws IOException { | |||
stdin(); | |||
executeTarget("testGreedyInlineHandler"); | |||
buildRule.executeTarget("testGreedyInlineHandler"); | |||
} | |||
public void testGreedyInlineHandlerClassname() { | |||
@Test | |||
public void testGreedyInlineHandlerClassname() throws IOException { | |||
stdin(); | |||
executeTarget("testGreedyInlineHandlerClassname"); | |||
buildRule.executeTarget("testGreedyInlineHandlerClassname"); | |||
} | |||
public void testGreedyInlineHandlerRefid() { | |||
@Test | |||
public void testGreedyInlineHandlerRefid() throws IOException { | |||
stdin(); | |||
executeTarget("testGreedyInlineHandlerRefid"); | |||
} | |||
private void stdin() { | |||
try { | |||
System.setIn(new FileInputStream( | |||
getProject().resolveFile("input.stdin"))); | |||
} catch (Exception e) { | |||
throw e instanceof RuntimeException | |||
? (RuntimeException) e : new RuntimeException(e.getMessage()); | |||
} | |||
buildRule.executeTarget("testGreedyInlineHandlerRefid"); | |||
} | |||
private String getKey(String key) { | |||
return key; // TODO what is this for? | |||
private void stdin() throws IOException { | |||
System.setIn(new FileInputStream(buildRule.getProject().resolveFile("input.stdin"))); | |||
} | |||
} |
@@ -28,29 +28,42 @@ import java.io.Reader; | |||
import java.util.Enumeration; | |||
import java.util.zip.ZipEntry; | |||
import java.util.zip.ZipFile; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.After; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class JarTest extends BuildFileTest { | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public class JarTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
private static String tempJar = "tmp.jar"; | |||
private static String tempDir = "jartmp/"; | |||
private Reader r1, r2; | |||
public JarTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/jar.xml"); | |||
executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@After | |||
public void tearDown() { | |||
if (r1 != null) { | |||
try { | |||
@@ -64,152 +77,192 @@ public class JarTest extends BuildFileTest { | |||
} catch (IOException e) { | |||
} | |||
} | |||
try { | |||
super.tearDown(); | |||
} catch (Exception exc) { | |||
} | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument not specified"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("BuildException expected: required argument not specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "manifest file does not exist"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("BuildException expected: manifest file does not exist"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
expectBuildException("test3", "Unrecognized whenempty attribute: format C: /y"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("BuildException expected: Unrecognized whenempty attribute: format C: /y"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
private File getOutputDir() { | |||
return new File(buildRule.getProject().getProperty("output")); | |||
} | |||
@Test | |||
public void test4() { | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
File jarFile = new File(getOutputDir(), tempJar); | |||
assertTrue(jarFile.exists()); | |||
} | |||
@Test | |||
public void testNoRecreateWithoutUpdate() { | |||
testNoRecreate("test4"); | |||
} | |||
@Test | |||
public void testNoRecreateWithUpdate() { | |||
testNoRecreate("testNoRecreateWithUpdate"); | |||
} | |||
private void testNoRecreate(String secondTarget) { | |||
executeTarget("test4"); | |||
buildRule.executeTarget("test4"); | |||
File jarFile = new File(getOutputDir(), tempJar); | |||
// move the modified date back a couple of seconds rather than delay the test on each run | |||
Assume.assumeTrue(jarFile.setLastModified(jarFile.lastModified() | |||
- (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); | |||
long jarModifiedDate = jarFile.lastModified(); | |||
try { | |||
Thread.sleep(2500); | |||
} catch (InterruptedException e) { | |||
} // end of try-catch | |||
executeTarget(secondTarget); | |||
buildRule.executeTarget(secondTarget); | |||
assertEquals("jar has not been recreated in " + secondTarget, | |||
jarModifiedDate, jarFile.lastModified()); | |||
} | |||
@Test | |||
public void testRecreateWithoutUpdateAdditionalFiles() { | |||
testRecreate("test4", "testRecreateWithoutUpdateAdditionalFiles"); | |||
} | |||
@Test | |||
public void testRecreateWithUpdateAdditionalFiles() { | |||
testRecreate("test4", "testRecreateWithUpdateAdditionalFiles"); | |||
} | |||
@Test | |||
public void testRecreateWithoutUpdateNewerFile() { | |||
testRecreate("testRecreateNewerFileSetup", | |||
"testRecreateWithoutUpdateNewerFile"); | |||
} | |||
@Test | |||
public void testRecreateWithUpdateNewerFile() { | |||
testRecreate("testRecreateNewerFileSetup", | |||
"testRecreateWithUpdateNewerFile"); | |||
} | |||
private void testRecreate(String firstTarget, String secondTarget) { | |||
executeTarget(firstTarget); | |||
long sleeptime = 3000 | |||
+ FILE_UTILS.getFileTimestampGranularity(); | |||
try { | |||
Thread.sleep(sleeptime); | |||
} catch (InterruptedException e) { | |||
} // end of try-catch | |||
//Move the modified date on all input back a couple of seconds rather then delay the test to achieve a similar effect | |||
FileUtilities.rollbackTimetamps(buildRule.getProject().getBaseDir(), 5); | |||
buildRule.executeTarget(firstTarget); | |||
File jarFile = new File(getOutputDir(), tempJar); | |||
//Move the modified date back a couple of seconds rather then delay the test to achieve a similar effect | |||
FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); | |||
long jarModifiedDate = jarFile.lastModified(); | |||
executeTarget(secondTarget); | |||
buildRule.executeTarget(secondTarget); | |||
jarFile = new File(getOutputDir(), tempJar); | |||
assertTrue("jar has been recreated in " + secondTarget, | |||
jarModifiedDate < jarFile.lastModified()); | |||
} | |||
@Test | |||
public void testManifestStaysIntact() | |||
throws IOException, ManifestException { | |||
executeTarget("testManifestStaysIntact"); | |||
buildRule.executeTarget("testManifestStaysIntact"); | |||
r1 = new FileReader(new File(getOutputDir(), | |||
tempDir + "manifest")); | |||
r2 = new FileReader(new File(getOutputDir(), | |||
tempDir + "META-INF/MANIFEST.MF")); | |||
Manifest mf1 = new Manifest(r1); | |||
Manifest mf2 = new Manifest(r2); | |||
assertEquals(mf1, mf2); | |||
} | |||
@Test | |||
public void testNoRecreateBasedirExcludesWithUpdate() { | |||
testNoRecreate("testNoRecreateBasedirExcludesWithUpdate"); | |||
} | |||
@Test | |||
public void testNoRecreateBasedirExcludesWithoutUpdate() { | |||
testNoRecreate("testNoRecreateBasedirExcludesWithoutUpdate"); | |||
} | |||
@Test | |||
public void testNoRecreateZipfilesetExcludesWithUpdate() { | |||
testNoRecreate("testNoRecreateZipfilesetExcludesWithUpdate"); | |||
} | |||
@Test | |||
public void testNoRecreateZipfilesetExcludesWithoutUpdate() { | |||
testNoRecreate("testNoRecreateZipfilesetExcludesWithoutUpdate"); | |||
} | |||
@Test | |||
public void testRecreateZipfilesetWithoutUpdateAdditionalFiles() { | |||
testRecreate("test4", | |||
"testRecreateZipfilesetWithoutUpdateAdditionalFiles"); | |||
} | |||
@Test | |||
public void testRecreateZipfilesetWithUpdateAdditionalFiles() { | |||
testRecreate("test4", | |||
"testRecreateZipfilesetWithUpdateAdditionalFiles"); | |||
} | |||
@Test | |||
public void testRecreateZipfilesetWithoutUpdateNewerFile() { | |||
testRecreate("testRecreateNewerFileSetup", | |||
"testRecreateZipfilesetWithoutUpdateNewerFile"); | |||
} | |||
@Test | |||
public void testRecreateZipfilesetWithUpdateNewerFile() { | |||
testRecreate("testRecreateNewerFileSetup", | |||
"testRecreateZipfilesetWithUpdateNewerFile"); | |||
} | |||
@Test | |||
public void testCreateWithEmptyFileset() { | |||
executeTarget("testCreateWithEmptyFilesetSetUp"); | |||
executeTarget("testCreateWithEmptyFileset"); | |||
executeTarget("testCreateWithEmptyFileset"); | |||
buildRule.executeTarget("testCreateWithEmptyFilesetSetUp"); | |||
buildRule.executeTarget("testCreateWithEmptyFileset"); | |||
buildRule.executeTarget("testCreateWithEmptyFileset"); | |||
} | |||
@Test | |||
public void testUpdateIfOnlyManifestHasChanged() { | |||
executeTarget("testUpdateIfOnlyManifestHasChanged"); | |||
buildRule.executeTarget("testUpdateIfOnlyManifestHasChanged"); | |||
File jarXml = new File(getOutputDir(), tempDir + "jar.xml"); | |||
assertTrue(jarXml.exists()); | |||
} | |||
// bugzilla report 10262 | |||
@Test | |||
public void testNoDuplicateIndex() throws IOException { | |||
ZipFile archive = null; | |||
try { | |||
executeTarget("testIndexTests"); | |||
buildRule.executeTarget("testIndexTests"); | |||
archive = new ZipFile(new File(getOutputDir(), tempJar)); | |||
Enumeration e = archive.entries(); | |||
int numberOfIndexLists = 0; | |||
@@ -228,10 +281,11 @@ public class JarTest extends BuildFileTest { | |||
} | |||
// bugzilla report 16972 | |||
@Test | |||
public void testRootFilesInIndex() throws IOException { | |||
ZipFile archive = null; | |||
try { | |||
executeTarget("testIndexTests"); | |||
buildRule.executeTarget("testIndexTests"); | |||
archive = new ZipFile(new File(getOutputDir(), tempJar)); | |||
ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST"); | |||
InputStream is = archive.getInputStream(ze); | |||
@@ -262,46 +316,60 @@ public class JarTest extends BuildFileTest { | |||
} | |||
} | |||
} | |||
@Test | |||
public void testManifestOnlyJar() { | |||
expectLogContaining("testManifestOnlyJar", "Building MANIFEST-only jar: "); | |||
buildRule.executeTarget("testManifestOnlyJar"); | |||
assertContains("Building MANIFEST-only jar: ", buildRule.getLog()); | |||
File manifestFile = new File(getOutputDir(), tempDir + "META-INF" + File.separator + "MANIFEST.MF"); | |||
assertTrue(manifestFile.exists()); | |||
} | |||
@Test | |||
public void testIndexJarsPlusJarMarker() { | |||
executeTarget("testIndexJarsPlusJarMarker"); | |||
buildRule.executeTarget("testIndexJarsPlusJarMarker"); | |||
} | |||
@Test | |||
public void testNoVersionInfoFail() { | |||
expectBuildExceptionContaining("testNoVersionInfoFail", "Manifest Implemention information missing.", "No Implementation-Title set."); | |||
try { | |||
buildRule.executeTarget("testNoVersionInfoFail"); | |||
fail("BuildException expected: Manifest Implemention information missing."); | |||
} catch (BuildException ex) { | |||
assertContains("No Implementation-Title set.", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNoVersionInfoIgnore() { | |||
executeTarget("testNoVersionInfoIgnore"); | |||
assertTrue( getFullLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertTrue( getFullLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertTrue( getFullLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
buildRule.executeTarget("testNoVersionInfoIgnore"); | |||
assertTrue(buildRule.getFullLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertTrue(buildRule.getFullLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertTrue(buildRule.getFullLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
} | |||
@Test | |||
public void testNoVersionInfoWarn() { | |||
executeTarget("testNoVersionInfoWarn"); | |||
assertTrue( getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertTrue( getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertTrue( getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
buildRule.executeTarget("testNoVersionInfoWarn"); | |||
assertTrue(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertTrue(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertTrue(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
} | |||
@Test | |||
public void testNoVersionInfoNoStrict() { | |||
executeTarget("testNoVersionInfoNoStrict"); | |||
assertFalse( getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertFalse( getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertFalse( getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
buildRule.executeTarget("testNoVersionInfoNoStrict"); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
} | |||
@Test | |||
public void testHasVersionInfo() { | |||
executeTarget("testHasVersionInfo"); | |||
assertFalse( getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertFalse( getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertFalse( getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
buildRule.executeTarget("testHasVersionInfo"); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | |||
assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | |||
} | |||
} |
@@ -29,15 +29,29 @@ import java.io.OutputStreamWriter; | |||
import java.io.PipedInputStream; | |||
import java.io.PipedOutputStream; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.input.DefaultInputHandler; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.TeeOutputStream; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.internal.AssumptionViolatedException; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* stress out java task | |||
* */ | |||
public class JavaTest extends BuildFileTest { | |||
public class JavaTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private static final int TIME_TO_WAIT = 1; | |||
// wait 1 second extra to allow for java to start ... | |||
@@ -49,18 +63,16 @@ public class JavaTest extends BuildFileTest { | |||
private boolean runFatalTests=false; | |||
public JavaTest(String name) { | |||
super(name); | |||
} | |||
/** | |||
* configure the project. | |||
* if the property junit.run.fatal.tests is set we run | |||
* the fatal tests | |||
*/ | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/java.xml"); | |||
project.executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/java.xml"); | |||
buildRule.executeTarget("setUp"); | |||
//final String propname="tests-classpath.value"; | |||
//String testClasspath=System.getProperty(propname); | |||
@@ -70,32 +82,49 @@ public class JavaTest extends BuildFileTest { | |||
runFatalTests=true; | |||
} | |||
@Test | |||
public void testNoJarNoClassname(){ | |||
expectBuildExceptionContaining("testNoJarNoClassname", | |||
"parameter validation", | |||
"Classname must not be null."); | |||
try { | |||
buildRule.executeTarget("testNoJarNoClassname"); | |||
fail("Build exception should have been thrown - parameter validation"); | |||
} catch (BuildException ex) { | |||
assertContains("Classname must not be null.", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testJarNoFork() { | |||
expectBuildExceptionContaining("testJarNoFork", | |||
"parameter validation", | |||
"Cannot execute a jar in non-forked mode. " | |||
+ "Please set fork='true'. "); | |||
try { | |||
buildRule.executeTarget("testJarNoFork"); | |||
fail("Build exception should have been thrown - parameter validation"); | |||
} catch (BuildException ex) { | |||
assertContains("Cannot execute a jar in non-forked mode. Please set fork='true'. ", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testJarAndClassName() { | |||
expectBuildException("testJarAndClassName", | |||
"Should not be able to set both classname AND jar"); | |||
try { | |||
buildRule.executeTarget("testJarAndClassName"); | |||
fail("Build exception should have been thrown - both classname and JAR are not allowed"); | |||
} catch (BuildException ex) { | |||
assertEquals("Cannot use 'jar' and 'classname' attributes in same command", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testClassnameAndJar() { | |||
expectBuildException("testClassnameAndJar", | |||
"Should not be able to set both classname AND jar"); | |||
try { | |||
buildRule.executeTarget("testClassnameAndJar"); | |||
fail("Build exception should have been thrown - both classname and JAR are not allowed"); | |||
} catch (BuildException ex) { | |||
assertEquals("Cannot use 'jar' and 'classname' attributes in same command.", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testRun() { | |||
executeTarget("testRun"); | |||
buildRule.executeTarget("testRun"); | |||
} | |||
@@ -103,90 +132,117 @@ public class JavaTest extends BuildFileTest { | |||
/** this test fails but we ignore the return value; | |||
* we verify that failure only matters when failonerror is set | |||
*/ | |||
@Test | |||
public void testRunFail() { | |||
if(runFatalTests) { | |||
executeTarget("testRunFail"); | |||
} | |||
Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests); | |||
buildRule.executeTarget("testRunFail"); | |||
} | |||
@Test | |||
public void testRunFailFoe() { | |||
if(runFatalTests) { | |||
expectBuildExceptionContaining("testRunFailFoe", | |||
"java failures being propagated", | |||
"Java returned:"); | |||
Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests); | |||
try { | |||
buildRule.executeTarget("testRunFailFoe"); | |||
fail("Build exception should have been thrown - " + "java failures being propagated"); | |||
} catch (BuildException ex) { | |||
assertContains("Java returned:", ex.getMessage()); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testRunFailFoeFork() { | |||
expectBuildExceptionContaining("testRunFailFoeFork", | |||
"java failures being propagated", | |||
"Java returned:"); | |||
try { | |||
buildRule.executeTarget("testRunFailFoeFork"); | |||
fail("Build exception should have been thrown - " + "java failures being propagated"); | |||
} catch (BuildException ex) { | |||
assertContains("Java returned:", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testExcepting() { | |||
expectLogContaining("testExcepting", | |||
"Exception raised inside called program"); | |||
buildRule.executeTarget("testExcepting"); | |||
assertContains("Exception raised inside called program", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testExceptingFork() { | |||
expectLogContaining("testExceptingFork", | |||
"Java Result:"); | |||
buildRule.executeTarget("testExceptingFork"); | |||
assertContains("Java Result:", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testExceptingFoe() { | |||
expectBuildExceptionContaining("testExceptingFoe", | |||
"passes exception through", | |||
"Exception raised inside called program"); | |||
try { | |||
buildRule.executeTarget("testExceptingFoe"); | |||
fail("Build exception should have been thrown - " + "passes exception through"); | |||
} catch (BuildException ex) { | |||
assertContains("Exception raised inside called program", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testExceptingFoeFork() { | |||
expectBuildExceptionContaining("testExceptingFoeFork", | |||
"exceptions turned into error codes", | |||
"Java returned:"); | |||
try { | |||
buildRule.executeTarget("testExceptingFoeFork"); | |||
fail("Build exception should have been thrown - " + "exceptions turned into error codes"); | |||
} catch (BuildException ex) { | |||
assertContains("Java returned:", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testResultPropertyZero() { | |||
executeTarget("testResultPropertyZero"); | |||
assertEquals("0",project.getProperty("exitcode")); | |||
buildRule.executeTarget("testResultPropertyZero"); | |||
assertEquals("0", buildRule.getProject().getProperty("exitcode")); | |||
} | |||
@Test | |||
public void testResultPropertyNonZero() { | |||
executeTarget("testResultPropertyNonZero"); | |||
assertEquals("2",project.getProperty("exitcode")); | |||
buildRule.executeTarget("testResultPropertyNonZero"); | |||
assertEquals("2", buildRule.getProject().getProperty("exitcode")); | |||
} | |||
@Test | |||
public void testResultPropertyZeroNoFork() { | |||
executeTarget("testResultPropertyZeroNoFork"); | |||
assertEquals("0",project.getProperty("exitcode")); | |||
buildRule.executeTarget("testResultPropertyZeroNoFork"); | |||
assertEquals("0", buildRule.getProject().getProperty("exitcode")); | |||
} | |||
@Test | |||
public void testResultPropertyNonZeroNoFork() { | |||
executeTarget("testResultPropertyNonZeroNoFork"); | |||
assertEquals("-1",project.getProperty("exitcode")); | |||
buildRule.executeTarget("testResultPropertyNonZeroNoFork"); | |||
assertEquals("-1", buildRule.getProject().getProperty("exitcode")); | |||
} | |||
@Test | |||
public void testRunFailWithFailOnError() { | |||
expectBuildExceptionContaining("testRunFailWithFailOnError", | |||
"non zero return code", | |||
"Java returned:"); | |||
try { | |||
buildRule.executeTarget("testRunFailWithFailOnError"); | |||
fail("Build exception should have been thrown - " + "non zero return code"); | |||
} catch (BuildException ex) { | |||
assertContains("Java returned:", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testRunSuccessWithFailOnError() { | |||
executeTarget("testRunSuccessWithFailOnError"); | |||
buildRule.executeTarget("testRunSuccessWithFailOnError"); | |||
} | |||
public void testSpawn() { | |||
File logFile = FILE_UTILS.createTempFile("spawn","log", getOutputDir(), false, false); | |||
@Test | |||
public void testSpawn() throws InterruptedException { | |||
File logFile = FILE_UTILS.createTempFile("spawn", "log", | |||
new File(buildRule.getProject().getProperty("output")), false, false); | |||
// this is guaranteed by FileUtils#createTempFile | |||
assertTrue("log file not existing", !logFile.exists()); | |||
project.setProperty("logFile", logFile.getAbsolutePath()); | |||
project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); | |||
project.executeTarget("testSpawn"); | |||
try { | |||
Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN); | |||
} catch (Exception ex) { | |||
System.out.println("my sleep was interrupted"); | |||
} | |||
buildRule.getProject().setProperty("logFile", logFile.getAbsolutePath()); | |||
buildRule.getProject().setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); | |||
buildRule.getProject().executeTarget("testSpawn"); | |||
Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN); | |||
// let's be nice with the next generation of developers | |||
if (!logFile.exists()) { | |||
System.out.println("suggestion: increase the constant" | |||
@@ -195,38 +251,44 @@ public class JavaTest extends BuildFileTest { | |||
assertTrue("log file exists", logFile.exists()); | |||
} | |||
@Test | |||
public void testRedirect1() { | |||
executeTarget("redirect1"); | |||
buildRule.executeTarget("redirect1"); | |||
} | |||
@Test | |||
public void testRedirect2() { | |||
executeTarget("redirect2"); | |||
buildRule.executeTarget("redirect2"); | |||
} | |||
@Test | |||
public void testRedirect3() { | |||
executeTarget("redirect3"); | |||
buildRule.executeTarget("redirect3"); | |||
} | |||
@Test | |||
public void testRedirector1() { | |||
executeTarget("redirector1"); | |||
buildRule.executeTarget("redirector1"); | |||
} | |||
@Test | |||
public void testRedirector2() { | |||
executeTarget("redirector2"); | |||
buildRule.executeTarget("redirector2"); | |||
} | |||
@Test | |||
public void testReleasedInput() throws Exception { | |||
PipedOutputStream out = new PipedOutputStream(); | |||
final PipedInputStream in = new PipedInputStream(out); | |||
project.setInputHandler(new DefaultInputHandler() { | |||
buildRule.getProject().setInputHandler(new DefaultInputHandler() { | |||
protected InputStream getInputStream() { | |||
return in; | |||
} | |||
}); | |||
project.setDefaultInputStream(in); | |||
buildRule.getProject().setDefaultInputStream(in); | |||
Java java = new Java(); | |||
java.setProject(project); | |||
java.setProject(buildRule.getProject()); | |||
java.setClassname("org.apache.tools.ant.Main"); | |||
java.setArgs("-version"); | |||
java.setFork(true); | |||
@@ -237,7 +299,7 @@ public class JavaTest extends BuildFileTest { | |||
Thread inputThread = new Thread(new Runnable() { | |||
public void run() { | |||
Input input = new Input(); | |||
input.setProject(project); | |||
input.setProject(buildRule.getProject()); | |||
input.setAddproperty("input.value"); | |||
input.execute(); | |||
} | |||
@@ -259,18 +321,19 @@ public class JavaTest extends BuildFileTest { | |||
inputThread.join(2000); | |||
assertEquals("foo", project.getProperty("input.value")); | |||
assertEquals("foo", buildRule.getProject().getProperty("input.value")); | |||
} | |||
@Test | |||
public void testFlushedInput() throws Exception { | |||
final PipedOutputStream out = new PipedOutputStream(); | |||
final PipedInputStream in = new PipedInputStream(out); | |||
project.setInputHandler(new DefaultInputHandler() { | |||
buildRule.getProject().setInputHandler(new DefaultInputHandler() { | |||
protected InputStream getInputStream() { | |||
return in; | |||
} | |||
}); | |||
project.setDefaultInputStream(in); | |||
buildRule.getProject().setDefaultInputStream(in); | |||
final boolean[] timeout = new boolean[1]; | |||
timeout[0] = false; | |||
@@ -281,7 +344,7 @@ public class JavaTest extends BuildFileTest { | |||
// wait a little bit to have the target executed | |||
Thread.sleep(500); | |||
} catch (InterruptedException e) { | |||
// don't care | |||
throw new AssumptionViolatedException("Thread interrupted", e); | |||
} | |||
try { | |||
out.write("foo-FlushedInput\n".getBytes()); | |||
@@ -293,7 +356,7 @@ public class JavaTest extends BuildFileTest { | |||
writingThread.setDaemon(true); | |||
writingThread.start(); | |||
executeTarget("flushedInput"); | |||
buildRule.executeTarget("flushedInput"); | |||
} | |||
/** | |||
@@ -348,7 +411,7 @@ public class JavaTest extends BuildFileTest { | |||
* test class for spawn | |||
*/ | |||
public static class SpawnEntryPoint { | |||
public static void main(String [] argv) { | |||
public static void main(String [] argv) throws InterruptedException { | |||
int sleepTime = 10; | |||
String logFile = "spawn.log"; | |||
if (argv.length >= 1) { | |||
@@ -359,11 +422,7 @@ public class JavaTest extends BuildFileTest { | |||
logFile = argv[1]; | |||
} | |||
OutputStreamWriter out = null; | |||
try { | |||
Thread.sleep(sleepTime * 1000); | |||
} catch (InterruptedException ex) { | |||
System.out.println("my sleep was interrupted"); | |||
} | |||
Thread.sleep(sleepTime * 1000); | |||
try { | |||
File dest = new File(logFile); | |||
@@ -386,7 +445,7 @@ public class JavaTest extends BuildFileTest { | |||
/** | |||
* pipe input to specified output | |||
*/ | |||
public static void main(String[] args) { | |||
public static void main(String[] args) throws InterruptedException { | |||
OutputStream os = null; | |||
if (args.length > 0) { | |||
if ("out".equalsIgnoreCase(args[0])) { | |||
@@ -401,10 +460,7 @@ public class JavaTest extends BuildFileTest { | |||
Thread t = new Thread(new StreamPumper(System.in, os, true)); | |||
t.setName("PipeEntryPoint " + args[0]); | |||
t.start(); | |||
try { | |||
t.join(); | |||
} catch (InterruptedException eyeEx) { | |||
} | |||
t.join(); | |||
} | |||
} | |||
} | |||
@@ -18,35 +18,31 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Arrays; | |||
import java.util.Date; | |||
import java.util.List; | |||
import junit.framework.TestCase; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | |||
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | |||
import org.apache.tools.ant.taskdefs.compilers.Javac13; | |||
import org.apache.tools.ant.taskdefs.compilers.JavacExternal; | |||
import org.apache.tools.ant.types.Path; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Testcase for <javac>. | |||
* | |||
*/ | |||
public class JavacTest extends TestCase { | |||
public class JavacTest { | |||
private Project project; | |||
private Javac javac; | |||
public JavacTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
project = new Project(); | |||
project.init(); | |||
@@ -57,6 +53,7 @@ public class JavacTest extends TestCase { | |||
/** | |||
* Test setting the name of the javac executable. | |||
*/ | |||
@Test | |||
public void testForkedExecutableName() { | |||
assertNull("no fork means no executable", javac.getJavacExecutable()); | |||
@@ -65,14 +62,13 @@ public class JavacTest extends TestCase { | |||
javac.setFork(true); | |||
assertNotNull("normal fork", javac.getJavacExecutable()); | |||
assertTrue("name should contain \"javac\"", | |||
javac.getJavacExecutable().indexOf("javac") > -1); | |||
assertContains("name should contain \"javac\"", "javac", | |||
javac.getJavacExecutable()); | |||
project.setProperty("build.compiler", "extJavac"); | |||
javac.setFork(false); | |||
assertNotNull("fork via property", javac.getJavacExecutable()); | |||
assertTrue("name should contain \"javac\"", | |||
javac.getJavacExecutable().indexOf("javac") > -1); | |||
assertContains("name should contain \"javac\"", "javac", javac.getJavacExecutable()); | |||
project.setProperty("build.compiler", "whatever"); | |||
assertNull("no fork and not extJavac means no executable", | |||
@@ -87,6 +83,7 @@ public class JavacTest extends TestCase { | |||
/** | |||
* Test nested compiler args. | |||
*/ | |||
@Test | |||
public void testCompilerArg() { | |||
String[] args = javac.getCurrentCompilerArgs(); | |||
assertNotNull(args); | |||
@@ -129,6 +126,7 @@ public class JavacTest extends TestCase { | |||
* Test nested compiler args in the fork="true" and | |||
* implementation="extJavac" case. | |||
*/ | |||
@Test | |||
public void testCompilerArgForForkAndExtJavac() { | |||
Javac.ImplementationSpecificArgument arg = javac.createCompilerArg(); | |||
String ford = "Ford"; | |||
@@ -145,6 +143,7 @@ public class JavacTest extends TestCase { | |||
/** | |||
* Test compiler attribute. | |||
*/ | |||
@Test | |||
public void testCompilerAttribute() { | |||
// check defaults | |||
String compiler = javac.getCompiler(); | |||
@@ -194,6 +193,7 @@ public class JavacTest extends TestCase { | |||
assertEquals("jvc", compiler); | |||
} | |||
@Test | |||
public void testCompilerAdapter() { | |||
javac.setCompiler("javac1.4"); | |||
@@ -209,30 +209,36 @@ public class JavacTest extends TestCase { | |||
assertTrue(adapter instanceof JavacExternal); | |||
} | |||
@Test | |||
public void testSourceNoDefault() { | |||
assertNull(javac.getSource()); | |||
} | |||
@Test | |||
public void testSourceWithDefault() { | |||
project.setNewProperty("ant.build.javac.source", "1.4"); | |||
assertEquals("1.4", javac.getSource()); | |||
} | |||
@Test | |||
public void testSourceOverridesDefault() { | |||
project.setNewProperty("ant.build.javac.source", "1.4"); | |||
javac.setSource("1.5"); | |||
assertEquals("1.5", javac.getSource()); | |||
} | |||
@Test | |||
public void testTargetNoDefault() { | |||
assertNull(javac.getTarget()); | |||
} | |||
@Test | |||
public void testTargetWithDefault() { | |||
project.setNewProperty("ant.build.javac.target", "1.4"); | |||
assertEquals("1.4", javac.getTarget()); | |||
} | |||
@Test | |||
public void testTargetOverridesDefault() { | |||
project.setNewProperty("ant.build.javac.target", "1.4"); | |||
javac.setTarget("1.5"); | |||
@@ -18,122 +18,115 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
public class JavadocTest extends BuildFileTest { | |||
public class JavadocTest { | |||
public JavadocTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
private static final String BUILD_PATH = "src/etc/testcases/taskdefs/javadoc/"; | |||
private static final String BUILD_FILENAME = "javadoc.xml"; | |||
private static final String BUILD_FILE = BUILD_PATH + BUILD_FILENAME; | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
configureProject(BUILD_FILE); | |||
@Before | |||
public void setUp() { | |||
buildRule.configureProject(BUILD_FILE); | |||
} | |||
// PR 38370 | |||
public void testDirsetPath() throws Exception { | |||
executeTarget("dirsetPath"); | |||
@Test | |||
public void testDirsetPath() { | |||
buildRule.executeTarget("dirsetPath"); | |||
} | |||
// PR 38370 | |||
public void testDirsetPathWithoutPackagenames() throws Exception { | |||
try { | |||
executeTarget("dirsetPathWithoutPackagenames"); | |||
} catch (BuildException e) { | |||
fail("Contents of path should be picked up without specifying package names: " + e); | |||
} | |||
@Test | |||
public void testDirsetPathWithoutPackagenames() { | |||
buildRule.executeTarget("dirsetPathWithoutPackagenames"); | |||
} | |||
// PR 38370 | |||
public void testNestedDirsetPath() throws Exception { | |||
executeTarget("nestedDirsetPath"); | |||
@Test | |||
public void testNestedDirsetPath() { | |||
buildRule.executeTarget("nestedDirsetPath"); | |||
} | |||
// PR 38370 | |||
public void testFilesetPath() throws Exception { | |||
try { | |||
executeTarget("filesetPath"); | |||
} catch (BuildException e) { | |||
fail("A path can contain filesets: " + e); | |||
} | |||
@Test | |||
public void testFilesetPath() { | |||
buildRule.executeTarget("filesetPath"); | |||
} | |||
// PR 38370 | |||
public void testNestedFilesetPath() throws Exception { | |||
try { | |||
executeTarget("nestedFilesetPath"); | |||
} catch (BuildException e) { | |||
fail("A path can contain nested filesets: " + e); | |||
} | |||
@Test | |||
public void testNestedFilesetPath() { | |||
buildRule.executeTarget("nestedFilesetPath"); | |||
} | |||
// PR 38370 | |||
public void testFilelistPath() throws Exception { | |||
try { | |||
executeTarget("filelistPath"); | |||
} catch (BuildException e) { | |||
fail("A path can contain filelists: " + e); | |||
} | |||
@Test | |||
public void testFilelistPath() { | |||
buildRule.executeTarget("filelistPath"); | |||
} | |||
// PR 38370 | |||
public void testNestedFilelistPath() throws Exception { | |||
try { | |||
executeTarget("nestedFilelistPath"); | |||
} catch (BuildException e) { | |||
fail("A path can contain nested filelists: " + e); | |||
} | |||
@Test | |||
public void testNestedFilelistPath() { | |||
buildRule.executeTarget("nestedFilelistPath"); | |||
} | |||
// PR 38370 | |||
public void testPathelementPath() throws Exception { | |||
executeTarget("pathelementPath"); | |||
@Test | |||
public void testPathelementPath() { | |||
buildRule.executeTarget("pathelementPath"); | |||
} | |||
// PR 38370 | |||
public void testPathelementLocationPath() throws Exception { | |||
try { | |||
executeTarget("pathelementLocationPath"); | |||
} catch (BuildException e) { | |||
fail("A path can contain pathelements pointing to a file: " + e); | |||
} | |||
@Test | |||
public void testPathelementLocationPath() { | |||
buildRule.executeTarget("pathelementLocationPath"); | |||
} | |||
// PR 38370 | |||
public void testNestedSource() throws Exception { | |||
executeTarget("nestedSource"); | |||
@Test | |||
public void testNestedSource() { | |||
buildRule.executeTarget("nestedSource"); | |||
} | |||
// PR 38370 | |||
public void testNestedFilesetRef() throws Exception { | |||
executeTarget("nestedFilesetRef"); | |||
@Test | |||
public void testNestedFilesetRef() { | |||
buildRule.executeTarget("nestedFilesetRef"); | |||
} | |||
// PR 38370 | |||
public void testNestedFilesetRefInPath() throws Exception { | |||
executeTarget("nestedFilesetRefInPath"); | |||
@Test | |||
public void testNestedFilesetRefInPath() { | |||
buildRule.executeTarget("nestedFilesetRefInPath"); | |||
} | |||
public void testNestedFilesetNoPatterns() throws Exception { | |||
executeTarget("nestedFilesetNoPatterns"); | |||
@Test | |||
public void testNestedFilesetNoPatterns() { | |||
buildRule.executeTarget("nestedFilesetNoPatterns"); | |||
} | |||
public void testDoublyNestedFileset() throws Exception { | |||
executeTarget("doublyNestedFileset"); | |||
@Test | |||
public void testDoublyNestedFileset() { | |||
buildRule.executeTarget("doublyNestedFileset"); | |||
} | |||
public void testDoublyNestedFilesetNoPatterns() throws Exception { | |||
executeTarget("doublyNestedFilesetNoPatterns"); | |||
@Test | |||
public void testDoublyNestedFilesetNoPatterns() { | |||
buildRule.executeTarget("doublyNestedFilesetNoPatterns"); | |||
} | |||
public void testNonJavaIncludes() throws Exception { // #41264 | |||
executeTarget("nonJavaIncludes"); | |||
@Test | |||
public void testNonJavaIncludes() { // #41264 | |||
buildRule.executeTarget("nonJavaIncludes"); | |||
} | |||
} |
@@ -18,83 +18,99 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Test the load file task | |||
* | |||
* @created 10 December 2001 | |||
*/ | |||
public class LoadFileTest extends BuildFileTest { | |||
/** | |||
* Constructor for the LoadFileTest object | |||
* | |||
* @param name Description of Parameter | |||
*/ | |||
public LoadFileTest(String name) { | |||
super(name); | |||
} | |||
public class LoadFileTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
/** | |||
* The JUnit setup method | |||
*/ | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/loadfile.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/loadfile.xml"); | |||
} | |||
/** | |||
* The teardown method for JUnit | |||
*/ | |||
@After | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
buildRule.executeTarget("cleanup"); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testNoSourcefileDefined() { | |||
expectBuildException("testNoSourcefileDefined", | |||
"source file not defined"); | |||
try { | |||
buildRule.executeTarget("testNoSourcefileDefined"); | |||
fail("BuildException expected: source file not defined"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testNoPropertyDefined() { | |||
expectBuildException("testNoPropertyDefined", | |||
"output property not defined"); | |||
try { | |||
buildRule.executeTarget("testNoPropertyDefined"); | |||
fail("BuildException expected: output property not defined"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testNoSourcefilefound() { | |||
expectBuildExceptionContaining("testNoSourcefilefound", | |||
"File not found", " doesn't exist"); | |||
try { | |||
buildRule.executeTarget("testNoSourcefilefound"); | |||
fail("BuildException expected: File not found"); | |||
} catch (BuildException ex) { | |||
assertContains(" doesn't exist", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testFailOnError() | |||
throws BuildException { | |||
expectPropertyUnset("testFailOnError","testFailOnError"); | |||
buildRule.executeTarget("testFailOnError"); | |||
assertNull(buildRule.getProject().getProperty("testFailOnError")); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testLoadAFile() | |||
throws BuildException { | |||
executeTarget("testLoadAFile"); | |||
if(project.getProperty("testLoadAFile").indexOf("eh?")<0) { | |||
buildRule.executeTarget("testLoadAFile"); | |||
if(buildRule.getProject().getProperty("testLoadAFile").indexOf("eh?")<0) { | |||
fail("property is not all in the file"); | |||
} | |||
} | |||
@@ -103,21 +119,21 @@ public class LoadFileTest extends BuildFileTest { | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testLoadAFileEnc() | |||
throws BuildException { | |||
executeTarget("testLoadAFileEnc"); | |||
if(project.getProperty("testLoadAFileEnc")==null) { | |||
fail("file load failed"); | |||
} | |||
buildRule.executeTarget("testLoadAFileEnc"); | |||
assertNotNull("file load files", buildRule.getProject().getProperty("testLoadAFileEnc")); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
@Test | |||
public void testEvalProps() | |||
throws BuildException { | |||
executeTarget("testEvalProps"); | |||
if(project.getProperty("testEvalProps").indexOf("rain")<0) { | |||
buildRule.executeTarget("testEvalProps"); | |||
if(buildRule.getProject().getProperty("testEvalProps").indexOf("rain")<0) { | |||
fail("property eval broken"); | |||
} | |||
} | |||
@@ -125,10 +141,11 @@ public class LoadFileTest extends BuildFileTest { | |||
/** | |||
* Test FilterChain and FilterReaders | |||
*/ | |||
@Test | |||
public void testFilterChain() | |||
throws BuildException { | |||
executeTarget("testFilterChain"); | |||
if(project.getProperty("testFilterChain").indexOf("World!")<0) { | |||
buildRule.executeTarget("testFilterChain"); | |||
if(buildRule.getProject().getProperty("testFilterChain").indexOf("World!")<0) { | |||
fail("Filter Chain broken"); | |||
} | |||
} | |||
@@ -136,20 +153,18 @@ public class LoadFileTest extends BuildFileTest { | |||
/** | |||
* Test StripJavaComments filterreader functionality. | |||
*/ | |||
@Test | |||
public final void testStripJavaComments() | |||
throws BuildException { | |||
executeTarget("testStripJavaComments"); | |||
final String expected = project.getProperty("expected"); | |||
final String generated = project.getProperty("testStripJavaComments"); | |||
buildRule.executeTarget("testStripJavaComments"); | |||
final String expected = buildRule.getProject().getProperty("expected"); | |||
final String generated = buildRule.getProject().getProperty("testStripJavaComments"); | |||
assertEquals(expected, generated); | |||
} | |||
/** | |||
* A unit test for JUnit | |||
*/ | |||
public void testOneLine() | |||
throws BuildException { | |||
expectPropertySet("testOneLine","testOneLine","1,2,3,4"); | |||
@Test | |||
public void testOneLine() { | |||
buildRule.executeTarget("testOneLine"); | |||
assertEquals("1,2,3,4", buildRule.getProject().getProperty("testOneLine")); | |||
} | |||
} |
@@ -19,124 +19,167 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class MacroDefTest extends BuildFileTest { | |||
public MacroDefTest(String name) { | |||
super(name); | |||
} | |||
public class MacroDefTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/macrodef.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/macrodef.xml"); | |||
} | |||
@Test | |||
public void testSimple() { | |||
expectLog("simple", "Hello World"); | |||
buildRule.executeTarget("simple"); | |||
assertEquals("Hello World", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testText() { | |||
expectLog("text", "Inner Text"); | |||
buildRule.executeTarget("text"); | |||
assertEquals("Inner Text", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testDuplicateAttribute() { | |||
expectBuildException( | |||
"duplicate.attribute", | |||
"the attribute text has already been specified"); | |||
try { | |||
buildRule.executeTarget("duplicate.attribute"); | |||
fail("BuildException expected: the attribute text has already been specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testDuplicateElement() { | |||
expectBuildException( | |||
"duplicate.element", | |||
"the element text has already been specified"); | |||
try { | |||
buildRule.executeTarget("duplicate.element"); | |||
fail("BuildException expected: the element text has already been specified"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testUri() { | |||
expectLog("uri", "Hello World"); | |||
buildRule.executeTarget("uri"); | |||
assertEquals("Hello World", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testNested() { | |||
expectLog("nested", "A nested element"); | |||
buildRule.executeTarget("nested"); | |||
assertEquals("A nested element", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testDouble() { | |||
expectLog( | |||
"double", | |||
"@{prop} is 'property', value of ${property} is 'A property value'"); | |||
buildRule.executeTarget("double"); | |||
assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testIgnoreCase() { | |||
expectLog( | |||
"ignorecase", | |||
"a is ab is b"); | |||
buildRule.executeTarget("ignorecase"); | |||
assertEquals("a is ab is b", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testIgnoreElementCase() { | |||
expectLog( | |||
"ignore-element-case", | |||
"nested elementnested element"); | |||
buildRule.executeTarget("ignore-element-case"); | |||
assertEquals("nested elementnested element", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testTextElement() { | |||
expectLogContaining( | |||
"textelement", "Hello world"); | |||
buildRule.executeTarget("textelement"); | |||
assertContains("Hello world", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testTextTrim() { | |||
expectLogContaining( | |||
"text.trim", "[Hello world]"); | |||
buildRule.executeTarget("text.trim"); | |||
assertContains("[Hello world]", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testDuplicateTextName() { | |||
expectBuildException( | |||
"duplicatetextname", | |||
"the name \"text\" is already used as an attribute"); | |||
try { | |||
buildRule.executeTarget("duplicatetextname"); | |||
fail("BuildException expected: the name \"text\" is already used as an attribute"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testDuplicateTextName2() { | |||
expectBuildException( | |||
"duplicatetextname2", | |||
"the attribute name \"text\" has already been used by the text element"); | |||
try { | |||
buildRule.executeTarget("duplicatetextname2"); | |||
fail("BuildException expected: the attribute name \"text\" has already been used by the text element"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testEscape() { | |||
expectLog( | |||
"escape", | |||
"a@b or a@b is avalue@bvalue"); | |||
buildRule.executeTarget("escape"); | |||
assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testAttributeDescription() { | |||
expectLog( | |||
"attribute.description", | |||
"description is hello world"); | |||
buildRule.executeTarget("attribute.description"); | |||
assertEquals("description is hello world", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testOverrideDefault() { | |||
expectLog( | |||
"override.default", | |||
"value is new"); | |||
buildRule.executeTarget("override.default"); | |||
assertEquals("value is new", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testImplicit() { | |||
expectLog( | |||
"implicit", "Before implicitIn implicitAfter implicit"); | |||
buildRule.executeTarget("implicit"); | |||
assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testImplicitNotOptional() { | |||
expectSpecificBuildException( | |||
"implicit.notoptional", | |||
"Missing nested elements for implicit element implicit", | |||
"Missing nested elements for implicit element implicit"); | |||
try { | |||
buildRule.executeTarget("implicit.notoptional"); | |||
fail("BuildException expected: Missing nested elements for implicit element implicit"); | |||
} catch (BuildException ex) { | |||
assertEquals("Missing nested elements for implicit element implicit", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testImplicitOptional() { | |||
expectLog( | |||
"implicit.optional", "Before implicitAfter implicit"); | |||
buildRule.executeTarget("implicit.optional"); | |||
assertEquals("Before implicitAfter implicit", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testImplicitExplicit() { | |||
expectSpecificBuildException( | |||
"implicit.explicit", | |||
"Only one element allowed when using implicit elements", | |||
"Only one element allowed when using implicit elements"); | |||
try { | |||
buildRule.executeTarget("implicit.explicit"); | |||
fail("BuildException expected: Only one element allowed when using implicit elements"); | |||
} catch (BuildException ex) { | |||
assertEquals("Only one element allowed when using implicit elements", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testBackTraceOff() { | |||
try { | |||
executeTarget("backtraceoff"); | |||
buildRule.executeTarget("backtraceoff"); | |||
} catch (BuildException ex) { | |||
if (ex.getMessage().indexOf("following error occurred") != -1) { | |||
fail("error message contained backtrace - " + ex.getMessage()); | |||
@@ -144,15 +187,20 @@ public class MacroDefTest extends BuildFileTest { | |||
} | |||
} | |||
@Test | |||
public void testBackTrace() { | |||
expectBuildExceptionContaining( | |||
"backtraceon", | |||
"Checking if a back trace is created", | |||
"following error occurred"); | |||
try { | |||
buildRule.executeTarget("backtraceon"); | |||
fail("BuildException expected: Checking if a back trace is created"); | |||
} catch (BuildException ex) { | |||
assertContains("following error occurred", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testTopLevelText() { | |||
expectLogContaining("top-level-text", "Hello World"); | |||
buildRule.executeTarget("top-level-text"); | |||
assertContains("Hello World", buildRule.getLog()); | |||
} | |||
} | |||
@@ -17,47 +17,82 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.InputStream; | |||
import java.io.IOException; | |||
import java.net.URL; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
public class MakeUrlTest extends BuildFileTest { | |||
public MakeUrlTest(String s) { | |||
super(s); | |||
} | |||
public class MakeUrlTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/makeurl.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); | |||
} | |||
@Test | |||
public void testEmpty() { | |||
expectBuildExceptionContaining("testEmpty", "missing property", "property"); | |||
try { | |||
buildRule.executeTarget("testEmpty"); | |||
fail("BuildException expected: missing property"); | |||
} catch (BuildException ex) { | |||
assertContains("property", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNoProperty() { | |||
expectBuildExceptionContaining("testNoProperty", "missing property", "property"); | |||
try { | |||
buildRule.executeTarget("testNoProperty"); | |||
fail("BuildException expected: missing property"); | |||
} catch (BuildException ex) { | |||
assertContains("property", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testNoFile() { | |||
expectBuildExceptionContaining("testNoFile", "missing file", "file"); | |||
try { | |||
buildRule.executeTarget("testNoFile"); | |||
fail("BuildException expected: missing file"); | |||
} catch (BuildException ex) { | |||
assertContains("file", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testValidation() { | |||
expectBuildExceptionContaining("testValidation", MakeUrl.ERROR_MISSING_FILE, "file"); | |||
try { | |||
buildRule.executeTarget("testValidation"); | |||
fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE); | |||
} catch (BuildException ex) { | |||
assertContains("file", ex.getMessage()); | |||
} | |||
} | |||
@Test | |||
public void testWorks() { | |||
executeTarget("testWorks"); | |||
buildRule.executeTarget("testWorks"); | |||
assertPropertyContains("testWorks", "file:"); | |||
assertPropertyContains("testWorks", "/foo"); | |||
} | |||
@Test | |||
public void testIllegalChars() { | |||
executeTarget("testIllegalChars"); | |||
buildRule.executeTarget("testIllegalChars"); | |||
assertPropertyContains("testIllegalChars", "file:"); | |||
assertPropertyContains("testIllegalChars", "fo%20o%25"); | |||
} | |||
@@ -67,8 +102,9 @@ public class MakeUrlTest extends BuildFileTest { | |||
* | |||
* @throws IOException | |||
*/ | |||
@Test | |||
public void testRoundTrip() throws IOException { | |||
executeTarget("testRoundTrip"); | |||
buildRule.executeTarget("testRoundTrip"); | |||
assertPropertyContains("testRoundTrip", "file:"); | |||
String property = getProperty("testRoundTrip"); | |||
URL url = new URL(property); | |||
@@ -76,26 +112,30 @@ public class MakeUrlTest extends BuildFileTest { | |||
instream.close(); | |||
} | |||
@Test | |||
public void testIllegalCombinations() { | |||
executeTarget("testIllegalCombinations"); | |||
buildRule.executeTarget("testIllegalCombinations"); | |||
assertPropertyContains("testIllegalCombinations", "/foo"); | |||
assertPropertyContains("testIllegalCombinations", ".xml"); | |||
} | |||
@Test | |||
public void testFileset() { | |||
executeTarget("testFileset"); | |||
buildRule.executeTarget("testFileset"); | |||
assertPropertyContains("testFileset", ".xml "); | |||
assertPropertyEndsWith("testFileset", ".xml"); | |||
} | |||
@Test | |||
public void testFilesetSeparator() { | |||
executeTarget("testFilesetSeparator"); | |||
buildRule.executeTarget("testFilesetSeparator"); | |||
assertPropertyContains("testFilesetSeparator", ".xml\",\""); | |||
assertPropertyEndsWith("testFilesetSeparator", ".xml"); | |||
} | |||
@Test | |||
public void testPath() { | |||
executeTarget("testPath"); | |||
buildRule.executeTarget("testPath"); | |||
assertPropertyContains("testPath", "makeurl.xml"); | |||
} | |||
@@ -131,6 +171,6 @@ public class MakeUrlTest extends BuildFileTest { | |||
* @return | |||
*/ | |||
protected String getProperty(String property) { | |||
return project.getProperty(property); | |||
return buildRule.getProject().getProperty(property); | |||
} | |||
} |
@@ -18,57 +18,96 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.fail; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.taskdefs.condition.Os; | |||
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
* Tests <bm:manifestclasspath>. | |||
*/ | |||
public class ManifestClassPathTest | |||
extends BuildFileTest { | |||
public class ManifestClassPathTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); | |||
} | |||
@Test | |||
public void testBadDirectory() { | |||
expectBuildExceptionContaining("test-bad-directory", "bad-jar-dir", | |||
"Jar's directory not found:"); | |||
assertPropertyUnset("jar.classpath"); | |||
try { | |||
buildRule.executeTarget("test-bad-directory"); | |||
fail("Build exception should have been thrown on bad directory"); | |||
} catch (BuildException ex) { | |||
assertContains("Jar's directory not found:", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("jar.classpath")); | |||
} | |||
@Test | |||
public void testBadNoProperty() { | |||
expectBuildExceptionContaining("test-bad-no-property", "no-property", | |||
"Missing 'property' attribute!"); | |||
assertPropertyUnset("jar.classpath"); | |||
try { | |||
buildRule.executeTarget("test-bad-no-property"); | |||
fail("Build exception should have been thrown on no property"); | |||
} catch (BuildException ex) { | |||
assertContains("Missing 'property' attribute!", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("jar.classpath")); | |||
} | |||
@Test | |||
public void testBadPropertyExists() { | |||
expectBuildExceptionContaining("test-bad-property-exists", | |||
"property-exits", "Property 'jar.classpath' already set!"); | |||
assertPropertyEquals("jar.classpath", "exists"); | |||
try { | |||
buildRule.executeTarget("test-bad-property-exists"); | |||
fail("Build exception should have been thrown on bad property"); | |||
} catch (BuildException ex) { | |||
assertContains("Property 'jar.classpath' already set!", ex.getMessage()); | |||
} | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "exists"); | |||
} | |||
@Test | |||
public void testBadNoJarfile() { | |||
expectBuildExceptionContaining("test-bad-no-jarfile", "no-jarfile", | |||
"Missing 'jarfile' attribute!"); | |||
assertPropertyUnset("jar.classpath"); | |||
try { | |||
buildRule.executeTarget("test-bad-no-jarfile"); | |||
fail("Build exception should have been thrown on bad jar file"); | |||
} catch (BuildException ex) { | |||
assertContains("Missing 'jarfile' attribute!", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("jar.classpath")); | |||
} | |||
@Test | |||
public void testBadNoClassPath() { | |||
expectBuildExceptionContaining("test-bad-no-classpath", "no-classpath", | |||
"Missing nested <classpath>!"); | |||
assertPropertyUnset("jar.classpath"); | |||
try { | |||
buildRule.executeTarget("test-bad-no-classpath"); | |||
fail("Build exception should have been thrown on no classpath"); | |||
} catch (BuildException ex) { | |||
assertContains("Missing nested <classpath>!", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("jar.classpath")); | |||
} | |||
@Test | |||
public void testParentLevel1() { | |||
executeTarget("test-parent-level1"); | |||
buildRule.executeTarget("test-parent-level1"); | |||
assertPropertyEquals("jar.classpath", "dsp-core/ " + | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "dsp-core/ " + | |||
"dsp-pres/ " + | |||
"dsp-void/ " + | |||
"../generated/dsp-core/ " + | |||
@@ -79,10 +118,11 @@ public class ManifestClassPathTest | |||
"../resources/dsp-void/"); | |||
} | |||
@Test | |||
public void testParentLevel2() { | |||
executeTarget("test-parent-level2"); | |||
buildRule.executeTarget("test-parent-level2"); | |||
assertPropertyEquals("jar.classpath", "../dsp-core/ " + | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../dsp-core/ " + | |||
"../dsp-pres/ " + | |||
"../dsp-void/ " + | |||
"../../generated/dsp-core/ " + | |||
@@ -93,19 +133,23 @@ public class ManifestClassPathTest | |||
"../../resources/dsp-void/"); | |||
} | |||
@Test | |||
public void testParentLevel2TooDeep() { | |||
expectBuildExceptionContaining("test-parent-level2-too-deep", "nopath", | |||
"No suitable relative path from "); | |||
assertPropertyUnset("jar.classpath"); | |||
try { | |||
buildRule.executeTarget("test-parent-level2-too-deep"); | |||
fail("Build exception should have been thrown on no suitable path"); | |||
} catch (BuildException ex) { | |||
assertContains("No suitable relative path from ", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("jar.classpath")); | |||
} | |||
@Test | |||
public void testPseudoTahoeRefid() { | |||
if (!RegexpMatcherFactory.regexpMatcherPresent(project)) { | |||
System.out.println("Test 'testPseudoTahoeRefid' skipped because no regexp matcher is present."); | |||
return; | |||
} | |||
executeTarget("test-pseudo-tahoe-refid"); | |||
assertPropertyEquals("jar.classpath", "classes/dsp-core/ " + | |||
Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); | |||
buildRule.executeTarget("test-pseudo-tahoe-refid"); | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + | |||
"classes/dsp-pres/ " + | |||
"classes/dsp-void/ " + | |||
"generated/dsp-core/ " + | |||
@@ -113,13 +157,12 @@ public class ManifestClassPathTest | |||
"resources/dsp-pres/"); | |||
} | |||
@Test | |||
public void testPseudoTahoeNested() { | |||
if (!RegexpMatcherFactory.regexpMatcherPresent(project)) { | |||
System.out.println("Test 'testPseudoTahoeNested' skipped because no regexp matcher is present."); | |||
return; | |||
} | |||
executeTarget("test-pseudo-tahoe-nested"); | |||
assertPropertyEquals("jar.classpath", "classes/dsp-core/ " + | |||
Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); | |||
buildRule.executeTarget("test-pseudo-tahoe-nested"); | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + | |||
"classes/dsp-pres/ " + | |||
"classes/dsp-void/ " + | |||
"generated/dsp-core/ " + | |||
@@ -127,10 +170,11 @@ public class ManifestClassPathTest | |||
"resources/dsp-pres/"); | |||
} | |||
@Test | |||
public void testParentLevel2WithJars() { | |||
executeTarget("test-parent-level2-with-jars"); | |||
buildRule.executeTarget("test-parent-level2-with-jars"); | |||
assertPropertyEquals("jar.classpath", "../../lib/acme-core.jar " + | |||
assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../../lib/acme-core.jar " + | |||
"../../lib/acme-pres.jar " + | |||
"../dsp-core/ " + | |||
"../dsp-pres/ " + | |||
@@ -142,64 +186,64 @@ public class ManifestClassPathTest | |||
"../../resources/dsp-pres/ " + | |||
"../../resources/dsp-void/"); | |||
} | |||
@Test | |||
public void testInternationalGerman() { | |||
executeTarget("international-german"); | |||
expectLogContaining("run-two-jars", "beta alpha"); | |||
buildRule.executeTarget("international-german"); | |||
buildRule.executeTarget("run-two-jars"); | |||
assertContains("beta alpha", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testInternationalHebrew() { | |||
if (!Os.isFamily("windows")) { | |||
executeTarget("international-hebrew"); | |||
expectLogContaining("run-two-jars", "beta alpha"); | |||
} else { | |||
System.out.println("Test with hebrew path not attempted under Windows"); | |||
} | |||
Assume.assumeFalse("Test with hebrew path not attempted under Windows", Os.isFamily("windows")); | |||
buildRule.executeTarget("international-hebrew"); | |||
buildRule.executeTarget("run-two-jars"); | |||
assertContains("beta alpha", buildRule.getLog()); | |||
} | |||
@Test | |||
public void testSameWindowsDrive() { | |||
if (!Os.isFamily("windows")) { | |||
System.out.println("Test with drive letters only run on windows"); | |||
} else { | |||
executeTarget("testSameDrive"); | |||
assertPropertyEquals("cp", "../a/b/x.jar"); | |||
} | |||
Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows")); | |||
buildRule.executeTarget("testSameDrive"); | |||
assertEquals(buildRule.getProject().getProperty("cp"), "../a/b/x.jar"); | |||
} | |||
@Test | |||
public void testDifferentWindowsDrive() { | |||
if (!Os.isFamily("windows")) { | |||
System.out.println("Test with drive letters only run on windows"); | |||
} else { | |||
// the lines below try to find a drive name different than the one containing the temp dir | |||
// if the temp dir is C will try to use D | |||
// if the temp dir is on D or other will try to use C | |||
File tmpdir = new File(System.getProperty("java.io.tmpdir")); | |||
String driveLetter = "C"; | |||
try { | |||
String tmpCanonicalPath = tmpdir.getCanonicalPath(); | |||
driveLetter = tmpCanonicalPath.substring(1).toUpperCase(); | |||
} catch (IOException ioe) { | |||
System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage()); | |||
} | |||
String altDriveLetter = null; | |||
try { | |||
if ("C".equals(driveLetter)) { | |||
altDriveLetter = "D"; | |||
} else { | |||
altDriveLetter = "C"; | |||
} | |||
new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); | |||
} catch (java.io.IOException e) { | |||
System.out.println("drive " + altDriveLetter + ": doesn't exist or is not ready," | |||
+ " skipping test"); | |||
return; | |||
Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows")); | |||
// the lines below try to find a drive name different than the one containing the temp dir | |||
// if the temp dir is C will try to use D | |||
// if the temp dir is on D or other will try to use C | |||
File tmpdir = new File(System.getProperty("java.io.tmpdir")); | |||
String driveLetter = "C"; | |||
try { | |||
String tmpCanonicalPath = tmpdir.getCanonicalPath(); | |||
driveLetter = tmpCanonicalPath.substring(0, 1).toUpperCase(); | |||
} catch (IOException ioe) { | |||
System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage()); | |||
} | |||
String altDriveLetter = null; | |||
try { | |||
if ("C".equals(driveLetter)) { | |||
altDriveLetter = "D"; | |||
} else { | |||
altDriveLetter = "C"; | |||
} | |||
project.setProperty("altDriveLetter", altDriveLetter); | |||
expectBuildExceptionContaining("testDifferentDrive", | |||
"different drive", | |||
"No suitable relative path from "); | |||
assertPropertyUnset("cp"); | |||
new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); | |||
} catch (java.io.IOException e) { | |||
Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e); | |||
} | |||
buildRule.getProject().setProperty("altDriveLetter", altDriveLetter); | |||
try { | |||
buildRule.executeTarget("testDifferentDrive"); | |||
fail("Build exception should have been thrown on no alternative drive"); | |||
} catch (BuildException ex) { | |||
assertContains("No suitable relative path from ", ex.getMessage()); | |||
} | |||
assertNull(buildRule.getProject().getProperty("cp")); | |||
} | |||
} // END class ManifestClassPathTest | |||
@@ -26,14 +26,28 @@ import java.util.Enumeration; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.Project; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
/** | |||
* Testcase for the Manifest class used in the jar task. | |||
* | |||
*/ | |||
public class ManifestTest extends BuildFileTest { | |||
public class ManifestTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
public static final String EXPANDED_MANIFEST | |||
= "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF"; | |||
@@ -53,23 +67,23 @@ public class ManifestTest extends BuildFileTest { | |||
public static final String VALUE = "NOT_LONG"; | |||
public ManifestTest(String name) { | |||
super(name); | |||
} | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/manifest.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/manifest.xml"); | |||
} | |||
@After | |||
public void tearDown() { | |||
executeTarget("clean"); | |||
buildRule.executeTarget("clean"); | |||
} | |||
/** | |||
* Empty manifest - is OK | |||
*/ | |||
@Test | |||
public void test1() throws ManifestException, IOException { | |||
executeTarget("test1"); | |||
buildRule.executeTarget("test1"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
String version = manifest.getManifestVersion(); | |||
assertEquals("Manifest was not created with correct version - ", "1.0", version); | |||
@@ -78,8 +92,9 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Simple Manifest with version 2.0 | |||
*/ | |||
@Test | |||
public void test2() throws ManifestException, IOException { | |||
executeTarget("test2"); | |||
buildRule.executeTarget("test2"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
String version = manifest.getManifestVersion(); | |||
assertEquals("Manifest was not created with correct version - ", "2.0", version); | |||
@@ -88,25 +103,36 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Malformed manifest - no : on the line | |||
*/ | |||
@Test | |||
public void test3() { | |||
expectBuildExceptionContaining("test3", "Manifest is invalid - no colon on header line", | |||
"Invalid Manifest"); | |||
try { | |||
buildRule.executeTarget("test3"); | |||
fail("BuildException expected: Manifest is invalid - no colon on header line"); | |||
} catch (BuildException ex) { | |||
assertContains("Invalid Manifest", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Malformed manifest - starts with continuation line | |||
*/ | |||
@Test | |||
public void test4() { | |||
expectBuildExceptionContaining("test4", "Manifest is invalid - section starts with continuation line", | |||
"Invalid Manifest"); | |||
try { | |||
buildRule.executeTarget("test4"); | |||
fail("BuildException expected: Manifest is invalid - section starts with continuation line"); | |||
} catch (BuildException ex) { | |||
assertContains("Invalid Manifest", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Malformed manifest - Name attribute in main section | |||
*/ | |||
@Test | |||
public void test5() { | |||
executeTarget("test5"); | |||
String output = getLog(); | |||
buildRule.executeTarget("test5"); | |||
String output = buildRule.getLog(); | |||
boolean hasWarning = output.indexOf("Manifest warning: \"Name\" attributes should not occur in the main section") != -1; | |||
assertTrue("Expected warning about Name in main section", hasWarning); | |||
} | |||
@@ -114,29 +140,37 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* New Section not starting with Name attribute. | |||
*/ | |||
@Test | |||
public void test6() { | |||
expectBuildExceptionContaining("test6", "Manifest is invalid - section starts with incorrect attribute", | |||
"Invalid Manifest"); | |||
String output = getLog(); | |||
try { | |||
buildRule.executeTarget("test6"); | |||
fail("BuildException expected: Manifest is invalid - section starts with incorrect attribute"); | |||
} catch (BuildException ex) { | |||
assertContains("Invalid Manifest", ex.getMessage()); | |||
} | |||
String output = buildRule.getLog(); | |||
boolean hasWarning = output.indexOf("Manifest sections should start with a \"Name\" attribute") != -1; | |||
assertTrue("Expected warning about section not starting with Name: attribute", hasWarning); | |||
} | |||
/** | |||
* From attribute is illegal | |||
*/ | |||
@Test | |||
public void test7() { | |||
executeTarget("test7"); | |||
buildRule.executeTarget("test7"); | |||
boolean hasWarning = getLog().indexOf(Manifest.ERROR_FROM_FORBIDDEN) != -1; | |||
boolean hasWarning = buildRule.getLog().indexOf(Manifest.ERROR_FROM_FORBIDDEN) != -1; | |||
assertTrue("Expected warning about From: attribute", hasWarning); | |||
} | |||
/** | |||
* Inline manifest - OK | |||
*/ | |||
@Test | |||
public void test8() throws IOException, ManifestException { | |||
executeTarget("test8"); | |||
buildRule.executeTarget("test8"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
Manifest.Section mainSection = manifest.getMainSection(); | |||
String classpath = mainSection.getAttributeValue("class-path"); | |||
@@ -150,48 +184,75 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Inline manifest - Invalid since has a Name attribute in the section element | |||
*/ | |||
@Test | |||
public void test9() { | |||
expectBuildExceptionContaining("test9", "Construction is invalid - Name attribute should not be used", | |||
"Specify the section name using the \"name\" attribute of the <section> element"); | |||
try { | |||
buildRule.executeTarget("test9"); | |||
fail("BuildException expected: Construction is invalid - Name attribute should not be used"); | |||
} catch (BuildException ex) { | |||
assertContains("Specify the section name using the \"name\" attribute of the <section> element", | |||
ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Inline manifest - Invalid attribute without name | |||
*/ | |||
@Test | |||
public void test10() { | |||
expectBuildExceptionContaining("test10", "Attribute has no name", | |||
"Attributes must have name and value"); | |||
try { | |||
buildRule.executeTarget("test10"); | |||
fail("BuildException expected: Attribute has no name"); | |||
} catch (BuildException ex) { | |||
assertContains("Attributes must have name and value", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Inline manifest - Invalid attribute without value | |||
*/ | |||
@Test | |||
public void test11() { | |||
expectBuildExceptionContaining("test11", "Attribute has no value", | |||
"Attributes must have name and value"); | |||
try { | |||
buildRule.executeTarget("test11"); | |||
fail("BuildException expected: Attribute has no value"); | |||
} catch (BuildException ex) { | |||
assertContains("Attributes must have name and value", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Inline manifest - Invalid attribute without value | |||
*/ | |||
@Test | |||
public void test12() { | |||
expectBuildExceptionContaining("test12", "Section with no name", | |||
"Sections must have a name"); | |||
try { | |||
buildRule.executeTarget("test12"); | |||
fail("BuildException expected: Section with no name"); | |||
} catch (BuildException ex) { | |||
assertContains("Sections must have a name", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Inline manifest - Duplicate attribute | |||
*/ | |||
@Test | |||
public void test13() { | |||
expectBuildExceptionContaining("test13", "Duplicate Attribute", | |||
"The attribute \"Test\" may not occur more than once in the same section"); | |||
try { | |||
buildRule.executeTarget("test13"); | |||
fail("BuildException expected: Duplicate Attribute"); | |||
} catch (BuildException ex) { | |||
assertContains("The attribute \"Test\" may not occur more than once in the same section", ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* Inline manifest - OK since classpath entries can be duplicated. | |||
*/ | |||
@Test | |||
public void test14() throws IOException, ManifestException { | |||
executeTarget("test14"); | |||
buildRule.executeTarget("test14"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
Manifest.Section mainSection = manifest.getMainSection(); | |||
String classpath = mainSection.getAttributeValue("class-path"); | |||
@@ -202,14 +263,15 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Tets long line wrapping | |||
*/ | |||
@Test | |||
public void testLongLine() throws IOException, ManifestException { | |||
Project p = getProject(); | |||
Project p = buildRule.getProject(); | |||
p.setUserProperty("test.longline", LONG_LINE); | |||
p.setUserProperty("test.long68name" , LONG_68_NAME); | |||
p.setUserProperty("test.long70name" , LONG_70_NAME); | |||
p.setUserProperty("test.notlongname" , NOT_LONG_NAME); | |||
p.setUserProperty("test.value", VALUE); | |||
executeTarget("testLongLine"); | |||
buildRule.executeTarget("testLongLine"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
Manifest.Section mainSection = manifest.getMainSection(); | |||
@@ -247,8 +309,9 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Tests ordering of sections | |||
*/ | |||
@Test | |||
public void testOrder1() throws IOException, ManifestException { | |||
executeTarget("testOrder1"); | |||
buildRule.executeTarget("testOrder1"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
Enumeration e = manifest.getSectionNames(); | |||
@@ -270,8 +333,9 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* Tests ordering of sections | |||
*/ | |||
@Test | |||
public void testOrder2() throws IOException, ManifestException { | |||
executeTarget("testOrder2"); | |||
buildRule.executeTarget("testOrder2"); | |||
Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
Enumeration e = manifest.getSectionNames(); | |||
@@ -293,15 +357,22 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* file attribute for manifest task is required. | |||
*/ | |||
@Test | |||
public void testNoFile() { | |||
expectBuildException("testNoFile", "file is required"); | |||
try { | |||
buildRule.executeTarget("testNoFile"); | |||
fail("BuildException expected: file is required"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
* replace changes Manifest-Version from 2.0 to 1.0 | |||
*/ | |||
@Test | |||
public void testReplace() throws IOException, ManifestException { | |||
executeTarget("testReplace"); | |||
buildRule.executeTarget("testReplace"); | |||
Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||
assertNotNull(mf); | |||
assertEquals(Manifest.getDefaultManifest(), mf); | |||
@@ -310,8 +381,9 @@ public class ManifestTest extends BuildFileTest { | |||
/** | |||
* update keeps the Manifest-Version and adds a new attribute Foo | |||
*/ | |||
@Test | |||
public void testUpdate() throws IOException, ManifestException { | |||
executeTarget("testUpdate"); | |||
buildRule.executeTarget("testUpdate"); | |||
Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||
assertNotNull(mf); | |||
assertTrue(!Manifest.getDefaultManifest().equals(mf)); | |||
@@ -328,28 +400,60 @@ public class ManifestTest extends BuildFileTest { | |||
assertTrue(mfAsString.indexOf("Foo: Baz") > -1); | |||
} | |||
@Test | |||
public void testFrom() { | |||
expectLogContaining("testFrom", Manifest.ERROR_FROM_FORBIDDEN); | |||
buildRule.executeTarget("testFrom"); | |||
assertContains(Manifest.ERROR_FROM_FORBIDDEN, buildRule.getLog()); | |||
} | |||
@Test | |||
public void testIllegalName() { | |||
expectBuildException("testIllegalName", "Manifest attribute names must not contain ' '"); | |||
try { | |||
buildRule.executeTarget("testIllegalName"); | |||
fail("BuildException expected: Manifest attribute names must not contain ' '"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testIllegalNameInSection() { | |||
expectBuildException("testIllegalNameInSection", "Manifest attribute names must not contain ' '"); | |||
try { | |||
buildRule.executeTarget("testIllegalNameInSection"); | |||
fail("BuildException expected: Manifest attribute names must not contain ' '"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testIllegalNameBegin() { | |||
expectBuildException("testIllegalNameInSection", "Manifest attribute names must not start with '-' at the begin."); | |||
try { | |||
buildRule.executeTarget("testIllegalNameInSection"); | |||
fail("BuildException expected: Manifest attribute names must not start with '-' at the begin."); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testIllegalName2() { | |||
expectBuildException("testIllegalName", "Manifest attribute names must not contain '.'"); | |||
try { | |||
buildRule.executeTarget("testIllegalName"); | |||
fail("BuildException expected: Manifest attribute names must not contain '.'"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void testIllegalName3() { | |||
expectBuildException("testIllegalName", "Manifest attribute names must not contain '*'"); | |||
try { | |||
buildRule.executeTarget("testIllegalName"); | |||
fail("BuildException expected: Manifest attribute names must not contain '*'"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
/** | |||
@@ -17,31 +17,50 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import static org.junit.Assert.fail; | |||
/** | |||
*/ | |||
public class MkdirTest extends BuildFileTest { | |||
public class MkdirTest { | |||
public MkdirTest(String name) { | |||
super(name); | |||
} | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/mkdir.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml"); | |||
} | |||
@Test | |||
public void test1() { | |||
expectBuildException("test1", "required argument missing"); | |||
try { | |||
buildRule.executeTarget("test1"); | |||
fail("BuildException expected: required argument missing"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test2() { | |||
expectBuildException("test2", "directory already exists as a file"); | |||
try { | |||
buildRule.executeTarget("test2"); | |||
fail("BuildException expected: directory already exists as a file"); | |||
} catch (BuildException ex) { | |||
//TODO assert value | |||
} | |||
} | |||
@Test | |||
public void test3() { | |||
executeTarget("test3"); | |||
java.io.File f = new java.io.File(getOutputDir(), "testdir.tmp"); | |||
buildRule.executeTarget("test3"); | |||
java.io.File f = new java.io.File(buildRule.getProject().getProperty("output"), "testdir.tmp"); | |||
if (!f.exists() || !f.isDirectory()) { | |||
fail("mkdir failed"); | |||
} else { | |||
@@ -18,126 +18,151 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.FileUtilities; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
/** | |||
* Tests the Move task. | |||
* | |||
*/ | |||
public class MoveTest extends BuildFileTest { | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
public MoveTest(String name) { | |||
super(name); | |||
} | |||
public class MoveTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/move.xml"); | |||
project.executeTarget("setUp"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/move.xml"); | |||
buildRule.executeTarget("setUp"); | |||
} | |||
@Test | |||
public void testFilterSet() throws IOException { | |||
executeTarget("testFilterSet"); | |||
File tmp = new File(getOutputDir(), "move.filterset.tmp"); | |||
File check = new File(getProjectDir(), "expected/copy.filterset.filtered"); | |||
buildRule.executeTarget("testFilterSet"); | |||
File tmp = new File(buildRule.getProject().getProperty("output"), "move.filterset.tmp"); | |||
File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); | |||
assertTrue(tmp.exists()); | |||
assertTrue(FILE_UTILS.contentEquals(tmp, check)); | |||
assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); | |||
} | |||
@Test | |||
public void testFilterChain() throws IOException { | |||
executeTarget("testFilterChain"); | |||
File tmp = new File(getOutputDir(), "move.filterchain.tmp"); | |||
File check = new File(getProjectDir(), "expected/copy.filterset.filtered"); | |||
buildRule.executeTarget("testFilterChain"); | |||
File tmp = new File(buildRule.getProject().getProperty("output"), "move.filterchain.tmp"); | |||
File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); | |||
assertTrue(tmp.exists()); | |||
assertTrue(FILE_UTILS.contentEquals(tmp, check)); | |||
assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); | |||
} | |||
/** Bugzilla Report 11732 */ | |||
@Test | |||
public void testDirectoryRemoval() throws IOException { | |||
executeTarget("testDirectoryRemoval"); | |||
assertTrue(!new File(getOutputDir(),"E/B/1").exists()); | |||
assertTrue(new File(getOutputDir(),"E/C/2").exists()); | |||
assertTrue(new File(getOutputDir(),"E/D/3").exists()); | |||
assertTrue(new File(getOutputDir(),"A/B/1").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/C/2").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/D/3").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/C").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/D").exists()); | |||
buildRule.executeTarget("testDirectoryRemoval"); | |||
String output = buildRule.getProject().getProperty("output"); | |||
assertTrue(!new File(output,"E/B/1").exists()); | |||
assertTrue(new File(output, "E/C/2").exists()); | |||
assertTrue(new File(output,"E/D/3").exists()); | |||
assertTrue(new File(output,"A/B/1").exists()); | |||
assertTrue(!new File(output,"A/C/2").exists()); | |||
assertTrue(!new File(output,"A/D/3").exists()); | |||
assertTrue(!new File(output,"A/C").exists()); | |||
assertTrue(!new File(output,"A/D").exists()); | |||
} | |||
/** Bugzilla Report 18886 */ | |||
@Test | |||
public void testDirectoryRetaining() throws IOException { | |||
executeTarget("testDirectoryRetaining"); | |||
assertTrue(new File(getOutputDir(),"E").exists()); | |||
assertTrue(new File(getOutputDir(),"E/1").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/1").exists()); | |||
assertTrue(new File(getOutputDir(),"A").exists()); | |||
buildRule.executeTarget("testDirectoryRetaining"); | |||
String output = buildRule.getProject().getProperty("output"); | |||
assertTrue(new File(output,"E").exists()); | |||
assertTrue(new File(output,"E/1").exists()); | |||
assertTrue(!new File(output,"A/1").exists()); | |||
assertTrue(new File(output,"A").exists()); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMove() throws IOException { | |||
testCompleteDirectoryMove("testCompleteDirectoryMove"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMove2() throws IOException { | |||
testCompleteDirectoryMove("testCompleteDirectoryMove2"); | |||
} | |||
private void testCompleteDirectoryMove(String target) throws IOException { | |||
executeTarget(target); | |||
assertTrue(new File(getOutputDir(),"E").exists()); | |||
assertTrue(new File(getOutputDir(),"E/1").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/1").exists()); | |||
buildRule.executeTarget(target); | |||
String output = buildRule.getProject().getProperty("output"); | |||
assertTrue(new File(output,"E").exists()); | |||
assertTrue(new File(output,"E/1").exists()); | |||
assertTrue(!new File(output,"A/1").exists()); | |||
// <path> swallows the basedir, it seems | |||
//assertTrue(!new File(getOutputDir(),"A").exists()); | |||
} | |||
@Test | |||
public void testPathElementMove() throws IOException { | |||
executeTarget("testPathElementMove"); | |||
assertTrue(new File(getOutputDir(),"E").exists()); | |||
assertTrue(new File(getOutputDir(),"E/1").exists()); | |||
assertTrue(!new File(getOutputDir(),"A/1").exists()); | |||
assertTrue(new File(getOutputDir(),"A").exists()); | |||
buildRule.executeTarget("testPathElementMove"); | |||
String output = buildRule.getProject().getProperty("output"); | |||
assertTrue(new File(output,"E").exists()); | |||
assertTrue(new File(output,"E/1").exists()); | |||
assertTrue(!new File(output,"A/1").exists()); | |||
assertTrue(new File(output,"A").exists()); | |||
} | |||
@Test | |||
public void testMoveFileAndFileset() { | |||
executeTarget("testMoveFileAndFileset"); | |||
buildRule.executeTarget("testMoveFileAndFileset"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveToExistingDir() { | |||
executeTarget("testCompleteDirectoryMoveToExistingDir"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveToExistingDir"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToFile() { | |||
executeTarget("testCompleteDirectoryMoveFileToFile"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToFile"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToDir() { | |||
executeTarget("testCompleteDirectoryMoveFileToDir"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToDir"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileAndFileset() { | |||
executeTarget("testCompleteDirectoryMoveFileAndFileset"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileAndFileset"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToExistingFile() { | |||
executeTarget("testCompleteDirectoryMoveFileToExistingFile"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingFile"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToExistingDir() { | |||
executeTarget("testCompleteDirectoryMoveFileToExistingDir"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingDir"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToDirWithExistingFile() { | |||
executeTarget("testCompleteDirectoryMoveFileToDirWithExistingFile"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingFile"); | |||
} | |||
@Test | |||
public void testCompleteDirectoryMoveFileToDirWithExistingDir() { | |||
executeTarget("testCompleteDirectoryMoveFileToDirWithExistingDir"); | |||
buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingDir"); | |||
} | |||
} |
@@ -18,44 +18,53 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.util.FileNameMapper; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
/** | |||
*/ | |||
public class MultiMapTest extends BuildFileTest { | |||
public MultiMapTest(String name) { | |||
super(name); | |||
} | |||
public class MultiMapTest { | |||
@Rule | |||
public final BuildFileRule buildRule = new BuildFileRule(); | |||
@Before | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/multimap.xml"); | |||
buildRule.configureProject("src/etc/testcases/taskdefs/multimap.xml"); | |||
} | |||
@Test | |||
public void testMultiCopy() { | |||
executeTarget("multicopy"); | |||
buildRule.executeTarget("multicopy"); | |||
} | |||
@Test | |||
public void testMultiMove() { | |||
executeTarget("multimove"); | |||
buildRule.executeTarget("multimove"); | |||
} | |||
@Test | |||
public void testSingleCopy() { | |||
executeTarget("singlecopy"); | |||
buildRule.executeTarget("singlecopy"); | |||
} | |||
@Test | |||
public void testSingleMove() { | |||
executeTarget("singlemove"); | |||
buildRule.executeTarget("singlemove"); | |||
} | |||
@Test | |||
public void testCopyWithEmpty() { | |||
executeTarget("copywithempty"); | |||
buildRule.executeTarget("copywithempty"); | |||
} | |||
@Test | |||
public void testMoveWithEmpty() { | |||
executeTarget("movewithempty"); | |||
buildRule.executeTarget("movewithempty"); | |||
} | |||
public static class TestMapper implements FileNameMapper { | |||