Browse Source

Parametrize filter tests

master
Gintas Grigelionis 7 years ago
parent
commit
50ceb93b62
4 changed files with 88 additions and 156 deletions
  1. +18
    -17
      src/etc/testcases/filters/build.xml
  2. +4
    -5
      src/etc/testcases/filters/head-tail.xml
  3. +36
    -97
      src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
  4. +30
    -37
      src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java

+ 18
- 17
src/etc/testcases/filters/build.xml View File

@@ -16,12 +16,13 @@
limitations under the License.
-->
<project default="tearDown" basedir=".">

<import file="../buildfiletest-base.xml"/>

<target name="setUp">
<mkdir dir="${output}" />
<mkdir dir="${output}"/>
</target>


<target name="testLineContains" depends="setUp">
<copy todir="${output}">
<fileset dir="input">
@@ -34,7 +35,7 @@
</filterchain>
</copy>
</target>
<target name="testNegateLineContains" depends="setUp">
<copy file="input/linecontains.test"
tofile="${output}/negatelinecontains.test">
@@ -49,12 +50,12 @@
<condition>
<not>
<filesmatch file1="${output}/negatelinecontains.test"
file2="expected/negatelinecontains.test" />
file2="expected/negatelinecontains.test"/>
</not>
</condition>
</fail>
</target>
<target name="testEscapeUnicode" depends="setUp">
<copy todir="${output}" encoding="UTF-8">
<fileset dir="input">
@@ -71,16 +72,16 @@

<target name="testStripJavaComments" depends="setUp">
<copy todir="${output}">
<fileset dir="input" includes="stripjavacomments.test" />
<fileset dir="input" includes="stripjavacomments.test"/>
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.StripJavaComments" />
<filterreader classname="org.apache.tools.ant.filters.StripJavaComments"/>
</filterchain>
</copy>
</target>

<target name="testReplaceTokens" depends="setUp">
<copy todir="${output}">
<fileset dir="input" includes="replacetokens.test" />
<copy tofile="${output}/replaceTokens.test">
<fileset dir="input" includes="replacetokens.test"/>
<filterchain>
<replacetokens>
<token key="foo" value=""/>
@@ -90,8 +91,8 @@
</target>

<target name="testReplaceTokensPropertyFile" depends="setUp">
<copy tofile="${output}/replacetokensPropertyFile.test">
<fileset dir="input" includes="replacetokens.test" />
<copy tofile="${output}/replaceTokensPropertyFile.test">
<fileset dir="input" includes="replacetokens.test"/>
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
<param type="propertiesfile" value="${basedir}/input/sample.properties"/>
@@ -101,8 +102,8 @@
</target>

<target name="testReplaceTokensDoubleEncoded" depends="setUp">
<copy todir="${output}">
<fileset dir="input" includes="replacetokens.double.test" />
<copy tofile="${output}/replaceTokensDoubleEncoded.test">
<fileset dir="input" includes="replacetokens.double.test"/>
<filterchain>
<replacetokens>
<token key="foo" value=""/>
@@ -112,8 +113,8 @@
</target>

<target name="testReplaceTokensDoubleEncodedToSimple" depends="setUp">
<copy todir="${output}">
<fileset dir="input" includes="replacetokens.double.test" />
<copy tofile="${output}/replaceTokensDoubleEncodedToSimple.test">
<fileset dir="input" includes="replacetokens.double.test"/>
<filterchain>
<replacetokens begintoken="@@" endtoken="@@">
<token key="foo" value=""/>
@@ -123,8 +124,8 @@
</target>

<target name="testReplaceTokensMustacheStyle" depends="setUp">
<copy todir="${output}">
<fileset dir="input" includes="replacetokens.mustache.test" />
<copy tofile="${output}/replaceTokensMustacheStyle.test">
<fileset dir="input" includes="replacetokens.mustache.test"/>
<filterchain>
<replacetokens begintoken="{{" endtoken="}}">
<token key="foo" value=""/>


+ 4
- 5
src/etc/testcases/filters/head-tail.xml View File

@@ -20,10 +20,9 @@
<import file="../buildfiletest-base.xml"/>

<target name="setUp">
<mkdir dir="${output}" />
<mkdir dir="${output}"/>
</target>


<!-- Testcases for HeadFilter -->

<target name="testHead" depends="setUp">
@@ -59,7 +58,7 @@
</target>

<target name="testFilterReaderHeadLinesSkip" depends="setUp">
<copy file="input/head-tail.test"
<copy file="input/head-tail.test"
tofile="${output}/head-tail.filterReaderHeadLinesSkip.test">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.HeadFilter">
@@ -113,7 +112,7 @@
</target>

