diff options
Diffstat (limited to 'framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters')
9 files changed, 928 insertions, 0 deletions
diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java new file mode 100644 index 00000000..38583540 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java @@ -0,0 +1,143 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 { + + private static final String lSep = StringUtils.LINE_SEP; + + private static final String FILE_PREPEND_WITH = + "this-should-be-the-first-line" + lSep + + "Line 1" + lSep + + "Line 2" + lSep + + "Line 3" + lSep + + "Line 4" + lSep + ; + + private static final String FILE_PREPEND = + "Line 1" + lSep + + "Line 2" + lSep + + "Line 3" + lSep + + "Line 4" + lSep + + "Line 5" + lSep + ; + + private static final String FILE_APPEND_WITH = + "Line 57" + lSep + + "Line 58" + lSep + + "Line 59" + lSep + + "Line 60" + lSep + + "this-should-be-the-last-line" + lSep + ; + + private static final String FILE_APPEND = + "Line 56" + lSep + + "Line 57" + lSep + + "Line 58" + lSep + + "Line 59" + lSep + + "Line 60" + lSep + ; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/concat.xml"); + } + + @Test + public void testFilterReaderNoArgs() throws IOException { + 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)); + } + + @Test + public void testFilterReaderBefore() throws IOException { + doTest("testFilterReaderPrepend", FILE_PREPEND_WITH, FILE_APPEND); + } + + @Test + public void testFilterReaderAfter() throws IOException { + doTest("testFilterReaderAppend", FILE_PREPEND, FILE_APPEND_WITH); + } + + @Test + public void testFilterReaderBeforeAfter() throws IOException { + doTest("testFilterReaderPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); + } + + @Test + public void testConcatFilter() throws IOException { + doTest("testConcatFilter", FILE_PREPEND, FILE_APPEND); + } + + @Test + public void testConcatFilterBefore() throws IOException { + doTest("testConcatFilterPrepend", FILE_PREPEND_WITH, FILE_APPEND); + } + + @Test + public void testConcatFilterAfter() throws IOException { + doTest("testConcatFilterAppend", FILE_PREPEND, FILE_APPEND_WITH); + } + + @Test + public void testConcatFilterBeforeAfter() throws IOException { + doTest("testConcatFilterPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); + } + + + /** + * Executes a target and checks the beginning and the ending of a file. + * The filename depends on the target name: target name <i>testHelloWorld</i> + * will search for a file <i>result/concat.HelloWorld.test</i>. + * @param target The target to invoke + * @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) 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)); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java new file mode 100644 index 00000000..5de7f6bc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java @@ -0,0 +1,80 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.Reader; +import java.io.IOException; + +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.apache.tools.ant.AntAssert.assertContains; + +public class DynamicFilterTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/dynamicfilter.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testCustomFilter() throws IOException { + buildRule.executeTarget("dynamicfilter"); + String content = FileUtilities.getFileContents( + new File(buildRule.getProject().getProperty("output") + "/dynamicfilter")); + assertContains("hellO wOrld", content); + } + + + + public static class CustomFilter implements ChainableReader { + char replace = 'x'; + char with = 'y'; + + public void setReplace(char replace) { + this.replace = replace; + } + + public void setWith(char with) { + this.with = with; + } + + public Reader chain(final Reader rdr) { + return new BaseFilterReader(rdr) { + public int read() + throws IOException + { + int c = in.read(); + if (c == replace) + return with; + else + return c; + } + }; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java new file mode 100644 index 00000000..7c5e3040 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java @@ -0,0 +1,50 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 EscapeUnicodeTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @Test + public void testEscapeUnicode() throws IOException { + 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)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java new file mode 100644 index 00000000..7c910d12 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java @@ -0,0 +1,137 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/head-tail.xml"); + } + + @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)); + } + + @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)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java new file mode 100644 index 00000000..9dcb291b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java @@ -0,0 +1,57 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 LineContainsTest { + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @Test + public void testLineContains() throws IOException { + 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 { + buildRule.executeTarget("testNegateLineContains"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java new file mode 100644 index 00000000..c12a1d3f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java @@ -0,0 +1,50 @@ +/* + * 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.filters; + +import java.io.IOException; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + + @Test + public void testNoAddNewLine() throws IOException { + buildRule.executeTarget("testNoAddNewLine"); + } + + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java new file mode 100644 index 00000000..4db8d7a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java @@ -0,0 +1,81 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 ReplaceTokensTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @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)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java new file mode 100644 index 00000000..7114d497 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java @@ -0,0 +1,51 @@ +/* + * 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.filters; + +import java.io.File; +import java.io.IOException; + +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 StripJavaCommentsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + + @Test + public void testStripJavaComments() throws IOException { + 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)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java new file mode 100644 index 00000000..f0db15a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java @@ -0,0 +1,279 @@ +/* + * 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.filters; + +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.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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); + buildRule.executeTarget("setUp"); + } + + /** make sure tokenfilter exists */ + @Test + public void testTokenfilter() throws IOException { + buildRule.executeTarget("tokenfilter"); + } + + @Test + public void testTrimignore() throws IOException { + buildRule.executeTarget("trimignore"); + assertContains("Hello-World", buildRule.getLog()); + } + + @Test + public void testStringTokenizer() throws IOException { + buildRule.executeTarget("stringtokenizer"); + assertContains("#This#is#a#number#of#words#", buildRule.getLog()); + } + + @Test + public void testUnixLineOutput() throws IOException { + buildRule.executeTarget("unixlineoutput"); + assertContains("\nThis\nis\na\nnumber\nof\nwords\n", + getFileString(buildRule.getProject().getProperty("output") + "/unixlineoutput")); + } + + @Test + public void testDosLineOutput() throws IOException { + + 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 { + 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 { + buildRule.executeTarget("replacestring"); + assertContains("this is the moon", + getFileString(buildRule.getProject().getProperty("output") + "/replacestring")); + } + + @Test + public void testReplaceStrings() throws IOException { + buildRule.executeTarget("replacestrings"); + assertContains("bar bar bar", buildRule.getLog()); + } + + @Test + public void testContainsString() throws IOException { + 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 { + + 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 { + 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 { + 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 { + 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.")); + assertContains(" This is the second", contents); + } + + @Test + public void testTrimFileByLine() throws IOException { + 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.")); + assertNotContains(" This is the second", contents); + assertContains("file.\nThis is the second", contents); + } + + @Test + public void testFilterReplaceString() throws IOException { + buildRule.executeTarget("filterreplacestring"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplacestring"); + assertContains("This is the moon", contents); + } + + @Test + public void testFilterReplaceStrings() throws IOException { + buildRule.executeTarget("filterreplacestrings"); + assertContains("bar bar bar", buildRule.getLog()); + } + + @Test + public void testContainsRegex() throws IOException { + 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 { + 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 { + 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 { + 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 { + 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")); + + } + + @Test + public void testScriptFilter2() throws IOException { + 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 { + buildRule.executeTarget("customtokenfilter"); + assertContains("Hello World", getFileString(buildRule.getProject().getProperty("output") + "/custom")); + } + + // ------------------------------------------------------ + // Helper methods + // ----------------------------------------------------- + + private String getFileString(String filename) + throws IOException + { + Reader r = null; + try { + r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename)); + return FileUtils.readFully(r); + } + finally { + FileUtils.close(r); + } + } + + + public static class Capitalize + implements TokenFilter.Filter + { + public String filter(String token) { + if (token.length() == 0) + return token; + return token.substring(0, 1).toUpperCase() + + token.substring(1); + } + } + +} |