<target name="testFilterReaderTailLinesSkip" depends="setUp">
<copy file="input/head-tail.test"
<copy file="input/head-tail.test"
tofile="${output}/head-tail.filterReaderTailLinesSkip.test">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.TailFilter">
@@ -135,7 +134,7 @@
<!-- Testcases for combined scenarios -->

<target name="testHeadTail" depends="setUp">
<copy file="input/head-tail.test" tofile="${output}/head-tail.headtail.test">
<copy file="input/head-tail.test" tofile="${output}/head-tail.headTail.test">
<filterchain>
<headfilter lines="4"/>
<tailfilter lines="2"/>


+ 36
- 97
src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java View File

@@ -20,12 +20,16 @@ package org.apache.tools.ant.filters;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;

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 org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.junit.Assert.assertEquals;

@@ -34,8 +38,31 @@ import static org.junit.Assert.assertEquals;
/* I wrote the testcases in one java file because I want also to test the
* combined behaviour (see end of the class).
*/
@RunWith(Parameterized.class)
public class HeadTailTest {

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> targets() {
return Arrays.asList(new Object [][] {
{"head", "head"},
{"headLines", "headLines"},
{"headSkip", "headSkip"},
{"headLinesSkip", "headLinesSkip"},
{"filterReaderHeadLinesSkip", "headLinesSkip"},
{"tail", "tail"},
{"tailSkip", "tailSkip"},
{"tailLines", "tailLines"},
{"tailLinesSkip", "tailLinesSkip"},
{"filterReaderTailLinesSkip", "tailLinesSkip"},
{"headTail", "headtail"}});
}

@Parameterized.Parameter
public String result;

@Parameterized.Parameter(1)
public String input;

@Rule
public BuildFileRule buildRule = new BuildFileRule();

@@ -45,102 +72,14 @@ public class HeadTailTest {
}

@Test
public void testHead() throws IOException {
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 {
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 {
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));
public void test() throws IOException {
buildRule.executeTarget("test" + result.substring(0, 1).toUpperCase()
+ result.substring(1));
File expected = buildRule.getProject().resolveFile("expected/head-tail."
+ input + ".test");
File actual = new File(buildRule.getProject().getProperty("output")
+ "/head-tail." + result + ".test");
assertEquals(result + ": Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(actual));
}

@Test
public void testHeadLinesSkip() throws IOException {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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));
}

}

+ 30
- 37
src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java View File

@@ -20,17 +20,38 @@ package org.apache.tools.ant.filters;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;

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 org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class ReplaceTokensTest {

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> targets() {
return Arrays.asList(new Object [][] {
{"replaceTokens", "replacetokens"},
{"replaceTokensPropertyFile", "replacetokens"},
{"replaceTokensDoubleEncoded", "replacetokens.double"},
{"replaceTokensDoubleEncodedToSimple", "replacetokens"},
{"replaceTokensMustacheStyle", "replacetokens"}});
}

@Parameterized.Parameter
public String result;

@Parameterized.Parameter(1)
public String input;

@Rule
public BuildFileRule buildRule = new BuildFileRule();

@@ -40,42 +61,14 @@ public class ReplaceTokensTest {
}

@Test
public void testReplaceTokens() throws IOException {
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 {
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));
}

@Test
public void testReplaceTokensDoubleEncoded() throws IOException {
buildRule.executeTarget("testReplaceTokensDoubleEncoded");
File expected = buildRule.getProject().resolveFile("expected/replacetokens.double.test");
File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.double.test");
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
}

@Test
public void testReplaceTokensDoubleEncodedToSimple() throws IOException {
buildRule.executeTarget("testReplaceTokensDoubleEncodedToSimple");
File expected = buildRule.getProject().resolveFile("expected/replacetokens.test");
File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.double.test");
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
}

@Test
public void testReplaceTokensMustacheStyle() throws IOException {
buildRule.executeTarget("testReplaceTokensMustacheStyle");
File expected = buildRule.getProject().resolveFile("expected/replacetokens.test");
File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.mustache.test");
assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
public void test() throws IOException {
buildRule.executeTarget("test" + result.substring(0, 1).toUpperCase()
+ result.substring(1));
File expected = buildRule.getProject().resolveFile("expected/"
+ input + ".test");
File actual = new File(buildRule.getProject().getProperty("output")
+ "/" + result + ".test");
assertEquals(result + ": Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(actual));
}
}

Loading…
Cancel
Save