diff options
Diffstat (limited to 'framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs')
152 files changed, 22300 insertions, 0 deletions
diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java new file mode 100644 index 00000000..227987fa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java @@ -0,0 +1,71 @@ +/* + * 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.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 static org.junit.Assert.assertTrue; + +/** + */ +public class AbstractCvsTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/abstractcvstask.xml"); + buildRule.executeTarget("setUp"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testAbstractCvsTask() { + buildRule.executeTarget("all"); + } + + @Test + public void testPackageAttribute() { + File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); + assertTrue("starting empty", !f.exists()); + 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(buildRule.getProject().getProperty("output") + "/src/Makefile"); + assertTrue("starting empty", !f.exists()); + buildRule.executeTarget("tag-attribute"); + AntAssert.assertContains("OPENBSD_5_3", buildRule.getLog()); + assertTrue("now it is there", f.exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java new file mode 100644 index 00000000..298bf098 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java @@ -0,0 +1,70 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildException; +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testAnt() { + try { + 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" + + " build file.", e.getMessage()); + } + } + + @Test + public void testSubant() { + try { + 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" + + " build file.", e.getMessage()); + } + } + + @Test + public void testAntcall() { + try { + 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.", + e.getMessage()); + } + } + +}// AntLikeTasksAtTopLevelTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java new file mode 100644 index 00000000..da51b5d9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java @@ -0,0 +1,114 @@ +/* + * 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.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 static org.junit.Assert.fail; + +/** + */ +public class AntStructureTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/antstructure.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void 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. + AntAssert.assertContains(MyPrinter.TAIL_CALLED, buildRule.getLog()); + } + + public static class MyPrinter implements AntStructure.StructurePrinter { + private static final String TAIL_CALLED = "tail has been called"; + private boolean headCalled = false; + private boolean targetCalled = false; + private boolean tailCalled = false; + private int elementCalled = 0; + private Project p; + + public void printHead(PrintWriter out, Project p, Hashtable tasks, + Hashtable types) { + Assert.assertTrue(!headCalled); + Assert.assertTrue(!targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertEquals(0, elementCalled); + headCalled = true; + } + public void printTargetDecl(PrintWriter out) { + Assert.assertTrue(headCalled); + Assert.assertTrue(!targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertEquals(0, elementCalled); + targetCalled = true; + } + public void printElementDecl(PrintWriter out, Project p, String name, + Class element) { + Assert.assertTrue(headCalled); + Assert.assertTrue(targetCalled); + Assert.assertTrue(!tailCalled); + elementCalled++; + this.p = p; + } + public void printTail(PrintWriter out) { + Assert.assertTrue(headCalled); + Assert.assertTrue(targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertTrue(elementCalled > 0); + tailCalled = true; + p.log(TAIL_CALLED); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java new file mode 100644 index 00000000..0d6453c4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java @@ -0,0 +1,607 @@ +/* + * 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.taskdefs; + +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.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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/ant.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + // target must be specified + @Test + public void test2() { + 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() { + try { + buildRule.executeTarget("test1"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("target attribute must not be empty"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4b() { + try { + buildRule.executeTarget("test4b"); + fail("target doesn't exist"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void testExplicitBasedir1() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile(".."); + testBaseDirs("explicitBasedir1", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath() + }); + } + + @Test + public void testExplicitBasedir2() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile(".."); + testBaseDirs("explicitBasedir2", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath() + }); + } + + @Test + public void testInheritBasedir() { + String basedir = buildRule.getProject().getBaseDir().getAbsolutePath(); + testBaseDirs("inheritBasedir", new String[] {basedir, basedir}); + } + + @Test + public void testDoNotInheritBasedir() { + 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 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile("ant"); + testBaseDirs("tripleCall", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir1.getAbsolutePath() + }); + } + + protected void testBaseDirs(String target, String[] dirs) { + BasedirChecker bc = new BasedirChecker(dirs); + buildRule.getProject().addBuildListener(bc); + buildRule.executeTarget(target); + AssertionFailedError ae = bc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(bc); + } + + @Test + public void testReferenceInheritance() { + Path p = Path.systemClasspath; + 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", + new String[] {"no-override", "no-override"}, + new boolean[] {true, false}, p); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {false, false}, null); + } + + @Test + public void testReferenceNoInheritance() { + Path p = Path.systemClasspath; + 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"}, + new boolean[] {false, true}, null); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {true, false}, p); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {false, false}, null); + } + + @Test + public void testReferenceRename() { + Path p = Path.systemClasspath; + 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"}, + new boolean[] {false, true}, null); + testReference("testRename", new String[] {"newpath", "newpath"}, + new boolean[] {false, true}, p); + } + + @Test + public void testInheritPath() { + buildRule.executeTarget("testInheritPath"); + } + + protected void testReference(String target, String[] keys, + boolean[] expect, Object value) { + ReferenceChecker rc = new ReferenceChecker(keys, expect, value); + buildRule.getProject().addBuildListener(rc); + buildRule.executeTarget(target); + AssertionFailedError ae = rc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(rc); + } + + @Test + public void testLogfilePlacement() { + File[] logFiles = new File[] { + 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()); + } + + buildRule.executeTarget("testLogfilePlacement"); + + for (int i=0; i<logFiles.length; i++) { + assertTrue(logFiles[i].getName()+" exists", + logFiles[i].exists()); + } + } + + @Test + public void testInputHandlerInheritance() { + InputHandler ih = new PropertyFileInputHandler(); + buildRule.getProject().setInputHandler(ih); + InputHandlerChecker ic = new InputHandlerChecker(ih); + buildRule.getProject().addBuildListener(ic); + buildRule.executeTarget("tripleCall"); + AssertionFailedError ae = ic.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(ic); + } + + @Test + public void testRefId() { + Path testPath = new Path(buildRule.getProject()); + testPath.createPath().setPath(System.getProperty("java.class.path")); + PropertyChecker pc = + new PropertyChecker("testprop", + new String[] {null, + testPath.toString()}); + buildRule.getProject().addBuildListener(pc); + buildRule.executeTarget("testRefid"); + AssertionFailedError ae = pc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(pc); + } + + @Test + public void testUserPropertyWinsInheritAll() { + 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() { + 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() { + buildRule.executeTarget("test-property-override-inheritall-start"); + + AntAssert.assertContains("The value of test is 4", buildRule.getLog()); + } + + @Test + public void testOverrideWinsNoInheritAll() { + buildRule.executeTarget("test-property-override-no-inheritall-start"); + AntAssert.assertContains("The value of test is 4", buildRule.getLog()); + } + + @Test + public void testPropertySet() { + 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() { + try { + buildRule.executeTarget("infinite-loop-via-depends"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testMultiSameProperty() { + buildRule.executeTarget("multi-same-property"); + assertEquals("prop is two", buildRule.getLog()); + } + + @Test + public void testTopLevelTarget() { + 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"}); + buildRule.getProject().addBuildListener(pcBar); + buildRule.getProject().addBuildListener(pcFoo); + buildRule.executeTarget("multiple-property-file-children"); + AssertionFailedError aeBar = pcBar.getError(); + if (aeBar != null) { + throw aeBar; + } + AssertionFailedError aeFoo = pcFoo.getError(); + if (aeFoo != null) { + throw aeFoo; + } + buildRule.getProject().removeBuildListener(pcBar); + buildRule.getProject().removeBuildListener(pcFoo); + } + + @Test + public void testBlankTarget() { + try { + buildRule.executeTarget("blank-target"); + fail("target name must not be empty"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multiple-targets"); + assertEquals("tadadctbdbtc", buildRule.getLog()); + } + + @Test + public void testMultipleTargets2() { + buildRule.executeTarget("multiple-targets-2"); + assertEquals("dadctb", buildRule.getLog()); + } + + @Test + public void testAntCoreLib() { + // Cf. #42263 + buildRule.executeTarget("sub-show-ant.core.lib"); + String realLog = buildRule.getLog(); + assertTrue("found ant.core.lib in: " + realLog, realLog.matches(".*(ant[.]jar|build.classes).*")); + } + + private class BasedirChecker implements BuildListener { + private String[] expectedBasedirs; + private int calls = 0; + private AssertionFailedError error; + + BasedirChecker(String[] dirs) { + expectedBasedirs = dirs; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + assertEquals(expectedBasedirs[calls++], + event.getProject().getBaseDir().getAbsolutePath()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class ReferenceChecker implements BuildListener { + private String[] keys; + private boolean[] expectSame; + private Object value; + private int calls = 0; + private AssertionFailedError error; + + ReferenceChecker(String[] keys, boolean[] expectSame, Object value) { + this.keys = keys; + this.expectSame = expectSame; + this.value = value; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + String msg = + "Call " + calls + " refid=\'" + keys[calls] + "\'"; + if (value == null) { + Object o = event.getProject().getReference(keys[calls]); + if (expectSame[calls++]) { + assertNull(msg, o); + } else { + assertNotNull(msg, o); + } + } else { + // a rather convoluted equals() test + Path expect = (Path) value; + Path received = (Path) event.getProject().getReference(keys[calls]); + boolean shouldBeEqual = expectSame[calls++]; + if (received == null) { + assertTrue(msg, !shouldBeEqual); + } else { + String[] l1 = expect.list(); + String[] l2 = received.list(); + if (l1.length == l2.length) { + for (int i=0; i<l1.length; i++) { + if (!l1[i].equals(l2[i])) { + assertTrue(msg, !shouldBeEqual); + } + } + assertTrue(msg, shouldBeEqual); + } else { + assertTrue(msg, !shouldBeEqual); + } + } + } + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class InputHandlerChecker implements BuildListener { + private InputHandler ih; + private AssertionFailedError error; + + InputHandlerChecker(InputHandler value) { + ih = value; + } + + public void buildStarted(BuildEvent event) { + check(event); + } + public void buildFinished(BuildEvent event) { + check(event); + } + public void targetFinished(BuildEvent event) { + check(event); + } + public void taskStarted(BuildEvent event) { + check(event); + } + public void taskFinished(BuildEvent event) { + check(event); + } + public void messageLogged(BuildEvent event) { + check(event); + } + + public void targetStarted(BuildEvent event) { + check(event); + } + + private void check(BuildEvent event) { + if (error == null) { + try { + assertNotNull(event.getProject().getInputHandler()); + assertSame(ih, event.getProject().getInputHandler()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class PropertyChecker implements BuildListener { + private String[] expectedValues; + private String key; + private int calls = 0; + private AssertionFailedError error; + + PropertyChecker(String key, String[] values) { + this.key = key; + this.expectedValues = values; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (calls >= expectedValues.length) { + error = new AssertionFailedError("Unexpected invocation of" + + " target " + + event.getTarget().getName()); + } + + if (error == null) { + try { + assertEquals(expectedValues[calls++], + event.getProject().getProperty(key)); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java new file mode 100644 index 00000000..c5c78ab3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java @@ -0,0 +1,106 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/antlib.xml"); + } + + /** + * only do the antlib tests if we are in the same JVM as ant. + * @return + */ + private boolean isSharedJVM() { + String property = System.getProperty("tests.and.ant.share.classloader"); + return property!=null && Project.toBoolean(property); + } + + @Test + public void testAntlibFile() { + buildRule.executeTarget("antlib.file"); + assertEquals("MyTask called", buildRule.getLog()); + } + + /** + * Confirms that all matching resources will be used, so that you + * can collect several antlibs in one Definer call. + * @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=24024" + */ + @Test + public void testAntlibResource() { + buildRule.executeTarget("antlib.resource"); + assertEquals("MyTask called-and-then-MyTask2 called", buildRule.getLog()); + } + + @Test + public void testNsCurrent() { + buildRule.executeTarget("ns.current"); + assertEquals("Echo2 inside a macroHello from x:p", buildRule.getLog()); + } + + @Test + public void testAntlib_uri() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri"); + } + + @Test + public void testAntlib_uri_auto() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri_auto"); + } + + @Test + public void testAntlib_uri_auto2() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri_auto2"); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + + public static class MyTask2 extends Task { + public void execute() { + log("MyTask2 called"); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java new file mode 100644 index 00000000..ef97e375 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java @@ -0,0 +1,272 @@ +/* + * 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.taskdefs; + +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 { + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/available.xml"); + buildRule.executeTarget("setUp"); + } + + // Nothing specified -> Fail + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // Only property specified -> Fail + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // Only file specified -> Fail + @Test + public void test3() { + 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() { + buildRule.executeTarget("test4"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // file does exist -> property 'test' == 'true' + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // resource doesn't exist -> property 'test' == null + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // resource does exist -> property 'test' == 'true' + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // class doesn't exist -> property 'test' == null + @Test + public void test8() { + buildRule.executeTarget("test8"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // class does exist -> property 'test' == 'true' + @Test + public void test9() { + buildRule.executeTarget("test9"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // All three specified and all three exist -> true + @Test + public void test10() { + buildRule.executeTarget("test10"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // All three specified but class missing -> null + @Test + public void test11() { + buildRule.executeTarget("test11"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified property-name is "" -> true + @Test + public void test12() { + 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() { + buildRule.executeTarget("test13"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified file is "" actually a directory, so it should pass + @Test + public void test13b() { + buildRule.executeTarget("test13b"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Specified resource is "" -> can such a thing exist? + /* + * returns non null IBM JDK 1.3 Linux + */ +// public void test14() { +// buildRule.executeTarget("test14"); +// assertEquals(buildRule.getProject().getProperty("test"), null); +// } + + // Specified class is "" -> can not exist + @Test + public void test15() { + buildRule.executeTarget("test15"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified dir is "" -> this is the current directory and should + // always exist + @Test + public void test16() { + 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() { + buildRule.executeTarget("test17"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Specified dir is "../this_dir_should_never_exist" -> null + @Test + public void test18() { + buildRule.executeTarget("test18"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Invalid type specified + @Test + public void test19() { + 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() { + 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() { + 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() { + 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() { + buildRule.executeTarget("test23"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Class is found in specified classpath + @Test + public void test24() { + buildRule.executeTarget("test24"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // File is not found in specified filepath + @Test + public void testSearchInPathNotThere() { + buildRule.executeTarget("searchInPathNotThere"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // File is not found in specified filepath + @Test + public void testSearchInPathIsThere() { + buildRule.executeTarget("searchInPathIsThere"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // test when file begins with basedir twice + @Test + public void testDoubleBasedir() { + buildRule.executeTarget("testDoubleBasedir"); + } + + // test for searching parents + @Test + public void testSearchParents() { + buildRule.executeTarget("search-parents"); + } + // test for not searching parents + @Test + public void testSearchParentsNot() { + buildRule.executeTarget("search-parents-not"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java new file mode 100644 index 00000000..9ea9a4ff --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java @@ -0,0 +1,66 @@ +/* + * 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.taskdefs; + +import java.io.File; +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private File outputDir; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/bunzip2.xml"); + outputDir = new File(buildRule.getProject().getProperty("output")); + buildRule.executeTarget("prepare"); + } + + @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 { + buildRule.executeTarget(target); + assertEquals("File content mismatch after bunzip2", + FileUtilities.getFileContents(new File(outputDir, "asf-logo-huge-from-gzip.tar")), + FileUtilities.getFileContents(new File(outputDir, "asf-logo-huge.tar"))); + } + + @Test + public void testDocumentationClaimsOnCopy() throws java.io.IOException { + testRealTest("testDocumentationClaimsOnCopy"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java new file mode 100644 index 00000000..bd881430 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java @@ -0,0 +1,117 @@ +/* + * 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.taskdefs; + +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.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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private File outputDir; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/bzip2.xml"); + outputDir = new File(buildRule.getProject().getProperty("output")); + buildRule.executeTarget("prepare"); + } + + @Test + public void testRealTest() throws IOException { + buildRule.executeTarget("realTest"); + + // doesn't work: Depending on the compression engine used, + // compressed bytes may differ. False errors would be + // reported. + // assertTrue("File content mismatch", + // FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"), + // project.resolveFile("asf-logo-huge.tar.bz2"))); + + // We have to compare the decompressed content instead: + + File originalFile = + buildRule.getProject().resolveFile("expected/asf-logo-huge.tar.bz2"); + File actualFile = new File(outputDir, "asf-logo-huge.tar.bz2"); + + InputStream originalIn = + new BufferedInputStream(new FileInputStream(originalFile)); + assertEquals((byte) 'B', originalIn.read()); + assertEquals((byte) 'Z', originalIn.read()); + + InputStream actualIn = + new BufferedInputStream(new FileInputStream(actualFile)); + assertEquals((byte) 'B', actualIn.read()); + assertEquals((byte) 'Z', actualIn.read()); + + originalIn = new CBZip2InputStream(originalIn); + actualIn = new CBZip2InputStream(actualIn); + + while (true) { + int expected = originalIn.read(); + int actual = actualIn.read(); + if (expected >= 0) { + if (expected != actual) { + fail("File content mismatch"); + } + } else { + if (actual >= 0) { + fail("File content mismatch"); + } + break; + } + } + + originalIn.close(); + actualIn.close(); + } + + @Test + public void testResource(){ + buildRule.executeTarget("realTestWithResource"); + } + + @Test + public void testDateCheck(){ + 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.")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java new file mode 100644 index 00000000..3915d6b1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java @@ -0,0 +1,114 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/basename.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + String checkprop = buildRule.getProject().getProperty("file.w.suf"); + assertEquals("foo.txt", checkprop); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo", checkprop); + } + + @Test + public void testMultipleDots() { + buildRule.executeTarget("testMultipleDots"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo.bar", checkprop); + } + + @Test + public void testNoDots() { + buildRule.executeTarget("testNoDots"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo.bar", checkprop); + } + + @Test + public void testValueEqualsSuffixWithDot() { + buildRule.executeTarget("testValueEqualsSuffixWithDot"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("", checkprop); + } + + @Test + public void testValueEqualsSuffixWithoutDot() { + buildRule.executeTarget("testValueEqualsSuffixWithoutDot"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("", checkprop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java new file mode 100644 index 00000000..9fe42b15 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java @@ -0,0 +1,119 @@ +/* + * 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.taskdefs; + +import java.io.*; + +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 { + 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"; + private static final String XML_URL = + ":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(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/cvspass.xml"); + } + + @Test + public void testNoCVSRoot() { + try{ + buildRule.executeTarget("test1"); + fail("BuildException not thrown"); + }catch(BuildException e){ + assertEquals("cvsroot is required", e.getMessage()); + } + } + + @Test + public void testNoPassword() { + try{ + buildRule.executeTarget("test2"); + fail("BuildException not thrown"); + }catch(BuildException e){ + assertEquals("password is required", e.getMessage()); + } + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testPassFile() throws Exception { + buildRule.executeTarget("test3"); + File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); + + assertTrue( "Passfile "+f+" not created", f.exists()); + + assertEquals(JAKARTA_URL+EOL, FileUtilities.getFileContents(f)); + + } + + @Test + public void testPassFileDuplicateEntry() throws Exception { + 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, + FileUtilities.getFileContents(f)); + } + + @Test + public void testPassFileMultipleEntry() throws Exception { + buildRule.executeTarget("test5"); + File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); + + assertTrue( "Passfile "+f+" not created", f.exists()); + + assertEquals( + JAKARTA_URL+ EOL+ + XML_URL+ EOL+ + TIGRIS_URL+ EOL, + FileUtilities.getFileContents(f)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java new file mode 100644 index 00000000..337c6a46 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java @@ -0,0 +1,92 @@ +/* + * 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.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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class CallTargetTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void 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() { + buildRule.executeTarget("testinheritreffileset"); + AntAssert.assertContains("calltarget.xml", buildRule.getLog()); + } + + // see bugrep 21724 (references not passing through with antcall) + @Test + public void testInheritFilterset() { + 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<String> v = new Vector<String>(); + v.add("call-multi"); + v.add("call-multi"); + buildRule.getProject().executeTargets(v); + AntAssert.assertContains("multi is SETmulti is SET", buildRule.getLog()); + } + + @Test + public void testBlankTarget() { + try { + buildRule.executeTarget("blank-target"); + fail("target name must not be empty"); + } catch (BuildException ex) { + //TODO assert exception contents + } + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multiple-targets"); + assertEquals("tadadctbdbtc", buildRule.getLog()); + } + + @Test + public void testMultipleTargets2() { + buildRule.executeTarget("multiple-targets-2"); + assertEquals("dadctb", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java new file mode 100644 index 00000000..bd4bdfcf --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java @@ -0,0 +1,109 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/checksum.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testCreateMd5() throws IOException { + buildRule.executeTarget("createMd5"); + } + + @Test + public void testCreateMD5SUMformat() throws IOException { + buildRule.executeTarget("createMD5SUMformat"); + } + + @Test + public void testCreateSVFformat() throws IOException { + buildRule.executeTarget("createSVFformat"); + } + + @Test + public void testCreatePattern() throws IOException { + buildRule.executeTarget("createPattern"); + } + + @Test + public void testSetProperty() { + buildRule.executeTarget("setProperty"); + } + + @Test + public void testVerifyTotal() { + buildRule.executeTarget("verifyTotal"); + } + + @Test + public void testVerifyTotalRC() { + buildRule.executeTarget("verifyTotalRC"); + } + + @Test + public void testVerifyChecksumdir() { + buildRule.executeTarget("verifyChecksumdir"); + } + + @Test + public void testVerifyAsTask() { + buildRule.executeTarget("verifyAsTask"); + } + + @Test + public void testVerifyMD5SUMAsTask() { + buildRule.executeTarget("verifyMD5SUMAsTask"); + } + + @Test + public void testVerifyAsCondition() { + buildRule.executeTarget("verifyAsCondition"); + } + + @Test + public void testVerifyFromProperty() { + buildRule.executeTarget("verifyFromProperty"); + } + + @Test + public void testVerifyChecksumdirNoTotal() { + buildRule.executeTarget("verifyChecksumdirNoTotal"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java new file mode 100644 index 00000000..b5441830 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java @@ -0,0 +1,315 @@ +/* + * 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.taskdefs; + +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.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; + +/** + * A test class for the 'concat' task, used to concatenate a series of + * files into a single stream. + * + */ +public class ConcatTest { + + /** + * The name of the temporary file. + */ + private static final String tempFile = "concat.tmp"; + + /** + * The name of the temporary file. + */ + private static final String tempFile2 = "concat.tmp.2"; + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + /** + * Test set up, called by the unit test framework prior to each + * test. + */ + @Before + public void setUp() { + 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() { + buildRule.executeTarget("cleanup"); + } + + /** + * Expect an exception when insufficient information is provided. + */ + @Test + public void test1() { + 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() { + 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(buildRule.getProject().getBaseDir(), tempFile); + if (file.exists()) { + file.delete(); + } + + buildRule.executeTarget("test3"); + + assertTrue(file.exists()); + } + + /** + * Cats the file created in test3 three times. + */ + @Test + public void test4() { + test3(); + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("test4"); + + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + final long newSize = file2.length(); + + assertEquals(origSize * 3, newSize); + } + + /** + * Cats the string 'Hello, World!' to the console. + */ + @Test + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("Hello, World!", buildRule.getLog()); + } + + @Test + public void test6() { + String filename = "src/etc/testcases/taskdefs/thisfiledoesnotexist" + .replace('/', File.separatorChar); + buildRule.executeTarget("test6"); + assertContains(filename + " does not exist", buildRule.getLog()); + } + + @Test + public void testConcatNoNewline() { + buildRule.executeTarget("testConcatNoNewline"); + assertEquals("ab", buildRule.getLog()); + } + + @Test + public void testConcatNoNewlineEncoding() { + buildRule.executeTarget("testConcatNoNewlineEncoding"); + assertEquals("ab", buildRule.getLog()); + } + + @Test + public void testPath() { + test3(); + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("testPath"); + + 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(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("testAppend"); + + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + final long newSize = file2.length(); + + assertEquals(origSize*2, newSize); + + } + + @Test + public void testFilter() { + buildRule.executeTarget("testfilter"); + assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); + } + + @Test + public void testNoOverwrite() { + buildRule.executeTarget("testnooverwrite"); + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + long size = file2.length(); + assertEquals(size, 0); + } + + @Test + public void testOverwrite() { + buildRule.executeTarget("testoverwrite"); + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + long size = file2.length(); + assertTrue(size > 0); + } + + @Test + public void testheaderfooter() { + test3(); + buildRule.executeTarget("testheaderfooter"); + assertEquals("headerHello, World!footer", buildRule.getLog()); + } + + @Test + public void testfileheader() { + test3(); + 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() { + 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() { + buildRule.executeTarget("testfilterinline"); + assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); + } + + /** + * Check if multireader works + */ + @Test + public void testmultireader() { + 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 + { + 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 + { + buildRule.executeTarget("testfixlastlineeol"); + assertContains("end of line\rThis has", FileUtilities.getFileContents(buildRule.getProject(), "concat.linecr")); + } + + + @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)); + } + + // ------------------------------------------------------ + // Helper methods - should be in a utility class + // ----------------------------------------------------- + private void expectFileContainsx( + String target, String filename, String contains) + throws IOException + { + buildRule.executeTarget(target); + String content = FileUtilities.getFileContents(buildRule.getProject(), filename); + assertTrue( + "expecting file " + filename + " to contain " + + contains + + " but got " + content, content.indexOf(contains) > -1); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java new file mode 100644 index 00000000..1b6c1039 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -0,0 +1,379 @@ +/* + * 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.taskdefs; + +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.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +public class ConditionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + /** + * The JUnit setup method + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/condition.xml"); + } + + + /** + * The teardown method for JUnit + */ + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testBasic() { + buildRule.executeTarget("basic"); + assertEquals("true", buildRule.getProject().getProperty("basic")); + } + + @Test + public void testConditionIncomplete() { + 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() { + 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() { + buildRule.executeTarget("shortcut"); + assertEquals("set", buildRule.getProject().getProperty("shortcut")); + } + + @Test + public void testUnset() { + buildRule.executeTarget("dontset"); + assertNull(buildRule.getProject().getProperty("dontset")); + } + + @Test + public void testSetValue() { + buildRule.executeTarget("setvalue"); + assertEquals("woowoo", buildRule.getProject().getProperty("setvalue")); + } + + @Test + public void testNegation() { + buildRule.executeTarget("negation"); + assertEquals("true", buildRule.getProject().getProperty("negation")); + } + + @Test + public void testNegationFalse() { + buildRule.executeTarget("negationfalse"); + assertNull(buildRule.getProject().getProperty("negationfalse")); + } + + @Test + public void testNegationIncomplete() { + 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() { + buildRule.executeTarget("and"); + assertEquals("true", buildRule.getProject().getProperty("and")); + } + + @Test + public void testAndFails() { + buildRule.executeTarget("andfails"); + assertNull(buildRule.getProject().getProperty("andfails")); + } + + @Test + public void testAndIncomplete() { + buildRule.executeTarget("andincomplete"); + assertNull(buildRule.getProject().getProperty("andincomplete")); + } + + @Test + public void testAndempty() { + buildRule.executeTarget("andempty"); + assertEquals("true", buildRule.getProject().getProperty("andempty")); + } + + @Test + public void testOr() { + buildRule.executeTarget("or"); + assertEquals("true", buildRule.getProject().getProperty("or")); + } + + @Test + public void testOrincomplete() { + buildRule.executeTarget("or"); + assertEquals("true", buildRule.getProject().getProperty("or")); + } + + @Test + public void testOrFails() { + buildRule.executeTarget("orfails"); + assertNull(buildRule.getProject().getProperty("orfails")); + } + + @Test + public void testOrboth() { + buildRule.executeTarget("orboth"); + assertEquals("true", buildRule.getProject().getProperty("orboth")); + } + + @Test + public void testFilesmatchIdentical() { + buildRule.executeTarget("filesmatch-identical"); + assertEquals("true", buildRule.getProject().getProperty("filesmatch-identical")); + } + + @Test + public void testFilesmatchIncomplete() { + 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() { + buildRule.executeTarget("filesmatch-oddsizes"); + assertNull(buildRule.getProject().getProperty("filesmatch-oddsizes")); + } + + @Test + public void testFilesmatchExistence() { + buildRule.executeTarget("filesmatch-existence"); + assertNull(buildRule.getProject().getProperty("filesmatch-existence")); + } + + @Test + public void testFilesmatchDifferent() { + buildRule.executeTarget("filesmatch-different"); + assertNull(buildRule.getProject().getProperty("filesmatch-different")); + } + + @Test + public void testFilesmatchMatch() { + buildRule.executeTarget("filesmatch-match"); + assertEquals("true", buildRule.getProject().getProperty("filesmatch-match")); + } + + @Test + public void testFilesmatchDifferentSizes() { + buildRule.executeTarget("filesmatch-different-sizes"); + assertNull(buildRule.getProject().getProperty("filesmatch-different-sizes")); + } + + @Test + public void testFilesmatchDifferentOnemissing() { + buildRule.executeTarget("filesmatch-different-onemissing"); + assertNull(buildRule.getProject().getProperty("filesmatch-different-onemissing")); + } + + @Test + public void testFilesmatchDifferentEol() { + buildRule.executeTarget("filesmatch-different-eol"); + } + + @Test + public void testFilesmatchSameEol() { + buildRule.executeTarget("filesmatch-same-eol"); + } + + @Test + public void testFilesmatchNeitherExist() { + buildRule.executeTarget("filesmatch-neitherexist"); + } + + @Test + public void testContains() { + buildRule.executeTarget("contains"); + assertEquals("true", buildRule.getProject().getProperty("contains")); + } + + @Test + public void testContainsDoesnt() { + buildRule.executeTarget("contains-doesnt"); + assertNull(buildRule.getProject().getProperty("contains-doesnt")); + } + + @Test + public void testContainsAnycase() { + buildRule.executeTarget("contains-anycase"); + assertEquals("true", buildRule.getProject().getProperty("contains-anycase")); + } + + @Test + public void testContainsIncomplete1() { + 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() { + 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() { + buildRule.executeTarget("istrue"); + assertEquals("true", buildRule.getProject().getProperty("istrue")); + } + + @Test + public void testIstrueNot() { + buildRule.executeTarget("istrue-not"); + assertNull(buildRule.getProject().getProperty("istrue-not")); + } + + @Test + public void testIstrueFalse() { + buildRule.executeTarget("istrue-false"); + assertNull(buildRule.getProject().getProperty("istrue-false")); + } + + @Test + public void testIstrueIncomplete1() { + 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() { + buildRule.executeTarget("isfalse-true"); + assertNull(buildRule.getProject().getProperty("isfalse-true")); + } + + @Test + public void testIsfalseNot() { + buildRule.executeTarget("isfalse-not"); + assertEquals("true", buildRule.getProject().getProperty("isfalse-not")); + } + + @Test + public void testIsfalseFalse() { + + buildRule.executeTarget("isfalse-false"); + assertEquals("true", buildRule.getProject().getProperty("isfalse-false")); + } + + @Test + public void testIsfalseIncomplete1() { + 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() { + buildRule.executeTarget("testElse"); + } + + @Test + public void testResourcesmatchError() { + try { + buildRule.executeTarget("resourcematch-error"); + fail("BuildException should have been thrown - no resources specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testResourcesmatchEmpty() { + buildRule.executeTarget("resourcesmatch-match-empty"); + } + + @Test + public void testResourcesmatchOne() { + buildRule.executeTarget("resourcesmatch-match-one"); + } + + @Test + public void testResourcesmatchBinary() { + buildRule.executeTarget("resourcesmatch-match-binary"); + } + + @Test + public void testResourcesmatchMultipleBinary() { + buildRule.executeTarget("resourcesmatch-match-multiple-binary"); + } + + @Test + public void testResourcesmatchDiffer() { + buildRule.executeTarget("resourcesmatch-differ"); + } + + @Test + public void testResourcesmatchText() { + buildRule.executeTarget("resourcesmatch-match-text"); + } + + @Test + public void testResourcesmatchNoneExist() { + buildRule.executeTarget("resourcesmatch-noneexist"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java new file mode 100644 index 00000000..a7a32a9a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java @@ -0,0 +1,280 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copy.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + File f = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); + if ( !f.exists()) { + fail("Copy failed"); + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + File f = new File(buildRule.getProject().getProperty("output"), "copytest1dir/copy.xml"); + if ( !f.exists()) { + fail("Copy failed"); + } + } + + @Test + public void test3() { + 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(buildRule.getProject().getProperty("output"), "copytest3a.tmp"); + assertTrue(file3a.exists()); + File file3b = new File(buildRule.getProject().getProperty("output"), "copytest3b.tmp"); + assertTrue(file3b.exists()); + File file3c = new File(buildRule.getProject().getProperty("output"), "copytest3c.tmp"); + assertTrue(file3c.exists()); + + //file length checks rely on touch generating a zero byte file + if(file3.length()==0) { + fail("could not overwrite an existing, older file"); + } + if(file3c.length()!=0) { + fail("could not force overwrite an existing, newer file"); + } + if(file3b.length()==0) { + fail("unexpectedly overwrote an existing, newer file"); + } + + //file time checks for java1.2+ + assertTrue(file3a.lastModified()==file3.lastModified()); + assertTrue(file3c.lastModified()<file3a.lastModified()); + + } + + @Test + public void testFilterTest() { + buildRule.executeTarget("filtertest"); + assertTrue(buildRule.getLog().indexOf("loop in tokens") == -1); + } + + @Test + public void testInfiniteFilter() { + buildRule.executeTarget("infinitetest"); + assertContains("loop in tokens", buildRule.getOutput()); + } + + @Test + public void testFilterSet() throws IOException { + 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()); + assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); + } + + @Test + public void testFilterChain() throws IOException { + 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()); + assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); + } + + @Test + public void testSingleFileFileset() { + 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() { + 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 { + 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() { + buildRule.executeTarget("testMissingFileIgnore"); + assertContains("Warning: Could not find file", buildRule.getLog()); + } + + @Test + public void testMissingFileBail() { + 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() { + buildRule.executeTarget("testMissingDirIgnore"); + assertContains("Warning: ", buildRule.getLog()); + } + + @Test + public void testMissingDirBail() { + try { + buildRule.executeTarget("testMissingDirBail"); + fail("not-there doesn't exist"); + } catch (BuildException ex) { + assertTrue(ex.getMessage().endsWith(" does not exist.")); + } + } + + @Test + public void testFileResourcePlain() { + 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()); + } + + @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() { + 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)); + assertEquals("This is file 42", file1Content); + } catch (IOException e) { + // no-op: not a real business error + } + } + + @Test + public void testPathAsResource() { + 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() { + 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() { + buildRule.executeTarget("testDirset"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlain() { + buildRule.executeTarget("testResourcePlain"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlainWithMapper() { + buildRule.executeTarget("testResourcePlainWithMapper"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlainWithFilter() { + buildRule.executeTarget("testResourcePlainWithFilter"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testOnlineResources() { + buildRule.executeTarget("testOnlineResources"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java new file mode 100644 index 00000000..a7fdd5cb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java @@ -0,0 +1,100 @@ +/* + * 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.taskdefs; + +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 CopydirTest { + + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copydir.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertEquals("DEPRECATED - The copydir task is deprecated. Use copy instead.Warning: src == dest", + buildRule.getLog()); + } + + @Test + public void test5() { + 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() { + try { + buildRule.executeTarget("test6"); + fail("target is file"); + } catch (BuildException ex) { + //TODO assert value + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java new file mode 100644 index 00000000..a3d84eeb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java @@ -0,0 +1,100 @@ +/* + * 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.taskdefs; + +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 { + + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copyfile.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertEquals("DEPRECATED - The copyfile task is deprecated. Use copy instead.Warning: src == dest", + buildRule.getLog()); + } + + @Test + public void test5() { + 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 + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java new file mode 100644 index 00000000..e093d4f7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java @@ -0,0 +1,170 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + // Output the default excludes + @Test + public void test1() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + "**/CVS", + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store"}; + buildRule.getProject().executeTarget("test1"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + // adding something to the excludes' + @Test + public void test2() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + "**/CVS", + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store", + "foo"}; + buildRule.executeTarget("test2"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + // removing something from the defaults + @Test + public void test3() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + //CVS missing + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store"}; + buildRule.executeTarget("test3"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + 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++) { + boolean found = false; + for (int i = 0; !found && i < actual.length; i++) { + found |= expected[counter].equals(actual[i]); + } + assertTrue(message + " : didn't find element " + + expected[counter] + " in array match", found); + } + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java new file mode 100644 index 00000000..fb244213 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java @@ -0,0 +1,112 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } +//where oh where has my test case 3 gone? + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + @Test + public void test7() { + buildRule.executeTarget("test7"); + } + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + @Test + public void test9() { + buildRule.executeTarget("test9"); + } + @Test + public void test10() { + buildRule.executeTarget("test10"); + } + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + @Test + public void test12() { + buildRule.executeTarget("test12"); + } + @Test + public void test13() { + buildRule.executeTarget("test13"); + } + @Test + public void test14() { + buildRule.executeTarget("test14"); + } + @Test + public void test15() { + buildRule.executeTarget("test15"); + } + @Test + public void test16() { + buildRule.executeTarget("test16"); + } + @Test + public void test17() { + buildRule.executeTarget("test17"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java new file mode 100644 index 00000000..b2dcc69e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java @@ -0,0 +1,55 @@ +/* + * 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.taskdefs; + +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 DeltreeTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml"); + } + + @Test + public void test1() { + 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 + buildRule.executeTarget("test2"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java new file mode 100644 index 00000000..e5e3b2f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java @@ -0,0 +1,75 @@ +/* + * 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.taskdefs; + +import java.util.Random; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +/** + * A simple task that prints to System.out and System.err and then catches + * the output which it then checks. If the output does not match, an + * exception is thrown + * + * @since 1.5 + * @created 21 February 2002 + */ +public class DemuxOutputTask extends Task { + private String randomOutValue; + private String randomErrValue; + private boolean outputReceived = false; + private boolean errorReceived = false; + + public void execute() { + Random generator = new Random(); + randomOutValue = "Output Value is " + generator.nextInt(); + randomErrValue = "Error Value is " + generator.nextInt(); + + System.out.println(randomOutValue); + System.err.println(randomErrValue); + if (!outputReceived) { + throw new BuildException("Did not receive output"); + } + + if (!errorReceived) { + throw new BuildException("Did not receive error"); + } + } + + protected void handleOutput(String line) { + line = line.trim(); + if (line.length() != 0 && !line.equals(randomOutValue)) { + String message = "Received = [" + line + "], expected = [" + + randomOutValue + "]"; + throw new BuildException(message); + } + outputReceived = true; + } + + protected void handleErrorOutput(String line) { + line = line.trim(); + if (line.length() != 0 && !line.equals(randomErrValue)) { + String message = "Received = [" + line + "], expected = [" + + randomErrValue + "]"; + throw new BuildException(message); + } + errorReceived = true; + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java new file mode 100644 index 00000000..96c6c4a1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -0,0 +1,92 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/dirname.xml"); + } + + @Test + public void test1() { + 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() { + 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() { + 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() { + 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 = buildRule.getProject().getProperty("local.dir"); + assertEquals("dirname failed", expected, checkprop); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + String expected = buildRule.getProject().getProperty("basedir"); + String checkprop = buildRule.getProject().getProperty("base.dir"); + assertEquals("dirname failed", expected, checkprop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java new file mode 100644 index 00000000..0d4b6cda --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java @@ -0,0 +1,46 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.DynamicConfigurator; +import org.apache.tools.ant.Task; + +public class DynamicTask extends Task implements DynamicConfigurator { + + public void execute() { + } + + public void setDynamicAttribute(String name, String value) { + getProject().setNewProperty(name, value); + } + + public Object createDynamicElement(String name) { + return new Sub(); + } + + public class Sub implements DynamicConfigurator { + public void setDynamicAttribute(String name, String value) { + getProject().setNewProperty(name, value); + } + + public Object createDynamicElement(String name) { + return null; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java new file mode 100644 index 00000000..615dd903 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java @@ -0,0 +1,46 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DynamicTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/dynamictask.xml"); + } + + @Test + public void testSimple() { + 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")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java new file mode 100644 index 00000000..5c2ae28e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java @@ -0,0 +1,105 @@ +/* + * 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.taskdefs; + +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 { + + private File removeThis; + + @Test + public void testLogBlankEcho() { + Project p = new Project(); + p.init(); + EchoTestLogger logger = new EchoTestLogger(); + p.addBuildListener(logger); + Echo echo = new Echo(); + echo.setProject(p); + echo.setTaskName("testLogBlankEcho"); + echo.execute(); + assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage ); + } + + @Test + public void testLogUTF8Echo() throws IOException { + Project p = new Project(); + p.init(); + EchoTestLogger logger = new EchoTestLogger(); + p.addBuildListener(logger); + Echo echo = new Echo(); + echo.setProject(p); + echo.setTaskName("testLogUTF8Echo"); + echo.setMessage("\u00e4\u00a9"); + removeThis = new File("abc.txt"); + echo.setFile(removeThis); + echo.setEncoding("UTF-8"); + echo.execute(); + String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8" )); + assertEquals(x,"\u00e4\u00a9"); + } + + @After + public void tearDown() { + if (removeThis != null && removeThis.exists()) { + if (!removeThis.delete()) + { + removeThis.deleteOnExit(); + } + } + } + + private class EchoTestLogger extends DefaultLogger { + String lastLoggedMessage; + + /** + * Create a new EchoTestLogger. + */ + public EchoTestLogger() { + super(); + this.setMessageOutputLevel(Project.MSG_DEBUG); + this.setOutputPrintStream(new PrintStream(new ByteArrayOutputStream(256))); + this.setErrorPrintStream(new PrintStream(new ByteArrayOutputStream(256))); + } + + /** + * {@inheritDoc} + */ + protected void log(String message) { + this.lastLoggedMessage = message; + } + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java new file mode 100644 index 00000000..cc9ec24e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java @@ -0,0 +1,71 @@ +/* + * 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.taskdefs; + +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.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +public class EchoXMLTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testPass() { + buildRule.executeTarget("testPass"); + } + + @Test + public void testFail() { + try { + buildRule.executeTarget("testFail"); + fail("BuildException expected: must fail"); + } catch (BuildException ex) { + assertContains("${foo}=bar", ex.getMessage()); + } + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("BuildException expected: must fail"); + } catch (BuildException ex) { + assertContains("No nested XML specified", ex.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java new file mode 100644 index 00000000..b7427606 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java @@ -0,0 +1,192 @@ +/* + * 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.taskdefs; + +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 { + + @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; + /** maximum time allowed for the build in milliseconds */ + private static final int MAX_BUILD_TIME = 6000; + private static final int SECURITY_MARGIN = 4000; // wait 4 second extras + // the test failed with 100 ms of margin on cvs.apache.org on August 1st, 2003 + // the test randomly failed with 3 s of margin on Windows Jenkins slaves on during July 2014 + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + private File logFile; + private MonitoredBuild myBuild = null; + volatile private boolean buildFinished = false; + + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + @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", 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 1 seconds + myBuild.setTimeToWait(TIME_TO_WAIT); + myBuild.setLogFile(logFile.getAbsolutePath()); + myBuild.addBuildListener(new MonitoredBuildListener()); + myBuild.start(); + GregorianCalendar startwait = new GregorianCalendar(); + // this loop runs parallel to the build + while (!buildFinished) { + Thread.sleep(10); + GregorianCalendar now = new GregorianCalendar(); + // security + if (now.getTime().getTime() - startwait.getTime().getTime() > MAX_BUILD_TIME) { + System.out.println("aborting wait, too long " + + (now.getTime().getTime() - startwait.getTime().getTime()) + + "milliseconds"); + break; + } + } + // now wait until the spawned process is finished + 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", + TIME_TO_WAIT * 1000 + SECURITY_MARGIN > elapsed); + logFile = new File(logFile.getAbsolutePath()); + assertTrue("log file found after spawn", logFile.exists()); + } + + @Test + @Ignore("#50507 - fails at least on Linux") + /* TODO #50507 - fails at least on Linux */ + public void testOutAndErr() { + 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 GregorianCalendar timeStarted = null; + private GregorianCalendar timeFinished = null; + + public void setLogFile(String logFile) { + project.setProperty("logFile", logFile); + } + + public void setTimeToWait(int timeToWait) { + project.setProperty("timeToWait", Long.toString(timeToWait)); + } + + public void addBuildListener(BuildListener bl) { + project.addBuildListener(bl); + } + + public MonitoredBuild(File buildFile, String target) { + myBuildFile = buildFile; + this.target = target; + project = new Project(); + project = new Project(); + project.init(); + project.setUserProperty("ant.file", myBuildFile.getAbsolutePath()); + ProjectHelper.configureProject(project, myBuildFile); + } + + /** + * + * @return time in millis of the build + */ + public long getTimeElapsed() { + return timeFinished.getTime().getTime() - timeStarted.getTime().getTime(); + } + + public void start() { + worker = new Thread(this, myBuildFile.toString() + "/" + target); + worker.start(); + } + + public void run() { + startProject(); + } + + private void startProject() { + timeStarted = new GregorianCalendar(); + project.executeTarget(target); + timeFinished = new GregorianCalendar(); + } + } + + private class MonitoredBuildListener implements BuildListener { + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetStarted(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + if (event.getTarget().getName().equals("spawn")) { + buildFinished = true; + } + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java new file mode 100644 index 00000000..069645b3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java @@ -0,0 +1,131 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.MagicNames; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Commandline; + +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 { + + private final static int TIME_OUT = 5000; + + private final static int CLOCK_ERROR=200; + private final static int TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + + private ExecuteJava ej; + private Project project; + private Path cp; + + @Before + public void setUp(){ + ej = new ExecuteJava(); + ej.setTimeout((long)TIME_OUT); + project = new Project(); + project.setBasedir("."); + project.setProperty(MagicNames.ANT_HOME, System.getProperty(MagicNames.ANT_HOME)); + cp = new Path(project, getTestClassPath()); + ej.setClasspath(cp); + } + + private Commandline getCommandline(int timetorun) throws Exception { + Commandline cmd = new Commandline(); + cmd.setExecutable(TimeProcess.class.getName()); + cmd.createArgument().setValue(String.valueOf(timetorun)); + return cmd; + } + + @Test + public void testNoTimeOut() throws Exception { + Commandline cmd = getCommandline(TIME_OUT/2); + ej.setJavaCommand(cmd); + ej.execute(project); + assertTrue("process should not have been killed", !ej.killedProcess()); + } + + // test that the watchdog ends the process + @Test + public void testTimeOut() throws Exception { + Commandline cmd = getCommandline(TIME_OUT*2); + ej.setJavaCommand(cmd); + long now = System.currentTimeMillis(); + ej.execute(project); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", ej.killedProcess()); + + assertTrue("elapse time of "+elapsed + +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed + +" ms is greater than run value of "+(TIME_OUT*2)+" ms", + elapsed < TIME_OUT*2); + } + + @Test + public void testNoTimeOutForked() throws Exception { + Commandline cmd = getCommandline(TIME_OUT/2); + ej.setJavaCommand(cmd); + ej.fork(cp); + assertTrue("process should not have been killed", !ej.killedProcess()); + } + + // test that the watchdog ends the process + @Test + public void testTimeOutForked() throws Exception { + Commandline cmd = getCommandline(TIME_OUT*2); + ej.setJavaCommand(cmd); + long now = System.currentTimeMillis(); + ej.fork(cp); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", ej.killedProcess()); + + assertTrue("elapse time of "+elapsed + +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed + +" ms is greater than run value of "+(TIME_OUT*2)+" ms", + elapsed < TIME_OUT*2); + } + + /** + * Dangerous method to obtain the classpath for the test. This is + * severely tighted to the build.xml properties. + */ + private static String getTestClassPath(){ + String classpath = System.getProperty("build.tests"); + if (classpath == null) { + System.err.println("WARNING: 'build.tests' property is not available !"); + classpath = System.getProperty("java.class.path"); + } + + return classpath; + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java new file mode 100644 index 00000000..1834d5e3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java @@ -0,0 +1,162 @@ +/* + * 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.taskdefs; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import org.apache.tools.ant.util.JavaEnvUtils; +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 { + + private final static long TIME_OUT = 5000; + + private final static String TEST_CLASSPATH = getTestClassPath(); + + private final static int CLOCK_ERROR=200; + private final static long TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + + private ExecuteWatchdog watchdog; + + @Before + public void setUp(){ + watchdog = new ExecuteWatchdog(TIME_OUT); + } + + /** + * Dangerous method to obtain the classpath for the test. This is + * severely tied to the build.xml properties. + */ + private static String getTestClassPath(){ + String classpath = System.getProperty("build.tests"); + if (classpath == null) { + System.err.println("WARNING: 'build.tests' property is not available !"); + classpath = System.getProperty("java.class.path"); + } + + return classpath; + } + + private Process getProcess(long timetorun) throws Exception { + String[] cmdArray = { + JavaEnvUtils.getJreExecutable("java"), "-classpath", TEST_CLASSPATH, + TimeProcess.class.getName(), String.valueOf(timetorun) + }; + //System.out.println("Testing with classpath: " + System.getProperty("java.class.path")); + return Runtime.getRuntime().exec(cmdArray); + } + + private String getErrorOutput(Process p) throws Exception { + BufferedReader err = new BufferedReader( new InputStreamReader(p.getErrorStream()) ); + StringBuffer buf = new StringBuffer(); + String line; + while ( (line = err.readLine()) != null){ + buf.append(line); + } + return buf.toString(); + } + + private int waitForEnd(Process p) throws Exception { + int retcode = p.waitFor(); + if (retcode != 0){ + String err = getErrorOutput(p); + if (err.length() > 0){ + System.err.println("ERROR:"); + System.err.println(err); + } + } + return retcode; + } + + @Test + public void testNoTimeOut() throws Exception { + Process process = getProcess(TIME_OUT/2); + watchdog.start(process); + int retCode = waitForEnd(process); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertFalse(Execute.isFailure(retCode)); + } + + // test that the watchdog ends the process + @Test + public void testTimeOut() throws Exception { + Process process = getProcess(TIME_OUT*2); + long now = System.currentTimeMillis(); + watchdog.start(process); + int retCode = process.waitFor(); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", watchdog.killedProcess()); + // assertTrue("return code is invalid: " + retCode, retCode!=0); + assertTrue("elapse time of "+elapsed+" ms is less than timeout value of "+TIME_OUT_TEST+" ms", elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed+" ms is greater than run value of "+(TIME_OUT*2)+" ms", elapsed < TIME_OUT*2); + } + + // test a process that runs and failed + @Test + public void testFailed() throws Exception { + Process process = getProcess(-1); // process should abort + watchdog.start(process); + int retCode = process.waitFor(); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertTrue("return code is invalid: " + retCode, retCode!=0); + } + + @Test + public void testManualStop() throws Exception { + final Process process = getProcess(TIME_OUT*2); + watchdog.start(process); + + // I assume that starting this takes less than TIME_OUT/2 ms... + Thread thread = new Thread(){ + public void run(){ + try { + process.waitFor(); + } catch(InterruptedException e){ + // not very nice but will do the job + throw new AssumptionViolatedException("process interrupted in thread", e); + } + } + }; + thread.start(); + + // wait for TIME_OUT/2, there should be about TIME_OUT/2 ms remaining before timeout + thread.join(TIME_OUT/2); + + // now stop the watchdog. + watchdog.stop(); + + // wait for the thread to die, should be the end of the process + thread.join(); + + // process should be dead and well finished + assertEquals(0, process.exitValue()); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java new file mode 100644 index 00000000..8883558d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java @@ -0,0 +1,210 @@ +/* + * 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.taskdefs; + +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 FailTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/fail.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("No message", ex.getMessage()); + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("test2", ex.getMessage()); + } + } + + @Test + public void 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 { + buildRule.executeTarget("testIf"); + fail("testIf must fail if foo has been set") ; + } catch (BuildException ex) { + //TODO assert result + } + } + + @Test + public void testUnless() { + try { + 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"); + + } + + /** + * see that the different combinations work, and + * that the autogenerated text contains information + * about which condition was not met + */ + @Test + public void testIfAndUnless() { + //neither + 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 + 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() { + buildRule.getProject().setProperty("unless", ""); + buildRule.executeTarget("testIfAndUnless"); + } + + @Test + public void testNested1() { + try { + buildRule.executeTarget("testNested1"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("condition satisfied", ex.getMessage()); + } + } + + @Test + public void testNested2() { + buildRule.executeTarget("testNested2"); + } + + @Test + public void 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"; + + char[] c = {'a', 'b', 'c'}; + StringBuffer target = new StringBuffer("testNested4x"); + + for (int i = 0; i < c.length; i++) { + target.setCharAt(target.length() - 1, c[i]); + try { + buildRule.executeTarget(target.toString()); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals(specificMessage, ex.getMessage()); + } + } + } + + @Test + public void testNested5() { + 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() { + 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."; + + char[] c = {'a', 'b'}; + StringBuffer target = new StringBuffer("testNested7x"); + + for (int i = 0; i < c.length; i++) { + target.setCharAt(target.length() - 1, c[i]); + try { + buildRule.executeTarget(target.toString()); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals(specificMessage, ex.getMessage()); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java new file mode 100644 index 00000000..fdbec6e8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java @@ -0,0 +1,147 @@ +/* + * 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.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +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.assertEquals; +import static org.junit.Assert.fail; + + +public class FilterTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/filter.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("2000", + getFilteredFile("5", "filtered.tmp")); + } + + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("2000", + getFilteredFile("6", "taskdefs.tmp/filter1.txt")); + } + + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("<%@ include file=\"root/some/include.jsp\"%>", + getFilteredFile("7", "filtered.tmp")); + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + assertEquals("<%@ include file=\"root/some/include.jsp\"%>", + getFilteredFile("8", "taskdefs.tmp/filter2.txt")); + } + + @Test + public void test9() { + buildRule.executeTarget("test9"); + assertEquals("included", + getFilteredFile("9", "taskdefs.tmp/filter3.txt")); + } + + private String getFilteredFile(String testNumber, String filteredFile) { + + String line = null; + File f = new File(buildRule.getProject().getBaseDir(), filteredFile); + if (!f.exists()) { + fail("filter test"+testNumber+" failed"); + } else { + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(f)); + } catch (FileNotFoundException fnfe) { + fail("filter test"+testNumber+" failed, filtered file: " + f.toString() + " not found"); + } + try { + line = in.readLine(); + in.close(); + } catch (IOException ioe) { + fail("filter test"+testNumber+" failed. IOException while reading filtered file: " + ioe); + } + } + f.delete(); + return line; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java new file mode 100644 index 00000000..06a18cc8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java @@ -0,0 +1,262 @@ +/* + * 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.taskdefs; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.AssertionFailedError; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml"); + } + + @Test + public void test1() throws IOException { + buildRule.executeTarget("test1"); + } + + @Test + public void test2() throws IOException { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() throws IOException { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() throws IOException { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() throws IOException { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() throws IOException { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() throws IOException { + buildRule.executeTarget("test7"); + } + + @Test + public void test8() throws IOException { + buildRule.executeTarget("test8"); + } + + @Test + public void test9() throws IOException { + buildRule.executeTarget("test9"); + } + + @Test + public void testMacLines() throws IOException { + buildRule.executeTarget("testMacLines"); + } + + @Test + public void testNoOverwrite() throws IOException { + buildRule.executeTarget("testNoOverwrite"); + } + + @Test + public void testEncoding() throws IOException { + buildRule.executeTarget("testEncoding"); + } + + @Test + public void testOutputEncoding() throws IOException { + buildRule.executeTarget("testOutputEncoding"); + } + + @Test + public void testLongLines() throws IOException { + buildRule.executeTarget("testLongLines"); + } + + @Test + public void testCrCrLfSequenceUnix() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-unix"); + } + + @Test + public void testCrCrLfSequenceDos() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-dos"); + } + + @Test + public void testCrCrLfSequenceMac() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-mac"); + } + + @Test + public void testFixlastDos() throws IOException { + buildRule.executeTarget("testFixlastDos"); + } + + @Test + public void testFixlastFalseMac() throws IOException { + buildRule.executeTarget("testFixlastFalseMac"); + } + + @Test + public void testFixFile() throws Exception { + buildRule.executeTarget("testFixFile"); + } + + @Test + public void testFixFileExclusive() throws Exception { + try { + buildRule.executeTarget("testFixFileExclusive"); + fail(FixCRLF.ERROR_FILE_AND_SRCDIR); + } catch (BuildException ex) { + AntAssert.assertContains(FixCRLF.ERROR_FILE_AND_SRCDIR, ex.getMessage()); + } + } + + /** + * Bugzilla Report 20840 + * + * Will fail with an exception if the parent directories do not + * get created. + */ + @Test + public void testCreateParentDirs() { + buildRule.executeTarget("createParentDirs"); + } + + @Test + public void testPreserveLastModified() { + buildRule.executeTarget("testPreserveLastModified"); + } + + @Test + public void testFilter1() { + buildRule.executeTarget("testFilter1"); + } + + @Test + public void testFilter2() { + buildRule.executeTarget("testFilter2"); + } + + @Test + public void testFilter3() { + buildRule.executeTarget("testFilter3"); + } + + @Test + public void testFilter4() { + buildRule.executeTarget("testFilter4"); + } + + @Test + public void testFilter5() { + buildRule.executeTarget("testFilter5"); + } + + @Test + public void testFilter6() { + buildRule.executeTarget("testFilter6"); + } + + @Test + public void testFilter7() { + buildRule.executeTarget("testFilter7"); + } + + @Test + public void testFilter8() { + buildRule.executeTarget("testFilter8"); + } + + @Test + public void testFilter9() { + buildRule.executeTarget("testFilter9"); + } + + @Test + public void testCannotDoubleEof() { + buildRule.executeTarget("testCannotDoubleEof"); + } + + @Test + public void 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()) { + fail("Expected file "+result+" doesn\'t exist"); + } + + InputStream inExpect = null; + InputStream inResult = null; + try { + inExpect = new BufferedInputStream(new FileInputStream(expect)); + inResult = new BufferedInputStream(new FileInputStream(result)); + + int expectedByte = inExpect.read(); + while (expectedByte != -1) { + assertEquals(expectedByte, inResult.read()); + expectedByte = inExpect.read(); + } + assertEquals("End of file", -1, inResult.read()); + } finally { + if (inResult != null) { + inResult.close(); + } + if (inExpect != null) { + inExpect.close(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java new file mode 100644 index 00000000..fc731f75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java @@ -0,0 +1,91 @@ +/* + * 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.taskdefs; + +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.fail; + +public class GUnzipTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/gunzip.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + 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 { + 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"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java new file mode 100644 index 00000000..3e1157d8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java @@ -0,0 +1,122 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/get.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("src invalid"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("dest invalid (or no http-server on local machine"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("userAgent may not be null or empty"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testUseTimestamp() { + buildRule.executeTarget("testUseTimestamp"); + } + + @Test + public void testUseTomorrow() { + buildRule.executeTarget("testUseTomorrow"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java new file mode 100644 index 00000000..00ea0638 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java @@ -0,0 +1,113 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/gzip.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: zipfile must not point to a directory"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testGZip(){ + 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(){ + buildRule.executeTarget("realTestWithResource"); + } + + @Test + public void testDateCheck(){ + 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(){ + buildRule.executeTarget("cleanup"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java new file mode 100644 index 00000000..e64d6f8c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java @@ -0,0 +1,174 @@ +/* + * 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.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.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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testSimpleImport() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/import.xml"); + assertContains("Before importIn imported topAfter import", buildRule.getLog()); + } + + @Test + public void testUnnamedNesting() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", + Project.MSG_WARN); + String log = buildRule.getLog(); + assertTrue("Warnings logged when not expected: " + log, + log.length() == 0); + } + + @Test + public void testSerial() { + 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 + @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")); + } + + @Ignore("deactivate this test as imports within targets are not allowed") + @Test + public void notTestImportInTargetWithEffect() { + 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() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); + 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() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/subdir/importinsequential.xml"); + buildRule.executeTarget("within-imported"); + assertEquals(buildRule.getProject().getProperty("foo"), "bar"); + assertNotNull(buildRule.getProject().getReference("baz")); + } + + @Test + public void testImportSameTargets() { + try { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/same_target.xml"); + fail("Expected build exception"); + } catch (BuildException ex) { + assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); + } + } + + @Test + public void testImportError() { + try { + 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(); + 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()); + } + } + + @Test + public void testSymlinkedImports() throws Exception { + String ln = "/usr/bin/ln"; + if (!new File(ln).exists()) { + ln = "/bin/ln"; + } + 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 { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/symlinks/d1/p1.xml"); + assertEquals( + buildRule.getProject().getProperty("ant.file.p2"), + new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d2/p2.xml") + .getAbsolutePath()); + assertEquals( + buildRule.getProject().getProperty("ant.file.p3"), + new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d3b/p3.xml") + .getAbsolutePath()); + } finally { + symlinkFile.delete(); + } + } + + @Test + public void testTargetFirst() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); + assertContains("Importing targetfirstAfter target firstAfter importing", buildRule.getLog()); + } + + @Test + public void testTargetName() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/c.xml"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java new file mode 100644 index 00000000..a44303f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java @@ -0,0 +1,77 @@ +/* + * 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.taskdefs; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +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 { + + @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"); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/initializeclass.xml"); + } + + @Test + public void testAll() throws IOException { + 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(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java new file mode 100644 index 00000000..4b6efaa1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java @@ -0,0 +1,126 @@ +/* + * 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.taskdefs; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private InputStream originalStdIn; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/input.xml"); + System.getProperties() + .put(PropertyFileInputHandler.FILE_NAME_KEY, + buildRule.getProject().resolveFile("input.properties") + .getAbsolutePath()); + buildRule.getProject().setInputHandler(new PropertyFileInputHandler()); + originalStdIn = System.in; + } + + @After + public void tearDown() { + System.setIn(originalStdIn); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() { + 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() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("scott", buildRule.getProject().getProperty("db.user")); + } + + @Test + public void testPropertyFileInlineHandler() { + buildRule.executeTarget("testPropertyFileInlineHandler"); + } + + @Test + public void testDefaultInlineHandler() throws IOException { + stdin(); + buildRule.executeTarget("testDefaultInlineHandler"); + } + + @Test + public void testGreedyInlineHandler() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandler"); + } + + @Test + public void testGreedyInlineHandlerClassname() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandlerClassname"); + } + + @Test + public void testGreedyInlineHandlerRefid() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandlerRefid"); + } + + private void stdin() throws IOException { + System.setIn(new FileInputStream(buildRule.getProject().resolveFile("input.stdin"))); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java new file mode 100644 index 00000000..9b8ff155 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java @@ -0,0 +1,375 @@ +/* + * 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.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static String tempJar = "tmp.jar"; + private static String tempDir = "jartmp/"; + private Reader r1, r2; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); + buildRule.executeTarget("setUp"); + } + + @After + public void tearDown() { + if (r1 != null) { + try { + r1.close(); + } catch (IOException e) { + } + } + if (r2 != null) { + try { + r2.close(); + } catch (IOException e) { + } + } + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: manifest file does not exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + 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() { + 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) { + 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(); + + 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) { + //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(); + 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 { + 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() { + buildRule.executeTarget("testCreateWithEmptyFilesetSetUp"); + buildRule.executeTarget("testCreateWithEmptyFileset"); + buildRule.executeTarget("testCreateWithEmptyFileset"); + } + + @Test + public void 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 { + buildRule.executeTarget("testIndexTests"); + archive = new ZipFile(new File(getOutputDir(), tempJar)); + Enumeration e = archive.entries(); + int numberOfIndexLists = 0; + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + if (ze.getName().equals("META-INF/INDEX.LIST")) { + numberOfIndexLists++; + } + } + assertEquals(1, numberOfIndexLists); + } finally { + if (archive != null) { + archive.close(); + } + } + } + + // bugzilla report 16972 + @Test + public void testRootFilesInIndex() throws IOException { + ZipFile archive = null; + try { + buildRule.executeTarget("testIndexTests"); + archive = new ZipFile(new File(getOutputDir(), tempJar)); + ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST"); + InputStream is = archive.getInputStream(ze); + BufferedReader r = new BufferedReader(new InputStreamReader(is, + "UTF8")); + boolean foundSub = false; + boolean foundSubFoo = false; + boolean foundFoo = false; + + String line = r.readLine(); + while (line != null) { + if (line.equals("foo")) { + foundFoo = true; + } else if (line.equals("sub")) { + foundSub = true; + } else if (line.equals("sub/foo")) { + foundSubFoo = true; + } + line = r.readLine(); + } + + assertTrue(foundSub); + assertTrue(!foundSubFoo); + assertTrue(foundFoo); + } finally { + if (archive != null) { + archive.close(); + } + } + } + @Test + public void testManifestOnlyJar() { + + 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() { + buildRule.executeTarget("testIndexJarsPlusJarMarker"); + } + + @Test + public void testNoVersionInfoFail() { + 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() { + 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() { + 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() { + 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() { + 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 ); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java new file mode 100644 index 00000000..d54b8f28 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java @@ -0,0 +1,475 @@ +/* + * 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.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private static final int TIME_TO_WAIT = 1; + // wait 1 second extra to allow for java to start ... + // this time was OK on a Win NT machine and on nagoya + private static final int SECURITY_MARGIN = 2000; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + private boolean runFatalTests=false; + + + /** + * configure the project. + * if the property junit.run.fatal.tests is set we run + * the fatal tests + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/java.xml"); + buildRule.executeTarget("setUp"); + + //final String propname="tests-classpath.value"; + //String testClasspath=System.getProperty(propname); + //System.out.println("Test cp="+testClasspath); + String runFatal=System.getProperty("junit.run.fatal.tests"); + if(runFatal!=null) + runFatalTests=true; + } + + @Test + public void testNoJarNoClassname(){ + 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() { + 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() { + 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() { + 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() { + buildRule.executeTarget("testRun"); + } + + + + /** this test fails but we ignore the return value; + * we verify that failure only matters when failonerror is set + */ + @Test + public void testRunFail() { + Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests); + buildRule.executeTarget("testRunFail"); + } + + @Test + public void testRunFailFoe() { + 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() { + 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() { + buildRule.executeTarget("testExcepting"); + assertContains("Exception raised inside called program", buildRule.getLog()); + } + + @Test + public void testExceptingFork() { + buildRule.executeTarget("testExceptingFork"); + assertContains("Java Result:", buildRule.getLog()); + } + + @Test + public void testExceptingFoe() { + 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() { + 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() { + buildRule.executeTarget("testResultPropertyZero"); + assertEquals("0", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyNonZero() { + buildRule.executeTarget("testResultPropertyNonZero"); + assertEquals("2", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyZeroNoFork() { + buildRule.executeTarget("testResultPropertyZeroNoFork"); + assertEquals("0", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyNonZeroNoFork() { + buildRule.executeTarget("testResultPropertyNonZeroNoFork"); + assertEquals("-1", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testRunFailWithFailOnError() { + 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() { + buildRule.executeTarget("testRunSuccessWithFailOnError"); + } + + @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()); + 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" + + " SECURITY_MARGIN to give more time for java to start."); + } + assertTrue("log file exists", logFile.exists()); + } + + @Test + public void testRedirect1() { + buildRule.executeTarget("redirect1"); + } + + @Test + public void testRedirect2() { + buildRule.executeTarget("redirect2"); + } + + @Test + public void testRedirect3() { + buildRule.executeTarget("redirect3"); + } + + @Test + public void testRedirector1() { + buildRule.executeTarget("redirector1"); + } + + @Test + public void testRedirector2() { + buildRule.executeTarget("redirector2"); + } + + @Test + public void testReleasedInput() throws Exception { + PipedOutputStream out = new PipedOutputStream(); + final PipedInputStream in = new PipedInputStream(out); + buildRule.getProject().setInputHandler(new DefaultInputHandler() { + protected InputStream getInputStream() { + return in; + } + }); + buildRule.getProject().setDefaultInputStream(in); + + Java java = new Java(); + java.setProject(buildRule.getProject()); + java.setClassname("org.apache.tools.ant.Main"); + java.setArgs("-version"); + java.setFork(true); + // note: due to the missing classpath it will fail, but the input stream + // reader will be read + java.execute(); + + Thread inputThread = new Thread(new Runnable() { + public void run() { + Input input = new Input(); + input.setProject(buildRule.getProject()); + input.setAddproperty("input.value"); + input.execute(); + } + }); + inputThread.start(); + + // wait a little bit for the task to wait for input + Thread.sleep(100); + + // write some stuff in the input stream to be catched by the input task + out.write("foo\n".getBytes()); + out.flush(); + try { + out.write("bar\n".getBytes()); + out.flush(); + } catch (IOException x) { + // "Pipe closed" on XP; ignore? + } + + inputThread.join(2000); + + assertEquals("foo", buildRule.getProject().getProperty("input.value")); + } + + @Test + public void testFlushedInput() throws Exception { + final PipedOutputStream out = new PipedOutputStream(); + final PipedInputStream in = new PipedInputStream(out); + buildRule.getProject().setInputHandler(new DefaultInputHandler() { + protected InputStream getInputStream() { + return in; + } + }); + buildRule.getProject().setDefaultInputStream(in); + + final boolean[] timeout = new boolean[1]; + timeout[0] = false; + + Thread writingThread = new Thread(new Runnable() { + public void run() { + try { + // wait a little bit to have the target executed + Thread.sleep(500); + } catch (InterruptedException e) { + throw new AssumptionViolatedException("Thread interrupted", e); + } + try { + out.write("foo-FlushedInput\n".getBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + writingThread.setDaemon(true); + + writingThread.start(); + buildRule.executeTarget("flushedInput"); + } + + /** + * entry point class with no dependencies other + * than normal JRE runtime + */ + public static class EntryPoint { + + /** + * this entry point is used by the java.xml tests to + * generate failure strings to handle + * argv[0] = exit code (optional) + * argv[1] = string to print to System.out (optional) + * argv[1] = string to print to System.err (optional) + */ + public static void main(String[] argv) { + int exitCode=0; + if(argv.length>0) { + try { + exitCode=Integer.parseInt(argv[0]); + } catch(NumberFormatException nfe) { + exitCode=-1; + } + } + if(argv.length>1) { + System.out.println(argv[1]); + } + if(argv.length>2) { + System.err.println(argv[2]); + } + if(exitCode!=0) { + System.exit(exitCode); + } + } + } + + /** + * entry point class with no dependencies other + * than normal JRE runtime + */ + public static class ExceptingEntryPoint { + + /** + * throw a run time exception which does not need + * to be in the signature of the entry point + */ + public static void main(String[] argv) { + throw new NullPointerException("Exception raised inside called program"); + } + } + /** + * test class for spawn + */ + public static class SpawnEntryPoint { + public static void main(String [] argv) throws InterruptedException { + int sleepTime = 10; + String logFile = "spawn.log"; + if (argv.length >= 1) { + sleepTime = Integer.parseInt(argv[0]); + } + if (argv.length >= 2) + { + logFile = argv[1]; + } + OutputStreamWriter out = null; + Thread.sleep(sleepTime * 1000); + + try { + File dest = new File(logFile); + FileOutputStream fos = new FileOutputStream(dest); + out = new OutputStreamWriter(fos); + out.write("bye bye\n"); + } catch (Exception ex) {} + finally { + try {out.close();} catch (IOException ioe) {}} + + } + } + + /** + * entry point class to pipe System.in to the specified stream: + * "out", "err", or "both". If none specified, swallow the input. + */ + public static class PipeEntryPoint { + + /** + * pipe input to specified output + */ + public static void main(String[] args) throws InterruptedException { + OutputStream os = null; + if (args.length > 0) { + if ("out".equalsIgnoreCase(args[0])) { + os = System.out; + } else if ("err".equalsIgnoreCase(args[0])) { + os = System.err; + } else if ("both".equalsIgnoreCase(args[0])) { + os = new TeeOutputStream(System.out, System.err); + } + } + if (os != null) { + Thread t = new Thread(new StreamPumper(System.in, os, true)); + t.setName("PipeEntryPoint " + args[0]); + t.start(); + t.join(); + } + } + } + + public static class ReadPoint { + public static void main(String[] args) throws IOException { + String line = new BufferedReader(new InputStreamReader(System.in)).readLine(); + System.out.println(line); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java new file mode 100644 index 00000000..12ceea28 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java @@ -0,0 +1,247 @@ +/* + * 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.taskdefs; + +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.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 { + + private Project project; + private Javac javac; + + @Before + public void setUp() { + project = new Project(); + project.init(); + javac = new Javac(); + javac.setProject(project); + } + + /** + * Test setting the name of the javac executable. + */ + @Test + public void testForkedExecutableName() { + assertNull("no fork means no executable", javac.getJavacExecutable()); + + project.setProperty("build.compiler", "modern"); + assertNull("no fork means no executable", javac.getJavacExecutable()); + + javac.setFork(true); + assertNotNull("normal fork", javac.getJavacExecutable()); + assertContains("name should contain \"javac\"", "javac", + javac.getJavacExecutable()); + + project.setProperty("build.compiler", "extJavac"); + javac.setFork(false); + assertNotNull("fork via property", javac.getJavacExecutable()); + assertContains("name should contain \"javac\"", "javac", javac.getJavacExecutable()); + + project.setProperty("build.compiler", "whatever"); + assertNull("no fork and not extJavac means no executable", + javac.getJavacExecutable()); + + String myJavac = "Slartibartfast"; + javac.setFork(true); + javac.setExecutable(myJavac); + assertEquals(myJavac, javac.getJavacExecutable()); + } + + /** + * Test nested compiler args. + */ + @Test + public void testCompilerArg() { + String[] args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("no args", 0, args.length); + + Javac.ImplementationSpecificArgument arg = javac.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + args = javac.getCurrentCompilerArgs(); + assertEquals("unconditional single arg", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setCompiler("jikes"); + args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is jikes but build.compiler is null", + 0, args.length); + + project.setProperty("build.compiler", "jvc"); + args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is jikes but build.compiler is jvc", + 0, args.length); + + project.setProperty("build.compiler", "jikes"); + args = javac.getCurrentCompilerArgs(); + assertEquals("both are jikes", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setLine(testArg); + args = javac.getCurrentCompilerArgs(); + assertEquals("split at space", 2, args.length); + assertEquals(ford, args[0]); + assertEquals(prefect, args[1]); + } + + /** + * Test nested compiler args in the fork="true" and + * implementation="extJavac" case. + */ + @Test + public void testCompilerArgForForkAndExtJavac() { + Javac.ImplementationSpecificArgument arg = javac.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + arg.setCompiler("extJavac"); + javac.setFork(true); + String[] args = javac.getCurrentCompilerArgs(); + assertEquals("both are forked javac", 1, args.length); + assertEquals(testArg, args[0]); + } + + /** + * Test compiler attribute. + */ + @Test + public void testCompilerAttribute() { + // check defaults + String compiler = javac.getCompiler(); + assertNotNull(compiler); + if (System.getProperty("build.compiler") != null) { + assertEquals(System.getProperty("build.compiler"), + compiler); + } else { + assertTrue("default value", + "javac1.1".equals(compiler) + || "javac1.2".equals(compiler) + || "javac1.3".equals(compiler) + || "javac1.4".equals(compiler) + || "javac1.5".equals(compiler) + || "classic".equals(compiler)); + } + + javac.setFork(true); + assertNotNull(javac.getCompiler()); + assertEquals("extJavac", javac.getCompiler()); + assertEquals(compiler, javac.getCompilerVersion()); + + // check build.compiler provides defaults + javac = new Javac(); + javac.setProject(project); + // setUserProperty to override system properties + project.setUserProperty("build.compiler", "jikes"); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jikes", compiler); + + javac.setFork(true); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jikes", compiler); + + // check attribute overrides build.compiler + javac.setFork(false); + javac.setCompiler("jvc"); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jvc", compiler); + + javac.setFork(true); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jvc", compiler); + } + + @Test + public void testCompilerAdapter() { + javac.setCompiler("javac1.4"); + + javac.setDepend(true); + CompilerAdapter adapter = + CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); + + assertTrue(adapter instanceof Javac13); + + javac.setFork(true); + adapter = + CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); + 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"); + assertEquals("1.5", javac.getTarget()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java new file mode 100644 index 00000000..f7a287d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java @@ -0,0 +1,132 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class JavadocTest { + + @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; + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + // PR 38370 + @Test + public void testDirsetPath() { + buildRule.executeTarget("dirsetPath"); + } + + // PR 38370 + @Test + public void testDirsetPathWithoutPackagenames() { + buildRule.executeTarget("dirsetPathWithoutPackagenames"); + } + + // PR 38370 + @Test + public void testNestedDirsetPath() { + buildRule.executeTarget("nestedDirsetPath"); + } + + // PR 38370 + @Test + public void testFilesetPath() { + buildRule.executeTarget("filesetPath"); + } + + // PR 38370 + @Test + public void testNestedFilesetPath() { + buildRule.executeTarget("nestedFilesetPath"); + } + + // PR 38370 + @Test + public void testFilelistPath() { + buildRule.executeTarget("filelistPath"); + } + + // PR 38370 + @Test + public void testNestedFilelistPath() { + buildRule.executeTarget("nestedFilelistPath"); + } + + // PR 38370 + @Test + public void testPathelementPath() { + buildRule.executeTarget("pathelementPath"); + } + + // PR 38370 + @Test + public void testPathelementLocationPath() { + buildRule.executeTarget("pathelementLocationPath"); + } + + // PR 38370 + @Test + public void testNestedSource() { + buildRule.executeTarget("nestedSource"); + } + + // PR 38370 + @Test + public void testNestedFilesetRef() { + buildRule.executeTarget("nestedFilesetRef"); + } + + // PR 38370 + @Test + public void testNestedFilesetRefInPath() { + buildRule.executeTarget("nestedFilesetRefInPath"); + } + + @Test + public void testNestedFilesetNoPatterns() { + buildRule.executeTarget("nestedFilesetNoPatterns"); + } + + @Test + public void testDoublyNestedFileset() { + buildRule.executeTarget("doublyNestedFileset"); + } + + @Test + public void testDoublyNestedFilesetNoPatterns() { + buildRule.executeTarget("doublyNestedFilesetNoPatterns"); + } + + @Test + public void testNonJavaIncludes() { // #41264 + buildRule.executeTarget("nonJavaIncludes"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java new file mode 100644 index 00000000..fd8c3281 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java @@ -0,0 +1,170 @@ +/* + * 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.taskdefs; + +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.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 + */ +public class LoadFileTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/loadfile.xml"); + } + + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testNoSourcefileDefined() { + 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() { + 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() { + 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 { + buildRule.executeTarget("testFailOnError"); + assertNull(buildRule.getProject().getProperty("testFailOnError")); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testLoadAFile() + throws BuildException { + buildRule.executeTarget("testLoadAFile"); + if(buildRule.getProject().getProperty("testLoadAFile").indexOf("eh?")<0) { + fail("property is not all in the file"); + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testLoadAFileEnc() + throws BuildException { + buildRule.executeTarget("testLoadAFileEnc"); + assertNotNull("file load files", buildRule.getProject().getProperty("testLoadAFileEnc")); + } + + /** + * A unit test for JUnit + */ + @Test + public void testEvalProps() + throws BuildException { + buildRule.executeTarget("testEvalProps"); + if(buildRule.getProject().getProperty("testEvalProps").indexOf("rain")<0) { + fail("property eval broken"); + } + } + + /** + * Test FilterChain and FilterReaders + */ + @Test + public void testFilterChain() + throws BuildException { + buildRule.executeTarget("testFilterChain"); + if(buildRule.getProject().getProperty("testFilterChain").indexOf("World!")<0) { + fail("Filter Chain broken"); + } + } + + /** + * Test StripJavaComments filterreader functionality. + */ + @Test + public final void testStripJavaComments() + throws BuildException { + buildRule.executeTarget("testStripJavaComments"); + final String expected = buildRule.getProject().getProperty("expected"); + final String generated = buildRule.getProject().getProperty("testStripJavaComments"); + assertEquals(expected, generated); + } + + @Test + public void testOneLine() { + buildRule.executeTarget("testOneLine"); + assertEquals("1,2,3,4", buildRule.getProject().getProperty("testOneLine")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java new file mode 100644 index 00000000..18b9786b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java @@ -0,0 +1,206 @@ +/* + * 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.taskdefs; + +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.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class MacroDefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/macrodef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("Hello World", buildRule.getLog()); + } + + @Test + public void testText() { + buildRule.executeTarget("text"); + assertEquals("Inner Text", buildRule.getLog()); + } + + @Test + public void testDuplicateAttribute() { + 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() { + 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() { + buildRule.executeTarget("uri"); + assertEquals("Hello World", buildRule.getLog()); + } + + @Test + public void testNested() { + buildRule.executeTarget("nested"); + assertEquals("A nested element", buildRule.getLog()); + } + + @Test + public void testDouble() { + buildRule.executeTarget("double"); + assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog()); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignorecase"); + assertEquals("a is ab is b", buildRule.getLog()); + } + + @Test + public void testIgnoreElementCase() { + buildRule.executeTarget("ignore-element-case"); + assertEquals("nested elementnested element", buildRule.getLog()); + } + + @Test + public void testTextElement() { + buildRule.executeTarget("textelement"); + assertContains("Hello world", buildRule.getLog()); + } + + @Test + public void testTextTrim() { + buildRule.executeTarget("text.trim"); + assertContains("[Hello world]", buildRule.getLog()); + } + + @Test + public void testDuplicateTextName() { + 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() { + 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() { + buildRule.executeTarget("escape"); + assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog()); + } + @Test + public void testAttributeDescription() { + buildRule.executeTarget("attribute.description"); + assertEquals("description is hello world", buildRule.getLog()); + } + @Test + public void testOverrideDefault() { + buildRule.executeTarget("override.default"); + assertEquals("value is new", buildRule.getLog()); + } + @Test + public void testImplicit() { + buildRule.executeTarget("implicit"); + assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog()); + } + @Test + public void testImplicitNotOptional() { + 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() { + buildRule.executeTarget("implicit.optional"); + assertEquals("Before implicitAfter implicit", buildRule.getLog()); + } + @Test + public void testImplicitExplicit() { + 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 { + buildRule.executeTarget("backtraceoff"); + } catch (BuildException ex) { + if (ex.getMessage().indexOf("following error occurred") != -1) { + fail("error message contained backtrace - " + ex.getMessage()); + } + } + } + + @Test + public void testBackTrace() { + 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() { + buildRule.executeTarget("top-level-text"); + assertContains("Hello World", buildRule.getLog()); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java new file mode 100644 index 00000000..8c2762a7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java @@ -0,0 +1,176 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("BuildException expected: missing property"); + } catch (BuildException ex) { + assertContains("property", ex.getMessage()); + } + } + + @Test + public void testNoProperty() { + try { + buildRule.executeTarget("testNoProperty"); + fail("BuildException expected: missing property"); + } catch (BuildException ex) { + assertContains("property", ex.getMessage()); + } + } + + @Test + public void testNoFile() { + try { + buildRule.executeTarget("testNoFile"); + fail("BuildException expected: missing file"); + } catch (BuildException ex) { + assertContains("file", ex.getMessage()); + } + } + + @Test + public void testValidation() { + try { + buildRule.executeTarget("testValidation"); + fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE); + } catch (BuildException ex) { + assertContains("file", ex.getMessage()); + } + } + + @Test + public void testWorks() { + buildRule.executeTarget("testWorks"); + assertPropertyContains("testWorks", "file:"); + assertPropertyContains("testWorks", "/foo"); + } + + @Test + public void testIllegalChars() { + buildRule.executeTarget("testIllegalChars"); + assertPropertyContains("testIllegalChars", "file:"); + assertPropertyContains("testIllegalChars", "fo%20o%25"); + } + + /** + * test that we can round trip by opening a url that exists + * + * @throws IOException + */ + @Test + public void testRoundTrip() throws IOException { + buildRule.executeTarget("testRoundTrip"); + assertPropertyContains("testRoundTrip", "file:"); + String property = getProperty("testRoundTrip"); + URL url = new URL(property); + InputStream instream = url.openStream(); + instream.close(); + } + + @Test + public void testIllegalCombinations() { + buildRule.executeTarget("testIllegalCombinations"); + assertPropertyContains("testIllegalCombinations", "/foo"); + assertPropertyContains("testIllegalCombinations", ".xml"); + } + + @Test + public void testFileset() { + buildRule.executeTarget("testFileset"); + assertPropertyContains("testFileset", ".xml "); + assertPropertyEndsWith("testFileset", ".xml"); + } + + @Test + public void testFilesetSeparator() { + buildRule.executeTarget("testFilesetSeparator"); + assertPropertyContains("testFilesetSeparator", ".xml\",\""); + assertPropertyEndsWith("testFilesetSeparator", ".xml"); + } + + @Test + public void testPath() { + buildRule.executeTarget("testPath"); + assertPropertyContains("testPath", "makeurl.xml"); + } + + /** + * assert that a property ends with + * + * @param property + * @param ending + */ + private void assertPropertyEndsWith(String property, String ending) { + String result = getProperty(property); + String substring = result.substring(result.length() - ending.length()); + assertEquals(ending, substring); + } + + /** + * assert that a property contains a string + * + * @param property name of property to look for + * @param contains what to search for in the string + */ + protected void assertPropertyContains(String property, String contains) { + String result = getProperty(property); + + assertTrue("expected " + contains + " in " + result, + result != null && result.indexOf(contains) >= 0); + } + + /** + * get a property from the project + * + * @param property + * @return + */ + protected String getProperty(String property) { + return buildRule.getProject().getProperty(property); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java new file mode 100644 index 00000000..95d4f3de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java @@ -0,0 +1,249 @@ +/* + * 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.taskdefs; + + +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 { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); + } + + @Test + public void testBadDirectory() { + 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() { + 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() { + 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() { + 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() { + 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() { + buildRule.executeTarget("test-parent-level1"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "dsp-core/ " + + "dsp-pres/ " + + "dsp-void/ " + + "../generated/dsp-core/ " + + "../generated/dsp-pres/ " + + "../generated/dsp-void/ " + + "../resources/dsp-core/ " + + "../resources/dsp-pres/ " + + "../resources/dsp-void/"); + } + + @Test + public void testParentLevel2() { + buildRule.executeTarget("test-parent-level2"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../dsp-core/ " + + "../dsp-pres/ " + + "../dsp-void/ " + + "../../generated/dsp-core/ " + + "../../generated/dsp-pres/ " + + "../../generated/dsp-void/ " + + "../../resources/dsp-core/ " + + "../../resources/dsp-pres/ " + + "../../resources/dsp-void/"); + } + + @Test + public void testParentLevel2TooDeep() { + 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() { + 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/ " + + "resources/dsp-core/ " + + "resources/dsp-pres/"); + } + + @Test + public void testPseudoTahoeNested() { + 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/ " + + "resources/dsp-core/ " + + "resources/dsp-pres/"); + } + + @Test + public void testParentLevel2WithJars() { + buildRule.executeTarget("test-parent-level2-with-jars"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../../lib/acme-core.jar " + + "../../lib/acme-pres.jar " + + "../dsp-core/ " + + "../dsp-pres/ " + + "../dsp-void/ " + + "../../generated/dsp-core/ " + + "../../generated/dsp-pres/ " + + "../../generated/dsp-void/ " + + "../../resources/dsp-core/ " + + "../../resources/dsp-pres/ " + + "../../resources/dsp-void/"); + } + + @Test + public void testInternationalGerman() { + buildRule.executeTarget("international-german"); + buildRule.executeTarget("run-two-jars"); + assertContains("beta alpha", buildRule.getLog()); + + } + + @Test + public void testInternationalHebrew() { + 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() { + 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() { + 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"; + } + 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 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java new file mode 100644 index 00000000..6e794327 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -0,0 +1,477 @@ +/* + * 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.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private File expandedManifest; + private File outDir; + + public static final String LONG_LINE + = "AReallyLongLineToTestLineBreakingInManifests-ACapabilityWhich" + + "IsSureToLeadToHundredsOfQuestionsAboutWhyAntMungesManifests" + + "OfCourseTheAnswerIsThatIsWhatTheSpecRequiresAndIfAnythingHas" + + "AProblemWithThatItIsNotABugInAnt"; + + public static final String LONG_70_NAME + = "ThisNameIsJustSeventyCharactersWhichIsAllowedAccordingToTheSpecsFiller"; + public static final String LONG_68_NAME + = "ThisNameIsJustSixtyEightCharactersWhichIsAllowedAccordingToTheSpecsX"; + public static final String NOT_LONG_NAME + = "NameIsJustUnderSeventyCharactersWhichIsAllowedAccordingTheSpec"; + + public static final String VALUE = "NOT_LONG"; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/manifest.xml"); + outDir = new File(buildRule.getProject().getProperty("output")); + expandedManifest = new File(outDir, "manifests/META-INF/MANIFEST.MF"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + /** + * Empty manifest - is OK + */ + @Test + public void test1() throws ManifestException, IOException { + buildRule.executeTarget("test1"); + Manifest manifest = getManifest(expandedManifest); + String version = manifest.getManifestVersion(); + assertEquals("Manifest was not created with correct version - ", "1.0", version); + } + + /** + * Simple Manifest with version 2.0 + */ + @Test + public void test2() throws ManifestException, IOException { + buildRule.executeTarget("test2"); + Manifest manifest = getManifest(expandedManifest); + String version = manifest.getManifestVersion(); + assertEquals("Manifest was not created with correct version - ", "2.0", version); + } + + /** + * Malformed manifest - no : on the line + */ + @Test + public void test3() { + 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() { + 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() { + 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); + } + + /** + * New Section not starting with Name attribute. + */ + @Test + public void test6() { + 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() { + buildRule.executeTarget("test7"); + + 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 { + buildRule.executeTarget("test8"); + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", "fubar", classpath); + + Manifest.Section testSection = manifest.getSection("Test"); + String testAttr = testSection.getAttributeValue("TestAttr"); + assertEquals("TestAttr attribute was not set correctly - ", "Test", testAttr); + } + + /** + * Inline manifest - Invalid since has a Name attribute in the section element + */ + @Test + public void test9() { + 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() { + 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() { + 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() { + 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() { + 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 { + buildRule.executeTarget("test14"); + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", + "Test1 Test2 Test3 Test4", classpath); + } + + /** + * Tets long line wrapping + */ + @Test + public void testLongLine() throws IOException, ManifestException { + 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); + buildRule.executeTarget("testLongLine"); + + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", + LONG_LINE, classpath); + + String value = mainSection.getAttributeValue(LONG_68_NAME); + assertEquals("LONG_68_NAME_VALUE_MISMATCH", VALUE, value); + value = mainSection.getAttributeValue(LONG_70_NAME); + assertEquals("LONG_70_NAME_VALUE_MISMATCH", VALUE, value); + value = mainSection.getAttributeValue(NOT_LONG_NAME); + assertEquals("NOT_LONG_NAME_VALUE_MISMATCH", VALUE, value); + + Set set = new HashSet(); + FileReader fin = new FileReader(expandedManifest); + try { + BufferedReader in = new BufferedReader(fin); + + String read = in.readLine(); + while (read != null) { + set.add(read); + read = in.readLine(); + } + in.close(); + } finally { + fin.close(); + } + + assertTrue("Manifest file should have contained string ", set + .remove(" NOT_LONG")); + assertTrue("Manifest file should have contained string ", set + .remove(" NG")); + assertTrue("Manifest file should have contained string ", set + .remove(LONG_70_NAME + ": ")); + assertTrue("Manifest file should have contained string ", set + .remove(NOT_LONG_NAME + ": NOT_LO")); + } + + /** + * Tests ordering of sections + */ + @Test + public void testOrder1() throws IOException, ManifestException { + buildRule.executeTarget("testOrder1"); + + Manifest manifest = getManifest(expandedManifest); + Enumeration e = manifest.getSectionNames(); + String section1 = (String)e.nextElement(); + String section2 = (String)e.nextElement(); + assertEquals("First section name unexpected", "Test1", section1); + assertEquals("Second section name unexpected", "Test2", section2); + + Manifest.Section section = manifest.getSection("Test1"); + e = section.getAttributeKeys(); + String attr1Key = (String)e.nextElement(); + String attr2Key = (String)e.nextElement(); + String attr1 = section.getAttribute(attr1Key).getName(); + String attr2 = section.getAttribute(attr2Key).getName(); + assertEquals("First attribute name unexpected", "TestAttr1", attr1); + assertEquals("Second attribute name unexpected", "TestAttr2", attr2); + } + + /** + * Tests ordering of sections + */ + @Test + public void testOrder2() throws IOException, ManifestException { + buildRule.executeTarget("testOrder2"); + + Manifest manifest = getManifest(expandedManifest); + Enumeration e = manifest.getSectionNames(); + String section1 = (String)e.nextElement(); + String section2 = (String)e.nextElement(); + assertEquals("First section name unexpected", "Test2", section1); + assertEquals("Second section name unexpected", "Test1", section2); + + Manifest.Section section = manifest.getSection("Test1"); + e = section.getAttributeKeys(); + String attr1Key = (String)e.nextElement(); + String attr2Key = (String)e.nextElement(); + String attr1 = section.getAttribute(attr1Key).getName(); + String attr2 = section.getAttribute(attr2Key).getName(); + assertEquals("First attribute name unexpected", "TestAttr2", attr1); + assertEquals("Second attribute name unexpected", "TestAttr1", attr2); + } + + /** + * file attribute for manifest task is required. + */ + @Test + public void testNoFile() { + 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 { + buildRule.executeTarget("testReplace"); + Manifest mf = getManifest(new File(outDir, "mftest.mf")); + assertNotNull(mf); + assertEquals(Manifest.getDefaultManifest(), mf); + } + + /** + * update keeps the Manifest-Version and adds a new attribute Foo + */ + @Test + public void testUpdate() throws IOException, ManifestException { + buildRule.executeTarget("testUpdate"); + Manifest mf = getManifest(new File(outDir, "mftest.mf")); + assertNotNull(mf); + assertTrue(!Manifest.getDefaultManifest().equals(mf)); + String mfAsString = mf.toString(); + assertNotNull(mfAsString); + assertTrue(mfAsString.startsWith("Manifest-Version: 2.0")); + assertTrue(mfAsString.indexOf("Foo: Bar") > -1); + + mf = getManifest(new File(outDir, "mftest2.mf")); + assertNotNull(mf); + mfAsString = mf.toString(); + assertNotNull(mfAsString); + assertEquals(-1, mfAsString.indexOf("Foo: Bar")); + assertTrue(mfAsString.indexOf("Foo: Baz") > -1); + } + + @Test + public void testFrom() { + buildRule.executeTarget("testFrom"); + assertContains(Manifest.ERROR_FROM_FORBIDDEN, buildRule.getLog()); + } + + @Test + public void testIllegalName() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain ' '"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalNameInSection() { + try { + buildRule.executeTarget("testIllegalNameInSection"); + fail("BuildException expected: Manifest attribute names must not contain ' '"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalNameBegin() { + 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() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain '.'"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalName3() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain '*'"); + } catch (BuildException ex) { + //TODO assert value + } + } + + /** + * Reads mftest.mf. + */ + private Manifest getManifest(File file) throws IOException, ManifestException { + FileReader r = new FileReader(file); + try { + return new Manifest(r); + } finally { + r.close(); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java new file mode 100644 index 00000000..d8f1bfc5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java @@ -0,0 +1,70 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: directory already exists as a file"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + 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 { + f.delete(); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java new file mode 100644 index 00000000..0537c0a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java @@ -0,0 +1,168 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/move.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testFilterSet() throws IOException { + 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()); + assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); + } + + @Test + public void testFilterChain() throws IOException { + 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()); + assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); + } + + /** Bugzilla Report 11732 */ + @Test + public void testDirectoryRemoval() throws IOException { + + 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 { + 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 { + 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 { + 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() { + buildRule.executeTarget("testMoveFileAndFileset"); + } + + @Test + public void testCompleteDirectoryMoveToExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveToExistingDir"); + } + + @Test + public void testCompleteDirectoryMoveFileToFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDir"); + } + + @Test + public void testCompleteDirectoryMoveFileAndFileset() { + buildRule.executeTarget("testCompleteDirectoryMoveFileAndFileset"); + } + + @Test + public void testCompleteDirectoryMoveFileToExistingFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingDir"); + } + + @Test + public void testCompleteDirectoryMoveFileToDirWithExistingFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToDirWithExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingDir"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java new file mode 100644 index 00000000..95f9eafd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java @@ -0,0 +1,79 @@ +/* + * 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.taskdefs; + +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 { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/multimap.xml"); + } + + @Test + public void testMultiCopy() { + buildRule.executeTarget("multicopy"); + } + + @Test + public void testMultiMove() { + buildRule.executeTarget("multimove"); + } + + @Test + public void testSingleCopy() { + buildRule.executeTarget("singlecopy"); + } + + @Test + public void testSingleMove() { + buildRule.executeTarget("singlemove"); + } + + @Test + public void testCopyWithEmpty() { + buildRule.executeTarget("copywithempty"); + } + + @Test + public void testMoveWithEmpty() { + buildRule.executeTarget("movewithempty"); + } + + public static class TestMapper implements FileNameMapper { + public TestMapper() {} + public void setFrom(String from) {} + public void setTo(String to) {} + public String[] mapFileName(final String source_file_name) { + return new String[] { + source_file_name, source_file_name+".copy2" }; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java new file mode 100644 index 00000000..98d9fa58 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java @@ -0,0 +1,83 @@ +/* + * 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.taskdefs; + +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.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * test nice + */ +public class NiceTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/nice.xml"); + } + + @Test + public void testNoop() { + buildRule.executeTarget("noop"); + } + + @Test + public void testCurrent() { + buildRule.executeTarget("current"); + } + + @Test + public void testFaster() { + buildRule.executeTarget("faster"); + } + + @Test + public void testSlower() { + buildRule.executeTarget("slower"); + } + + @Test + public void testTooSlow() { + try { + buildRule.executeTarget("too_slow"); + fail("BuildException expected: out of range"); + } catch (BuildException ex) { + assertContains("out of the range 1-10", ex.getMessage()); + } + } + + @Test + public void testTooFast() { + try { + buildRule.executeTarget("too_fast"); + fail("BuildException expected: out of range"); + } catch (BuildException ex) { + assertContains("out of the range 1-10", ex.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java new file mode 100644 index 00000000..3ca7cf78 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java @@ -0,0 +1,195 @@ +/* + * 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.taskdefs; + +import java.io.PrintStream; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DemuxOutputStream; +import org.apache.tools.ant.ExitStatusException; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Test of the parallel TaskContainer + */ +public class ParallelTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + /** Standard property value for the basic test */ + public final static String DIRECT_MESSAGE = "direct"; + /** Standard property value for the basic and fail test */ + public final static String DELAYED_MESSAGE = "delayed"; + /** Standard property value for the fail test */ + public final static String FAILURE_MESSAGE = "failure"; + + /** the build fiel associated with this test */ + public final static String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/parallel.xml"; + + + /** The JUnit setup method */ + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** tests basic operation of the parallel task */ + @Test + public void testBasic() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.direct", DIRECT_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + buildRule.executeTarget("testBasic"); + assertEquals("", buildRule.getOutput()); + assertEquals("", buildRule.getError()); + String log = buildRule.getLog(); + assertEquals("parallel tasks didn't output correct data", log, + DIRECT_MESSAGE + DELAYED_MESSAGE); + + } + + /** tests basic operation of the parallel task */ + @Test + public void testThreadCount() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.direct", DIRECT_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + buildRule.executeTarget("testThreadCount"); + assertEquals("", buildRule.getOutput()); + assertEquals("", buildRule.getError()); + String log = buildRule.getLog(); + int pos = 0; + while (pos > -1) { + pos = countThreads(log, pos); + } + } + + /** + * the test result string should match the regex + * <code>^(\|\d+\/(+-)*)+\|$</code> for someting like + * <code>|3/++--+-|5/+++++-----|</code> + * + *@return -1 no more tests + * # start pos of next test + */ + static int countThreads(String s, int start) { + int firstPipe = s.indexOf('|', start); + int beginSlash = s.indexOf('/', firstPipe); + int lastPipe = s.indexOf('|', beginSlash); + if ((firstPipe == -1) || (beginSlash == -1) || (lastPipe == -1)) { + return -1; + } + + int max = Integer.parseInt(s.substring(firstPipe + 1, beginSlash)); + int current = 0; + int pos = beginSlash + 1; + while (pos < lastPipe) { + switch (s.charAt(pos++)) { + case '+': + current++; + break; + case '-': + current--; + break; + default: + fail("Only expect '+-' in result count, found " + + s.charAt(--pos) + " at position " + pos); + } + if (current > max) { + fail("Number of executing threads exceeded number allowed: " + + current + " > " + max); + } + } + return lastPipe; + } + + + /** tests the failure of a task within a parallel construction */ + @Test + public void testFail() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.failure", FAILURE_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + try { + buildRule.executeTarget("testFail"); + fail("fail task in one parallel branch"); + } catch (BuildException ex) { + assertEquals(FAILURE_MESSAGE, ex.getMessage()); + } + } + + /** tests the demuxing of output streams in a multithreaded situation */ + @Test + public void testDemux() { + Project p = buildRule.getProject(); + p.addTaskDefinition("demuxtest", DemuxOutputTask.class); + synchronized (System.out) { + PrintStream out = System.out; + PrintStream err = System.err; + System.setOut(new PrintStream(new DemuxOutputStream(p, false))); + System.setErr(new PrintStream(new DemuxOutputStream(p, true))); + + try { + p.executeTarget("testDemux"); + } finally { + System.setOut(out); + System.setErr(err); + } + } + } + + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + @Test + public void testSingleExit() { + try { + buildRule.executeTarget("testSingleExit"); + fail("ExitStatusException should have been thrown"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + @Test + public void testExitAndOtherException() { + try { + buildRule.executeTarget("testExitAndOtherException"); + fail("ExitStatusException should have been thrown"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java new file mode 100644 index 00000000..31a516e3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java @@ -0,0 +1,65 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unit test for the <pathconvert> task. + */ +public class PathConvertTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static final String BUILD_PATH = "src/etc/testcases/taskdefs/"; + private static final String BUILD_FILENAME = "pathconvert.xml"; + private static final String BUILD_FILE = BUILD_PATH + BUILD_FILENAME; + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + @Test + public void testMap() { + test("testmap"); + } + + @Test + public void testMapper() { + test("testmapper"); + } + + @Test + public void testNoTargetOs() { + buildRule.executeTarget("testnotargetos"); + } + + private void test(String target) { + buildRule.executeTarget(target); + assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java new file mode 100644 index 00000000..8c7c1f3f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java @@ -0,0 +1,154 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.FileSet; +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 PreSetDefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/presetdef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("Hello world", buildRule.getLog()); + } + + @Test + public void testText() { + buildRule.executeTarget("text"); + assertEquals("Inner Text", buildRule.getLog()); + } + + @Test + public void testUri() { + buildRule.executeTarget("uri"); + assertEquals("Hello world", buildRule.getLog()); + } + + @Test + public void testDefaultTest() { + buildRule.executeTarget("defaulttest"); + assertEquals("attribute is false", buildRule.getLog()); + } + + @Test + public void testDoubleDefault() { + buildRule.executeTarget("doubledefault"); + assertEquals("attribute is falseattribute is true", buildRule.getLog()); + } + + @Test + public void testTextOptional() { + buildRule.executeTarget("text.optional"); + assertEquals("MyTextoverride text", buildRule.getLog()); + } + + @Test + public void testElementOrder() { + buildRule.executeTarget("element.order"); + assertEquals("Line 1Line 2", buildRule.getLog()); + } + + @Test + public void testElementOrder2() { + buildRule.executeTarget("element.order2"); + assertEquals("Line 1Line 2Line 3", buildRule.getLog()); + } + + @Test + public void testAntTypeTest() { + buildRule.executeTarget("antTypeTest"); + assertEquals("", buildRule.getLog()); + } + + @Test + public void testCorrectTaskNameBadAttr() { + try { + buildRule.executeTarget("correct_taskname_badattr"); + fail("BuildException expected: attribute message"); + } catch (BuildException ex) { + assertContains("javac doesn't support the", ex.getMessage()); + } + } + + @Test + public void testCorrectTaskNameBadEl() { + try { + buildRule.executeTarget("correct_taskname_badel"); + fail("BuildException expected: element message"); + } catch (BuildException ex) { + assertContains("javac doesn't support the", ex.getMessage()); + } + } + + @Test + public void testPresetdefWithNestedElementTwice() { // #38056 + buildRule.executeTarget("presetdef-with-nested-element-twice"); + buildRule.executeTarget("presetdef-with-nested-element-twice"); + } + + /** + * A test class to check default properties + */ + public static class DefaultTest extends Task { + boolean isSet = false; + boolean attribute = false; + public void setAttribute(boolean b) { + if (isSet) { + throw new BuildException("Attribute Already set"); + } + attribute = b; + isSet = true; + } + + public void execute() { + getProject().log("attribute is " + attribute); + } + } + + /** + * A test class to check presetdef with add and addConfigured and ant-type + */ + public static class AntTypeTest extends Task { + public void addFileSet(FileSet fileset) { + } + public void addConfiguredConfigured(FileSet fileset) { + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java new file mode 100644 index 00000000..eadac406 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java @@ -0,0 +1,68 @@ +/* + * 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. + * + */ + +/* + * Created on Feb 19, 2003 + */ +package org.apache.tools.ant.taskdefs; + +import java.io.IOException; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + */ +//TODO this test seems really unsafe due to the infinite loop +public class ProcessDestroyerTest { + + @Test + public void testProcessDestroyer() throws IOException { + ProcessDestroyer processDestroyer = new ProcessDestroyer(); + Process process = + Runtime.getRuntime().exec( + "java -cp " + + System.getProperty("java.class.path") + + " " + + getClass().getName()); + + assertFalse("Not registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + + processDestroyer.add(process); + + assertTrue("Registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + try { + process.destroy(); + } finally { + processDestroyer.remove(process); + } + + assertFalse("Not registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + + } + + public static void main(String[] args) throws IOException, InterruptedException { + new ProcessDestroyerTest().testProcessDestroyer(); + Thread.sleep(60000); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java new file mode 100644 index 00000000..52b762d0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java @@ -0,0 +1,141 @@ +/* + * 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.taskdefs; + +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.BuildException; +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 PropertyTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/property.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + // should get no output at all + buildRule.executeTarget("test1"); + assertEquals("System output should have been empty", "", buildRule.getOutput()); + assertEquals("System error should have been empty", "", buildRule.getError()); + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + assertContains("testprop1=aa, testprop3=xxyy, testprop4=aazz", buildRule.getLog()); + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Did not throw exception on circular exception"); + } + catch (BuildException e) { + assertTrue("Circular definition not detected - ", + e.getMessage().indexOf("was circularly defined") != -1); + } + + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertContains("http.url is http://localhost:999", buildRule.getLog()); + } + + @Test + public void test5() { + String baseDir = buildRule.getProject().getProperty("basedir"); + String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); + buildRule.getProject().setNewProperty("test5.url", uri); + + buildRule.executeTarget("test5"); + assertContains("http.url is http://localhost:999", buildRule.getLog()); + } + + @Test + public void testPrefixSuccess() { + buildRule.executeTarget("prefix.success"); + assertEquals("80", buildRule.getProject().getProperty("server1.http.port")); + } + + @Test + public void testPrefixFailure() { + try { + buildRule.executeTarget("prefix.fail"); + fail("Did not throw exception on invalid use of prefix"); + } + catch (BuildException e) { + assertContains("Prefix allowed on non-resource/file load - ", + "Prefix is only valid", e.getMessage()); + } + } + + @Test + public void testCircularReference() { + try { + buildRule.executeTarget("testCircularReference"); + fail("Did not throw exception on circular exception"); + } catch (BuildException e) { + assertContains("Circular definition not detected - ", + "was circularly defined", e.getMessage()); + } + } + + @Test + public void testThisIsNotACircularReference() { + buildRule.executeTarget("thisIsNotACircularReference"); + assertContains("b is A/A/A", buildRule.getLog()); + } + + @Test + public void testXmlProperty() { + try { + Class.forName("java.lang.Iterable"); + } catch (ClassNotFoundException e) { + Assume.assumeNoException("XML Loading only on Java 5+", e); + } + buildRule.executeTarget("testXmlProperty"); + assertEquals("ONE", buildRule.getProject().getProperty("xml.one")); + assertEquals("TWO", buildRule.getProject().getProperty("xml.two")); + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java new file mode 100644 index 00000000..27b3c8c8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java @@ -0,0 +1,106 @@ +/* + * 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.taskdefs; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +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; + +/** + */ +public class ProtectedJarMethodsTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + private static String tempJar = "tmp.jar"; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testGrabFilesAndDirs() throws IOException { + buildRule.executeTarget("testIndexTests"); + String archive = buildRule.getProject().getProperty(tempJar); + ArrayList dirs = new ArrayList(); + ArrayList files = new ArrayList(); + String[] expectedDirs = new String[] { + "META-INF/", + "sub/", + }; + String[] expectedFiles = new String[] { + "foo", + }; + Jar.grabFilesAndDirs(archive, dirs, files); + assertEquals(expectedDirs.length, dirs.size()); + for (int i = 0; i < expectedDirs.length; i++) { + assertTrue("Found " + expectedDirs[i], + dirs.contains(expectedDirs[i])); + } + assertEquals(expectedFiles.length, files.size()); + for (int i = 0; i < expectedFiles.length; i++) { + assertTrue("Found " + expectedFiles[i], + files.contains(expectedFiles[i])); + } + } + + @Test + public void testFindJarNameNoClasspath() { + assertEquals("foo", Jar.findJarName("foo", null)); + assertEquals("foo", Jar.findJarName("lib" + File.separatorChar + "foo", + null)); + } + + @Test + public void testFindJarNameNoMatch() { + assertNull(Jar.findJarName("foo", new String[] {"bar"})); + } + + @Test + public void testFindJarNameSimpleMatches() { + assertEquals("foo", Jar.findJarName("foo", new String[] {"foo"})); + assertEquals("lib/foo", Jar.findJarName("foo", + new String[] {"lib/foo"})); + assertEquals("foo", Jar.findJarName("bar" + File.separatorChar + "foo", + new String[] {"foo"})); + assertEquals("lib/foo", + Jar.findJarName("bar" + File.separatorChar + "foo", + new String[] {"lib/foo"})); + } + + @Test + public void testFindJarNameLongestMatchWins() { + assertEquals("lib/foo", + Jar.findJarName("lib/foo", + new String[] {"foo", "lib/foo", + "lib/bar/foo"})); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java new file mode 100644 index 00000000..c4806cd8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java @@ -0,0 +1,103 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +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.assertTrue; + +/** + */ +public class RecorderTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static final String REC_IN = "recorder/"; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/recorder.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testNoAppend() throws IOException { + buildRule.executeTarget("noappend"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest1.result"), + new File(buildRule.getOutputDir(), + "rectest1.log"), true)); + } + + @Test + public void testAppend() throws IOException { + buildRule.executeTarget("append"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest2.result"), + new File(buildRule.getOutputDir(), + "rectest2.log"), true)); + } + + @Test + public void testRestart() throws IOException { + buildRule.executeTarget("restart"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest3.result"), + new File(buildRule.getOutputDir(), "rectest3.log"), true)); + } + + @Test + public void testDeleteRestart() throws IOException { + buildRule.executeTarget("deleterestart"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest4.result"), + new File(buildRule.getOutputDir(), + "rectest4.log"), true)); + } + + @Test + public void testSubBuild() throws IOException { + buildRule.executeTarget("subbuild"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest5.result"), + new File(buildRule.getOutputDir(), "rectest5.log"), true)); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest6.result"), + new File(buildRule.getOutputDir(), "rectest6.log"), true)); + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java new file mode 100644 index 00000000..0cb13441 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java @@ -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.taskdefs; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class RenameTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/rename.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException should have been thrown: source and destination the same"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test5() { + buildRule.executeTarget("test5"); + } + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java new file mode 100644 index 00000000..387c54dc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java @@ -0,0 +1,180 @@ +/* + * 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.taskdefs; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +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; +import static org.junit.Assume.assumeTrue; + +/** + */ +public class ReplaceTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/replace.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: empty token not allowed"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("BuildException expected: empty token not allowed"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + + @Test + public void test9() throws IOException { + + buildRule.executeTarget("test9"); + assertEqualContent(new File(buildRule.getOutputDir(), "result.txt"), + new File(buildRule.getOutputDir(), "output.txt")); + } + + @Test + public void testNoPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testNoPreserve"); + assertTrue(ts1 < new File(buildRule.getOutputDir(), "test.txt").lastModified()); + } + + @Test + public void testPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long ts1 = testFile.lastModified();buildRule.executeTarget("testPreserve"); + assertTrue(ts1 == new File(buildRule.getOutputDir(), "test.txt").lastModified()); + } + + public void assertEqualContent(File expect, File result) + throws AssertionFailedError, IOException { + if (!result.exists()) { + fail("Expected file "+result+" doesn\'t exist"); + } + + InputStream inExpect = null; + InputStream inResult = null; + try { + inExpect = new BufferedInputStream(new FileInputStream(expect)); + inResult = new BufferedInputStream(new FileInputStream(result)); + + int expectedByte = inExpect.read(); + while (expectedByte != -1) { + assertEquals(expectedByte, inResult.read()); + expectedByte = inExpect.read(); + } + assertEquals("End of file", -1, inResult.read()); + } finally { + if (inResult != null) { + inResult.close(); + } + if (inExpect != null) { + inExpect.close(); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java new file mode 100644 index 00000000..c9d25146 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java @@ -0,0 +1,467 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; +import org.apache.tools.ant.taskdefs.rmic.DefaultRmicAdapter; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Date: 04-Aug-2004 + * Time: 22:15:46 + */ +public class RmicAdvancedTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/rmic/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** + * The JUnit setup method + */ + @Before + public void setUp() throws Exception { + buildRule.configureProject(TASKDEFS_DIR + "rmic.xml"); + } + + /** + * verify that "default" binds us to the default compiler + */ + @Test + public void testDefault() throws Exception { + buildRule.executeTarget("testDefault"); + } + + /** + * verify that "default" binds us to the default compiler + */ + @Test + public void testDefaultDest() throws Exception { + buildRule.executeTarget("testDefaultDest"); + } + + /** + * verify that "" binds us to the default compiler + */ + @Test + public void testEmpty() throws Exception { + buildRule.executeTarget("testEmpty"); + } + + /** + * verify that "" binds us to the default compiler + */ + @Test + public void testEmptyDest() throws Exception { + buildRule.executeTarget("testEmptyDest"); + } + + /** + * test sun's rmic compiler + */ + @Test + public void testRmic() throws Exception { + buildRule.executeTarget("testRmic"); + } + + /** + * test sun's rmic compiler + */ + @Test + public void testRmicDest() throws Exception { + buildRule.executeTarget("testRmicDest"); + } + + /** + * test sun's rmic compiler strips + * out -J arguments when not forking + */ + @Test + public void testRmicJArg() throws Exception { + buildRule.executeTarget("testRmicJArg"); + } + + /** + * test sun's rmic compiler strips + * out -J arguments when not forking + */ + @Test + public void testRmicJArgDest() throws Exception { + buildRule.executeTarget("testRmicJArgDest"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testKaffe() throws Exception { + buildRule.executeTarget("testKaffe"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testKaffeDest() throws Exception { + buildRule.executeTarget("testKaffeDest"); + } + + // WLrmic tests don't work + /** + * test weblogic + */ + @Test + @Ignore("WLRmin tests don't work") + public void XtestWlrmic() throws Exception { + buildRule.executeTarget("testWlrmic"); + } + + /** + * test weblogic's stripping of -J args + */ + @Test + @Ignore("WLRmin tests don't work") + public void XtestWlrmicJArg() throws Exception { + buildRule.executeTarget("testWlrmicJArg"); + } + + /** + * test the forking compiler + */ + @Test + @Ignore("WLRmin tests don't work") + public void NotestForking() throws Exception { + buildRule.executeTarget("testForking"); + } + + /** + * test the forking compiler + */ + @Test + public void testForkingAntClasspath() throws Exception { + buildRule.executeTarget("testForkingAntClasspath"); + } + + /** + * test the forking compiler + */ + @Test + public void testForkingAntClasspathDest() throws Exception { + buildRule.executeTarget("testForkingAntClasspathDest"); + } + + /** + * test the forking compiler + */ + @Test + public void testAntClasspath() throws Exception { + buildRule.executeTarget("testAntClasspath"); + } + + /** + * test the forking compiler + */ + @Test + public void testAntClasspathDest() throws Exception { + buildRule.executeTarget("testAntClasspathDest"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testBadName() throws Exception { + try { + buildRule.executeTarget("testBadName"); + fail("Compile not known"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + /** + * load an adapter by name + */ + @Test + public void testExplicitClass() throws Exception { + buildRule.executeTarget("testExplicitClass"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testWrongClass() throws Exception { + try { + buildRule.executeTarget("testWrongClass"); + fail("Class not an RMIC adapter"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_NOT_RMIC_ADAPTER, ex.getMessage()); + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testDefaultBadClass() throws Exception { + try { + buildRule.executeTarget("testDefaultBadClass"); + fail("expected the class to fail"); + } catch(BuildException ex) { + AntAssert.assertContains(Rmic.ERROR_RMIC_FAILED, ex.getMessage()); + } + //dont look for much text here as it is vendor and version dependent + AntAssert.assertContains("unimplemented.class", buildRule.getLog()); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testMagicProperty() throws Exception { + try { + buildRule.executeTarget("testMagicProperty"); + fail("Magic property not working"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + /** + * A unit test for JUnit + */ + @Test + public void testMagicPropertyOverridesEmptyString() throws Exception { + try { + buildRule.executeTarget("testMagicPropertyOverridesEmptyString"); + fail("Magic property not working"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + + @Test + public void testMagicPropertyIsEmptyString() throws Exception { + buildRule.executeTarget("testMagicPropertyIsEmptyString"); + } + + + @Test + @Ignore("Previously named to prevent execution") + public void NotestFailingAdapter() throws Exception { + try { + buildRule.executeTarget("testFailingAdapter"); + fail("Expected failures to propogate"); + } catch (BuildException ex) { + AntAssert.assertContains(Rmic.ERROR_RMIC_FAILED, ex.getMessage()); + } + } + + + /** + * test that version 1.1 stubs are good + * @throws Exception + */ + @Test + public void testVersion11() throws Exception { + buildRule.executeTarget("testVersion11"); + } + + /** + * test that version 1.1 stubs are good + * @throws Exception + */ + @Test + public void testVersion11Dest() throws Exception { + buildRule.executeTarget("testVersion11Dest"); + } + + /** + * test that version 1.2 stubs are good + * + * @throws Exception + */ + @Test + public void testVersion12() throws Exception { + buildRule.executeTarget("testVersion12"); + } + + /** + * test that version 1.2 stubs are good + * + * @throws Exception + */ + @Test + public void testVersion12Dest() throws Exception { + buildRule.executeTarget("testVersion12Dest"); + } + + /** + * test that version compat stubs are good + * + * @throws Exception + */ + @Test + public void testVersionCompat() throws Exception { + buildRule.executeTarget("testVersionCompat"); + } + + /** + * test that version compat stubs are good + * + * @throws Exception + */ + @Test + public void testVersionCompatDest() throws Exception { + buildRule.executeTarget("testVersionCompatDest"); + } + + /** + * test that passes -Xnew to sun's rmic. + * + * @throws Exception + */ + @Test + public void testXnew() throws Exception { + buildRule.executeTarget("testXnew"); + } + + /** + * test that passes -Xnew to sun's rmic. + * + * @throws Exception + */ + @Test + public void testXnewDest() throws Exception { + buildRule.executeTarget("testXnewDest"); + } + + /** + * test that passes -Xnew to sun's rmic running in a different VM. + * + * @throws Exception + */ + @Test + public void testXnewForked() throws Exception { + buildRule.executeTarget("testXnewForked"); + } + + /** + * test that passes -Xnew to sun's rmic running in a different VM. + * + * @throws Exception + */ + @Test + public void testXnewForkedDest() throws Exception { + buildRule.executeTarget("testXnewForkedDest"); + } + + /** + * test that runs the new xnew compiler adapter. + * + * @throws Exception + */ + @Test + public void testXnewCompiler() throws Exception { + buildRule.executeTarget("testXnewCompiler"); + } + + /** + * test that runs the new xnew compiler adapter. + * + * @throws Exception + */ + @Test + public void testXnewCompilerDest() throws Exception { + buildRule.executeTarget("testXnewCompilerDest"); + } + + /** + * test that verifies that IDL compiles. + * + * @throws Exception + */ + @Test + public void testIDL() throws Exception { + buildRule.executeTarget("testIDL"); + } + + /** + * test that verifies that IDL compiles. + * + * @throws Exception + */ + @Test + public void testIDLDest() throws Exception { + buildRule.executeTarget("testIDLDest"); + } + + /** + * test that verifies that IIOP compiles. + * + * @throws Exception + */ + @Test + public void testIIOP() throws Exception { + buildRule.executeTarget("testIIOP"); + } + + /** + * test that verifies that IIOP compiles. + * + * @throws Exception + */ + @Test + public void testIIOPDest() throws Exception { + buildRule.executeTarget("testIIOPDest"); + } + + /** + * this little bunny verifies that we can load stuff, and that + * a failure to execute is turned into a fault + */ + public static class FailingRmicAdapter extends DefaultRmicAdapter { + public static final String LOG_MESSAGE = "hello from FailingRmicAdapter"; + + /** + * Executes the task. + * + * @return false -always + */ + public boolean execute() throws BuildException { + getRmic().log(LOG_MESSAGE); + return false; + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java new file mode 100644 index 00000000..8d3200c3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java @@ -0,0 +1,104 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + + +/** + * Testcase for <rmic>. + * + * @since Ant 1.5 + */ +public class RmicTest { + + private Project project; + private Rmic rmic; + + @Before + public void setUp() { + project = new Project(); + project.init(); + rmic = new Rmic(); + rmic.setProject(project); + } + + /** + * Test nested compiler args. + */ + @Test + public void testCompilerArg() { + String[] args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("no args", 0, args.length); + + Rmic.ImplementationSpecificArgument arg = rmic.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + args = rmic.getCurrentCompilerArgs(); + assertEquals("unconditional single arg", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setCompiler("weblogic"); + args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is weblogic but build.rmic is null", + 0, args.length); + + project.setProperty("build.rmic", "sun"); + args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is weblogic but build.rmic is sun", + 0, args.length); + + project.setProperty("build.rmic", "weblogic"); + args = rmic.getCurrentCompilerArgs(); + assertEquals("both are weblogic", 1, args.length); + assertEquals(testArg, args[0]); + } + + /** + * Test compiler attribute. + */ + @Test + public void testCompilerAttribute() { + // check defaults + String compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("expected sun or kaffe, but found "+compiler,compiler,"default"); + + project.setNewProperty("build.rmic", "weblogic"); + compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("weblogic", compiler); + + // check attribute overrides build.compiler + rmic.setCompiler("kaffe"); + compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("kaffe", compiler); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java new file mode 100644 index 00000000..fbce8a6d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java @@ -0,0 +1,326 @@ +/* + * 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.taskdefs; + +import java.sql.Driver; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.DriverPropertyInfo; +import java.util.Properties; +import java.io.File; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Simple testcase to test for driver caching. + * To test for your own database, you may need to tweak getProperties(int) + * and add a couple of keys. see testOracle and testMySQL for an example. + * + * It would be much better to extend this testcase by using HSQL + * as the test db, so that a db is really used. + * + */ +public class SQLExecTest { + + // some database keys, see #getProperties(int) + public final static int NULL = 0; + public final static int ORACLE = 1; + public final static int MYSQL = 2; + + // keys used in properties. + public final static String DRIVER = "driver"; + public final static String USER = "user"; + public final static String PASSWORD = "password"; + public final static String URL = "url"; + public final static String PATH = "path"; + public final static String SQL = "sql"; + + @Before + public void setUp() throws Exception { + // make sure the cache is cleared. + JDBCTask.getLoaderMap().clear(); + } + + // simple test to ensure that the caching does work... + @Test + public void testDriverCaching(){ + SQLExec sql = createTask(getProperties(NULL)); + assertTrue(!SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); + try { + sql.execute(); + fail("BuildException should have been thrown"); + } catch (BuildException e){ + assertContains("No suitable Driver", e.getMessage()); + } + assertTrue(SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); + assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER)); + ClassLoader loader1 = sql.getLoader(); + + // 2nd run.. + sql = createTask(getProperties(NULL)); + // the driver must still be cached. + assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER)); + try { + sql.execute(); + } catch (BuildException e){ + assertTrue(e.getCause().getMessage().indexOf("No suitable Driver") != -1); + } + assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER)); + assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER)); + assertSame(loader1, sql.getLoader()); + } + + @Test + public void testNull() throws Exception { + doMultipleCalls(1000, NULL, true, true); + } + + @Ignore + @Test + public void testOracle(){ + doMultipleCalls(1000, ORACLE, true, false); + } + + @Ignore + @Test + public void testMySQL(){ + doMultipleCalls(1000, MYSQL, true, false); + } + + + /** + * run a sql tasks multiple times. + * @param calls number of times to execute the task + * @param database the database to execute on. + * @param caching should caching be enabled ? + * @param catchexception true to catch exception for each call, false if not. + */ + protected void doMultipleCalls(int calls, int database, boolean caching, boolean catchexception){ + Properties props = getProperties(database); + for (int i = 0; i < calls; i++){ + SQLExec sql = createTask(props); + sql.setCaching(caching); + try { + sql.execute(); + } catch (BuildException e){ + if (!catchexception){ + throw e; + } + } + } + } + + /** + * Create a task from a set of properties + * @see #getProperties(int) + */ + protected SQLExec createTask(Properties props){ + SQLExec sql = new SQLExec(); + sql.setProject( new Project() ); + sql.setDriver( props.getProperty(DRIVER) ); + sql.setUserid( props.getProperty(USER) ); + sql.setPassword( props.getProperty(PASSWORD) ); + sql.setUrl( props.getProperty(URL) ); + sql.createClasspath().setLocation( new File(props.getProperty(PATH)) ); + sql.addText( props.getProperty(SQL) ); + return sql; + } + + /** + * try to find the path from a resource (jar file or directory name) + * so that it can be used as a classpath to load the resource. + */ + protected String findResourcePath(String resource){ + resource = resource.replace('.', '/') + ".class"; + URL url = getClass().getClassLoader().getResource(resource); + if (url == null) { + return null; + } + String u = url.toString(); + if (u.startsWith("jar:file:")) { + int pling = u.indexOf("!"); + return u.substring("jar:file:".length(), pling); + } else if (u.startsWith("file:")) { + int tail = u.indexOf(resource); + return u.substring("file:".length(), tail); + } + return null; + } + + /** + * returns a configuration associated to a specific database. + * If you want to test on your specific base, you'd better + * tweak this to make it run or add your own database. + * The driver lib should be dropped into the system classloader. + */ + protected Properties getProperties(int database){ + Properties props = null; + switch (database){ + case ORACLE: + props = getProperties("oracle.jdbc.driver.OracleDriver", "test", "test", "jdbc:oracle:thin:@127.0.0.1:1521:orcl"); + break; + case MYSQL: + props = getProperties("org.gjt.mm.mysql.Driver", "test", "test", "jdbc:mysql://127.0.0.1:3306/test"); + break; + case NULL: + default: + props = getProperties(NULL_DRIVER, "test", "test", "jdbc:database://hostname:port/name"); + } + // look for the driver path... + String path = findResourcePath(props.getProperty(DRIVER)); + props.put(PATH, path); + props.put(SQL, "create table OOME_TEST(X INTEGER NOT NULL);\ndrop table if exists OOME_TEST;"); + return props; + } + + /** helper method to build properties */ + protected Properties getProperties(String driver, String user, String pwd, String url){ + Properties props = new Properties(); + props.put(DRIVER, driver); + props.put(USER, user); + props.put(PASSWORD, pwd); + props.put(URL, url); + return props; + } + + +//--- NULL JDBC driver just for simple test since there are no db driver +// available as a default in Ant :) + + public final static String NULL_DRIVER = NullDriver.class.getName(); + + public static class NullDriver implements Driver { + public Connection connect(String url, Properties info) + throws SQLException { + return null; + } + + public boolean acceptsURL(String url) throws SQLException { + return false; + } + + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) + throws SQLException { + return new DriverPropertyInfo[0]; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public boolean jdbcCompliant() { + return false; + } + + public Logger getParentLogger() /*throws SQLFeatureNotSupportedException*/ { + return Logger.getAnonymousLogger(); + } + } + + @Test + public void testLastDelimiterPositionNormalModeStrict() { + SQLExec s = new SQLExec(); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer(), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("; "), null)); + assertEquals(2, + s.lastDelimiterPosition(new StringBuffer("ab;"), null)); + s.setDelimiter("GO"); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO "), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("go"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + } + + @Test + public void testLastDelimiterPositionNormalModeNonStrict() { + SQLExec s = new SQLExec(); + s.setStrictDelimiterMatching(false); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer(), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("; "), null)); + assertEquals(2, + s.lastDelimiterPosition(new StringBuffer("ab;"), null)); + s.setDelimiter("GO"); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO "), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("go"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + } + + @Test + public void testLastDelimiterPositionRowModeStrict() { + SQLExec s = new SQLExec(); + SQLExec.DelimiterType t = new SQLExec.DelimiterType(); + t.setValue("row"); + s.setDelimiterType(t); + assertEquals(-1, s.lastDelimiterPosition(null, "")); + assertEquals(-1, s.lastDelimiterPosition(null, "GO")); + assertEquals(-1, s.lastDelimiterPosition(null, "; ")); + assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";")); + s.setDelimiter("GO"); + assertEquals(-1, s.lastDelimiterPosition(null, "GO ")); + assertEquals(-1, s.lastDelimiterPosition(null, "go")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO")); + } + + @Test + public void testLastDelimiterPositionRowModeNonStrict() { + SQLExec s = new SQLExec(); + SQLExec.DelimiterType t = new SQLExec.DelimiterType(); + t.setValue("row"); + s.setDelimiterType(t); + s.setStrictDelimiterMatching(false); + assertEquals(-1, s.lastDelimiterPosition(null, "")); + assertEquals(-1, s.lastDelimiterPosition(null, "GO")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("; "), "; ")); + assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";")); + s.setDelimiter("GO"); + assertEquals(1, + s.lastDelimiterPosition(new StringBuffer("abcd"), "GO ")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("go"), "go")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java new file mode 100644 index 00000000..95585fde --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -0,0 +1,139 @@ +/* + * 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.taskdefs; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testcase for the Signjar task + * + */ +public class SignJarTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/signjar.xml"); + } + + /** + * check for being offline + * @return true if the system property "offline" is "true" + */ + private boolean isOffline() { + return Boolean.getBoolean("offline"); + } + + @Test + public void testSigFile() { + buildRule.executeTarget("sigfile"); + SignJarChild sj = new SignJarChild(); + sj.setAlias("testonly"); + sj.setKeystore("testkeystore"); + sj.setStorepass("apacheant"); + File jar = new File(buildRule.getProject().getProperty("test.jar")); + sj.setJar(jar); + assertFalse("mustn't find signature without sigfile attribute", + sj.isSigned()); + sj.setSigfile("TEST"); + assertTrue("must find signature with sigfile attribute", + sj.isSigned()); + } + + @Test + public void testInvalidChars() { + buildRule.executeTarget("invalidchars"); + SignJarChild sj = new SignJarChild(); + sj.setAlias("test@nly"); + sj.setKeystore("testkeystore"); + sj.setStorepass("apacheant"); + File jar = new File(buildRule.getProject().getProperty("test.jar")); + sj.setJar(jar); + assertTrue(sj.isSigned()); + } + + /** + * subclass in order to get access to protected isSigned method if + * tests and task come from different classloaders. + */ + private static class SignJarChild extends SignJar { + public boolean isSigned() { + return isSigned(jar); + } + } + + @Test + public void testURLKeystoreFile() { + buildRule.executeTarget("urlKeystoreFile"); + } + + @Test + public void testURLKeystoreHTTP() { + Assume.assumeFalse("Test is set offline", isOffline()); + buildRule.executeTarget("urlKeystoreHTTP"); + } + + @Test + public void testTsaLocalhost() { + Assume.assumeTrue("Only runs on Java 1.5+", JavaEnvUtils.getJavaVersionNumber()>=15); + try { + buildRule.executeTarget("testTsaLocalhost"); + fail("Should have thrown exception - no TSA at localhost:0"); + } catch(BuildException ex) { + assertEquals("jarsigner returned: 1", ex.getMessage()); + } + } + + /** + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=50081">bug 50081</a> + */ + @Test + public void testSignUnnormalizedJar() throws Exception { + buildRule.executeTarget("jar"); + File testJar = new File(buildRule.getProject().getProperty("test.jar")); + File testJarParent = testJar.getParentFile(); + File f = new File(testJarParent, + "../" + testJarParent.getName() + "/" + + testJar.getName()); + assertFalse(testJar.equals(f)); + assertEquals(testJar.getCanonicalPath(), f.getCanonicalPath()); + SignJar s = new SignJar(); + s.setProject(buildRule.getProject()); + s.setJar(f); + s.setAlias("testonly"); + s.setStorepass("apacheant"); + s.setKeystore("testkeystore"); + s.execute(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java new file mode 100644 index 00000000..d1487df9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java @@ -0,0 +1,120 @@ +/* + * 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.taskdefs; + +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.assertTrue; +import static org.junit.Assert.fail; + +public class SleepTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; + private final static int ERROR_RANGE=1000; + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "sleep.xml"); + } + + @Test + public void test1() { + Timer timer=new Timer(); + buildRule.executeTarget("test1"); + timer.stop(); + assertTrue(timer.time()>=0); + } + + @Test + public void test2() { + Timer timer=new Timer(); + buildRule.executeTarget("test2"); + timer.stop(); + assertTrue(timer.time()>=0); + } + + @Test + public void test3() { + Timer timer=new Timer(); + buildRule.executeTarget("test3"); + timer.stop(); + assertTrue(timer.time()>=(2000-ERROR_RANGE)); + } + + @Test + public void test4() { + Timer timer=new Timer(); + buildRule.executeTarget("test3"); + timer.stop(); + assertTrue(timer.time()>=(2000-ERROR_RANGE) && timer.time()<60000); + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("Negative sleep periods are not supported"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test6() { + Timer timer=new Timer(); + buildRule.executeTarget("test6"); + timer.stop(); + assertTrue(timer.time()<2000); + } + + + /** + * inner timer class + */ + private static class Timer { + long start=0; + long stop=0; + + public Timer() { + start(); + } + + public void start() { + start=System.currentTimeMillis(); + } + + public void stop() { + stop=System.currentTimeMillis(); + } + + public long time() { + return stop-start; + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java new file mode 100644 index 00000000..24c4e9de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java @@ -0,0 +1,225 @@ +/* + * 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.taskdefs; + + +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.FileUtilities; +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; + + +/** + * TestCases for {@link XSLTProcess} task. + * TODO merge with {@link org.apache.tools.ant.taskdefs.optional.XsltTest}? + * @version 2003-08-05 + */ +public class StyleTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/taskdefs/style/build.xml"); + } + + @Test + public void testStyleIsSet() throws Exception { + + try { + buildRule.executeTarget("testStyleIsSet"); + fail("Must throws a BuildException: no stylesheet specified"); + } catch (BuildException ex) { + assertEquals("specify the stylesheet either as a filename in style attribute or as a nested resource", + ex.getMessage()); + } + } + + @Test + public void testTransferParameterSet() throws Exception { + expectFileContains("testTransferParameterSet", // target + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", // file + "set='myvalue'"); // exptected string + } + + @Test + public void testTransferParameterEmpty() throws Exception { + expectFileContains("testTransferParameterEmpty", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "empty=''"); + } + + @Test + public void testTransferParameterUnset() throws Exception { + expectFileContains("testTransferParameterUnset", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "undefined='${value}'"); + } + + @Test + public void testTransferParameterUnsetWithIf() throws Exception { + expectFileContains("testTransferParameterUnsetWithIf", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "undefined='undefined default value'"); + } + + @Test + public void testNewerStylesheet() throws Exception { + expectFileContains("testNewerStylesheet", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "new-value"); + } + + @Test + public void testDefaultMapper() throws Exception { + testDefaultMapper("testDefaultMapper"); + } + + @Test + public void testExplicitFileset() throws Exception { + testDefaultMapper("testExplicitFileset"); + } + + public void testDefaultMapper(String target) throws Exception { + assertTrue(!( + new File(buildRule.getOutputDir().getAbsoluteFile(), "data.html").exists())); + expectFileContains(target, + buildRule.getOutputDir().getAbsoluteFile() + "/data.html", + "set='myvalue'"); + } + + @Test + public void testCustomMapper() throws Exception { + assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + expectFileContains("testCustomMapper", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "set='myvalue'"); + } + + @Test + public void testTypedMapper() throws Exception { + assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + expectFileContains("testTypedMapper", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "set='myvalue'"); + } + + @Test + public void testDirectoryHierarchyWithDirMatching() throws Exception { + buildRule.executeTarget("testDirectoryHierarchyWithDirMatching"); + assertTrue(new File(buildRule.getOutputDir().getAbsoluteFile(), "dest/level1/data.html") + .exists()); + } + + @Test + public void testDirsWithSpaces() throws Exception { + buildRule.executeTarget("testDirsWithSpaces"); + assertTrue(new File(buildRule.getOutputDir().getAbsoluteFile(), "d est/data.html") + .exists()); + } + + @Test + public void testWithStyleAttrAndResource() { + try { + buildRule.executeTarget("testWithStyleAttrAndResource"); + fail("Must throws a BuildException"); + } catch (BuildException ex) { + assertEquals("specify the stylesheet either as a filename in style attribute or as a " + + "nested resource but not as both", ex.getMessage()); + } + } + + @Test + public void testWithFileResource() throws Exception { + expectFileContains("testWithFileResource", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='value'"); + } + + @Test + public void testWithUrlResource() throws Exception { + expectFileContains("testWithUrlResource", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='value'"); + } + + @Test + public void testFilenameAsParam() throws Exception { + buildRule.executeTarget("testFilenameAsParam"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='one.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/two.txt", "filename='two.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/three.txt", "filename='three.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='four.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filedir ='-not-set-'"); + } + + @Test + public void testFilenameAsParamNoSetting() throws Exception { + buildRule.executeTarget("testFilenameAsParamNoSetting"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/two.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/three.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='-not-set-'"); + } + + @Test + public void testFilenameAndFiledirAsParam() throws Exception { + buildRule.executeTarget("testFilenameAndFiledirAsParam"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='one.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filedir ='.'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='four.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filedir ='dir'"); + } + + + // ************* copied from ConcatTest ************* + + // ------------------------------------------------------ + // Helper methods - should be in BuildFileTest + // ----------------------------------------------------- + + private String getFileString(String filename) + throws IOException + { + return FileUtilities.getFileContents(new File(filename)); + } + + private void expectFileContains( + String target, String filename, String contains) + throws IOException + { + buildRule.executeTarget(target); + assertFileContains(filename, contains); + } + + private void assertFileContains(String filename, String contains) throws IOException { + String content = getFileString(filename); + assertTrue( + "expecting file " + filename + + " to contain " + contains + + " but got " + content, + content.indexOf(contains) > -1); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java new file mode 100644 index 00000000..58ee4f3e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java @@ -0,0 +1,161 @@ +/* + * 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.taskdefs; + +import java.io.File; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildListener; +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 SubAntTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/subant.xml"); + } + + @Test + public void testnodirs() { + buildRule.executeTarget("testnodirs"); + assertEquals("No sub-builds to iterate on",buildRule.getLog()); + } + + // target must be specified + @Test + public void testgenericantfile() { + File dir1 = buildRule.getProject().resolveFile("."); + File dir2 = buildRule.getProject().resolveFile("subant/subant-test1"); + File dir3 = buildRule.getProject().resolveFile("subant/subant-test2"); + + testBaseDirs("testgenericantfile", + new String[] { dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir3.getAbsolutePath() + + }); + } + + @Test + public void testantfile() { + File dir1 = buildRule.getProject().resolveFile("."); + // basedir of subant/subant-test1/subant.xml is .. + // therefore we expect here the subant/subant-test1 subdirectory + File dir2 = buildRule.getProject().resolveFile("subant/subant-test1"); + // basedir of subant/subant-test2/subant.xml is .. + // therefore we expect here the subant subdirectory + File dir3 = buildRule.getProject().resolveFile("subant"); + + testBaseDirs("testantfile", + new String[] { dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir3.getAbsolutePath() + + }); + + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multipleTargets"); + assertContains("test1-one", buildRule.getLog()); + assertContains("test1-two", buildRule.getLog()); + assertContains("test2-one", buildRule.getLog()); + assertContains("test2-two", buildRule.getLog()); + } + + @Test + public void testMultipleTargetsOneDoesntExist_FOEfalse() { + buildRule.executeTarget("multipleTargetsOneDoesntExist_FOEfalse"); + assertContains("Target \"three\" does not exist in the project \"subant\"", buildRule.getLog()); + } + + @Test + public void testMultipleTargetsOneDoesntExist_FOEtrue() { + try { + buildRule.executeTarget("multipleTargetsOneDoesntExist_FOEtrue"); + fail("BuildException expected: Calling not existent target"); + } catch (BuildException ex) { + assertContains("Target \"three\" does not exist in the project \"subant\"", ex.getMessage()); + } + } + + protected void testBaseDirs(String target, String[] dirs) { + SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs); + buildRule.getProject().addBuildListener(bc); + buildRule.executeTarget(target); + AssertionFailedError ae = bc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(bc); + } + + private class BasedirChecker implements BuildListener { + private String[] expectedBasedirs; + private int calls = 0; + private AssertionFailedError error; + + BasedirChecker(String[] dirs) { + expectedBasedirs = dirs; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + assertEquals(expectedBasedirs[calls++], + event.getProject().getBaseDir().getAbsolutePath()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java new file mode 100644 index 00000000..93431dcb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java @@ -0,0 +1,148 @@ +/* + * 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.taskdefs; + +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.assertTrue; + +public class SyncTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/sync.xml"); + } + + @Test + public void testSimpleCopy() { + buildRule.executeTarget("simplecopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testEmptyCopy() { + buildRule.executeTarget("emptycopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsNotPresent(c); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testEmptyDirCopy() { + buildRule.executeTarget("emptydircopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsPresent(c); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testCopyAndRemove() { + testCopyAndRemove("copyandremove"); + } + + @Test + public void testCopyAndRemoveWithFileList() { + testCopyAndRemove("copyandremove-with-filelist"); + } + + @Test + public void testCopyAndRemoveWithZipfileset() { + testCopyAndRemove("copyandremove-with-zipfileset"); + } + + private void testCopyAndRemove(String target) { + buildRule.executeTarget(target); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") > -1); + assertContains("Removed 1 dangling file from", buildRule.getFullLog()); + assertContains("Removed 1 dangling directory from", buildRule.getFullLog()); + } + + @Test + public void testCopyAndRemoveEmptyPreserve() { + buildRule.executeTarget("copyandremove-emptypreserve"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") > -1); + assertContains("Removed 1 dangling file from", buildRule.getFullLog()); + assertContains("Removed 1 dangling directory from", buildRule.getFullLog()); + } + + @Test + public void testEmptyDirCopyAndRemove() { + buildRule.executeTarget("emptydircopyandremove"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsPresent(c); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan directory:") > -1); + assertContains("NO dangling file to remove from", buildRule.getFullLog()); + assertContains("Removed 2 dangling directories from", buildRule.getFullLog()); + } + + @Test + public void testCopyNoRemove() { + buildRule.executeTarget("copynoremove"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") == -1); + } + + @Test + public void testCopyNoRemoveSelectors() { + buildRule.executeTarget("copynoremove-selectors"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") == -1); + } + + public void assertFileIsPresent(String f) { + assertTrue("Expected file " + f, + buildRule.getProject().resolveFile(f).exists()); + } + + public void assertFileIsNotPresent(String f) { + assertTrue("Didn't expect file " + f, + !buildRule.getProject().resolveFile(f).exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java new file mode 100644 index 00000000..ed7403c7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java @@ -0,0 +1,117 @@ +/* + * 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.taskdefs; + +import java.util.Calendar; +import java.util.TimeZone; +import java.util.Date; +import java.text.SimpleDateFormat; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Location; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * + */ +public class TStampTest { + + protected Tstamp tstamp; + protected Project project; + protected Location location; + + @Before + public void setUp() throws Exception { + location = new Location("test.xml"); + project = new Project(); + tstamp = new Tstamp(); + tstamp.setLocation(location); + tstamp.setProject(project); + } + + @Test + public void testTimeZone() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("today"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("today"); + + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + assertEquals(expected, today); + } + + /** + * verifies that custom props have priority over the + * originals + * @throws Exception + */ + @Test + public void testWriteOrder() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("TODAY"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("TODAY"); + + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + assertEquals(expected, today); + + } + + /** + * verifies that custom props have priority over the + * originals + * @throws Exception + */ + @Test + public void testPrefix() throws Exception { + tstamp.setPrefix("prefix"); + tstamp.execute(); + String prop= project.getProperty("prefix.DSTAMP"); + assertNotNull(prop); + } + + @Test + public void testFormatPrefix() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("format"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + + tstamp.setPrefix("prefix"); + tstamp.execute(); + String prop= project.getProperty("prefix.format"); + assertNotNull(prop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java new file mode 100644 index 00000000..c5ba1200 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java @@ -0,0 +1,210 @@ +/* + * 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.taskdefs; + +import java.io.IOException; +import java.io.File; + +import org.apache.tools.ant.BuildException; +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; +import static org.junit.Assert.fail; + +public class TarTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/tar.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: tar cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + File f + = new File(buildRule.getProject().getProperty("output"), "test5.tar"); + + if (!f.exists()) { + fail("Tarring a directory failed"); + } + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("BuildException expected: Invalid value specified for longfile attribute."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test7() { + test7("test7"); + } + + @Test + public void test7UsingPlainFileSet() { + test7("test7UsingPlainFileSet"); + } + + @Test + public void test7UsingFileList() { + test7("test7UsingFileList"); + } + + private void test7(String target) { + buildRule.executeTarget(target); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test7-prefix"); + + if (!(f1.exists() && f1.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + + File f2 + = new File(buildRule.getProject().getProperty("output"), "untar/test7dir"); + + if (!(f2.exists() && f2.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + } + + @Test + public void test8() { + test8("test8"); + } + + @Test + public void test8UsingZipFileset() { + test8("test8UsingZipFileset"); + } + + @Test + public void test8UsingZipFilesetSrc() { + test8("test8UsingZipFilesetSrc"); + } + + @Test + public void test8UsingTarFilesetSrc() { + test8("test8UsingTarFilesetSrc"); + } + + @Test + public void test8UsingZipEntry() { + test8("test8UsingZipEntry"); + } + + private void test8(String target) { + buildRule.executeTarget(target); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test8.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void test9() { + try { + buildRule.executeTarget("test9"); + fail("BuildException expected: Invalid value specified for compression attribute."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test10() { + buildRule.executeTarget("test10"); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test10.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void test11() { + buildRule.executeTarget("test11"); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test11.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void testGZipResource() throws IOException { + buildRule.executeTarget("testGZipResource"); + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif.gz"))); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java new file mode 100644 index 00000000..eaa8a667 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java @@ -0,0 +1,128 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +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; + +/** + */ +public class TaskdefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/taskdef.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: classname specified doesn't exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("BuildException expected: No public execute() in " + Project.class); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5a() { + buildRule.executeTarget("test5a"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("simpletask: worked", buildRule.getLog()); + } + + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("worked", buildRule.getLog()); + } + + @Test + public void testGlobal() { + buildRule.executeTarget("testGlobal"); + assertEquals("worked", buildRule.getLog()); + } + + @Test + public void testOverride() { + buildRule.executeTarget("testOverride"); + String log = buildRule.getLog(); + assertTrue("override warning sent", + log.indexOf("Trying to override old definition of task copy") > -1); + assertTrue("task inside target worked", + log.indexOf("In target") > -1); + assertTrue("task inside target worked", + log.indexOf("In TaskContainer") > -1); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java new file mode 100644 index 00000000..9316059c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java @@ -0,0 +1,31 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileTest; + +/** + * @deprecated use {@link org.apache.tools.ant.BuildFileRule} instead. + */ +public abstract class TaskdefsTest extends BuildFileTest { + + public TaskdefsTest(String name) { + super(name); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java new file mode 100644 index 00000000..062003fa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java @@ -0,0 +1,96 @@ +/* + * 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.taskdefs; + +import org.junit.internal.AssumptionViolatedException; + +/** + * Interactive Testcase for Processdestroyer. + * + */ +public class TestProcess + implements Runnable +{ + private boolean run = true; + private boolean done = false; + + public void shutdown() + { + if (!done) + { + System.out.println("shutting down TestProcess"); + run = false; + + synchronized(this) + { + while (!done) + { + try { + wait(); + } catch (InterruptedException ie) { + throw new AssumptionViolatedException("Thread interrupted", ie); + } + } + } + + System.out.println("TestProcess shut down"); + } + } + + public void run() + { + for (int i = 0; i < 5 && run; i++) + { + System.out.println(Thread.currentThread().getName()); + + try { + Thread.sleep(2000); + } catch (InterruptedException ie) { + throw new AssumptionViolatedException("Thread interrupted", ie); + } + } + + synchronized(this) + { + done = true; + notifyAll(); + } + } + + public Thread getShutdownHook() + { + return new TestProcessShutdownHook(); + } + + private class TestProcessShutdownHook + extends Thread + { + public void run() + { + shutdown(); + } + } + + public static void main(String[] args) + { + TestProcess tp = new TestProcess(); + new Thread(tp, "TestProcess thread").start(); + Runtime.getRuntime().addShutdownHook(tp.getShutdownHook()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java new file mode 100644 index 00000000..eee15d12 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java @@ -0,0 +1,34 @@ +/* + * 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.taskdefs; + +/** + * Helper class for ExecuteWatchdogTest and ExecuteJavaTest. + * + * <p>Used to be an inner class of ExecuteWatchdogTest. + * + */ +public class TimeProcess { + public static void main(String[] args) throws Exception { + int time = Integer.parseInt(args[0]); + if (time < 1) { + throw new IllegalArgumentException("Invalid time: " + time); + } + Thread.sleep(time); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java new file mode 100644 index 00000000..0a968b25 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java @@ -0,0 +1,211 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class TouchTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static String TOUCH_FILE = "src/etc/testcases/taskdefs/touchtest"; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/touch.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + public long getTargetTime() { + + File file = new File(System.getProperty("root"), TOUCH_FILE); + if(!file.exists()) { + throw new BuildException("failed to touch file " + file); + } + return file.lastModified(); + } + + /** + * No real test, simply checks whether the dateformat without + * seconds is accepted - by erroring out otherwise. + */ + @Test + public void testNoSeconds() { + buildRule.executeTarget("noSeconds"); + getTargetTime(); + } + + /** + * No real test, simply checks whether the dateformat with + * seconds is accepted - by erroring out otherwise. + */ + @Test + public void testSeconds() { + buildRule.executeTarget("seconds"); + getTargetTime(); + } + /** + * verify that the millis test sets things up + */ + @Test + public void testMillis() { + touchFile("testMillis", 662256000000L); + } + + /** + * verify that the default value defaults to now + */ + @Test + public void testNow() { + long now=System.currentTimeMillis(); + buildRule.executeTarget("testNow"); + long time = getTargetTime(); + assertTimesNearlyMatch(time,now,5000); + } + /** + * verify that the millis test sets things up + */ + @Test + public void test2000() { + touchFile("test2000", 946080000000L); + } + + /** + * test the file list + */ + @Test + public void testFilelist() { + touchFile("testFilelist", 662256000000L); + } + + /** + * test the file set + */ + @Test + public void testFileset() { + touchFile("testFileset", 946080000000L); + } + + /** + * test the resource collection + */ + @Test + public void testResourceCollection() { + touchFile("testResourceCollection", 1662256000000L); + } + + /** + * test the mapped file set + */ + @Test + public void testMappedFileset() { + buildRule.executeTarget("testMappedFileset"); + } + + /** + * test the explicit mapped file set + */ + @Test + public void testExplicitMappedFileset() { + buildRule.executeTarget("testExplicitMappedFileset"); + } + + /** + * test the mapped file list + */ + @Test + public void testMappedFilelist() { + buildRule.executeTarget("testMappedFilelist"); + } + + /** + * test the pattern attribute + */ + @Test + public void testGoodPattern() { + buildRule.executeTarget("testGoodPattern"); + } + + /** + * test the pattern attribute again + */ + @Test + public void testBadPattern() { + try { + buildRule.executeTarget("testBadPattern"); + fail("No parsing exception thrown"); + } catch (BuildException ex) { + assertContains("Unparseable", ex.getMessage()); + } + + } + + /** + * run a target to touch the test file; verify the timestamp is as expected + * @param targetName + * @param timestamp + */ + private void touchFile(String targetName, long timestamp) { + buildRule.executeTarget(targetName); + long time = getTargetTime(); + assertTimesNearlyMatch(timestamp, time); + } + + /** + * assert that two times are within the current FS granularity; + * @param timestamp + * @param time + */ + public void assertTimesNearlyMatch(long timestamp,long time) { + long granularity= FILE_UTILS.getFileTimestampGranularity(); + assertTimesNearlyMatch(timestamp, time, granularity); + } + + /** + * assert that two times are within a specified range + * @param timestamp + * @param time + * @param range + */ + private void assertTimesNearlyMatch(long timestamp, long time, long range) { + assertTrue("Time " + timestamp + " is not within " + range + " ms of " + + time, (Math.abs(time - timestamp) <= range)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java new file mode 100644 index 00000000..3488f399 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java @@ -0,0 +1,176 @@ +/* + * 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.taskdefs; + +import java.lang.reflect.Method; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.TypeAdapter; +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 TypeAdapterTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/typeadapter.xml"); + } + + @Test + public void testTaskAdapter() { + buildRule.executeTarget("taskadapter"); + assertContains("MyExec called", buildRule.getLog()); + } + + @Test + public void testRunAdapter() { + buildRule.executeTarget("runadapter"); + assertContains("MyRunnable called", buildRule.getLog()); + } + + @Test + public void testRunAdapterError() { + try { + buildRule.executeTarget("runadaptererror"); + fail("BuildException expected: no public run method"); + } catch (BuildException ex) { + assertContains("No public run() method in", ex.getMessage()); + } + } + + @Test + public void testDelay() { + buildRule.executeTarget("delay"); + assertContains("MyTask called", buildRule.getLog()); + } + + @Test + public void testOnErrorReport() { + buildRule.executeTarget("onerror.report"); + assertContains("MyTaskNotPresent cannot be found", buildRule.getLog()); + } + + @Test + public void testOnErrorIgnore() { + buildRule.executeTarget("onerror.ignore"); + assertEquals("", buildRule.getLog()); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + + public static class MyExec { + private Project project; + public void setProject(Project project) { + this.project = project; + } + + public void execute() { + project.log("MyExec called"); + } + } + + public static class MyRunnable { + private Project project; + public void setProject(Project project) { + this.project = project; + } + + public void run() { + project.log("MyRunnable called"); + } + } + + public static class RunnableAdapter + extends Task implements TypeAdapter + { + private String execMethodName = "run"; + private Object proxy; + + public Method getExecuteMethod(Class proxyClass) { + try { + Method execMethod = proxyClass.getMethod(execMethodName); + if (!Void.TYPE.equals(execMethod.getReturnType())) { + String message = + "return type of " + execMethodName + "() should be " + + "void but was \"" + execMethod.getReturnType() + + "\" in " + + proxyClass; + log(message, Project.MSG_WARN); + } + return execMethod; + } catch (NoSuchMethodException e) { + String message = "No public "+ execMethodName + + "() method in " + + proxyClass; + log(message, Project.MSG_ERR); + throw new BuildException(message); + } + } + public void checkProxyClass(Class proxyClass) { + getExecuteMethod(proxyClass); + } + + public void setProxy(Object o) { + getExecuteMethod(o.getClass()); + this.proxy = o; + } + + public Object getProxy() { + return proxy; + } + + public void execute() { + getProject().setProjectReference(proxy); + Method executeMethod = getExecuteMethod(proxy.getClass()); + try { + executeMethod.invoke(proxy); + } catch (java.lang.reflect.InvocationTargetException ie) { + log("Error in " + proxy.getClass(), Project.MSG_ERR); + Throwable t = ie.getTargetException(); + if (t instanceof BuildException) { + throw ((BuildException) t); + } else { + throw new BuildException(t); + } + } catch (Exception ex) { + log("Error in " + proxy.getClass(), Project.MSG_ERR); + throw new BuildException(ex); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java new file mode 100644 index 00000000..bfc11dd4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java @@ -0,0 +1,136 @@ +/* + * 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.taskdefs; + +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.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +/** + */ +public class TypedefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/typedef.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("empty"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testNoName() { + try { + buildRule.executeTarget("noName"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testNoClassname() { + try { + buildRule.executeTarget("noClassname"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testClassNotFound() { + try { + buildRule.executeTarget("classNotFound"); + fail("BuildException expected: classname specified doesn't exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testGlobal() { + buildRule.executeTarget("testGlobal"); + assertEquals("", buildRule.getLog()); + Object ref = buildRule.getProject().getReferences().get("global"); + assertNotNull("ref is not null", ref); + assertEquals("org.example.types.TypedefTestType", + ref.getClass().getName()); + } + + @Test + public void testLocal() { + buildRule.executeTarget("testLocal"); + assertEquals("", buildRule.getLog()); + Object ref = buildRule.getProject().getReferences().get("local"); + assertNotNull("ref is not null", ref); + assertEquals("org.example.types.TypedefTestType", + ref.getClass().getName()); + } + + /** + * test to make sure that one can define a not present + * optional type twice and then have a valid definition. + */ + @Test + public void testDoubleNotPresent() { + buildRule.executeTarget("double-notpresent"); + assertContains("hi", buildRule.getLog()); + } + + @Test + public void testNoResourceOnErrorFailAll(){ + try { + buildRule.executeTarget("noresourcefailall"); + fail("BuildException expected: the requested resource does not exist"); + } catch (BuildException ex) { + assertContains("Could not load definitions from resource ", ex.getMessage()); + } + } + + @Test + public void testNoResourceOnErrorFail(){ + buildRule.executeTarget("noresourcefail"); + assertContains("Could not load definitions from resource ", buildRule.getLog()); + } + + @Test + public void testNoResourceOnErrorNotFail(){ + buildRule.executeTarget("noresourcenotfail"); + assertContains("Could not load definitions from resource ", buildRule.getLog()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java new file mode 100644 index 00000000..e0f7eb2a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java @@ -0,0 +1,111 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildException; +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 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 UntarTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/untar.xml"); + } + + @Test + public void testRealTest() throws java.io.IOException { + testLogoExtraction("realTest"); + } + + @Test + public void testRealGzipTest() throws java.io.IOException { + testLogoExtraction("realGzipTest"); + } + + @Test + public void testRealBzip2Test() throws java.io.IOException { + testLogoExtraction("realBzip2Test"); + } + + @Test + public void testTestTarTask() throws java.io.IOException { + testLogoExtraction("testTarTask"); + } + + @Test + public void testTestGzipTarTask() throws java.io.IOException { + testLogoExtraction("testGzipTarTask"); + } + + @Test + public void testTestBzip2TarTask() throws java.io.IOException { + testLogoExtraction("testBzip2TarTask"); + } + + @Test + public void testSrcDirTest() { + try { + buildRule.executeTarget("srcDirTest"); + fail("Src cannot be a directory."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testEncoding() { + buildRule.executeTarget("encodingTest"); + String filename = buildRule.getProject().getProperty("output") + "/untartestout/foo"; + assertTrue("foo has been properly named", + buildRule.getProject().resolveFile(filename).exists()); + } + + @Test + public void testResourceCollection() throws java.io.IOException { + testLogoExtraction("resourceCollection"); + } + + private void testLogoExtraction(String target) throws java.io.IOException { + buildRule.executeTarget(target); + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif"))); + + } + + @Test + public void testDocumentationClaimsOnCopy() { + buildRule.executeTarget("testDocumentationClaimsOnCopy"); + assertFalse(new File(buildRule.getProject().getProperty("output"), "untar/1/foo").exists()); + assertTrue(new File(buildRule.getProject().getProperty("output"), "untar/2/bar").exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java new file mode 100644 index 00000000..ad99620e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java @@ -0,0 +1,250 @@ +/* + * 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.taskdefs; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Ignore; +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; +import static org.junit.Assert.fail; + +public class UnzipTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/unzip.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + + @Test + public void testRealTest() throws java.io.IOException { + buildRule.executeTarget("realTest"); + assertLogoUncorrupted(); + } + + /** + * test that the logo gif file has not been corrupted + * @throws IOException + */ + private void assertLogoUncorrupted() throws IOException { + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); + + } + + @Test + public void testTestZipTask() throws java.io.IOException { + buildRule.executeTarget("testZipTask"); + assertLogoUncorrupted(); + } + + @Test + public void testTestUncompressedZipTask() throws java.io.IOException { + buildRule.executeTarget("testUncompressedZipTask"); + assertLogoUncorrupted(); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetExcludeOnly() { + buildRule.executeTarget("testPatternSetExcludeOnly"); + assertFileMissing("1/foo is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is not excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetIncludeOnly() { + buildRule.executeTarget("testPatternSetIncludeOnly"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetIncludeAndExclude() { + buildRule.executeTarget("testPatternSetIncludeAndExclude"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileMissing("2/bar is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 38973 + */ + @Test + public void testTwoPatternSets() { + buildRule.executeTarget("testTwoPatternSets"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 38973 + */ + @Test + public void testTwoPatternSetsWithExcludes() { + buildRule.executeTarget("testTwoPatternSetsWithExcludes"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileMissing("2/bar is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 16213 + */ + @Test + @Ignore("we lack a self extracting archive that we are allowed to distribute - see PR 49080") + public void testSelfExtractingArchive() { + // disabled because we lack a self extracting archive that we + // are allowed to distribute - see PR 49080 + buildRule.executeTarget("selfExtractingArchive"); + } + + + /* + * PR 20969 + */ + @Test + public void testPatternSetSlashOnly() { + buildRule.executeTarget("testPatternSetSlashOnly"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("\"2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + + /* + * PR 10504 + */ + @Test + public void testEncoding() { + buildRule.executeTarget("encodingTest"); + assertFileExists("foo has been properly named", buildRule.getProject().getProperty("output") + "/unziptestout/foo"); + } + + /* + * PR 21996 + */ + @Test + public void testFlattenMapper() { + buildRule.executeTarget("testFlattenMapper"); + assertFileMissing("1/foo is not flattened", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("foo is flattened", buildRule.getProject().getProperty("output") + "/unziptestout/foo"); + } + + /** + * assert that a file exists, relative to the project + * @param message message if there is no mpatch + * @param filename filename to resolve against the project + */ + private void assertFileExists(String message, String filename) { + assertTrue(message, + buildRule.getProject().resolveFile(filename).exists()); + } + + /** + * assert that a file doesnt exist, relative to the project + * + * @param message message if there is no mpatch + * @param filename filename to resolve against the project + */ + private void assertFileMissing(String message, String filename) { + assertTrue(message, + !buildRule.getProject().resolveFile(filename).exists()); + } + + /** + * PR 21996 + */ + @Test + public void testGlobMapper() { + buildRule.executeTarget("testGlobMapper"); + assertFileMissing("1/foo is not mapped", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("1/foo is mapped", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo.txt"); + } + + @Test + public void testTwoMappers() { + try { + buildRule.executeTarget("testTwoMappers"); + fail("BuildException expected: " + Expand.ERROR_MULTIPLE_MAPPERS); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testResourceCollections() { + buildRule.executeTarget("testResourceCollection"); + assertFileExists("junit.jar has been extracted", + buildRule.getProject().getProperty("output") + "/unziptestout/junit/framework/Assert.class"); + } + + @Test + public void testDocumentationClaimsOnCopy() { + buildRule.executeTarget("testDocumentationClaimsOnCopy"); + assertFileMissing("1/foo is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is not excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java new file mode 100644 index 00000000..b9677c4b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java @@ -0,0 +1,77 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assume.assumeTrue; + +public class UpToDateTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/uptodate.xml"); + buildRule.executeTarget("setUp"); + File srcDir = buildRule.getProject().resolveFile("source"); + assumeTrue("Could not change modification timestamp of source directory", + srcDir.setLastModified(srcDir.lastModified() + - (3 * FileUtils.getFileUtils().getFileTimestampGranularity()))); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testFilesetUpToDate() { + buildRule.executeTarget("testFilesetUpToDate"); + assertEquals("true", buildRule.getProject().getProperty("foo")); + } + + @Test + public void testFilesetOutOfDate() { + buildRule.executeTarget("testFilesetOutOfDate"); + assertNull(buildRule.getProject().getProperty("foo")); + } + + @Test + public void testRCUpToDate() { + buildRule.executeTarget("testRCUpToDate"); + assertEquals("true", buildRule.getProject().getProperty("foo")); + } + + @Test + public void testRCOutOfDate() { + buildRule.executeTarget("testRCOutOfDate"); + assertNull(buildRule.getProject().getProperty("foo")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java new file mode 100644 index 00000000..1513ac75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java @@ -0,0 +1,55 @@ +/* + * 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.taskdefs; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the war task + * + */ +public class WarTest { + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/war.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** + * Test direct dependency removal + */ + @Test + public void testLibRefs() { + buildRule.executeTarget("testlibrefs"); + File f = new File(buildRule.getOutputDir(), "WEB-INF/lib/war.xml"); + assertTrue("File has been put into lib", f.exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java new file mode 100644 index 00000000..8e282b3a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java @@ -0,0 +1,58 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class WhichResourceTest { + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/whichresource.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + @Test + public void testClassname() { + buildRule.executeTarget("testClassname"); + assertNotNull(buildRule.getProject().getProperty("antmain")); + } + + @Test + public void testResourcename() { + buildRule.executeTarget("testResourcename"); + assertNotNull(buildRule.getProject().getProperty("defaults")); + } + + @Test + public void testResourcenameWithLeadingSlash() { + buildRule.executeTarget("testResourcenameWithLeadingSlash"); + assertNotNull(buildRule.getProject().getProperty("defaults")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java new file mode 100644 index 00000000..89069173 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java @@ -0,0 +1,376 @@ +/* + * 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.taskdefs; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.util.Vector; + +import org.apache.tools.ant.BuildFileRule; +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.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class XmlPropertyTest { + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/xmlproperty.xml"); + } + + @Test + public void testFile() { + testProperties("test"); + } + + @Test + public void testResource() { + testProperties("testResource"); + } + + private void testProperties(String target) { + buildRule.executeTarget(target); + assertEquals("true", buildRule.getProject().getProperty("root-tag(myattr)")); + assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag")); + assertEquals("val", + buildRule.getProject().getProperty("root-tag.inner-tag(someattr)")); + assertEquals("false", buildRule.getProject().getProperty("root-tag.a2.a3.a4")); + assertEquals("CDATA failed", + "<test>", buildRule.getProject().getProperty("root-tag.cdatatag")); + } + + @Test + public void testDTD() { + buildRule.executeTarget("testdtd"); + assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag")); + } + + @Test + public void testNone () throws IOException { + doTest("testNone", false, false, false, false, false); + } + + @Test + public void testKeeproot() throws IOException { + doTest("testKeeproot", true, false, false, false, false); + } + + @Test + public void testCollapse () throws IOException { + doTest("testCollapse", false, true, false, false, false); + } + + @Test + public void testSemantic () throws IOException { + doTest("testSemantic", false, false, true, false, false); + } + + @Test + public void testKeeprootCollapse () throws IOException { + doTest("testKeeprootCollapse", true, true, false, false, false); + } + + @Test + public void testKeeprootSemantic () throws IOException { + doTest("testKeeprootSemantic", true, false, true, false, false); + } + + @Test + public void testCollapseSemantic () throws IOException { + doTest("testCollapseSemantic", false, true, true, false, false); + } + + @Test + public void testKeeprootCollapseSemantic () throws IOException { + doTest("testKeeprootCollapseSemantic", true, true, true, false, false); + } + + @Test + public void testInclude () throws IOException { + doTest("testInclude", false, false, false, true, false); + } + + @Test + public void testSemanticInclude () throws IOException { + doTest("testSemanticInclude", false, false, true, true, false); + } + + @Test + public void testSemanticLocal () throws IOException { + doTest("testSemanticInclude", false, false, true, false, true); + } + + @Test + public void testNeedsCatalog() { + buildRule.executeTarget("testneedscat"); + assertEquals("true", buildRule.getProject().getProperty("skinconfig.foo")); + } + + /** + * Actually run a test, finding all input files (and corresponding + * goldfile) + */ + private void doTest(String msg, boolean keepRoot, boolean collapse, + boolean semantic, boolean include, boolean localRoot) throws IOException { + Enumeration iter = + getFiles(new File(System.getProperty("root"), "src/etc/testcases/taskdefs/xmlproperty/inputs")); + while (iter.hasMoreElements()) { + File inputFile = (File) iter.nextElement(); + // What's the working directory? If local, then its the + // folder of the input file. Otherwise, its the "current" dir.. + File workingDir; + if ( localRoot ) { + workingDir = inputFile.getParentFile(); + } else { + workingDir = FILE_UTILS.resolveFile(new File("."), "."); + } + + + File propertyFile = getGoldfile(inputFile, keepRoot, collapse, + semantic, include, localRoot); + if (!propertyFile.exists()) { +// System.out.println("Skipping as " +// + propertyFile.getAbsolutePath() +// + ") doesn't exist."); + continue; + } + + // System.out.println(msg + " (" + propertyFile.getName() + ") in (" + workingDir + ")"); + + Project p = new Project(); + + XmlProperty xmlproperty = new XmlProperty(); + xmlproperty.setProject(p); + xmlproperty.setFile(inputFile); + + xmlproperty.setKeeproot(keepRoot); + xmlproperty.setCollapseAttributes(collapse); + xmlproperty.setSemanticAttributes(semantic); + xmlproperty.setIncludeSemanticAttribute(include); + xmlproperty.setRootDirectory(workingDir); + + // Set a property on the project to make sure that loading + // a property with the same name from an xml file will + // *not* change it. + p.setNewProperty("override.property.test", "foo"); + + xmlproperty.execute(); + + Properties props = new Properties(); + props.load(new FileInputStream(propertyFile)); + + //printProperties(p.getProperties()); + + ensureProperties(msg, inputFile, workingDir, p, props); + ensureReferences(msg, inputFile, p.getReferences()); + + } + } + + /** + * Make sure every property loaded from the goldfile was also + * read from the XmlProperty. We could try and test the other way, + * but some other properties may get set in the XmlProperty due + * to generic Project/Task configuration. + */ + private static void ensureProperties (String msg, File inputFile, + File workingDir, Project p, + Properties properties) { + Hashtable xmlproperties = p.getProperties(); + // Every key identified by the Properties must have been loaded. + Enumeration propertyKeyEnum = properties.propertyNames(); + while(propertyKeyEnum.hasMoreElements()){ + String currentKey = propertyKeyEnum.nextElement().toString(); + String assertMsg = msg + "-" + inputFile.getName() + + " Key=" + currentKey; + + String propertyValue = properties.getProperty(currentKey); + + String xmlValue = (String)xmlproperties.get(currentKey); + + if (propertyValue.startsWith("ID.")) { + // The property is an id's thing -- either a property + // or a path. We need to make sure + // that the object was created with the given id. + // We don't have an adequate way of testing the actual + // *value* of the Path object, though... + String id = currentKey; + Object obj = p.getReferences().get(id); + + if ( obj == null ) { + fail(assertMsg + " Object ID does not exist."); + } + + // What is the property supposed to be? + propertyValue = + propertyValue.substring(3, propertyValue.length()); + if (propertyValue.equals("path")) { + if (!(obj instanceof Path)) { + fail(assertMsg + " Path ID is a " + + obj.getClass().getName()); + } + } else { + assertEquals(assertMsg, propertyValue, obj.toString()); + } + + } else { + + if (propertyValue.startsWith("FILE.")) { + // The property is the name of a file. We are testing + // a location attribute, so we need to resolve the given + // file name in the provided folder. + String fileName = + propertyValue.substring(5, propertyValue.length()); + File f = new File(workingDir, fileName); + propertyValue = f.getAbsolutePath(); + } + + assertEquals(assertMsg, propertyValue, xmlValue); + } + + } + } + + /** + * Debugging method to print the properties in the given hashtable + */ + private static void printProperties(Hashtable xmlproperties) { + Enumeration keyEnum = xmlproperties.keys(); + while (keyEnum.hasMoreElements()) { + String currentKey = keyEnum.nextElement().toString(); + System.out.println(currentKey + " = " + + xmlproperties.get(currentKey)); + } + } + + /** + * Ensure all references loaded by the project are valid. + */ + private static void ensureReferences (String msg, File inputFile, + Hashtable references) { + Enumeration referenceKeyEnum = references.keys(); + while(referenceKeyEnum.hasMoreElements()){ + String currentKey = referenceKeyEnum.nextElement().toString(); + Object currentValue = references.get(currentKey); + + if (currentValue instanceof Path) { + } else if (currentValue instanceof String) { + } else { + if( ! currentKey.startsWith("ant.") ) { + fail(msg + "-" + inputFile.getName() + " Key=" + + currentKey + " is not a recognized type."); + } + } + } + } + + /** + * Munge the name of the input file to find an appropriate goldfile, + * based on hardwired naming conventions. + */ + private static File getGoldfile (File input, boolean keepRoot, + boolean collapse, boolean semantic, + boolean include, boolean localRoot) { + // Substitute .xml with .properties + String baseName = input.getName().toLowerCase(); + if (baseName.endsWith(".xml")) { + baseName = baseName.substring(0, baseName.length() - 4) + + ".properties"; + } + + File dir = input.getParentFile().getParentFile(); + + String goldFileFolder = "goldfiles/"; + + if (keepRoot) { + goldFileFolder += "keeproot-"; + } else { + goldFileFolder += "nokeeproot-"; + } + + if (semantic) { + goldFileFolder += "semantic-"; + if (include) { + goldFileFolder += "include-"; + } + } else { + if (collapse) { + goldFileFolder += "collapse-"; + } else { + goldFileFolder += "nocollapse-"; + } + } + + return new File(dir, goldFileFolder + baseName); + } + + /** + * Retrieve a list of xml files in the specified folder + * and below. + */ + private static Enumeration getFiles (final File startingDir) { + Vector result = new Vector(); + getFiles(startingDir, result); + return result.elements(); + } + + /** + * Collect a list of xml files in the specified folder + * and below. + */ + private static void getFiles (final File startingDir, Vector collect) { + FileFilter filter = new FileFilter() { + public boolean accept (File file) { + if (file.isDirectory()) { + return true; + } else { + return (file.getPath().indexOf("taskdefs") > 0 && + file.getPath().toLowerCase().endsWith(".xml") ); + } + } + }; + + File[] files = startingDir.listFiles(filter); + for (int i=0;i<files.length;i++) { + File f = files[i]; + if (!f.isDirectory()) { + collect.addElement(f); + } else { + getFiles(f, collect); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java new file mode 100644 index 00000000..590a4db9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java @@ -0,0 +1,89 @@ +/* + * 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.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Task; +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 XmlnsTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/xmlns.xml"); + } + + @Test + public void testXmlns() { + buildRule.executeTarget("xmlns"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testXmlnsFile() { + buildRule.executeTarget("xmlns.file"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testCore() { + buildRule.executeTarget("core"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testExcluded() { + try { + buildRule.executeTarget("excluded"); + fail("BuildException expected: excluded uri"); + } catch (BuildException ex) { + assertEquals("Attempt to use a reserved URI ant:notallowed", ex.getMessage()); + } + } + + @Test + public void testOther() { + buildRule.executeTarget("other"); + assertEquals("a message", buildRule.getLog()); + } + + @Test + public void testNsAttributes() { + buildRule.executeTarget("ns.attributes"); + assertEquals("hello world", buildRule.getLog()); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java new file mode 100644 index 00000000..c5a42162 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java @@ -0,0 +1,109 @@ +/* + * 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.taskdefs; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; + +import org.apache.tools.ant.types.Resource; + +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.ZipResource; +import org.apache.tools.zip.JarMarker; +import org.apache.tools.zip.Zip64ExtendedInformationExtraField; +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipExtraField; +import org.apache.tools.zip.ZipFile; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class ZipExtraFieldTest { + + @Test + public void testPreservesExtraFields() throws IOException { + testExtraField(new Zip(), true); + } + + public void testDoesntCreateZip64ExtraFieldForJar() throws IOException { + testExtraField(new Jar(), false); + } + + private void testExtraField(Zip testInstance, boolean expectZip64) + throws IOException { + + File f = File.createTempFile("ziptest", ".zip"); + f.delete(); + ZipFile zf = null; + try { + testInstance.setDestFile(f); + final ZipResource r = new ZipResource() { + public String getName() { + return "x"; + } + public boolean isExists() { + return true; + } + public boolean isDirectory() { + return false; + } + public long getLastModified() { + return 1; + } + public InputStream getInputStream() { + return new ByteArrayInputStream(new byte[0]); + } + public ZipExtraField[] getExtraFields() { + return new ZipExtraField[] { + new JarMarker() + }; + } + }; + testInstance.add(new ResourceCollection() { + public boolean isFilesystemOnly() { return false; } + public int size() { return 1; } + public Iterator<Resource> iterator() { + return Collections.<Resource>singleton(r).iterator(); + } + }); + testInstance.execute(); + + zf = new ZipFile(f); + ZipEntry ze = zf.getEntry("x"); + assertNotNull(ze); + assertEquals(expectZip64 ? 2 : 1, ze.getExtraFields().length); + assertTrue(ze.getExtraFields()[0] instanceof JarMarker); + if (expectZip64) { + assertTrue(ze.getExtraFields()[1] + instanceof Zip64ExtendedInformationExtraField); + } + } finally { + ZipFile.closeQuietly(zf); + if (f.exists()) { + f.delete(); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java new file mode 100644 index 00000000..5a7a3590 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -0,0 +1,300 @@ +/* + * 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.taskdefs; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.zip.UnixStat; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +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; +import static org.junit.Assume.assumeTrue; + + +public class ZipTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + //instance variable to allow cleanup + ZipFile zfPrefixAddsDir = null; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/zip.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: zip cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: zip cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @After + public void tearDown() { + try { + if ( zfPrefixAddsDir != null) { + zfPrefixAddsDir.close(); + } + + } catch (IOException e) { + //ignored + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + + @Test + public void test7() { + buildRule.executeTarget("test7"); + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + + @Test + public void testZipgroupfileset() throws IOException { + buildRule.executeTarget("testZipgroupfileset"); + + ZipFile zipFile = new ZipFile(new File(buildRule.getProject().getProperty("output"), "zipgroupfileset.zip")); + + assertTrue(zipFile.getEntry("ant.xml") != null); + assertTrue(zipFile.getEntry("optional/jspc.xml") != null); + assertTrue(zipFile.getEntry("zip/zipgroupfileset3.zip") != null); + + assertTrue(zipFile.getEntry("test6.mf") == null); + assertTrue(zipFile.getEntry("test7.mf") == null); + + zipFile.close(); + } + + @Test + public void testUpdateNotNecessary() { + buildRule.executeTarget("testUpdateNotNecessary"); + assertEquals(-1, buildRule.getLog().indexOf("Updating")); + } + + @Test + public void testUpdateIsNecessary() { + buildRule.executeTarget("testUpdateIsNecessary"); + assertContains("Updating", buildRule.getLog()); + } + + // Bugzilla Report 18403 + @Test + public void testPrefixAddsDir() throws IOException { + buildRule.executeTarget("testPrefixAddsDir"); + File archive = new File(buildRule.getProject().getProperty("output"), "test3.zip"); + zfPrefixAddsDir = new ZipFile(archive); + ZipEntry ze = zfPrefixAddsDir.getEntry("test/"); + assertNotNull("test/ has been added", ze); + + } + + // Bugzilla Report 19449 + @Test + public void testFilesOnlyDoesntCauseRecreate() { + buildRule.executeTarget("testFilesOnlyDoesntCauseRecreateSetup"); + File testFile = new File(buildRule.getOutputDir(), "test3.zip"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long l = testFile.lastModified(); + + buildRule.executeTarget("testFilesOnlyDoesntCauseRecreate"); + assertEquals(l, testFile.lastModified()); + } + + // Bugzilla Report 22865 + @Test + public void testEmptySkip() { + buildRule.executeTarget("testEmptySkip"); + } + // Bugzilla Report 30365 + @Test + public void testZipEmptyDir() { + buildRule.executeTarget("zipEmptyDir"); + } + // Bugzilla Report 40258 + @Test + public void testZipEmptyDirFilesOnly() { + buildRule.executeTarget("zipEmptyDirFilesOnly"); + } + @Test + public void testZipEmptyCreate() { + buildRule.executeTarget("zipEmptyCreate"); + assertContains("Note: creating empty", buildRule.getLog()); + } + // Bugzilla Report 25513 + @Test + public void testCompressionLevel() { + buildRule.executeTarget("testCompressionLevel"); + } + + // Bugzilla Report 33412 + @Test + public void testDefaultExcludesAndUpdate() + throws ZipException, IOException { + buildRule.executeTarget("testDefaultExcludesAndUpdate"); + ZipFile f = null; + try { + f = new ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + assertNotNull("ziptest~ should be included", + f.getEntry("ziptest~")); + } finally { + if (f != null) { + f.close(); + } + } + } + + @Test + public void testFileResource() { + buildRule.executeTarget("testFileResource"); + } + + @Test + public void testNonFileResource() { + buildRule.executeTarget("testNonFileResource"); + } + + @Test + public void testTarFileSet() throws IOException { + buildRule.executeTarget("testTarFileSet"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("asf-logo.gif"); + assertEquals(UnixStat.FILE_FLAG | 0446, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testRewriteZeroPermissions() throws IOException { + buildRule.executeTarget("rewriteZeroPermissions"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt"); + assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testAcceptZeroPermissions() throws IOException { + buildRule.executeTarget("acceptZeroPermissions"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt"); + assertEquals(0000, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testForBugzilla34764() throws IOException { + buildRule.executeTarget("testForBugzilla34764"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("file1"); + assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java new file mode 100644 index 00000000..750098f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -0,0 +1,223 @@ +/* + * 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.taskdefs.compilers; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.types.Commandline; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; + +public class DefaultCompilerAdapterTest { + + private static class LogCapturingJavac extends Javac { + private StringBuffer sb = new StringBuffer(); + public void log(String msg, int msgLevel) { + sb.append(msg); + } + String getLog() { + return sb.toString(); + } + } + + private static class SourceTargetHelper extends DefaultCompilerAdapter { + /** + * Overridden to have no effect. + */ + protected Commandline setupJavacCommandlineSwitches(Commandline cmd, + boolean debug) { + return cmd; + } + + public boolean execute() { return false; } + + /** + * public to avoid classloader issues. + */ + public Commandline setupModernJavacCommandlineSwitches(Commandline cmd) { + return super.setupModernJavacCommandlineSwitches(cmd); + } + } + + @Test + public void testSourceIsIgnoredForJavac13() { + testSource(null, "javac1.3", "", null, "1.1"); + testSource(null, "javac1.3", "", null, "1.2"); + testSource(null, "javac1.3", "", null, "1.3"); + testSource(null, "javac1.3", "", null, "1.4"); + } + + @Test + public void testSource11IsUpgradedTo13() { + testSource("1.3", "javac1.4", "", null, "1.1"); + testSource("1.3", "javac1.5", "", null, "1.1"); + testSource("1.3", "javac1.6", "", null, "1.1"); + testSource("1.3", "javac1.7", "", null, "1.1"); + testSource("1.3", "javac1.8", "", null, "1.1"); + } + + @Test + public void testSource12IsUpgradedTo13() { + testSource("1.3", "javac1.4", "", null, "1.2"); + testSource("1.3", "javac1.5", "", null, "1.2"); + testSource("1.3", "javac1.6", "", null, "1.2"); + testSource("1.3", "javac1.7", "", null, "1.2"); + testSource("1.3", "javac1.8", "", null, "1.2"); + } + + @Test + public void testImplicitSourceForJava15() { + commonSourceDowngrades("javac1.5"); + testSource(null, "javac1.5", "", "1.5"); + testSource(null, "javac1.5", "", "5"); + } + + @Test + public void testImplicitSourceForJava16() { + commonSourceDowngrades("javac1.6"); + testSource(null, "javac1.6", "", "1.5"); + testSource(null, "javac1.6", "", "5"); + testSource(null, "javac1.6", "", "1.6"); + testSource(null, "javac1.6", "", "6"); + } + + @Test + public void testImplicitSourceForJava17() { + commonSourceDowngrades("javac1.7"); + testSource("1.5", "javac1.7", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.7", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("5", "javac1.7", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.7", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource(null, "javac1.7", "", "1.7"); + testSource(null, "javac1.7", "", "7"); + } + + @Test + public void testImplicitSourceForJava18() { + commonSourceDowngrades("javac1.8"); + testSource("1.5", "javac1.8", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.8", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("1.7", "javac1.8", + "If you specify -target 1.7 you now must also specify" + + " -source 1.7", "1.7"); + testSource("5", "javac1.8", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.8", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource("7", "javac1.8", + "If you specify -target 7 you now must also specify" + + " -source 7", "7"); + testSource(null, "javac1.8", "", "1.8"); + testSource(null, "javac1.8", "", "8"); + } + + @Test + public void testImplicitSourceForJava19() { + commonSourceDowngrades("javac1.9"); + testSource("1.5", "javac1.9", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.9", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("1.7", "javac1.9", + "If you specify -target 1.7 you now must also specify" + + " -source 1.7", "1.7"); + testSource("1.8", "javac1.9", + "If you specify -target 1.8 you now must also specify" + + " -source 1.8", "1.8"); + testSource("5", "javac1.9", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.9", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource("7", "javac1.9", + "If you specify -target 7 you now must also specify" + + " -source 7", "7"); + testSource("8", "javac1.9", + "If you specify -target 8 you now must also specify" + + " -source 8", "8"); + testSource(null, "javac1.9", "", "1.9"); + testSource(null, "javac1.9", "", "9"); + } + + private void commonSourceDowngrades(String javaVersion) { + testSource("1.3", javaVersion, + "If you specify -target 1.1 you now must also specify" + + " -source 1.3", "1.1"); + testSource("1.3", javaVersion, + "If you specify -target 1.2 you now must also specify" + + " -source 1.3", "1.2"); + testSource("1.3", javaVersion, + "If you specify -target 1.3 you now must also specify" + + " -source 1.3", "1.3"); + testSource("1.4", javaVersion, + "If you specify -target 1.4 you now must also specify" + + " -source 1.4", "1.4"); + } + + private void testSource(String expectedSource, String javaVersion, + String expectedLog, String configuredTarget) { + testSource(expectedSource, javaVersion, expectedLog, configuredTarget, + null); + } + + private void testSource(String expectedSource, String javaVersion, + String expectedLog, String configuredTarget, + String configuredSource) { + LogCapturingJavac javac = new LogCapturingJavac(); + javac.setProject(new Project()); + javac.setCompiler(javaVersion); + javac.setSource(configuredSource); + javac.setTarget(configuredTarget); + SourceTargetHelper sth = new SourceTargetHelper(); + sth.setJavac(javac); + Commandline cmd = new Commandline(); + sth.setupModernJavacCommandlineSwitches(cmd); + if ("".equals(expectedLog)) { + assertEquals("", javac.getLog()); + } else { + String l = javac.getLog(); + assertContains(expectedLog, l); + } + String[] args = cmd.getCommandline(); + assertEquals(expectedSource == null ? 0 : 2, args.length); + if (expectedSource != null) { + assertEquals("-source", args[0]); + assertEquals(expectedSource, args[1]); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java new file mode 100644 index 00000000..b70a1381 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java @@ -0,0 +1,48 @@ +/* + * 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.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcases for the <antversion> condition. + * + */ +public class AntVersionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/antversion.xml"); + } + + @Test + public void testAtLeast() { + buildRule.executeTarget("testatleast"); + } + + @Test + public void testExactly() { + buildRule.executeTarget("testexactly"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java new file mode 100644 index 00000000..a45b511a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java @@ -0,0 +1,42 @@ +/* + * 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.taskdefs.condition; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the <contains> condition. + * + */ +public class ContainsTest { + + @Test + public void testCaseSensitive() { + Contains con = new Contains(); + con.setString("abc"); + con.setSubstring("A"); + assertTrue(!con.eval()); + + con.setCasesensitive(false); + assertTrue(con.eval()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java new file mode 100644 index 00000000..5f9b996a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java @@ -0,0 +1,56 @@ +/* + * 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.taskdefs.condition; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the <equals> condition. + * + */ +public class EqualsTest { + + @Test + public void testTrim() { + Equals eq = new Equals(); + eq.setArg1("a"); + eq.setArg2(" a"); + assertTrue(!eq.eval()); + + eq.setTrim(true); + assertTrue(eq.eval()); + + eq.setArg2("a\t"); + assertTrue(eq.eval()); + } + + @Test + public void testCaseSensitive() { + Equals eq = new Equals(); + eq.setArg1("a"); + eq.setArg2("A"); + assertTrue(!eq.eval()); + + eq.setCasesensitive(false); + assertTrue(eq.eval()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java new file mode 100644 index 00000000..15a9d2d3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java @@ -0,0 +1,76 @@ +/* + * 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.taskdefs.condition; + +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.fail; + +/** + * Testcases for the <http> condition. All these tests require + * us to be online as they attempt to get the status of various pages + * on the Ant Apache web site. + */ +public class HttpTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/http.xml"); + } + + @Test + public void testNoMethod() { + buildRule.executeTarget("basic-no-method"); + assertEquals("true", buildRule.getProject().getProperty("basic-no-method")); + assertNull(buildRule.getProject().getProperty("basic-no-method-bad-url")); + } + + @Test + public void testHeadRequest() { + buildRule.executeTarget("test-head-request"); + assertEquals("true", buildRule.getProject().getProperty("test-head-request")); + assertNull(buildRule.getProject().getProperty("test-head-request-bad-url")); + } + + @Test + public void testGetRequest() { + buildRule.executeTarget("test-get-request"); + assertEquals("true", buildRule.getProject().getProperty("test-get-request")); + assertNull(buildRule.getProject().getProperty("test-get-request-bad-url")); + } + + @Test + public void testBadRequestMethod() { + try { + buildRule.executeTarget("bad-request-method"); + fail("Exception should have been thrown as invalid HTTP request method specified"); + } catch (BuildException ex) { + //TODO we should assert the correct build exception was thrown + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java new file mode 100644 index 00000000..86594765 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java @@ -0,0 +1,44 @@ +/* + * 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.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcases for the <isfailure> condition. + * + */ +public class IsFailureTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfailure.xml"); + } + + @Test + public void testIsFailure() { + buildRule.executeTarget("testisfailure"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java new file mode 100644 index 00000000..84d88a55 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java @@ -0,0 +1,74 @@ +/* + * 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.taskdefs.condition; + +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.fail; + +/** + * Testcase for the <isfileselected> condition. + * + */ +public class IsFileSelectedTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfileselected.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + } + + @Test + public void testName() { + buildRule.executeTarget("name"); + } + + @Test + public void testBaseDir() { + buildRule.executeTarget("basedir"); + } + + @Test + public void testType() { + buildRule.executeTarget("type"); + } + + @Test + public void testNotSelector() { + try { + buildRule.executeTarget("not.selector"); + fail("Exception should have been thrown: checking for use as a selector (not allowed)"); + } catch(BuildException ex) { + AntAssert.assertContains("fileset doesn't support the nested \"isfile", + ex.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java new file mode 100644 index 00000000..d036834c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java @@ -0,0 +1,116 @@ +/* + * 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.taskdefs.condition; + +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.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * test for reachable things + */ +public class IsReachableTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/conditions/isreachable.xml"); + } + + + @Test + public void testLocalhost() throws Exception { + buildRule.executeTarget("testLocalhost"); + } + + @Test + public void testLocalhostURL() throws Exception { + buildRule.executeTarget("testLocalhostURL"); + } + + @Test + public void testIpv4localhost() throws Exception { + buildRule.executeTarget("testIpv4localhost"); + } + + @Test + public void testFTPURL() throws Exception { + buildRule.executeTarget("testFTPURL"); + } + + @Test + public void testBoth() throws Exception { + try { + buildRule.executeTarget("testBoth"); + fail("Build exception expected: error on two targets"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_BOTH_TARGETS, ex.getMessage()); + } + } + + @Test + public void testNoTargets() throws Exception { + try { + buildRule.executeTarget("testNoTargets"); + fail("Build exception expected: no params"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_NO_HOSTNAME, ex.getMessage()); + } + } + + @Test + public void testBadTimeout() throws Exception { + try { + buildRule.executeTarget("testBadTimeout"); + fail("Build exception expected: error on -ve timeout"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_BAD_TIMEOUT, ex.getMessage()); + } + } + + @Test + @Ignore("Previously named in a way to prevent execution") + public void NotestFile() throws Exception { + try { + buildRule.executeTarget("testFile"); + fail("Build exception expected: error on file URL"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_NO_HOST_IN_URL, ex.getMessage()); + } + } + + @Test + public void testBadURL() throws Exception { + try { + buildRule.executeTarget("testBadURL"); + fail("Build exception expected: error in URL"); + } catch(BuildException ex) { + AntAssert.assertContains(IsReachable.ERROR_BAD_URL, ex.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java new file mode 100644 index 00000000..01b6b47c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java @@ -0,0 +1,71 @@ +/* + * 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.taskdefs.condition; + +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; +import static org.junit.Assert.assertNull; + +/** + * Testcases for the <isreference> condition. + * + */ +public class IsReferenceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml"); + } + + @Test + public void testBasic() { + buildRule.executeTarget("basic"); + assertEquals("true", buildRule.getProject().getProperty("global-path")); + assertEquals("true", buildRule.getProject().getProperty("target-path")); + assertNull(buildRule.getProject().getProperty("undefined")); + } + + @Test + public void testNotEnoughArgs() { + try { + buildRule.executeTarget("isreference-incomplete"); + fail("Build exception expected: refid attirbute has been omitted"); + } catch(BuildException ex) { + assertEquals("No reference specified for isreference condition", ex.getMessage()); + } + } + + @Test + public void testType() { + buildRule.executeTarget("type"); + assertEquals("true", buildRule.getProject().getProperty("global-path")); + assertNull(buildRule.getProject().getProperty("global-path-as-fileset")); + assertNull(buildRule.getProject().getProperty("global-path-as-foo")); + assertEquals("true", buildRule.getProject().getProperty("global-echo")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java new file mode 100644 index 00000000..0f4001c3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java @@ -0,0 +1,59 @@ +/* + * 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.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <issigned> condition. + * + */ +public class IsSignedTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/issigned.xml"); + } + + @Test + public void testPass() { + buildRule.executeTarget("pass"); + } + + @Test + public void testPassword() { + buildRule.executeTarget("password"); + } + + @Test + public void testAPassword() { + buildRule.executeTarget("apassword"); + } + + @Test + public void testAllSigned() { + buildRule.executeTarget("allsigned"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java new file mode 100644 index 00000000..2a2354ff --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java @@ -0,0 +1,95 @@ +/* + * 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.taskdefs.condition; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + + */ +public class ParserSupportsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("Build exception expected: " + ParserSupports.ERROR_NO_ATTRIBUTES); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_NO_ATTRIBUTES, ex.getMessage()); + } + } + + @Test + public void testBoth() { + try { + buildRule.executeTarget("testBoth"); + fail("Build exception expected: " + ParserSupports.ERROR_BOTH_ATTRIBUTES); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_BOTH_ATTRIBUTES, ex.getMessage()); + } + } + + @Test + public void testNamespaces() { + buildRule.executeTarget("testNamespaces"); + } + + @Test + public void testPropertyNoValue() { + try { + buildRule.executeTarget("testPropertyNoValue"); + fail("Build exception expected: " + ParserSupports.ERROR_NO_VALUE); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_NO_VALUE, ex.getMessage()); + } + } + + @Test + public void testUnknownProperty() { + buildRule.executeTarget("testUnknownProperty"); + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void NotestPropertyInvalid() { + buildRule.executeTarget("testPropertyInvalid"); + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void NotestXercesProperty() { + buildRule.executeTarget("testXercesProperty"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java new file mode 100644 index 00000000..ab284943 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java @@ -0,0 +1,91 @@ +/* + * 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.taskdefs.condition; + +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; +import static org.junit.Assert.assertNull; + +/** + * test the typeexists condition + */ +public class TypeFoundTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/typefound.xml"); + } + + @Test + public void testTask() { + buildRule.executeTarget("testTask"); + assertEquals("true", buildRule.getProject().getProperty("testTask")); + } + + @Test + public void testUndefined() { + try { + buildRule.executeTarget("testUndefined"); + fail("Build exception expected: left out the name attribute"); + } catch(BuildException ex) { + AntAssert.assertContains("No type specified", ex.getMessage()); + } + } + + @Test + public void testTaskThatIsntDefined() { + buildRule.executeTarget("testTaskThatIsntDefined"); + assertNull(buildRule.getProject().getProperty("testTaskThatIsntDefined")); + } + + @Test + public void testTaskThatDoesntReallyExist() { + buildRule.executeTarget("testTaskThatDoesntReallyExist"); + assertNull(buildRule.getProject().getProperty("testTaskThatDoesntReallyExist")); + } + + @Test + public void testType() { + buildRule.executeTarget("testType"); + assertEquals("true", buildRule.getProject().getProperty("testType")); + } + + @Test + public void testPreset() { + buildRule.executeTarget("testPreset"); + assertEquals("true", buildRule.getProject().getProperty("testPreset")); + } + + @Test + public void testMacro() { + buildRule.executeTarget("testMacro"); + assertEquals("true", buildRule.getProject().getProperty("testMacro")); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java new file mode 100644 index 00000000..4f04c357 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java @@ -0,0 +1,75 @@ +/* + * 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.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test that Xor follows the conventional boolean logic semantics + * (a ^ b) === (a||b)&!(a&&b) + */ +public class XorTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/xor.xml"); + } + + @Test + public void testEmpty() { + buildRule.executeTarget("testEmpty"); + } + + @Test + public void test0() { + buildRule.executeTarget("test0"); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + } + + @Test + public void test00() { + buildRule.executeTarget("test00"); + } + + @Test + public void test10() { + buildRule.executeTarget("test10"); + } + + @Test + public void test01() { + buildRule.executeTarget("test01"); + } + + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java new file mode 100644 index 00000000..3dfaf8dd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java @@ -0,0 +1,67 @@ +/* + * 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.taskdefs.cvslib; + +import org.junit.Test; + +import java.util.Calendar; +import java.util.Locale; +import java.util.TimeZone; +import java.util.Date; + +import static org.junit.Assert.assertEquals; + +/** + * Minimal test of the parser implementation + */ +public class ChangeLogParserTest { + + protected ChangeLogParser parser = new ChangeLogParser(); + + @Test + public void testOldCvsFormat() throws Exception { + parser.stdout("Working file: build.xml"); + parser.stdout("revision 1.475"); + parser.stdout("date: 2004/06/05 16:10:32; author: somebody; state: Exp; lines: +2 -2"); + parser.stdout("I have done something. I swear."); + parser.stdout("============================================================================="); + CVSEntry[] entries = parser.getEntrySetAsArray(); + assertEquals("somebody", entries[0].getAuthor()); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); + cal.set(Calendar.MILLISECOND, 0); + cal.set(2004, Calendar.JUNE, 5, 16, 10, 32); + Date date = cal.getTime(); + assertEquals(date, entries[0].getDate()); + } + + @Test + public void testCvs112Format() throws Exception { + parser.stdout("Working file: build.xml"); + parser.stdout("revision 1.475"); + parser.stdout("date: 2004-06-05 16:10:32 +0000; author: somebody; state: Exp; lines: +2 -2"); + parser.stdout("I have done something. I swear."); + parser.stdout("============================================================================="); + CVSEntry[] entries = parser.getEntrySetAsArray(); + assertEquals("somebody", entries[0].getAuthor()); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); + cal.set(Calendar.MILLISECOND, 0); + cal.set(2004, Calendar.JUNE, 5, 16, 10, 32); + Date date = cal.getTime(); + assertEquals(date, entries[0].getDate()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java new file mode 100644 index 00000000..a2531d8e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java @@ -0,0 +1,96 @@ +/* + * 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.taskdefs.cvslib; + +import java.util.Date; +import java.io.PrintWriter; +import java.io.OutputStreamWriter; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Test; +import org.xml.sax.XMLReader; +import org.xml.sax.InputSource; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.Locator; +import org.xml.sax.Attributes; + +/** + * Test for the cvslib ChangeLogWriter + */ +public class ChangeLogWriterTest { + + private ChangeLogWriter writer = new ChangeLogWriter(); + + @Test + public void testNonUTF8Characters() throws Exception { + CVSEntry entry = new CVSEntry(new Date(), "Se\u00f1orita", "2003 < 2004 && 3 > 5"); + entry.addFile("Medicare & review.doc", "1.1"); + entry.addFile("El\u00e8ments de style", "1.2"); + CVSEntry[] entries = { entry }; + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(output, "UTF-8")); + writer.printChangeLog(pwriter, entries); + + // make sure that the parsing does not break + XMLReader xmlReader = JAXPUtils.getXMLReader(); + InputStream input = new ByteArrayInputStream(output.toByteArray()); + xmlReader.setContentHandler(new NullContentHandler()); + xmlReader.parse(new InputSource(input)); + } + + public static class NullContentHandler implements ContentHandler { + public void endDocument() throws SAXException { + } + + public void startDocument() throws SAXException { + } + + public void characters(char ch[], int start, int length) throws SAXException { + String debug = new String(ch, start, length); + } + + public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { + } + + public void endPrefixMapping(String prefix) throws SAXException { + } + + public void skippedEntity(String name) throws SAXException { + } + + public void setDocumentLocator(Locator locator) { + } + + public void processingInstruction(String target, String data) throws SAXException { + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + + public void endElement(String namespaceURI, String localName, String qName) throws SAXException { + } + + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java new file mode 100644 index 00000000..9057fa0c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java @@ -0,0 +1,30 @@ +/* + * 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.taskdefs.dir1; + +public class B extends org.apache.tools.ant.taskdefs.dir2.A { + static { + System.out.println("B CLASS INITIALIZATION"); + setA(new B()); + } + + public String toString() { + return "I am a B."; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java new file mode 100644 index 00000000..5186ac4c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java @@ -0,0 +1,40 @@ +/* + * 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.taskdefs.dir2; + +public class A { + public static void main(String [] args) { + System.out.println("MAIN"); + System.out.println(a); + } + + static A a=new A(); + + static { + System.out.println("A CLASS INITIALIZATION"); + } + + protected static void setA(A oa) { + a=oa; + } + + public String toString() { + return "I am a A."; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java new file mode 100644 index 00000000..31ecafba --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java @@ -0,0 +1,112 @@ +/* + * 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.taskdefs.email; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * @since Ant 1.6 + */ +public class EmailAddressTest { + + @Test + public void test1() { + expectNameAddress( new EmailAddress("address (name)") ); + } + + @Test + public void test2() { + expectNameAddress( new EmailAddress("(name) address") ); + } + + @Test + public void test3() { + expectNameAddress( new EmailAddress("name <address>") ); + } + + @Test + public void test4() { + expectNameAddress( new EmailAddress("<address> name") ); + } + + @Test + public void test5() { + expectNameAddress( new EmailAddress("<address> (name)") ); + } + + @Test + public void test6() { + expectNameAddress( new EmailAddress("(name) <address>") ); + } + + @Test + public void test7() { + expectNameAddress2( new EmailAddress("address (<name>)") ); + } + + @Test + public void test8() { + expectNameAddress2( new EmailAddress("(<name>) address") ); + } + + @Test + public void test9() { + expectNameAddress3( new EmailAddress("address") ); + } + + @Test + public void testA() { + expectNameAddress3( new EmailAddress("<address>") ); + } + + @Test + public void testB() { + expectNameAddress3( new EmailAddress(" <address> ") ); + } + + @Test + public void testC() { + expectNameAddress3( new EmailAddress("< address >") ); + } + + @Test + public void testD() { + expectNameAddress3( new EmailAddress(" < address > ") ); + } + + private void expectNameAddress(EmailAddress e) { + assertEquals( "name", e.getName() ); + assertEquals( "address", e.getAddress() ); + } + + // where the name contains <> + private void expectNameAddress2(EmailAddress e) { + assertEquals( "<name>", e.getName() ); + assertEquals( "address", e.getAddress() ); + } + + // where only an address is supplied + private void expectNameAddress3(EmailAddress e) { + assertNull("Expected null, found <" + e.getName() + ">", e.getName()); + assertEquals( "address", e.getAddress() ); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java new file mode 100644 index 00000000..6363f90d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java @@ -0,0 +1,63 @@ +/* + * 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.taskdefs.email; + +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; + +/** + * TODO : develop these testcases - the email task needs to have attributes allowing + * to simulate sending mail and to catch the output in text files or streams + */ +public class EmailTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/email/mail.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Build exception expected: SMTP auth only possibly with MIME mail"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Build exception expected: SSL only possibly with MIME mail"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java new file mode 100644 index 00000000..df75067f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java @@ -0,0 +1,62 @@ +/* + * 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.taskdefs.email; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Test; + +public class MessageTest { + private static final File f = new File(System.getProperty("java.io.tmpdir"), + "message.txt"); + /** + * test for bugzilla 48932 + */ + @Test + public void testPrintStreamDoesNotGetClosed() throws IOException { + Message ms = new Message(); + Project p = new Project(); + ms.setProject(p); + ms.addText("hi, this is an email"); + FileOutputStream fis = null; + try { + fis = new FileOutputStream(f); + ms.print(new PrintStream(fis)); + fis.write(120); + } finally { + FileUtils.close(fis); + } + + } + + @After + public void tearDown() { + if (f.exists()) { + FileUtils fu = FileUtils.getFileUtils(); + fu.tryHardToDelete(f); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java new file mode 100644 index 00000000..92584483 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java @@ -0,0 +1,216 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +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.FilenameFilter; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * If you want to run tests, it is highly recommended + * to download ANTLR (www.antlr.org), build the 'antlrall.jar' jar + * with <code>make antlr-all.jar</code> and drop the jar (about 300KB) into + * Ant lib. + * - Running w/ the default antlr.jar (70KB) does not work (missing class) + * + * Unless of course you specify the ANTLR classpath in your + * system classpath. (see ANTLR install.html) + * + */ +public class ANTLRTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "antlr.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument, target, missing"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Invalid output directory"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + // should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'" + // since it needs to run java.g first before java.tree.g + try { + buildRule.executeTarget("test5"); + fail("ANTLR returned: 1"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("Unable to determine generated class"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + /** + * This is a negative test for the super grammar (glib) option. + */ + @Test + public void test8() { + try { + buildRule.executeTarget("test8"); + fail("Invalid super grammar file"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + /** + * This is a positive test for the super grammar (glib) option. ANTLR + * will throw an error if everything is not correct. + */ + @Test + public void test9() { + buildRule.executeTarget("test9"); + } + + /** + * This test creates an html-ized version of the calculator grammar. + * The sanity check is simply whether or not an html file was generated. + */ + @Test + public void test10() { + buildRule.executeTarget("test10"); + File outputDirectory = new File(buildRule.getProject().getProperty("output")); + String[] calcFiles = outputDirectory.list(new HTMLFilter()); + assertTrue(calcFiles.length > 0); + } + + /** + * This is just a quick sanity check to run the diagnostic option and + * make sure that it doesn't throw any funny exceptions. + */ + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + + /** + * This is just a quick sanity check to run the trace option and + * make sure that it doesn't throw any funny exceptions. + */ + @Test + public void test12() { + buildRule.executeTarget("test12"); + } + + /** + * This is just a quick sanity check to run all the rest of the + * trace options (traceLexer, traceParser, and traceTreeWalker) to + * make sure that they don't throw any funny exceptions. + */ + @Test + public void test13() { + buildRule.executeTarget("test13"); + } + + @Test + public void testNoRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + buildRule.executeTarget("noRecompile"); + assertContains("Skipped grammar file.", buildRule.getFullLog()); + } + + @Test + public void testNormalRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + + buildRule.executeTarget("normalRecompile"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + } + + @Test + // Bugzilla Report 12961 + public void testSupergrammarChangeRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + + buildRule.executeTarget("supergrammarChangeRecompile"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + } + +} + +class HTMLFilter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.endsWith("html"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java new file mode 100644 index 00000000..434e81f5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java @@ -0,0 +1,104 @@ +/* + * 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.taskdefs.optional; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URL; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Abtract testcase for XSLTLiaison. + * Override createLiaison for each XSLTLiaison. + * + * <a href="sbailliez@apache.org">Stephane Bailliez</a> + */ +public abstract class AbstractXSLTLiaisonTest { + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + protected XSLTLiaison liaison; + + @Before + public void setUp() throws Exception { + liaison = createLiaison(); + } + + // to override + protected abstract XSLTLiaison createLiaison() throws Exception ; + + /** load the file from the caller classloader that loaded this class */ + protected File getFile(String name) throws FileNotFoundException { + URL url = getClass().getResource(name); + if (url == null){ + throw new FileNotFoundException("Unable to load '" + name + "' from classpath"); + } + return new File(FILE_UTILS.fromURI(url.toExternalForm())); + } + + /** keep it simple stupid */ + @Test + public void testTransform() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + liaison.setStylesheet(xsl); + liaison.addParam("param", "value"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); + File out = new File("xsltliaison.tmp"); + out.deleteOnExit(); // just to be sure + try { + liaison.transform(in, out); + } finally { + out.delete(); + } + } + + @Test + public void testEncoding() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-encoding-in.xsl"); + liaison.setStylesheet(xsl); + File in = getFile("/taskdefs/optional/xsltliaison-encoding-in.xml"); + File out = new File("xsltliaison-encoding.tmp"); + out.deleteOnExit(); // just to be sure + try { + liaison.transform(in, out); + Document doc = parseXML(out); + assertEquals("root",doc.getDocumentElement().getNodeName()); + assertEquals("message",doc.getDocumentElement().getFirstChild().getNodeName()); + assertEquals("\u00E9\u00E0\u00E8\u00EF\u00F9",doc.getDocumentElement().getFirstChild().getFirstChild().getNodeValue()); + } finally { + out.delete(); + } + } + + public Document parseXML(File file) throws Exception { + DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dbuilder = dbfactory.newDocumentBuilder(); + return dbuilder.parse(file); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java new file mode 100644 index 00000000..88020229 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java @@ -0,0 +1,48 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests the examples of the <script> task docs. + * + * @since Ant 1.5.2 + */ +public class BeanShellScriptTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml"); + } + + @Test + public void testCanLoad() { + buildRule.executeTarget("useBeanshell"); + assertEquals("I'm here", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java new file mode 100644 index 00000000..925777c5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -0,0 +1,266 @@ +/* + * 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.taskdefs.optional; + +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.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests the EchoProperties task. + * + * @created 17-Jan-2002 + * @since Ant 1.5 + */ +public class EchoPropertiesTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + private static final String GOOD_OUTFILE = "test.properties"; + private static final String GOOD_OUTFILE_XML = "test.xml"; + private static final String PREFIX_OUTFILE = "test-prefix.properties"; + private static final String TEST_VALUE = "isSet"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "echoproperties.xml"); + buildRule.getProject().setProperty("test.property", TEST_VALUE); + } + + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + + @Test + public void testEchoToLog() { + buildRule.executeTarget("testEchoToLog"); + assertContains("test.property=" + TEST_VALUE, buildRule.getLog()); + } + + @Test + public void testEchoWithEmptyPrefixToLog() { + buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); + assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + } + + + @Test + public void testReadBadFile() { + try { + buildRule.executeTarget("testReadBadFile"); + fail("BuildException should have been thrown on bad file"); + } + catch(BuildException ex) { + assertContains("srcfile is a directory","srcfile is a directory!", ex.getMessage()); + } + } + + @Test + public void testReadBadFileNoFail() { + buildRule.executeTarget("testReadBadFileNoFail"); + assertContains("srcfile is a directory!", buildRule.getLog()); + } + + + @Test + public void testEchoToBadFile() { + try { + buildRule.executeTarget("testEchoToBadFile"); + fail("BuildException should have been thrown on destination file being a directory"); + } catch(BuildException ex) { + assertContains("destfile is a directory", "destfile is a directory!", ex.getMessage()); + } + } + + + @Test + public void testEchoToBadFileNoFail() { + buildRule.executeTarget("testEchoToBadFileNoFail"); + assertContains("destfile is a directory!", buildRule.getLog()); + } + + + @Test + public void testEchoToGoodFile() throws Exception { + buildRule.executeTarget("testEchoToGoodFile"); + assertGoodFile(); + } + + + @Test + public void testEchoToGoodFileXml() throws Exception { + buildRule.executeTarget("testEchoToGoodFileXml"); + + // read in the file + File f = createRelativeFile(GOOD_OUTFILE_XML); + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + try { + String read = null; + while ((read = br.readLine()) != null) { + if (read.indexOf("<property name=\"test.property\" value=\""+TEST_VALUE+"\" />") >= 0) { + // found the property we set - it's good. + return; + } + } + fail("did not encounter set property in generated file."); + } finally { + try { + fr.close(); + } catch(IOException e) {} + try { + br.close(); + } catch(IOException e) {} + } + } + + + @Test + public void testEchoToGoodFileFail() throws Exception { + buildRule.executeTarget("testEchoToGoodFileFail"); + assertGoodFile(); + } + + + @Test + public void testEchoToGoodFileNoFail() throws Exception { + buildRule.executeTarget("testEchoToGoodFileNoFail"); + assertGoodFile(); + } + + @Test + public void testEchoPrefix() throws Exception { + testEchoPrefixVarious("testEchoPrefix"); + } + + @Test + public void testEchoPrefixAsPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsPropertyset"); + } + + @Test + public void testEchoPrefixAsNegatedPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset"); + } + + @Test + public void testEchoPrefixAsDoublyNegatedPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset"); + } + + @Test + public void testWithPrefixAndRegex() throws Exception { + try { + buildRule.executeTarget("testWithPrefixAndRegex"); + fail("BuildException should have been thrown on Prefix and RegEx beng set"); + } catch (BuildException ex) { + assertEquals("The target must fail with prefix and regex attributes set", "Please specify either prefix or regex, but not both", ex.getMessage()); + } + } + + @Test + public void testWithEmptyPrefixAndRegex() throws Exception { + buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); + assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + } + + @Test + public void testWithRegex() throws Exception { + assumeTrue("Test skipped because no regexp matcher is present.", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); + buildRule.executeTarget("testWithRegex"); + // the following line has been changed from checking ant.home to ant.version so the test will still work when run outside of an ant script + assertContains("ant.version=", buildRule.getFullLog()); + } + + private void testEchoPrefixVarious(String target) throws Exception { + buildRule.executeTarget(target); + Properties props = loadPropFile(PREFIX_OUTFILE); + assertEquals("prefix didn't include 'a.set' property", + "true", props.getProperty("a.set")); + assertNull("prefix failed to filter out property 'b.set'", + props.getProperty("b.set")); + } + + protected Properties loadPropFile(String relativeFilename) + throws IOException { + File f = createRelativeFile(relativeFilename); + Properties props=new Properties(); + InputStream in=null; + try { + in=new BufferedInputStream(new FileInputStream(f)); + props.load(in); + } finally { + if(in!=null) { + try { in.close(); } catch(IOException e) {} + } + } + return props; + } + + protected void assertGoodFile() throws Exception { + File f = createRelativeFile(GOOD_OUTFILE); + assertTrue("Did not create "+f.getAbsolutePath(), + f.exists()); + Properties props=loadPropFile(GOOD_OUTFILE); + props.list(System.out); + assertEquals("test property not found ", + TEST_VALUE, props.getProperty("test.property")); + } + + + protected String toAbsolute(String filename) { + return createRelativeFile(filename).getAbsolutePath(); + } + + + protected File createRelativeFile(String filename) { + if (filename.equals(".")) { + return buildRule.getProject().getBaseDir(); + } + // else + return new File(buildRule.getProject().getBaseDir(), filename); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java new file mode 100644 index 00000000..8b02fff5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java @@ -0,0 +1,60 @@ +/* + * 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.taskdefs.optional; + +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 static org.junit.Assert.assertTrue; + +public class JavahTest { + + private final static String BUILD_XML = + "src/etc/testcases/taskdefs/optional/javah/build.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(BUILD_XML); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testSimpleCompile() { + buildRule.executeTarget("simple-compile"); + assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h") + .exists()); + } + + @Test + public void testCompileFileset() { + buildRule.executeTarget("test-fileset"); + assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java new file mode 100644 index 00000000..57475cc1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java @@ -0,0 +1,200 @@ +/* + * 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.taskdefs.optional; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; +import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory; +import org.junit.Before; +import org.junit.Ignore; +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 the Jspc task. + * + * created 07 March 2002 + * @since Ant 1.5 + */ +public class JspcTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "jspc.xml"); + } + + + + @Test + public void testSimple() { + executeJspCompile("testSimple", "simple_jsp.java"); + } + + + @Test + public void testUriroot() throws Exception { + executeJspCompile("testUriroot", "uriroot_jsp.java"); + } + + + @Test + public void testXml() throws Exception { + executeJspCompile("testXml", "xml_jsp.java"); + } + + + /** + * try a keyword in a file + */ + @Test + public void testKeyword() throws Exception { + executeJspCompile("testKeyword", "default_jsp.java"); + } + + + /** + * what happens to 1nvalid-classname + */ + @Test + public void testInvalidClassname() throws Exception { + executeJspCompile("testInvalidClassname", + "_1nvalid_0002dclassname_jsp.java"); + } + + + @Test + public void testNoTld() throws Exception { + try { + buildRule.executeTarget("testNoTld"); + fail("Not found"); + } catch (BuildException ex) { + assertEquals("Java returned: 9", ex.getMessage()); + } + } + + + @Test + public void testNotAJspFile() throws Exception { + buildRule.executeTarget("testNotAJspFile"); + } + + /** + * webapp test is currently broken, because it picks up + * on the missing_tld file, and bails. + */ + @Ignore("picks up on the missing_tld file, and incorrectly bails") + @Test + public void testWebapp() throws Exception { + buildRule.executeTarget("testWebapp"); + } + + /** + * run a target then verify the named file gets created + * + * @param target Description of Parameter + * @param javafile Description of Parameter + */ + protected void executeJspCompile(String target, String javafile) { + buildRule.executeTarget(target); + assertJavaFileCreated(javafile); + } + + + /** + * verify that a named file was created + * + * @param filename Description of Parameter + */ + protected void assertJavaFileCreated(String filename) { + File file = getOutputFile(filename); + assertTrue("file " + filename + " not found", file.exists()); + assertTrue("file " + filename + " is empty", file.length() > 0); + } + + /** + * Gets the OutputFile attribute of the JspcTest object + * + * @param subpath Description of Parameter + * @return The OutputFile value + */ + protected File getOutputFile(String subpath) { + return new File(buildRule.getProject().getProperty("output"), subpath); + } + + /** + * verify that we select the appropriate mangler + */ + @Test + public void testJasperNameManglerSelection() { + JspCompilerAdapter adapter= + JspCompilerAdapterFactory.getCompiler("jasper", null,null); + JspMangler mangler=adapter.createMangler(); + assertTrue(mangler instanceof JspNameMangler); + adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null); + mangler = adapter.createMangler(); + assertTrue(mangler instanceof Jasper41Mangler); + } + + @Test + public void testJasper41() { + JspMangler mangler = new Jasper41Mangler(); + //java keywords are not special + assertMapped(mangler, "for.jsp", "for_jsp"); + //underscores go in front of invalid start chars + assertMapped(mangler, "0.jsp", "_0_jsp"); + //underscores at the front get an underscore too + assertMapped(mangler, "_.jsp", "___jsp"); + //non java char at start => underscore then the the _hex value + assertMapped(mangler, "-.jsp", "__0002d_jsp"); + //and paths are stripped + char s = File.separatorChar; + assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp"); + } + + /** + * assert our mapping rules + * @param mangler + * @param filename + * @param classname + */ + protected void assertMapped(JspMangler mangler, String filename, String classname) { + String mappedname = mangler.mapJspToJavaName(new File(filename)); + assertTrue(filename+" should have mapped to "+classname + +" but instead mapped to "+mappedname, + classname.equals(mappedname)); + } + + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java new file mode 100644 index 00000000..53da2af4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.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.taskdefs.optional; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class Native2AsciiTest { + + private final static String BUILD_XML = + "src/etc/testcases/taskdefs/optional/native2ascii/build.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(BUILD_XML); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testIso8859_1() throws java.io.IOException { + buildRule.executeTarget("testIso8859-1"); + File in = buildRule.getProject().resolveFile("expected/iso8859-1.test"); + File out = new File(buildRule.getProject().getProperty("output"), "iso8859-1.test"); + assertTrue(FileUtils.getFileUtils().contentEquals(in, out, true)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java new file mode 100644 index 00000000..7056ca90 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java @@ -0,0 +1,235 @@ +/* + * 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.taskdefs.optional; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * JUnit testcase that exercises the optional PropertyFile task in ant. + * (this is really more of a functional test so far.., but it's enough to let + * me start refactoring...) + * + *created October 2, 2001 + */ + +public class PropertyFileTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject(projectFilePath); + buildRule.executeTarget("setUp"); + initTestPropFile(); + initBuildPropFile(); + buildRule.configureProject(projectFilePath); + buildRule.getProject().setProperty(valueDoesNotGetOverwrittenPropertyFileKey, + valueDoesNotGetOverwrittenPropertyFile); + } + + + @Test + public void testNonExistingFile() { + PropertyFile props = new PropertyFile(); + props.setProject( buildRule.getProject() ); + File file = new File("this-file-does-not-exist.properties"); + props.setFile(file); + assertFalse("Properties file exists before test.", file.exists()); + props.execute(); + assertTrue("Properties file does not exist after test.", file.exists()); + file.delete(); + } + + /** + * A unit test for JUnit- Exercises the propertyfile tasks ability to + * update properties that are already defined- + */ + @Test + public void testUpdatesExistingProperties() throws Exception { + Properties beforeUpdate = getTestProperties(); + assertEquals(FNAME, beforeUpdate.getProperty(FNAME_KEY)); + assertEquals(LNAME, beforeUpdate.getProperty(LNAME_KEY)); + assertEquals(EMAIL, beforeUpdate.getProperty(EMAIL_KEY)); + assertEquals(null, beforeUpdate.getProperty(PHONE_KEY)); + assertEquals(null, beforeUpdate.getProperty(AGE_KEY)); + assertEquals(null, beforeUpdate.getProperty(DATE_KEY)); + + // ask ant to update the properties... + buildRule.executeTarget("update-existing-properties"); + + Properties afterUpdate = getTestProperties(); + assertEquals(NEW_FNAME, afterUpdate.getProperty(FNAME_KEY)); + assertEquals(NEW_LNAME, afterUpdate.getProperty(LNAME_KEY)); + assertEquals(NEW_EMAIL, afterUpdate.getProperty(EMAIL_KEY)); + assertEquals(NEW_PHONE, afterUpdate.getProperty(PHONE_KEY)); + assertEquals(NEW_AGE, afterUpdate.getProperty(AGE_KEY)); + assertEquals(NEW_DATE, afterUpdate.getProperty(DATE_KEY)); + } + + @Test + public void testDeleteProperties() throws Exception { + Properties beforeUpdate = getTestProperties(); + assertEquals("Property '" + FNAME_KEY + "' should exist before deleting", + FNAME, beforeUpdate.getProperty(FNAME_KEY)); + assertEquals("Property '" + LNAME_KEY + "' should exist before deleting", + LNAME, beforeUpdate.getProperty(LNAME_KEY)); + + buildRule.executeTarget("delete-properties"); + Properties afterUpdate = getTestProperties(); + + assertEquals("Property '" + LNAME_KEY + "' should exist after deleting", + LNAME, afterUpdate.getProperty(LNAME_KEY)); + assertNull("Property '" + FNAME_KEY + "' should be deleted", + afterUpdate.getProperty(FNAME_KEY)); + } + + @Test + public void testExerciseDefaultAndIncrement() throws Exception { + buildRule.executeTarget("exercise"); + assertEquals("3",buildRule.getProject().getProperty("int.with.default")); + assertEquals("1",buildRule.getProject().getProperty("int.without.default")); + assertEquals("-->",buildRule.getProject().getProperty("string.with.default")); + assertEquals(".",buildRule.getProject().getProperty("string.without.default")); + assertEquals("2002/01/21 12:18", buildRule.getProject().getProperty("ethans.birth")); + assertEquals("2003/01/21", buildRule.getProject().getProperty("first.birthday")); + assertEquals("0124", buildRule.getProject().getProperty("olderThanAWeek")); + assertEquals("37", buildRule.getProject().getProperty("existing.prop")); + assertEquals("6",buildRule.getProject().getProperty("int.without.value")); + } + + @Test + public void testValueDoesNotGetOverwritten() { + // this test shows that the bug report 21505 is fixed + buildRule.executeTarget("bugDemo1"); + buildRule.executeTarget("bugDemo2"); + assertEquals("5", buildRule.getProject().getProperty("foo")); + } + + + @Test + @Ignore("Previously commented out") + public void testDirect() throws Exception { + PropertyFile pf = new PropertyFile(); + pf.setProject(buildRule.getProject()); + pf.setFile(new File(System.getProperty("root"), testPropsFilePath)); + PropertyFile.Entry entry = pf.createEntry(); + + entry.setKey("date"); + entry.setValue("123"); + PropertyFile.Entry.Type type = new PropertyFile.Entry.Type(); + type.setValue("date"); + entry.setType(type); + + entry.setPattern("yyyy/MM/dd"); + + PropertyFile.Entry.Operation operation = new PropertyFile.Entry.Operation(); + operation.setValue("+"); + pf.execute(); + + Properties props = getTestProperties(); + assertEquals("yeehaw", props.getProperty("date")); + } + + + private Properties getTestProperties() throws Exception { + Properties testProps = new Properties(); + FileInputStream propsFile = new FileInputStream(new File(buildRule.getOutputDir(), testPropsFilePath)); + testProps.load(propsFile); + propsFile.close(); + return testProps; + } + + + private void initTestPropFile() throws IOException { + Properties testProps = new Properties(); + testProps.put(FNAME_KEY, FNAME); + testProps.put(LNAME_KEY, LNAME); + testProps.put(EMAIL_KEY, EMAIL); + testProps.put("existing.prop", "37"); + + FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), testPropsFilePath)); + testProps.store(fos, "defaults"); + fos.close(); + } + + + private void initBuildPropFile() throws IOException { + Properties buildProps = new Properties(); + buildProps.put(testPropertyFileKey, testPropertyFile); + buildProps.put(FNAME_KEY, NEW_FNAME); + buildProps.put(LNAME_KEY, NEW_LNAME); + buildProps.put(EMAIL_KEY, NEW_EMAIL); + buildProps.put(PHONE_KEY, NEW_PHONE); + buildProps.put(AGE_KEY, NEW_AGE); + buildProps.put(DATE_KEY, NEW_DATE); + + FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), buildPropsFilePath)); + buildProps.store(fos, null); + fos.close(); + } + + private static final String + projectFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.xml", + + testPropertyFile = "propertyfile.test.properties", + testPropertyFileKey = "test.propertyfile", + testPropsFilePath = testPropertyFile, + + valueDoesNotGetOverwrittenPropertyFile = "overwrite.test.properties", + valueDoesNotGetOverwrittenPropertyFileKey = "overwrite.test.propertyfile", + valueDoesNotGetOverwrittenPropsFilePath = valueDoesNotGetOverwrittenPropertyFile, + + buildPropsFilePath = "propertyfile.build.properties", + + FNAME = "Bruce", + NEW_FNAME = "Clark", + FNAME_KEY = "firstname", + + LNAME = "Banner", + NEW_LNAME = "Kent", + LNAME_KEY = "lastname", + + EMAIL = "incredible@hulk.com", + NEW_EMAIL = "kc@superman.com", + EMAIL_KEY = "email", + + NEW_PHONE = "(520) 555-1212", + PHONE_KEY = "phone", + + NEW_AGE = "30", + AGE_KEY = "age", + + NEW_DATE = "2001/01/01 12:45", + DATE_KEY = "date"; +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java new file mode 100644 index 00000000..cd7a4316 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java @@ -0,0 +1,79 @@ +/* + * 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.taskdefs.optional; + +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 PvcsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument repository not specified"); + } catch (BuildException ex) { + //TODO check exception message + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z " + + "-aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found"); + } catch(BuildException ex) { + //TODO assert exception message + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java new file mode 100644 index 00000000..b6c09a5c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java @@ -0,0 +1,132 @@ +/* + * 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.taskdefs.optional; + +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.Rule; +import org.junit.Test; + +import java.util.Properties; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assume.assumeTrue; + +/** + * JUnit Testcase for the optional replaceregexp task. + * + */ +public class ReplaceRegExpTest { + private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(PROJECT_PATH + "/replaceregexp.xml"); + } + + @Test + public void testReplace() throws IOException { + Properties original = new Properties(); + FileInputStream propsFile = null; + try { + propsFile = new FileInputStream(new File(buildRule.getProject().getBaseDir() + "/replaceregexp.properties")); + original.load(propsFile); + } finally { + if (propsFile != null) { + propsFile.close(); + propsFile = null; + } + } + + assertEquals("Def", original.get("OldAbc")); + + buildRule.executeTarget("testReplace"); + + Properties after = new Properties(); + try { + propsFile = new FileInputStream(new File(buildRule.getOutputDir(), "test.properties")); + after.load(propsFile); + } finally { + if (propsFile != null) { + propsFile.close(); + } + } + + assertNull(after.get("OldAbc")); + assertEquals("AbcDef", after.get("NewProp")); + } + + // inspired by bug 22541 + @Test + public void testDirectoryDateDoesNotChange() { + buildRule.executeTarget("touchDirectory"); + File myFile = buildRule.getOutputDir(); + long timeStampBefore = myFile.lastModified(); + buildRule.executeTarget("testDirectoryDateDoesNotChange"); + long timeStampAfter = myFile.lastModified(); + assertEquals("directory date should not change", + timeStampBefore, timeStampAfter); + } + + @Test + public void testDontAddNewline1() throws IOException { + buildRule.executeTarget("testDontAddNewline1"); + assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")), + FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties"))); + } + + @Test + public void testDontAddNewline2() throws IOException { + buildRule.executeTarget("testDontAddNewline2"); + assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")), + FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties"))); + } + + @Test + public void testNoPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue(testFile.setLastModified(testFile.lastModified() + - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testNoPreserve"); + assertTrue(ts1 < testFile.lastModified()); + } + + @Test + public void testPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue(testFile.setLastModified(testFile.lastModified() + - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testPreserve"); + assertEquals(ts1 , testFile.lastModified()); + } + +}// ReplaceRegExpTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java new file mode 100644 index 00000000..41803de6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java @@ -0,0 +1,45 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests using an undefined reference. + * + * @since Ant 1.6 + */ +public class RhinoReferenceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/optional/script_reference.xml"); + } + + @Test + public void testScript() { + buildRule.executeTarget("script"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java new file mode 100644 index 00000000..35576dcb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java @@ -0,0 +1,67 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Tests the examples of the <script> task docs. + * + * @since Ant 1.5.2 + */ +public class RhinoScriptTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml"); + } + + @Test + public void testExample1() { + buildRule.executeTarget("example1"); + int index = buildRule.getLog().indexOf("1"); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("4", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("9", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("16", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("25", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("36", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("49", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("64", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("81", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("100", index); + assertTrue(index > -1); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java new file mode 100644 index 00000000..ac4462d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java @@ -0,0 +1,71 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; +import org.apache.tools.ant.types.Commandline; + +import org.junit.Test; + +import static org.junit.Assert.fail; +import static org.apache.tools.ant.AntAssert.assertContains; + +public class RpmTest { + + @Test + public void testShouldThrowExceptionWhenRpmFails() throws Exception { + Rpm rpm = new MyRpm(); + rpm.setProject(new org.apache.tools.ant.Project()); + rpm.setFailOnError(true); + // execute + try { + rpm.execute(); + fail("should have thrown a build exception"); + } catch (BuildException ex) { + assertContains("' failed with exit code 2", ex.getMessage()); + } + } + + @Test + public void testShouldNotThrowExceptionWhenRpmFails() throws Exception { + Rpm rpm = new MyRpm(); + rpm.execute(); + } + + // override some of the code so we can test the handling of the + // return code only. + public static class MyRpm extends Rpm { + protected Execute getExecute(Commandline toExecute, + ExecuteStreamHandler streamhandler) { + return new Execute() { + public int execute() { + // 2 is != 0 and even, so it is considered + // failure on any platform currently supported + // by Execute#isFailure. + return 2; + } + }; + } + + public void log(String msg, int msgLevel) { + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java new file mode 100644 index 00000000..667c8904 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java @@ -0,0 +1,128 @@ +/* + * 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.taskdefs.optional; + +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.fail; + +/** + * Test schema validation + */ + +public class SchemaValidateTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "schemavalidate.xml"); + } + + /** + * test with no namespace + */ + @Test + public void testNoNamespace() throws Exception { + buildRule.executeTarget("testNoNamespace"); + } + + /** + * add namespace awareness. + */ + @Test + public void testNSMapping() throws Exception { + buildRule.executeTarget("testNSMapping"); + } + + @Test + public void testNoEmptySchemaNamespace() throws Exception { + try { + buildRule.executeTarget("testNoEmptySchemaNamespace"); + fail("Empty namespace URI"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_URI, ex.getMessage()); + } + } + + @Test + public void testNoEmptySchemaLocation() throws Exception { + try { + buildRule.executeTarget("testNoEmptySchemaLocation"); + fail("Empty schema location"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_LOCATION, + ex.getMessage()); + } + } + + @Test + public void testNoFile() throws Exception { + try { + buildRule.executeTarget("testNoFile"); + fail("No file at file attribute"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_FILE, + ex.getMessage()); + } + } + + @Test + public void testNoDoubleSchemaLocation() throws Exception { + try { + buildRule.executeTarget("testNoDoubleSchemaLocation"); + fail("Two locations for schemas"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_TWO_LOCATIONS, + ex.getMessage()); + } + } + + @Test + public void testNoDuplicateSchema() throws Exception { + try { + buildRule.executeTarget("testNoDuplicateSchema"); + fail("duplicate schemas with different values"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.ERROR_DUPLICATE_SCHEMA, + ex.getMessage()); + } + } + + @Test + public void testEqualsSchemasOK() throws Exception { + buildRule.executeTarget("testEqualsSchemasOK"); + } + + @Test + public void testFileset() throws Exception { + buildRule.executeTarget("testFileset"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java new file mode 100644 index 00000000..02281eb6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java @@ -0,0 +1,129 @@ +package org.apache.tools.ant.taskdefs.optional; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.security.Permission; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.taskdefs.XSLTLogger; +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Test; + +/* + * 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. + * + */ + +/** + * TraX XSLTLiaison testcase + */ +public class TraXLiaisonTest extends AbstractXSLTLiaisonTest + implements XSLTLogger { + + + @After + public void tearDown() { + File f = new File("xalan2-redirect-out.tmp"); + if (f.exists()) { + f.delete(); + } + } + + public XSLTLiaison createLiaison() throws Exception { + TraXLiaison l = new TraXLiaison(); + l.setLogger(this); + return l; + } + + @Test + public void testXalan2Redirect() throws Exception { + try { + getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect"); + } catch (Exception exc) { + Assume.assumeNoException("xalan redirect is not on the classpath", exc); + } + File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl"); + liaison.setStylesheet(xsl); + File out = new File("xalan2-redirect-out-dummy.tmp"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + ClassLoader orig = Thread.currentThread().getContextClassLoader(); + try { + liaison.addParam("xalan-version", "2"); + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + // work around JAXP #6723276 in JDK 6 + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + // Tickle #52382: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + liaison.transform(in, out); + } finally { + out.delete(); + Thread.currentThread().setContextClassLoader(orig); + System.setSecurityManager(null); + } + } + + @Test + public void testMultipleTransform() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + liaison.setStylesheet(xsl); + liaison.addParam("param", "value"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); + // test for 10 consecutives transform + for (int i = 0; i < 50; i++){ + File out = new File("xsltliaison" + i + ".tmp"); + try { + liaison.transform(in, out); + } catch (Exception e){ + throw new BuildException("failed in transform " + i, e); + } finally { + out.delete(); + } + } + } + + @Test + public void testSystemId(){ + File file = null; + if ( File.separatorChar == '\\' ){ + file = new File("d:\\jdk"); + } else { + file = new File("/user/local/bin"); + } + String systemid = JAXPUtils.getSystemId(file); + assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); + assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + } + + public void log(String message) { + throw new AssertionFailedError("Liaison sent message: "+message); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java new file mode 100644 index 00000000..c9948bb9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java @@ -0,0 +1,71 @@ +/* + * 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.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests the XMLValidate optional task with nested external catalogs. + * + * @see XmlValidateTest + * @since Ant 1.6 + */ +public class XmlValidateCatalogTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml"); + } + + + /** + * catalogfiles fileset should be ignored + * if resolver.jar is not present, but will + * be used if it is. either way, test should + * work b/c we have a nested dtd with the same + * entity + */ + @Test + public void testXmlCatalogFiles() { + buildRule.executeTarget("xmlcatalogfiles"); + } + + /** + * Test nested catalogpath. + * It should be ignored if resolver.jar is not + * present, but will be used if it is. either + * way, test should work b/c we have a nested + * dtd with the same entity + */ + @Test + public void testXmlCatalogPath() { + buildRule.executeTarget("xmlcatalogpath"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java new file mode 100644 index 00000000..58f7a4b1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java @@ -0,0 +1,193 @@ +/* + * 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.taskdefs.optional; + +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 org.junit.internal.AssumptionViolatedException; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the XMLValidate optional task, by running targets in the test script + * <code>src/etc/testcases/taskdefs/optional/xmlvalidate.xml</code> + * <p> + * + * @see XmlValidateCatalogTest + * @since Ant 1.5 + */ +public class XmlValidateTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml"); + } + + /** + * Basic inline 'dtd' element test. + */ + @Test + public void testValidate() throws Exception { + buildRule.executeTarget("testValidate"); + } + + /** + * Test indirect validation. + */ + @Test + public void testDeepValidate() throws Exception { + buildRule.executeTarget("testDeepValidate"); + } + + @Test + public void testXmlCatalog() { + buildRule.executeTarget("xmlcatalog"); + } + + @Test + public void testXmlCatalogViaRefid() { + buildRule.executeTarget("xmlcatalogViaRefid"); + } + + /** + * Test that the nested dtd element is used when resolver.jar is not + * present. This test should pass either way. + */ + @Test + public void testXmlCatalogFiles() { + buildRule.executeTarget("xmlcatalogfiles-override"); + } + + /** + * Test nested catalogpath. + * Test that the nested dtd element is used when resolver.jar is not + * present. This test should pass either way. + */ + @Test + public void testXmlCatalogPath() { + buildRule.executeTarget("xmlcatalogpath-override"); + } + + /** + * Test nested xmlcatalog definitions + */ + @Test + public void testXmlCatalogNested() { + buildRule.executeTarget("xmlcatalognested"); + } + + /** + * Test xml schema validation + */ + @Test + public void testXmlSchemaGood() throws BuildException { + try { + buildRule.executeTarget("testSchemaGood"); + } catch (BuildException e) { + if (e + .getMessage() + .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") + || e.getMessage().endsWith( + " doesn't support feature http://apache.org/xml/features/validation/schema")) { + throw new AssumptionViolatedException("parser doesn't support schema"); + } else { + throw e; + } + } + } + /** + * Test xml schema validation + */ + @Test + public void testXmlSchemaBad() { + try { + buildRule.executeTarget("testSchemaBad"); + fail("Should throw BuildException because 'Bad Schema Validation'"); + + } catch (BuildException e) { + if (e + .getMessage() + .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") + || e.getMessage().endsWith( + " doesn't support feature http://apache.org/xml/features/validation/schema")) { + throw new AssumptionViolatedException("parser doesn't support schema"); + } else { + assertTrue( + e.getMessage().indexOf("not a valid XML document") > -1); + } + } + } + + /** + * iso-2022-jp.xml is valid but wouldn't get recognized on systems + * with a different native encoding. + * + * Bug 11279 + */ + @Test + public void testIso2022Jp() { + buildRule.executeTarget("testIso2022Jp"); + } + + /** + * utf-8.xml is invalid as it contains non-UTF-8 characters, but + * would pass on systems with a native iso-8859-1 (or similar) + * encoding. + * + * Bug 11279 + */ + @Test + public void testUtf8() { + try { + buildRule.executeTarget("testUtf8"); + fail("Invalid characters in file"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + // Tests property element, using XML schema properties as an example. + @Test + public void testPropertySchemaForValidXML() { + buildRule.executeTarget("testProperty.validXML"); + } + + @Test + public void testPropertySchemaForInvalidXML() { + try { + buildRule.executeTarget("testProperty.invalidXML"); + fail("XML file does not satisfy schema"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java new file mode 100644 index 00000000..a5b71def --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java @@ -0,0 +1,86 @@ +/* + * 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.taskdefs.optional; + +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; + +/** + * Tests the {@link org.apache.tools.ant.taskdefs.XSLTProcess} task. + * TODO merge with {@link org.apache.tools.ant.taskdefs.StyleTest}? + * @since Ant 1.5 + */ +public class XsltTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xslt.xml"); + } + + + @Test + public void testCatchNoDtd() { + try { + buildRule.executeTarget("testCatchNoDtd"); + fail("Expected failure"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testCatalog() throws Exception { + buildRule.executeTarget("testCatalog"); + } + + @Test + public void testOutputProperty() throws Exception { + buildRule.executeTarget("testOutputProperty"); + } + + @Test + public void testXMLWithEntitiesInNonAsciiPath() throws Exception { + buildRule.executeTarget("testXMLWithEntitiesInNonAsciiPath"); + } + + /** + * check that the system id gets set properly on stylesheets. + * @throws Exception if something goes wrong. + */ + @Test + public void testStyleSheetWithInclude() throws Exception { + buildRule.executeTarget("testStyleSheetWithInclude"); + if (buildRule.getLog().indexOf("java.io.FileNotFoundException") != -1) { + fail("xsl:include was not found"); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java new file mode 100644 index 00000000..95c1eb0b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java @@ -0,0 +1,213 @@ +/* + * 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.taskdefs.optional.depend; + +import java.io.File; +import java.util.Hashtable; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.types.FileSet; +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.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testcase for the Depend optional task. + * + */ +public class DependTest { + public static final String RESULT_FILESET = "result"; + + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/optional/depend/depend.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** + * Test direct dependency removal + */ + @Test + public void testDirect() { + buildRule.executeTarget("src1setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testdirect"); + Hashtable files = getResultFiles(); + assertEquals("Depend did not leave correct number of files", 3, + files.size()); + assertTrue("Result did not contain A.class", + files.containsKey("A.class")); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + } + + /** + * Test dependency traversal (closure) + */ + @Test + public void testClosure() { + buildRule.executeTarget("src1setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testclosure"); + Hashtable files = getResultFiles(); + assertTrue("Depend did not leave correct number of files", + files.size() <= 2); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + } + + /** + * Test that inner class dependencies trigger deletion of the outer class + */ + @Test + public void testInner() { + buildRule.executeTarget("src2setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + + buildRule.executeTarget("testinner"); + assertEquals("Depend did not leave correct number of files", 0, + getResultFiles().size()); + } + + /** + * Test that multi-leve inner class dependencies trigger deletion of + * the outer class + */ + @Test + public void testInnerInner() { + buildRule.executeTarget("src3setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testinnerinner"); + assertEquals("Depend did not leave correct number of files", 0, + getResultFiles().size()); + } + + /** + * Test that an exception is thrown when there is no source + */ + @Test + public void testNoSource() { + try { + buildRule.executeTarget("testnosource"); + fail("Build exception expected: No source specified"); + } catch(BuildException ex) { + assertContains("srcdir attribute must be set", ex.getMessage()); + } + } + + /** + * Test that an exception is thrown when the source attribute is empty + */ + @Test + public void testEmptySource() { + try { + buildRule.executeTarget("testemptysource"); + fail("Build exception expected: No source specified"); + } catch(BuildException ex) { + assertContains("srcdir attribute must be non-empty", ex.getMessage()); + } + } + + /** + * Read the result fileset into a Hashtable + * + * @return a Hashtable containing the names of the files in the result + * fileset + */ + private Hashtable getResultFiles() { + FileSet resultFileSet = (FileSet) buildRule.getProject().getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject()); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + return files; + } + + + /** + * Test mutual dependency between inner and outer do not cause both to be + * deleted + */ + @Test + public void testInnerClosure() { + buildRule.executeTarget("testinnerclosure"); + assertEquals("Depend did not leave correct number of files", 4, + getResultFiles().size()); + } + + /** + * Test the operation of the cache + */ + @Test + public void testCache() { + buildRule.executeTarget("testcache"); + } + + /** + * Test the detection and warning of non public classes + */ + @Test + public void testNonPublic() { + buildRule.executeTarget("src5setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testnonpublic"); + String log = buildRule.getLog(); + assertContains("Expected warning about APrivate", + "The class APrivate in file", log); + assertContains("but has not been deleted because its source file " + + "could not be determined", + "The class APrivate in file", log); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java new file mode 100644 index 00000000..6abc4f2d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java @@ -0,0 +1,87 @@ +/* + * 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.taskdefs.optional.i18n; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertTrue; + +/** + * Tests the Translate task. + * + * @since Ant 1.6 + */ +public class TranslateTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + static private final int BUF_SIZE = 32768; + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate"; + + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "/translate.xml"); + } + + @Test + public void test1() throws IOException { + buildRule.executeTarget("test1"); + assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"), + new File(buildRule.getOutputDir(), "de/template.txt"))); + } + private boolean compareFiles(File file1, File file2) throws IOException { + if (!file1.exists() || !file2.exists()) { + return false; + } + + if (file1.length() != file2.length()) { + return false; + } + + // byte - byte compare + byte[] buffer1 = new byte[BUF_SIZE]; + byte[] buffer2 = new byte[BUF_SIZE]; + + FileInputStream fis1 = new FileInputStream(file1); + FileInputStream fis2 = new FileInputStream(file2); + int index = 0; + int read = 0; + while ((read = fis1.read(buffer1)) != -1) { + fis2.read(buffer2); + for (int i = 0; i < read; ++i, ++index) { + if (buffer1[i] != buffer2[i]) { + return false; + } + } + } + return true; + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java new file mode 100644 index 00000000..be79262d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java @@ -0,0 +1,133 @@ +/* + * 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.taskdefs.optional.image; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +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 static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + + +/** + * Tests the Image task. + * + * @since Ant 1.5 + */ +public class ImageTest { + + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/image/"; + private final static String LARGEIMAGE = "largeimage.jpg"; + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "image.xml"); + } + + + @Test + public void testEchoToLog() { + buildRule.executeTarget("testEchoToLog"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + } + + @Test + public void testSimpleScale(){ + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + assertTrue( + "Did not create "+f.getAbsolutePath(), + f.exists()); + + } + + @Test + public void testOverwriteTrue() throws InterruptedException { + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + assumeTrue("Could not change file modificaiton date", + f.setLastModified(f.lastModified() - (FILE_UTILS.getFileTimestampGranularity() * 2))); + long lastModified = f.lastModified(); + buildRule.executeTarget("testOverwriteTrue"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long overwrittenLastModified = f.lastModified(); + assertTrue("File was not overwritten.", + lastModified < overwrittenLastModified); + } + + @Test + public void testOverwriteFalse() { + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long lastModified = f.lastModified(); + buildRule.executeTarget("testOverwriteFalse"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long overwrittenLastModified = f.lastModified(); + assertTrue("File was overwritten.", + lastModified == overwrittenLastModified); + } + + @Test + public void testSimpleScaleWithMapper() { + buildRule.executeTarget("testSimpleScaleWithMapper"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE); + assertTrue( + "Did not create "+f.getAbsolutePath(), + f.exists()); + + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void testFailOnError() { + try { + buildRule.executeTarget("testFailOnError"); + AntAssert.assertContains("Unable to process image stream", buildRule.getLog()); + } + catch (RuntimeException re){ + assertTrue("Run time exception should say " + + "'Unable to process image stream'. :" + + re.toString(), + re.toString() + .indexOf("Unable to process image stream") > -1); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java new file mode 100644 index 00000000..545b7cbc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java @@ -0,0 +1,99 @@ +/* + * 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.taskdefs.optional.jdepend; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the JDepend optional task. + * + */ +public class JDependTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml"); + } + + /** + * Test simple + */ + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", + buildRule.getOutput()); + } + + /** + * Test xml + */ + @Test + public void testXml() { + buildRule.executeTarget("xml"); + AntAssert.assertContains("<DependsUpon>", buildRule.getOutput()); + } + + /** + * Test fork + * - forked output goes to log + */ + @Test + public void testFork() { + buildRule.executeTarget("fork"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog()); + } + + /** + * Test fork xml + */ + @Test + public void testForkXml() { + buildRule.executeTarget("fork-xml"); + AntAssert.assertContains("<DependsUpon>", buildRule.getLog()); + } + + /** + * Test timeout + */ + @Test + public void testTimeout() { + buildRule.executeTarget("fork-xml"); + AntAssert.assertContains( "JDepend FAILED - Timed out", buildRule.getLog()); + } + + + /** + * Test timeout without timing out + */ + @Test + public void testTimeoutNot() { + buildRule.executeTarget("fork-timeout-not"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java new file mode 100644 index 00000000..52a12ecc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java @@ -0,0 +1,121 @@ +/* + * 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.taskdefs.optional.junit; + + +import static org.junit.Assert.fail; +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +/** + * + * @author Marian Petras + */ +public class BatchTestTest { + + @Test + public void testParseTestMethodNamesList() { + try { + JUnitTest.parseTestMethodNamesList(null); + fail("IllegalArgumentException expected when the param is <null>"); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList("")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + + checkParseCausesIAE(","); + checkParseCausesIAE(" ,"); + checkParseCausesIAE(", "); + checkParseCausesIAE(" , "); + checkParseCausesIAE(",a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" , a"); + checkParseCausesIAE(" ,a "); + checkParseCausesIAE(" ,a ,"); + checkParseCausesIAE("ab,,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd,"); + checkParseCausesIAE(",ab, ,cd,"); + + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,")); + + /* legal Java identifiers: */ + assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a")); + assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1")); + assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$")); + assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1")); + assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc")); + assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___")); + + /* illegal Java identifiers: */ + checkParseCausesIAE("1"); + checkParseCausesIAE("1a"); + checkParseCausesIAE("1ab"); + checkParseCausesIAE("1abc"); + checkParseCausesIAE("1abc d"); + checkParseCausesIAE("1abc de"); + checkParseCausesIAE("1abc def"); + checkParseCausesIAE("1abc def,"); + checkParseCausesIAE(",1abc def"); + + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,")); + } + + private static void checkParseCausesIAE(String param) { + try { + JUnitTest.parseTestMethodNamesList(param); + fail("IllegalArgumentException expected when the param is \"" + param + '"'); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java new file mode 100644 index 00000000..b72f69cc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java @@ -0,0 +1,53 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; + +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class DOMUtilTest { + + @Test + public void testListChildNodes() throws SAXException, IOException { + DocumentBuilder db = JAXPUtils.getDocumentBuilder(); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml"); + Document doc = db.parse(is); + NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true); + assertEquals("expecting 3", 3, nl.getLength()); + } + + public class FooNodeFilter implements DOMUtil.NodeFilter { + public boolean accept(Node node) { + if (node.getNodeName().equals("foo")) { + return true; + } + return false; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java new file mode 100644 index 00000000..4baf7418 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java @@ -0,0 +1,37 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Test to ensure that the classloader loading JUnit testcase + * is also the context classloader. + * + */ +public class JUnitClassLoaderTest { + + @Test + public void testContextClassLoader(){ + ClassLoader context = Thread.currentThread().getContextClassLoader(); + ClassLoader caller = getClass().getClassLoader(); + assertSame(context, caller); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java new file mode 100644 index 00000000..c5b6feb9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java @@ -0,0 +1,211 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Small testcase for the junitreporttask. + * First test added to reproduce an fault, still a lot to improve + * + */ +public class JUnitReportTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml"); + } + + /** + * Verifies that no empty junit-noframes.html is generated when frames + * output is selected via the default. + * Needs reports1 task from junitreport.xml. + */ + @Test + public void testNoFileJUnitNoFrames() { + buildRule.executeTarget("reports1"); + assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists())); + + } + + public void assertIndexCreated() { + if (!new File(buildRule.getProject().getProperty("output"), "html/index.html").exists()) { + fail("No file index file found"); + } + + } + + + @Test + public void testEmptyFile() throws Exception { + buildRule.executeTarget("testEmptyFile"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog()); + } + + @Test + public void testIncompleteFile() throws Exception { + buildRule.executeTarget("testIncompleteFile"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog()); + } + + @Test + public void testWrongElement() throws Exception { + buildRule.executeTarget("testWrongElement"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog()); + } + + // Bugzilla Report 34963 + @Test + public void testStackTraceLineBreaks() throws Exception { + buildRule.executeTarget("testStackTraceLineBreaks"); + assertIndexCreated(); + FileReader r = null; + try { + r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html")); + String report = FileUtils.readFully(r); + assertContains("output must contain <br>:\n" + report, "junit.framework.AssertionFailedError: DOEG<br>", report); + assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report); + } finally { + FileUtils.close(r); + } + } + + + // Bugzilla Report 38477 + @Test + public void testSpecialSignsInSrcPath() throws Exception { + buildRule.executeTarget("testSpecialSignsInSrcPath"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testSpecialSignsInHtmlPath() throws Exception { + buildRule.executeTarget("testSpecialSignsInHtmlPath"); + File reportFile = new File(buildRule.getOutputDir(), "html# $%\u00A7&-!report/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + //Bugzilla Report 39708 + @Test + public void testWithStyleFromDir() throws Exception { + buildRule.executeTarget("testWithStyleFromDir"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + //Bugzilla Report 40021 + @Test + public void testNoFrames() throws Exception { + buildRule.executeTarget("testNoFrames"); + File reportFile = new File(buildRule.getOutputDir(), "html/junit-noframes.html"); + // tests one the file object + assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + //Bugzilla Report 39708 + @Test + public void testWithStyleFromDirAndXslImport() throws Exception { + buildRule.executeTarget("testWithStyleFromDirAndXslImport"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testWithStyleFromClasspath() throws Exception { + buildRule.executeTarget("testWithStyleFromClasspath"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testWithParams() throws Exception { + buildRule.executeTarget("testWithParams"); + assertContains("key1=value1,key2=value2", buildRule.getLog()); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java new file mode 100644 index 00000000..61504ad1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -0,0 +1,398 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.apache.tools.ant.AntAssert.assertContains; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class JUnitTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** + * The JUnit setup method. + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); + } + + @Test + public void testCrash() { + buildRule.executeTarget("crash"); + assertEquals("true", buildRule.getProject().getProperty("crashed")); + } + + @Test + public void testNoCrash() { + buildRule.executeTarget("nocrash"); + assertNull(buildRule.getProject().getProperty("crashed")); + } + + @Test + public void testTimeout() { + buildRule.executeTarget("timeout"); + assertEquals("true", buildRule.getProject().getProperty("timeout")); + } + + @Test + public void testNoTimeout() { + buildRule.executeTarget("notimeout"); + assertNull(buildRule.getProject().getProperty("timeout")); + } + + @Test + public void testNonForkedCapture() throws IOException { + buildRule.executeTarget("capture"); + assertNoPrint(buildRule.getLog(), "log"); + assertNoPrint(buildRule.getFullLog(), "debug log"); + } + + @Test + public void testForkedCapture() throws IOException { + buildRule.getProject().setProperty("fork", "true"); + testNonForkedCapture(); + // those would fail because of the way BuildFileRule captures output + assertNoPrint(buildRule.getOutput(), "output"); + assertNoPrint(buildRule.getError(), "error output"); + assertOutput(); + } + + @Test + public void testBatchTestForkOnceToDir() { + assertResultFilesExist("testBatchTestForkOnceToDir", ".xml"); + } + + /** Bugzilla Report 32973 */ + @Test + public void testBatchTestForkOnceExtension() { + assertResultFilesExist("testBatchTestForkOnceExtension", ".foo"); + } + + + /* Bugzilla Report 42984 */ + //TODO This scenario works from command line, but not from JUnit ... + // Running these steps from the junit.xml-directory work + // $ ant -f junit.xml failureRecorder.prepare + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.fixing + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.runtest + // But running the JUnit testcase fails in 4th run. + @Test + public void testFailureRecorder() { + if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { + try { + Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); + Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); + } catch (ClassNotFoundException e) { + // OK, this is JUnit3, can run test + } + } + + File testDir = new File(buildRule.getOutputDir(), "out"); + File collectorFile = new File(buildRule.getOutputDir(), + "out/FailedTests.java"); + + // ensure that there is a clean test environment + assertFalse("Test directory '" + testDir.getAbsolutePath() + + "' must not exist before the test preparation.", + testDir.exists()); + assertFalse("The collector file '" + + collectorFile.getAbsolutePath() + + "'must not exist before the test preparation.", + collectorFile.exists()); + + + // prepare the test environment + buildRule.executeTarget("failureRecorder.prepare"); + assertTrue("Test directory '" + testDir.getAbsolutePath() + + "' was not created.", testDir.exists()); + assertTrue("There should be one class.", + (new File(testDir, "A.class")).exists()); + assertFalse("The collector file '" + + collectorFile.getAbsolutePath() + + "' should not exist before the 1st run.", + collectorFile.exists()); + + + // 1st junit run: should do all tests - failing and not failing tests + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 1st run.", + collectorFile.exists()); + // the passing test cases + buildRule.executeTarget("A.test01"); + assertContains("1st run: should run A.test01", buildRule.getOutput()); + buildRule.executeTarget("B.test05"); + assertContains("1st run: should run B.test05", buildRule.getOutput()); + buildRule.executeTarget("B.test06"); + assertContains("1st run: should run B.test06", buildRule.getOutput()); + buildRule.executeTarget("C.test07"); + assertContains("1st run: should run C.test07", buildRule.getOutput()); + buildRule.executeTarget("C.test08"); + assertContains("1st run: should run C.test08", buildRule.getOutput()); + buildRule.executeTarget("C.test09"); + assertContains("1st run: should run C.test09", buildRule.getOutput()); + // the failing test cases + buildRule.executeTarget("A.test02"); + assertContains("1st run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("1st run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("1st run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("1st run: should run D.test10", buildRule.getOutput()); + + + // 2nd junit run: should do only failing tests + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 2nd run.", + collectorFile.exists()); + // the passing test cases + buildRule.executeTarget("A.test01"); + assertNotContains("2nd run: should not run A.test01", buildRule.getOutput()); + buildRule.executeTarget("B.test05"); + assertNotContains("2nd run: should not run A.test05", buildRule.getOutput()); + buildRule.executeTarget("B.test06"); + assertNotContains("2nd run: should not run B.test06", buildRule.getOutput()); + buildRule.executeTarget("C.test07"); + assertNotContains("2nd run: should not run C.test07", buildRule.getOutput()); + buildRule.executeTarget("C.test08"); + assertNotContains("2nd run: should not run C.test08", buildRule.getOutput()); + buildRule.executeTarget("C.test09"); + assertNotContains("2nd run: should not run C.test09", buildRule.getOutput()); + // the failing test cases + buildRule.executeTarget("A.test02"); + assertContains("2nd run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("2nd run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("2nd run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("2nd run: should run D.test10", buildRule.getOutput()); + + + // "fix" errors in class A + buildRule.executeTarget("failureRecorder.fixing"); + + // 3rd run: four running tests with two errors + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 3rd run.", + collectorFile.exists()); + buildRule.executeTarget("A.test02"); + assertContains("3rd run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("3rd run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("3rd run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("3rd run: should run D.test10", buildRule.getOutput()); + + + // 4rd run: two running tests with errors + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 4th run.", + collectorFile.exists()); + //TODO: these two statements fail + //buildRule.executeTarget("A.test02");assertNotContains("4th run: should not run A.test02", buildRule.getOutput()); + //buildRule.executeTarget("A.test03");assertNotContains("4th run: should not run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("4th run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("4th run: should run D.test10", buildRule.getOutput()); + + } + + @Test + public void testBatchTestForkOnceCustomFormatter() { + assertResultFilesExist("testBatchTestForkOnceCustomFormatter", "foo"); + } + + // Bugzilla Issue 45411 + @Test + public void testMultilineAssertsNoFork() { + buildRule.executeTarget("testMultilineAssertsNoFork"); + assertNotContains("messaged up", buildRule.getLog()); + assertNotContains("crashed)", buildRule.getLog()); + } + + // Bugzilla Issue 45411 + @Test + public void testMultilineAssertsFork() { + buildRule.executeTarget("testMultilineAssertsFork"); + assertNotContains("messaged up", buildRule.getLog()); + assertNotContains("crashed)", buildRule.getLog()); + } + + private void assertResultFilesExist(String target, String extension) { + buildRule.executeTarget(target); + assertResultFileExists("JUnitClassLoader", extension); + assertResultFileExists("JUnitTestRunner", extension); + assertResultFileExists("JUnitVersionHelper", extension); + } + + private void assertResultFileExists(String classNameFragment, String ext) { + assertTrue("result for " + classNameFragment + "Test" + ext + " exists", + + new File(buildRule.getOutputDir(), "TEST-org.apache.tools.ant." + + "taskdefs.optional.junit." + + classNameFragment + "Test" + ext) + .exists()); + } + + private void assertNoPrint(String result, String where) { + assertNotContains(where + " '" + result + "' must not contain print statement", + "print to System.", result); + } + + private void assertOutput() throws IOException { + FileReader inner = new FileReader(new File(buildRule.getOutputDir(), + "testlog.txt")); + BufferedReader reader = new BufferedReader(inner); + try { + String line = reader.readLine(); + assertEquals("Testsuite: org.apache.tools.ant.taskdefs.optional.junit.Printer", + line); + line = reader.readLine(); + assertNotNull(line); + assertTrue(line.startsWith("Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:")); + line = reader.readLine(); + assertEquals("------------- Standard Output ---------------", + line); + assertPrint(reader.readLine(), "static", "out"); + assertPrint(reader.readLine(), "constructor", "out"); + assertPrint(reader.readLine(), "method", "out"); + line = reader.readLine(); + assertEquals("------------- ---------------- ---------------", + line); + line = reader.readLine(); + assertEquals("------------- Standard Error -----------------", + line); + assertPrint(reader.readLine(), "static", "err"); + assertPrint(reader.readLine(), "constructor", "err"); + assertPrint(reader.readLine(), "method", "err"); + line = reader.readLine(); + assertEquals("------------- ---------------- ---------------", + line); + line = reader.readLine(); + assertEquals("", line); + line = reader.readLine(); + assertNotNull(line); + assertTrue(line.startsWith("Testcase: testNoCrash took ")); + } finally { + inner.close(); + } + } + + private void assertPrint(String line, String from, String to) { + String search = from + " print to System." + to; + assertEquals(search, line); + } + + @Test + public void testJUnit4Skip() throws Exception { + buildRule.executeTarget("testSkippableTests"); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit4Skippable.xml")); + + assertEquals("Incorrect number of nodes created", 8, doc.getElementsByTagName("testcase").getLength()); + + XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath(); + + assertEquals("Incorrect number of skipped tests in header", 4, Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc))); + assertEquals("Incorrect number of error tests in header", 1, Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc))); + assertEquals("Incorrect number of failure tests in header", 2, Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc))); + assertEquals("Incorrect number of tests in header", 8, Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc))); + + + assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc)); + assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)).getAttributes().getLength()); + assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc)); + assertNotNull("Implicit ignore test should have an ignore element", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)); + + } + + @Test + public void testTestMethods() throws Exception { + buildRule.executeTarget("testTestMethods"); + } + + @Test + public void testNonTestsSkipped() throws Exception { + + buildRule.executeTarget("testNonTests"); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + + buildRule.executeTarget("testNonTestsRun"); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java new file mode 100644 index 00000000..38eaa142 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java @@ -0,0 +1,111 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class JUnitTestListenerTest{ + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // The captureToSummary test writes to stdout and stderr, good for + // verifying that the TestListener support doesn't break anything. + private static final String PASS_TEST_TARGET = "captureToSummary"; + + // testNoCrash is the test invoked by the captureToSummary's junit task + private static final String PASS_TEST = "testNoCrash"; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); + } + + + @Test + public void testFullLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog()); + } + + @Test + public void testTestCountFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX + + "tests to run: ", buildRule.getFullLog()); + } + + @Test + public void testStartTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX + + "startTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testEndTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX + + "endTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputByDefault() { + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testFullLogOutputMagicProperty() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputMagicPropertyWins() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false"); + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java new file mode 100644 index 00000000..a75c5cbe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java @@ -0,0 +1,217 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +/** + * Small testcase for the runner, tests are very very very basics. + * They must be enhanced with time. + * + */ +public class JUnitTestRunnerTest{ + + + + // check that a valid method name generates no errors + @Test + public void testValidMethod(){ + TestRunner runner = createRunnerForTestMethod(ValidMethodTestCase.class,"testA"); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that having an invalid method name generates an error + @Test + public void testInvalidMethod(){ + TestRunner runner = createRunnerForTestMethod(InvalidMethodTestCase.class,"testInvalid"); + runner.run(); + String error = runner.getFormatter().getError(); + // might be FAILURES or ERRORS depending on JUnit version? + assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); + } + + // check that having no suite generates no errors + @Test + public void testNoSuite(){ + TestRunner runner = createRunner(NoSuiteTestCase.class); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that a suite generates no errors + @Test + public void testSuite(){ + TestRunner runner = createRunner(SuiteTestCase.class); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that an invalid suite generates an error. + @Test + public void testInvalidSuite(){ + TestRunner runner = createRunner(InvalidSuiteTestCase.class); + runner.run(); + String error = runner.getFormatter().getError(); + assertEquals(error, JUnitTestRunner.ERRORS, runner.getRetCode()); + assertTrue(error, error.indexOf("thrown on purpose") != -1); + } + + // check that something which is not a testcase generates no errors + // at first even though this is incorrect. + @Test + public void testNoTestCase(){ + TestRunner runner = createRunner(NoTestCase.class); + runner.run(); + // On junit3 this is a FAILURE, on junit4 this is an ERROR + int ret = runner.getRetCode(); + + if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { + fail("Unexpected result " + ret + " from junit runner"); + } + // JUnit3 test + //assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode()); + } + + // check that an exception in the constructor is noticed + @Test + public void testInvalidTestCase(){ + TestRunner runner = createRunner(InvalidTestCase.class); + runner.run(); + // On junit3 this is a FAILURE, on junit4 this is an ERROR + int ret = runner.getRetCode(); + if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { + fail("Unexpected result " + ret + " from junit runner"); + } + // JUNIT3 test + //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode()); + //@fixme as of now does not report the original stacktrace. + //assertTrue(error, error.indexOf("thrown on purpose") != -1); + } + + protected TestRunner createRunner(Class<?> clazz){ + return new TestRunner(new JUnitTest(clazz.getName()), null, + true, true, true); + } + + protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method){ + return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, + true, true, true); + } + + // the test runner that wrap the dummy formatter that interests us + private final static class TestRunner extends JUnitTestRunner { + private ResultFormatter formatter = new ResultFormatter(); + TestRunner(JUnitTest test, String[] methods, boolean haltonerror, + boolean filtertrace, boolean haltonfailure){ + super(test, methods, haltonerror, filtertrace, haltonfailure, + false, false, TestRunner.class.getClassLoader()); + // use the classloader that loaded this class otherwise + // it will not be able to run inner classes if this test + // is ran in non-forked mode. + addFormatter(formatter); + } + ResultFormatter getFormatter(){ + return formatter; + } + } + + // dummy formatter just to catch the error + private final static class ResultFormatter implements JUnitResultFormatter { + private Throwable error; + public void setSystemOutput(String output){} + public void setSystemError(String output){} + public void startTestSuite(JUnitTest suite) throws BuildException{} + public void endTestSuite(JUnitTest suite) throws BuildException{} + public void setOutput(java.io.OutputStream out){} + public void startTest(junit.framework.Test t) {} + public void endTest(junit.framework.Test test) {} + public void addFailure(junit.framework.Test test, AssertionFailedError t) { } + public void addError(junit.framework.Test test, Throwable t) { + error = t; + } + String getError(){ + if (error == null){ + return ""; + } + StringWriter sw = new StringWriter(); + error.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + } + + public static class NoTestCase { + } + + public static class InvalidMethodTestCase extends TestCase { + public InvalidMethodTestCase(String name){ super(name); } + public void testA(){ + throw new NullPointerException("thrown on purpose"); + } + } + + public static class ValidMethodTestCase extends TestCase { + public ValidMethodTestCase(String name){ super(name); } + public void testA(){ + // expected to be executed + } + public void testB(){ + // should not be executed + throw new NullPointerException("thrown on purpose"); + } + } + + public static class InvalidTestCase extends TestCase { + public InvalidTestCase(String name){ + super(name); + throw new NullPointerException("thrown on purpose"); + } + } + + public static class NoSuiteTestCase extends TestCase { + public NoSuiteTestCase(String name){ super(name); } + public void testA(){} + } + + public static class SuiteTestCase extends NoSuiteTestCase { + public SuiteTestCase(String name){ super(name); } + public static junit.framework.Test suite(){ + return new TestSuite(SuiteTestCase.class); + } + } + + public static class InvalidSuiteTestCase extends NoSuiteTestCase { + public InvalidSuiteTestCase(String name){ super(name); } + public static junit.framework.Test suite(){ + throw new NullPointerException("thrown on purpose"); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java new file mode 100644 index 00000000..8af3d23c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java @@ -0,0 +1,102 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; +import junit.framework.JUnit4TestAdapterCache; +import junit.framework.TestCase; +import junit.framework.TestResult; + +import org.junit.Test; +import org.junit.runner.Description; + +/** + */ +public class JUnitVersionHelperTest { + + @Test + public void testMyOwnName() { + assertEquals("testMyOwnName", + JUnitVersionHelper.getTestCaseName( + JUnit4TestAdapterCache.getDefault().asTest( + Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName") + ) + ) + ); + } + + @Test + public void testNonTestCaseName() { + assertEquals("I'm a foo", + JUnitVersionHelper.getTestCaseName(new Foo1())); + } + + @Test + public void testNoStringReturn() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo2())); + } + + @Test + public void testNoGetName() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo3())); + } + + @Test + public void testNameNotGetName() { + assertEquals("I'm a foo, too", + JUnitVersionHelper.getTestCaseName(new Foo4())); + } + + @Test + public void testNull() { + assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null)); + } + + @Test + public void testTestCaseSubClass() { + assertEquals("overridden getName", + JUnitVersionHelper.getTestCaseName(new Foo5())); + } + + public static class Foo implements junit.framework.Test { + public int countTestCases() {return 0;} + public void run(TestResult result) {} + } + + public static class Foo1 extends Foo { + public String getName() {return "I'm a foo";} + } + + public static class Foo2 extends Foo { + public int getName() {return 1;} + } + + public static class Foo3 extends Foo { + } + + public static class Foo4 extends Foo { + public String name() {return "I'm a foo, too";} + } + + public static class Foo5 extends TestCase { + public String getName() {return "overridden getName";} + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java new file mode 100644 index 00000000..392a92ee --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java @@ -0,0 +1,30 @@ +/* + * 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.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class NoVmCrash { + + @Test + public void testNoCrash() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java new file mode 100644 index 00000000..0200648d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java @@ -0,0 +1,42 @@ +/* + * 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.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class Printer { + + public Printer() { + System.err.println("constructor print to System.err"); + System.out.println("constructor print to System.out"); + } + + static { + System.err.println("static print to System.err"); + System.out.println("static print to System.out"); + } + + @Test + public void testNoCrash() { + System.err.println("method print to System.err"); + System.out.println("method print to System.out"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java new file mode 100644 index 00000000..15098948 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java @@ -0,0 +1,30 @@ +/* + * 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.taskdefs.optional.junit; + + +import org.junit.Test; + +public class Sleeper { + + @Test + public void testSleep() throws InterruptedException { + Thread.sleep(5 * 1000); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java new file mode 100644 index 00000000..14a09661 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java @@ -0,0 +1,42 @@ +/* + * 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.taskdefs.optional.junit; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * validates that the suite() method works in classes that don't + * implement Test. + */ +public class SuiteMethodTest { + + public static Test suite() { + return new Nested("testMethod"); + } + + public static class Nested extends TestCase { + public Nested(String name) { + super(name); + } + + public void testMethod() { + assertTrue(true); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java new file mode 100644 index 00000000..9908eeea --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java @@ -0,0 +1,53 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertEquals; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class TearDownOnVmCrashTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml"); + } + + @Test + public void testNoTeardown() { + buildRule.executeTarget("testNoTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertNotContains("tearDown called on Timeout", buildRule.getOutput()); + } + + @Test + public void testTeardown() { + buildRule.executeTarget("testTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertContains("tearDown called on Timeout", buildRule.getOutput()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java new file mode 100644 index 00000000..27420d6f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java @@ -0,0 +1,112 @@ +/* + * 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.taskdefs.optional.junit; + +import java.io.IOException; +import java.io.OutputStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildException; + +public class TestFormatter implements JUnitResultFormatter { + + private static final byte[] grafitto = new byte[] { + (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o', + (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e', + (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ', + (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10 + }; + + /** + * Where to write the log to. + */ + private OutputStream out; + + /** + * Empty + */ + public TestFormatter() { + } + + /** + * Empty + */ + public void startTestSuite(JUnitTest suite) { + } + /** + * Empty + */ + public void startTest(Test t) { + } + /** + * Empty + */ + public void endTest(Test test) { + } + /** + * Empty + */ + public void addFailure(Test test, Throwable t) { + } + /** + * Empty + */ + public void addFailure(Test test, AssertionFailedError t) { + } + /** + * Empty + */ + public void addError(Test test, Throwable t) { + } + /** + * Empty + */ + public void setSystemOutput(String out) { + } + /** + * Empty + */ + public void setSystemError(String err) { + } + + public void setOutput(OutputStream out) { + this.out = out; + } + + public void endTestSuite(JUnitTest suite) throws BuildException { + if (out != null) { + try { + out.write(grafitto); + out.flush(); + } catch (IOException ioex) { + throw new BuildException("Unable to write output", ioex); + } finally { + if (out != System.out && out != System.err) { + try { + out.close(); + } catch (IOException e) { + // ignore + } + } + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java new file mode 100644 index 00000000..92d21b68 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java @@ -0,0 +1,31 @@ +/* + * 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.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class VmCrash { + + @Test + public void testCrash() { + System.exit(0); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java new file mode 100644 index 00000000..3f464d87 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java @@ -0,0 +1,83 @@ +/* + * 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.taskdefs.optional.junit; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class XMLFormatterWithCDATAOnSystemOut { + + private static final String DIR = "src/etc/testcases/taskdefs/optional/junit"; + private static final String REPORT = + "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml"; + + private static final String TESTDATA = + "<ERROR>" + + "<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + " <RESPONSE>" + + " <GDS/>" + + " <ERROR>" + + " <ID/>" + + " <MESSAGE/>" + + " <REQUEST_TYPE/>" + + " <RESEND/>" + + " <RAW_RESPONSE/>" + + " </ERROR>" + + " </RESPONSE>" + + "]]>" + + "</ERROR>"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testOutput() { + System.out.println(TESTDATA); + } + + @Test + public void testBuildfile() throws IOException { + buildRule.configureProject(DIR + "/cdataoutput.xml"); + if (buildRule.getProject().getProperty("cdata.inner") == null) { + // avoid endless loop + buildRule.executeTarget("run-junit"); + File f = buildRule.getProject().resolveFile(REPORT); + FileReader reader = null; + try { + reader = new FileReader(f); + String content = FileUtils.readFully(reader); + assertTrue(content.indexOf("</RESPONSE>]]>" + + "</ERROR>") > 0); + } finally { + if (reader != null) { + reader.close(); + } + f.delete(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java new file mode 100644 index 00000000..da67fec8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java @@ -0,0 +1,93 @@ +/* + * 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.taskdefs.optional.junit; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.security.Permission; + +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.types.FileSet; +import org.junit.Assume; +import org.junit.Test; + +public class XMLResultAggregatorTest { + + @Test + public void testFrames() throws Exception { + // For now, skip this test on JDK 6 (and below); see below for why: + try { + Class.forName("java.nio.file.Files"); + } catch (ClassNotFoundException x) { + Assume.assumeNoException("Skip test on JDK 6 and below", x); + } + final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); + if (d.exists()) { + new Delete() {{removeDir(d);}}; // is there no utility method for this? + } + assertTrue(d.getAbsolutePath(), d.mkdir()); + File xml = new File(d, "x.xml"); + PrintWriter pw = new PrintWriter(new FileOutputStream(xml)); + try { + pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>"); + pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>"); + pw.println("</testsuite>"); + pw.flush(); + } finally { + pw.close(); + } + XMLResultAggregator task = new XMLResultAggregator(); + task.setTodir(d); + Project project = new Project(); + DefaultLogger logger = new DefaultLogger(); + logger.setOutputPrintStream(System.out); + logger.setErrorPrintStream(System.err); + logger.setMessageOutputLevel(Project.MSG_INFO); + project.addBuildListener(logger); + project.init(); + task.setProject(project); + AggregateTransformer report = task.createReport(); + report.setTodir(d); + FileSet fs = new FileSet(); + fs.setFile(xml); + task.addFileSet(fs); + /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + */ + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent()); + // Tickle #51668: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + task.execute(); + assertTrue(new File(d, "index.html").isFile()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java new file mode 100644 index 00000000..1a22115e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java @@ -0,0 +1,879 @@ +/* + * 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.taskdefs.optional.net; + +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 java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.Vector; + +import org.apache.commons.net.ftp.FTPClient; +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.util.RetryHandler; +import org.apache.tools.ant.util.Retryable; +import org.apache.tools.ant.util.regexp.RegexpMatcher; +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +//FIXME these tests are more integration than unit tests and report errors badly +public class FTPTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // keep track of what operating systems are supported here. + private boolean supportsSymlinks = Os.isFamily("unix"); + + private FTPClient ftp; + + private boolean loginSuceeded = false; + + private String loginFailureMessage; + + private String tmpDir = null; + private String remoteTmpDir = null; + private String ftpFileSep = null; + private myFTP myFTPTask = new myFTP(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml"); + Project project = buildRule.getProject(); + project.executeTarget("setup"); + tmpDir = project.getProperty("tmp.dir"); + ftp = new FTPClient(); + ftpFileSep = project.getProperty("ftp.filesep"); + myFTPTask.setSeparator(ftpFileSep); + myFTPTask.setProject(project); + remoteTmpDir = myFTPTask.resolveFile(tmpDir); + String remoteHost = project.getProperty("ftp.host"); + int port = Integer.parseInt(project.getProperty("ftp.port")); + String remoteUser = project.getProperty("ftp.user"); + String password = project.getProperty("ftp.password"); + boolean connectionSucceeded = false; + try { + ftp.connect(remoteHost, port); + connectionSucceeded = true; + } catch (Exception ex) { + loginFailureMessage = "could not connect to host " + remoteHost + " on port " + port; + } + if (connectionSucceeded) { + try { + ftp.login(remoteUser, password); + loginSuceeded = true; + } catch (IOException ioe) { + loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser; + } + } + } + + @After + public void tearDown() { + try { + if (ftp!= null) { + ftp.disconnect(); + } + } catch (IOException ioe) { + // do nothing + } + buildRule.getProject().executeTarget("cleanup"); + } + + private boolean changeRemoteDir(String remoteDir) { + boolean result = true; + try { + ftp.cwd(remoteDir); + } + catch (Exception ex) { + System.out.println("could not change directory to " + remoteTmpDir); + result = false; + } + return result; + } + + @Test + public void test1() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha"}); + ds.scan(); + compareFiles(ds, new String[] {} ,new String[] {"alpha"}); + } + + @Test + public void test2() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void test3() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", + "alpha/beta/gamma"}); + } + + @Test + public void testFullPathMatchesCaseSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + @Test + public void testFullPathMatchesCaseInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setCaseSensitive(false); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + 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() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void test2bisButCaseInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/BETA/gamma/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + @Test + public void testGetWithSelector() { + buildRule.executeTarget("ftp-get-with-selector"); + assertContains("selectors are not supported in remote filesets", buildRule.getLog()); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + String [] sortedDestinationDirectories = dsDestination.getIncludedDirectories(); + String [] sortedDestinationFiles = dsDestination.getIncludedFiles(); + for (int counter = 0; counter < sortedDestinationDirectories.length; counter++) { + sortedDestinationDirectories[counter] = + sortedDestinationDirectories[counter].replace(File.separatorChar, '/'); + } + for (int counter = 0; counter < sortedDestinationFiles.length; counter++) { + sortedDestinationFiles[counter] = + sortedDestinationFiles[counter].replace(File.separatorChar, '/'); + } + FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector"); + DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject()); + dsSource.scan(); + compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories); + } + + @Test + public void testGetFollowSymlinksTrue() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link"); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testGetFollowSymlinksFalse() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link"); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + compareFiles(dsDestination, new String[] {}, + new String[] {}); + } + + @Test + public void testAllowSymlinks() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(true); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + @Test + public void testProhibitSymlinks() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(false); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + @Test + public void testFileSymlink() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-file-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(true); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + // father and child pattern test + @Test + public void testOrderOfIncludePatternsIrrelevant() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + String [] expectedFiles = {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}; + String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" }; + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + 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 = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"}); + ds.scan(); + compareFiles(ds, expectedFiles, expectedDirectories); + } + + @Test + public void testPatternsDifferInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testPatternsDifferInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testFullpathDiffersInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testFullpathDiffersInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testParentDiffersInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testParentDiffersInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testExcludeOneFile() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "**/*.xml" + }); + ds.setExcludes(new String[] { + "alpha/beta/b*xml" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testExcludeHasPrecedence() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/**" + }); + ds.setExcludes(new String[] { + "alpha/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + @Test + public void testAlternateIncludeExclude() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setExcludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {"alpha"}); + + } + + @Test + public void testAlternateExcludeInclude() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setIncludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + /** + * Test inspired by Bug#1415. + */ + @Test + public void testChildrenOfExcludedDirectory() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] {"alpha/**"}); + ds.scan(); + compareFiles(ds, new String[] {"delta/delta.xml"}, + new String[] {"delta"}); + + ds = myFTPTask.newScanner(ftp); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] {"alpha"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml", + "delta/delta.xml"}, + new String[] {"alpha/beta", "alpha/beta/gamma", "delta"}); + + } + + /** + * This class enables the use of the log messages as a way of testing + * the number of files actually transferred. + * It uses the ant regular expression mechanism to get a regex parser + * to parse the log output. + */ + private class CountLogListener extends DefaultLogger { + private Vector lastMatchGroups = null; + private RegexpMatcher matcher = new RegexpMatcherFactory().newRegexpMatcher(); + + /** + * The only constructor for a CountLogListener + * @param pattern a regular expression pattern. It should have + * one parenthesized group and that group should contain the + * number desired. + */ + public CountLogListener(String pattern) { + super(); + this.matcher.setPattern(pattern); + } + + + /* + * @param event the build event that is being logged. + */ + public void messageLogged(BuildEvent event) { + String message = event.getMessage(); + if (this.matcher.matches(message)) { + lastMatchGroups = this.matcher.getGroups(message); + } + super.messageLogged(event); + } + + /** + * returns the desired number that results from parsing the log + * message + * @return the number of files indicated in the desired message or -1 + * if a matching log message was never found. + */ + public int getCount() { + if (this.lastMatchGroups == null) { + return -1; + } + return Integer.parseInt((String) this.lastMatchGroups.get(1)); + } + } + + /** + * This class enables the use of the log to count the number + * of times a message has been emitted. + */ + private class LogCounter extends DefaultLogger { + private Map searchMap = new HashMap(); + private int matchCount; + + public void addLogMessageToSearch(String message) { + searchMap.put(message, new Integer(0)); + } + + /* + * @param event the build event that is being logged. + */ + public void messageLogged(BuildEvent event) { + String message = event.getMessage(); + Integer mcnt = (Integer) searchMap.get(message); + if (null != mcnt) { + searchMap.put(message, new Integer(mcnt.intValue() + 1)); + } + super.messageLogged(event); + } + + /** + * @return the number of times that the looked for message was sent + * to the log + */ + public int getMatchCount(String message) { + Integer mcnt = (Integer) searchMap.get(message); + if (null != mcnt) { + return mcnt.intValue(); + } + return 0; + } + } + /** + * Tests the combination of the newer parameter and the + * serverTimezoneConfig parameter in the PUT action. The default + * configuration is an ftp server on localhost which formats + * timestamps as GMT. + */ + @Test + public void testTimezonePut() { + CountLogListener log = new CountLogListener("(\\d+) files? sent"); + buildRule.getProject().executeTarget("timed.test.setup"); + buildRule.getProject().addBuildListener(log); + buildRule.getProject().executeTarget("timed.test.put.older"); + assertEquals(1, log.getCount()); + } + + /** + * Tests the combination of the newer parameter and the + * serverTimezoneConfig parameter in the GET action. The default + * configuration is an ftp server on localhost which formats + * timestamps as GMT. + */ + @Test + public void testTimezoneGet() { + CountLogListener log = new CountLogListener("(\\d+) files? retrieved"); + buildRule.getProject().executeTarget("timed.test.setup"); + buildRule.getProject().addBuildListener(log); + buildRule.getProject().executeTarget("timed.test.get.older"); + assertEquals(3, log.getCount()); + } + + + /** + * Tests that the presence of one of the server config params forces + * the system type to Unix if not specified. + */ + @Test + public void testConfiguration1() { + int[] expectedCounts = { + 1,1,0,1,0,0,0 + }; + performConfigTest("configuration.1", expectedCounts); + + } + + /** + * Tests the systemTypeKey attribute. + */ + @Test + public void testConfiguration2() { + int[] expectedCounts = { + 1,0,0,1,1,0,0 + }; + performConfigTest("configuration.2", expectedCounts); + + } + + /** + * Tests the systemTypeKey attribute with UNIX specified. + */ + @Test + public void testConfiguration3() { + int[] expectedCounts = { + 1,0,1,0,0,1,0 + }; + performConfigTest("configuration.3", expectedCounts); + + } + + @Test + public void testConfigurationLang() { + int[] expectedCounts = { + 1,1,0,0,0,0,1 + }; + performConfigTest("configuration.lang.good", expectedCounts); + + try { + performConfigTest("configuration.lang.bad", expectedCounts); + fail("BuildException Expected"); + } catch (Exception bx) { + assertTrue(bx instanceof BuildException); + } + } + /** + * Tests the systemTypeKey attribute. + */ + @Test + public void testConfigurationNone() { + int[] expectedCounts = { + 0,0,0,0,0,0,0 + }; + performConfigTest("configuration.none", expectedCounts); + + } + + private void performConfigTest(String target, int[] expectedCounts) { + String[] messages = new String[]{ + "custom configuration", + "custom config: system key = default (UNIX)", + "custom config: system key = UNIX", + "custom config: server time zone ID = " + buildRule.getProject().getProperty("ftp.server.timezone"), + "custom config: system key = WINDOWS", + "custom config: default date format = yyyy/MM/dd HH:mm", + "custom config: server language code = de" + + }; + LogCounter counter = new LogCounter(); + for (int i=0; i < messages.length; i++) { + counter.addLogMessageToSearch(messages[i]); + } + + buildRule.getProject().addBuildListener(counter); + buildRule.getProject().executeTarget(target); + for (int i=0; i < messages.length; i++) { + assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + } + + } + + + /** + * this test is inspired by a user reporting that deletions of directories with the ftp task do not work + */ + @Test + public void testFTPDelete() { + buildRule.getProject().executeTarget("ftp-delete"); + } + + private void compareFiles(DirectoryScanner ds, String[] expectedFiles, + String[] expectedDirectories) { + String includedFiles[] = ds.getIncludedFiles(); + String includedDirectories[] = ds.getIncludedDirectories(); + assertEquals("file present: ", expectedFiles.length, + includedFiles.length); + assertEquals("directories present: ", expectedDirectories.length, + includedDirectories.length); + + for (int counter=0; counter < includedFiles.length; counter++) { + includedFiles[counter] = includedFiles[counter].replace(File.separatorChar, '/'); + } + Arrays.sort(includedFiles); + for (int counter=0; counter < includedDirectories.length; counter++) { + includedDirectories[counter] = includedDirectories[counter] + .replace(File.separatorChar, '/'); + } + Arrays.sort(includedDirectories); + for (int counter=0; counter < includedFiles.length; counter++) { + assertEquals(expectedFiles[counter], includedFiles[counter]); + } + for (int counter=0; counter < includedDirectories.length; counter++) { + assertEquals(expectedDirectories[counter], includedDirectories[counter]); + counter++; + } + } + private static class myFTP extends FTP { + public FTP.FTPDirectoryScanner newScanner(FTPClient client) { + return new FTP.FTPDirectoryScanner(client); + } + // provide public visibility + public String resolveFile(String file) { + return super.resolveFile(file); + } + } + + + public abstract static class myRetryableFTP extends FTP { + private final int numberOfFailuresToSimulate; + private int simulatedFailuresLeft; + + protected myRetryableFTP(int numberOfFailuresToSimulate) { + this.numberOfFailuresToSimulate = numberOfFailuresToSimulate; + this.simulatedFailuresLeft = numberOfFailuresToSimulate; + } + + protected void getFile(FTPClient ftp, String dir, String filename) + throws IOException, BuildException + { + if (this.simulatedFailuresLeft > 0) { + this.simulatedFailuresLeft--; + throw new IOException("Simulated failure for testing"); + } + super.getFile(ftp, dir, filename); + } + protected void executeRetryable(RetryHandler h, Retryable r, + String filename) throws IOException + { + this.simulatedFailuresLeft = this.numberOfFailuresToSimulate; + super.executeRetryable(h, r, filename); + } + } + public static class oneFailureFTP extends myRetryableFTP { + public oneFailureFTP() { + super(1); + } + } + public static class twoFailureFTP extends myRetryableFTP { + public twoFailureFTP() { + super(2); + } + } + public static class threeFailureFTP extends myRetryableFTP { + public threeFailureFTP() { + super(3); + } + } + + public static class randomFailureFTP extends myRetryableFTP { + public randomFailureFTP() { + super(new Random().nextInt(Short.MAX_VALUE)); + } + } + public void testGetWithSelectorRetryable1() { + buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Two retries expected, failed after one."); + } + } + + @Test + public void testGetWithSelectorRetryable2() { + buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Two retries expected, failed after two."); + } + } + + @Test + public void testGetWithSelectorRetryable3() { + buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + fail("Two retries expected, continued after two."); + } catch (BuildException bx) { + } + } + + @Test + public void testGetWithSelectorRetryableRandom() { + buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class); + try { + buildRule.getProject().setProperty("ftp.retries", "forever"); + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Retry forever specified, but failed."); + } + } + + @Test + public void testInitialCommand() { + performCommandTest("test-initial-command", new int[] { 1,0 }); + } + + @Test + public void testSiteAction() { + performCommandTest("test-site-action", new int[] { 1,0 }); + } + + private void performCommandTest(String target, int[] expectedCounts) { + String[] messages = new String[]{ + "Doing Site Command: umask 222", + "Failed to issue Site Command: umask 222", + + }; + LogCounter counter = new LogCounter(); + for (int i=0; i < messages.length; i++) { + counter.addLogMessageToSearch(messages[i]); + } + + buildRule.getProject().addBuildListener(counter); + buildRule.getProject().executeTarget(target); + for (int i=0; i < messages.length; i++) { + assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + } + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java new file mode 100644 index 00000000..5d4d4cf6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java @@ -0,0 +1,146 @@ +/* + * 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.taskdefs.optional.script; + +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.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the examples of the <scriptdef> task. + * + * @since Ant 1.6 + */ +public class ScriptDefTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + // get the fileset and its basedir + Project p = buildRule.getProject(); + FileSet fileset = (FileSet) p.getReference("testfileset"); + File baseDir = fileset.getDir(p); + String log = buildRule.getLog(); + assertTrue("Expecting attribute value printed", + log.indexOf("Attribute attr1 = test") != -1); + + assertTrue("Expecting nested element value printed", + log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); + } + + @Test + public void testNoLang() { + try { + buildRule.executeTarget("nolang"); + fail("Absence of language attribute not detected"); + } catch(BuildException ex) { + AntAssert.assertContains("requires a language attribute", ex.getMessage()); + } + } + + @Test + public void testNoName() { + try { + buildRule.executeTarget("noname"); + fail("Absence of name attribute not detected"); + } catch(BuildException ex) { + AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage()); + } + } + + @Test + public void testNestedByClassName() { + buildRule.executeTarget("nestedbyclassname"); + // get the fileset and its basedir + Project p = buildRule.getProject(); + FileSet fileset = (FileSet) p.getReference("testfileset"); + File baseDir = fileset.getDir(p); + String log = buildRule.getLog(); + assertTrue("Expecting attribute value to be printed", + log.indexOf("Attribute attr1 = test") != -1); + + assertTrue("Expecting nested element value to be printed", + log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); + } + + @Test + public void testNoElement() { + buildRule.executeTarget("noelement"); + assertEquals("Attribute attr1 = test", buildRule.getOutput().trim()); + } + + @Test + public void testException() { + try { + buildRule.executeTarget("exception"); + fail("Should have thrown an exception in the script"); + } catch(BuildException ex) { + AntAssert.assertContains("TypeError", ex.getMessage()); + } + } + + @Test + public void testDoubleDef() { + buildRule.executeTarget("doubledef"); + String log = buildRule.getLog(); + assertTrue("Task1 did not execute", + log.indexOf("Task1") != -1); + assertTrue("Task2 did not execute", + log.indexOf("Task2") != -1); + } + + @Test + public void testDoubleAttribute() { + try { + buildRule.executeTarget("doubleAttributeDef"); + fail("Should have detected duplicate attirbute definition"); + } catch(BuildException ex) { + AntAssert.assertContains("attr1 attribute more than once", ex.getMessage()); + } + } + + @Test + public void testProperty() { + buildRule.executeTarget("property"); + // get the fileset and its basedir + String log = buildRule.getLog(); + assertTrue("Expecting property in attribute value replaced", + log.indexOf("Attribute value = test") != -1); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java new file mode 100644 index 00000000..c45ec17e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java @@ -0,0 +1,351 @@ +/* + * 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.taskdefs.optional.sos; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Commandline; +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.fail; + +/** + * Testcase to ensure that command line generation and required attributes are + * correct. + * + */ +public class SOSTest { + + private Commandline commandline; + + private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini"; + private static final String VSS_PROJECT_PATH = "/SourceRoot/Project"; + private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project"; + private static final String SOS_SERVER_PATH = "192.168.0.1:8888"; + private static final String SOS_USERNAME = "ant"; + private static final String SOS_PASSWORD = "rocks"; + private static final String LOCAL_PATH = "testdir"; + private static final String SRC_FILE = "Class1.java"; + private static final String SRC_LABEL = "label1"; + private static final String SRC_COMMENT = "I fixed a bug"; + private static final String SOS_HOME = "/home/user/.sos"; + private static final String VERSION = "007"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.init(); + project.setBasedir("."); + } + + @After + public void tearDown() { + File file = new File(project.getBaseDir(), LOCAL_PATH); + if (file.exists()) { + file.delete(); + } + } + + /** Test SOSGetFile flags & commandline generation */ + @Test + public void testGetFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file", + SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name", + SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, + "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", + "-nocache", "-workdir", project.getBaseDir().getAbsolutePath() + + File.separator + LOCAL_PATH}; + + // Set up a SOSGet task + SOSGet sosGet = new SOSGet(); + sosGet.setProject(project); + sosGet.setVssServerPath(VSS_SERVER_PATH); + sosGet.setSosServerPath(SOS_SERVER_PATH); + sosGet.setProjectPath(VSS_PROJECT_PATH); + sosGet.setFile(SRC_FILE); + sosGet.setUsername(SOS_USERNAME); + sosGet.setPassword(SOS_PASSWORD); + sosGet.setVersion(VERSION); + sosGet.setLocalPath(new Path(project, LOCAL_PATH)); + sosGet.setNoCache(true); + sosGet.setNoCompress(true); + sosGet.setVerbose(true); + sosGet.setRecursive(true); + + commandline = sosGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSGetProject flags & commandline generation */ + @Test + public void testGetProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive", + "-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath()}; + + // Set up a SOSGet task + SOSGet sosGet = new SOSGet(); + sosGet.setProject(project); + sosGet.setVssServerPath(VSS_SERVER_PATH); + sosGet.setSosServerPath(SOS_SERVER_PATH); + sosGet.setProjectPath(DS_VSS_PROJECT_PATH); + sosGet.setLabel(SRC_LABEL); + sosGet.setUsername(SOS_USERNAME); + sosGet.setSosHome(SOS_HOME); + sosGet.setNoCache(true); + sosGet.setNoCompress(false); + sosGet.setVerbose(false); + sosGet.setRecursive(true); + + commandline = sosGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests SOSGet required attributes. */ + @Test + public void testGetExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("sosget.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test CheckInFile option flags */ + @Test + public void testCheckinFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file", + SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache", + "-workdir", project.getBaseDir().getAbsolutePath() + File.separator + + LOCAL_PATH, "-log", SRC_COMMENT}; + + // Set up a SOSCheckin task + SOSCheckin sosCheckin = new SOSCheckin(); + sosCheckin.setProject(project); + sosCheckin.setVssServerPath(VSS_SERVER_PATH); + sosCheckin.setSosServerPath(SOS_SERVER_PATH); + sosCheckin.setProjectPath(VSS_PROJECT_PATH); + sosCheckin.setFile(SRC_FILE); + sosCheckin.setComment(SRC_COMMENT); + sosCheckin.setUsername(SOS_USERNAME); + sosCheckin.setPassword(SOS_PASSWORD); + sosCheckin.setLocalPath(new Path(project, LOCAL_PATH)); + sosCheckin.setNoCache(true); + sosCheckin.setNoCompress(true); + sosCheckin.setVerbose(true); + sosCheckin.setRecursive(true); + + commandline = sosCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test CheckInProject option flags */ + @Test + public void testCheckinProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject", + "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath(), "-log", SRC_COMMENT,}; + + // Set up a SOSCheckin task + SOSCheckin sosCheckin = new SOSCheckin(); + sosCheckin.setProject(project); + sosCheckin.setVssServerPath(VSS_SERVER_PATH); + sosCheckin.setSosServerPath(SOS_SERVER_PATH); + sosCheckin.setProjectPath(DS_VSS_PROJECT_PATH); + sosCheckin.setComment(SRC_COMMENT); + sosCheckin.setUsername(SOS_USERNAME); + sosCheckin.setSosHome(SOS_HOME); + sosCheckin.setNoCache(true); + sosCheckin.setNoCompress(false); + sosCheckin.setVerbose(false); + sosCheckin.setRecursive(true); + + commandline = sosCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSCheckIn required attributes. */ + @Test + public void testCheckinExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soscheckin.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test CheckOutFile option flags */ + @Test + public void testCheckoutFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file", + SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache", + "-workdir", project.getBaseDir().getAbsolutePath() + + File.separator + LOCAL_PATH}; + + // Set up a SOSCheckout task + SOSCheckout sosCheckout = new SOSCheckout(); + sosCheckout.setProject(project); + sosCheckout.setVssServerPath(VSS_SERVER_PATH); + sosCheckout.setSosServerPath(SOS_SERVER_PATH); + sosCheckout.setProjectPath(DS_VSS_PROJECT_PATH); + sosCheckout.setFile(SRC_FILE); + sosCheckout.setUsername(SOS_USERNAME); + sosCheckout.setPassword(SOS_PASSWORD); + sosCheckout.setLocalPath(new Path(project, LOCAL_PATH)); + sosCheckout.setNoCache(true); + sosCheckout.setNoCompress(true); + sosCheckout.setVerbose(true); + sosCheckout.setRecursive(true); + + commandline = sosCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test CheckOutProject option flags */ + @Test + public void testCheckoutProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject", + "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath()}; + + // Set up a sosCheckout task + SOSCheckout sosCheckout = new SOSCheckout(); + sosCheckout.setProject(project); + sosCheckout.setVssServerPath(VSS_SERVER_PATH); + sosCheckout.setSosServerPath(SOS_SERVER_PATH); + sosCheckout.setProjectPath(VSS_PROJECT_PATH); + sosCheckout.setUsername(SOS_USERNAME); + sosCheckout.setSosHome(SOS_HOME); + sosCheckout.setNoCache(true); + sosCheckout.setNoCompress(false); + sosCheckout.setVerbose(false); + sosCheckout.setRecursive(true); + + commandline = sosCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSCheckout required attributes. */ + @Test + public void testCheckoutExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soscheckout.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test Label option flags */ + @Test + public void testLabelFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server", + SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database", + VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-label", + SRC_LABEL, "-verbose", "-log", SRC_COMMENT}; + + // Set up a sosCheckout task + SOSLabel sosLabel = new SOSLabel(); + sosLabel.setVssServerPath(VSS_SERVER_PATH); + sosLabel.setSosServerPath(SOS_SERVER_PATH); + sosLabel.setProjectPath(DS_VSS_PROJECT_PATH); + sosLabel.setUsername(SOS_USERNAME); + sosLabel.setSosHome(SOS_HOME); + sosLabel.setComment(SRC_COMMENT); + sosLabel.setLabel(SRC_LABEL); + sosLabel.setNoCache(true); + sosLabel.setNoCompress(false); + sosLabel.setVerbose(true); + + commandline = sosLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSLabel required attributes. */ + @Test + public void testLabelExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soslabel.4", "some cause", "projectpath attribute must be set!"); + expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!"); + } + + private void expectSpecificBuildException(String target, String errorMessage, + String exceptionMessage) { + try { + buildRule.executeTarget(target); + fail(errorMessage); + } catch(BuildException ex) { + assertEquals(exceptionMessage, ex.getMessage()); + } + } + + /** + * Iterate through the generated command line comparing it to reference + * one. + * + * @param sTestCmdLine The reference command line; + * @param sGeneratedCmdLine The generated command line; + */ + private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { + int length = sTestCmdLine.length; + for (int i = 0; i < length; i++) { + try { + assertEquals("arg # " + String.valueOf(i), + sTestCmdLine[i], + sGeneratedCmdLine[i]); + } catch (ArrayIndexOutOfBoundsException aioob) { + fail("missing arg " + sTestCmdLine[i]); + } + } + if (sGeneratedCmdLine.length > sTestCmdLine.length) { + // We have extra elements + fail("extra args"); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java new file mode 100644 index 00000000..fb0b3eaf --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.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.taskdefs.optional.splash; + +import org.apache.tools.ant.Project; + +/** + * This is an "interactive" test, it passes if the splash screen + * disappears after the "finished" but before the "exiting" message. + * + * This even isn't a JUnit test case. + * + * @since Ant 1.5.2 + */ +public class SplashScreenTest { + + public static void main(String[] args) throws InterruptedException { + Project p = new Project(); + SplashTask t = new SplashTask(); + t.setProject(p); + t.execute(); + + // give it some time to display + Thread.sleep(2000); + + p.fireBuildFinished(null); + System.err.println("finished"); + + Thread.sleep(2000); + System.err.println("exiting"); + System.exit(0); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java new file mode 100644 index 00000000..dff5b25a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java @@ -0,0 +1,206 @@ +/* + * 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.taskdefs.optional.ssh; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.FilesMatch; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.selectors.FilenameSelector; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * This is a unit test for the Scp task in Ant. It must be + * configured with command line options in order for it to work. + * Here are the options: + * + * scp.tmp This is a local path to a temporary + * directory for this task to use. + * scp.host This is the remote location of the form: + * "user:password@host:/path/to/directory" + * scp.port The port of the listening SSH service. + * Defaults to 22. (optional) + * scp.known.hosts The file containing the public keys of known + * hosts. Must be a SSH2 version file, but + * supports RSA and DSA keys. If it is not present + * this task setTrust() to true. (optional) + */ +public class ScpTest { + + private File tempDir; + private String sshHostUri = System.getProperty("scp.host"); + private int port = Integer.parseInt( System.getProperty( "scp.port", "22" ) ); + private String knownHosts = System.getProperty("scp.known.hosts"); + + private List cleanUpList = new ArrayList(); + + public ScpTest() { + if (System.getProperty("scp.tmp") != null) { + tempDir = new File(System.getProperty("scp.tmp")); + } + } + + @Before + public void setUp() { + cleanUpList.clear(); + } + + @After + public void tearDown() { + for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) { + File file = (File) i.next(); + file.delete(); + } + } + + @Test + public void testSingleFileUploadAndDownload() throws IOException { + assertNotNull("system property scp.tmp must be set", tempDir); + File uploadFile = createTemporaryFile(); + + // upload + Scp scpTask = createTask(); + scpTask.setFile( uploadFile.getPath() ); + scpTask.setTodir( sshHostUri ); + scpTask.execute(); + + File testFile = new File( tempDir.getPath() + File.separator + + "download-testSingleFileUploadAndDownload.test" ); + addCleanup(testFile ); + assertFalse("Assert that the testFile does not exist.", testFile.exists()); + + // download + scpTask = createTask(); + scpTask.setFile( sshHostUri + "/" + uploadFile.getName() ); + scpTask.setTodir( testFile.getPath() ); + scpTask.execute(); + + assertTrue( "Assert that the testFile exists.", testFile.exists() ); + compareFiles( uploadFile, testFile ); + } + + @Test + public void testMultiUploadAndDownload() throws IOException { + assertNotNull("system property scp.tmp must be set", tempDir); + List uploadList = new ArrayList(); + for( int i = 0; i < 5; i++ ) { + uploadList.add( createTemporaryFile() ); + } + + Scp scp = createTask(); + FilenameSelector selector = new FilenameSelector(); + selector.setName( "scp*" ); + FileSet fileset = new FileSet(); + fileset.setDir( tempDir ); + fileset.addFilename( selector ); + scp.addFileset( fileset ); + scp.setTodir( sshHostUri ); + scp.execute(); + + File multi = new File( tempDir, "multi" ); + multi.mkdir(); + addCleanup( multi ); + + Scp scp2 = createTask(); + scp2.setFile( sshHostUri + "/scp*" ); + scp2.setTodir( multi.getPath() ); + scp2.execute(); + + FilesMatch match = new FilesMatch(); + for( Iterator i = uploadList.iterator(); i.hasNext(); ) { + File f = (File)i.next(); + match.setFile1( f ); + File f2 = new File( multi, f.getName() ); + match.setFile2( f2 ); + assertTrue("Assert file '" + f.getPath() + "' and file '" + + f2.getPath() + "'", match.eval() ); + } + } + + @Test + public void testRemoteToDir() throws IOException { + Scp scpTask = createTask(); + + // first try an invalid URI + try { + scpTask.setRemoteTodir( "host:/a/path/without/an/at" ); + fail("Expected a BuildException to be thrown due to invalid" + + " remoteToDir"); + } + catch (BuildException e) + { + // expected + //TODO we should be asserting a value in here + } + + // And this one should work + scpTask.setRemoteTodir( "user:password@host:/a/path/with/an/at" ); + // no exception + } + + public void addCleanup( File file ) { + cleanUpList.add( file ); + } + + private void compareFiles(File src, File dest) { + FilesMatch match = new FilesMatch(); + match.setFile1( src ); + match.setFile2( dest ); + + assertTrue( "Assert files are equal.", match.eval() ); + } + + private File createTemporaryFile() throws IOException { + File uploadFile; + uploadFile = File.createTempFile( "scp", "test", tempDir ); + FileWriter writer = new FileWriter( uploadFile ); + writer.write("Can you hear me now?\n"); + writer.close(); + addCleanup( uploadFile ); + return uploadFile; + } + + private Scp createTask() { + Scp scp = new Scp(); + Project p = new Project(); + p.init(); + scp.setProject( p ); + if( knownHosts != null ) { + scp.setKnownhosts( knownHosts ); + } else { + scp.setTrust( true ); + } + scp.setPort( port ); + return scp; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java new file mode 100644 index 00000000..e36d6838 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java @@ -0,0 +1,297 @@ +/* + * 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. + * + */ + +/* + * Since the initial version of this file was deveolped on the clock on + * an NSF grant I should say the following boilerplate: + * + * This material is based upon work supported by the National Science + * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and + * conclusions or recommendations expressed in this material are those + * of the author and do not necessarily reflect the views of the + * National Science Foundation. + */ + +package org.apache.tools.ant.taskdefs.optional.unix; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.condition.Os; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.SymbolicLinkUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; + +/** + * Test cases for the Symlink task. Link creation, link deletion, recording + * of links in multiple directories, and restoration of links recorded are + * all tested. A separate test for the utility method Symlink.deleteSymlink + * is not included because action="delete" only prints a message and calls + * Symlink.deleteSymlink, making a separate test redundant. + * + */ + +public class SymlinkTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private boolean supportsSymlinks = Os.isFamily("unix"); + + @Before + public void setUp() { + Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks); + buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testSingle() { + buildRule.executeTarget("test-single"); + Project p = buildRule.getProject(); + assertNotNull("Failed to create file", + p.getProperty("test.single.file.created")); + assertNotNull("Failed to create link", + p.getProperty("test.single.link.created")); + } + + @Test + public void testDelete() { + buildRule.executeTarget("test-delete"); + Project p = buildRule.getProject(); + String linkDeleted = p.getProperty("test.delete.link.still.there"); + assertNotNull("Actual file deleted by symlink", + p.getProperty("test.delete.file.still.there")); + if (linkDeleted != null) { + fail(linkDeleted); + } + } + + @Test + public void testRecord() { + buildRule.executeTarget("test-record"); + Project p = buildRule.getProject(); + + assertNotNull("Failed to create dir1", + p.getProperty("test.record.dir1.created")); + + assertNotNull("Failed to create dir2", + p.getProperty("test.record.dir2.created")); + + assertNotNull("Failed to create file1", + p.getProperty("test.record.file1.created")); + + assertNotNull("Failed to create file2", + p.getProperty("test.record.file2.created")); + + assertNotNull("Failed to create fileA", + p.getProperty("test.record.fileA.created")); + + assertNotNull("Failed to create fileB", + p.getProperty("test.record.fileB.created")); + + assertNotNull("Failed to create fileC", + p.getProperty("test.record.fileC.created")); + + assertNotNull("Failed to create link1", + p.getProperty("test.record.link1.created")); + + assertNotNull("Failed to create link2", + p.getProperty("test.record.link2.created")); + + assertNotNull("Failed to create link3", + p.getProperty("test.record.link3.created")); + + assertNotNull("Failed to create dirlink", + p.getProperty("test.record.dirlink.created")); + + assertNotNull("Failed to create dirlink2", + p.getProperty("test.record.dirlink2.created")); + + assertNotNull("Couldn't record links in dir1", + p.getProperty("test.record.dir1.recorded")); + + assertNotNull("Couldn't record links in dir2", + p.getProperty("test.record.dir2.recorded")); + + String dir3rec = p.getProperty("test.record.dir3.recorded"); + + if (dir3rec != null) { + fail(dir3rec); + } + + } + + @Test + public void testRecreate() { + buildRule.executeTarget("test-recreate"); + Project p = buildRule.getProject(); + String link1Rem = p.getProperty("test.recreate.link1.not.removed"); + String link2Rem = p.getProperty("test.recreate.link2.not.removed"); + String link3Rem = p.getProperty("test.recreate.link3.not.removed"); + String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed"); + if (link1Rem != null) { + fail(link1Rem); + } + if (link2Rem != null) { + fail(link2Rem); + } + if (link3Rem != null) { + fail(link3Rem); + } + if (dirlinkRem != null) { + fail(dirlinkRem); + } + assertNotNull("Failed to recreate link1", + p.getProperty("test.recreate.link1.recreated")); + assertNotNull("Failed to recreate link2", + p.getProperty("test.recreate.link2.recreated")); + assertNotNull("Failed to recreate link3", + p.getProperty("test.recreate.link3.recreated")); + assertNotNull("Failed to recreate dirlink", + p.getProperty("test.recreate.dirlink.recreated")); + + String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice"); + + if (doubleRecreate != null) { + fail(doubleRecreate); + } + + assertNotNull("Failed to alter dirlink3", + p.getProperty("test.recreate.dirlink3.was.altered")); + } + + @Test + public void testSymbolicLinkUtilsMethods() throws Exception { + + buildRule.executeTarget("test-fileutils"); + SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils(); + + java.io.File f = new File(buildRule.getOutputDir(), "file1"); + assertTrue(f.exists()); + assertFalse(f.isDirectory()); + assertTrue(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir1"); + assertTrue(f.exists()); + assertTrue(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "file2"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir2"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + + f = new File(buildRule.getOutputDir(), "file.there"); + assertTrue(f.exists()); + assertFalse(f.isDirectory()); + assertTrue(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir.there"); + assertTrue(f.exists()); + assertTrue(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + // it is not possible to find out that symbolic links pointing + // to inexistent files or directories are symbolic links + // it used to be possible to detect this on Mac + // this is not true under Snow Leopard and JDK 1.5 + // Removing special handling of MacOS until someone shouts + // Antoine + f = new File(buildRule.getOutputDir(), "file.notthere"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); + assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir.notthere"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); + assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + } + + @After + public void tearDown() { + if (buildRule.getProject() != null) { + buildRule.executeTarget("tearDown"); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java new file mode 100644 index 00000000..aa96d8d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java @@ -0,0 +1,475 @@ +/* + * 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.taskdefs.optional.vss; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Location; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Tstamp; +import org.apache.tools.ant.types.Commandline; +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.fail; + +/** + * Testcase to ensure that command line generation and required attributes are correct. + * + */ +public class MSVSSTest implements MSVSSConstants { + + private Commandline commandline; + + private static final String VSS_PROJECT_PATH = "/SourceRoot/Project"; + private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project"; + private static final String VSS_USERNAME = "ant"; + private static final String VSS_PASSWORD = "rocks"; + private static final String LOCAL_PATH = "testdir"; + private static final String SRC_LABEL = "label1"; + private static final String LONG_LABEL = "123456789012345678901234567890"; + private static final String SRC_COMMENT = "I fixed a bug"; + private static final String VERSION = "007"; + private static final String DATE = "00-00-00"; + private static final String DATE2 = "01-01-01"; + private static final String OUTPUT = "output.log"; + private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + private Project project; + + @Before + public void setUp(){ + project = new Project(); + project.setBasedir("."); + project.init(); + } + + @After + public void tearDown() { + File file = new File(project.getBaseDir(), LOCAL_PATH); + if (file.exists()) { + file.delete(); + } + } + + @Test + public void testGetCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir() + .getAbsolutePath() + + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, + MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN + + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE}; + + // Set up a VSSGet task + MSVSSGET vssGet = new MSVSSGET(); + vssGet.setProject(project); + vssGet.setRecursive(true); + vssGet.setLocalpath(new Path(project, LOCAL_PATH)); + vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssGet.setVersion(VERSION); + vssGet.setQuiet(false); + vssGet.setDate(DATE); + vssGet.setLabel(SRC_LABEL); + vssGet.setVsspath(VSS_PROJECT_PATH); + MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); + cmu.setValue(TIME_UPDATED); + vssGet.setFileTimeStamp(cmu); + MSVSS.WritableFiles wf = new MSVSS.WritableFiles(); + wf.setValue(WRITABLE_SKIP); + vssGet.setWritableFiles(wf); + + commandline = vssGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSGet required attributes. */ + @Test + public void testGetExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests Label commandline generation. */ + @Test + public void testLabelCommandLine1() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES, + MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN + + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSLabel task + MSVSSLABEL vssLabel = new MSVSSLABEL(); + vssLabel.setProject(project); + vssLabel.setComment(SRC_COMMENT); + vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssLabel.setVersion(VERSION); + vssLabel.setAutoresponse("Y"); + vssLabel.setLabel(SRC_LABEL); + vssLabel.setVsspath(VSS_PROJECT_PATH); + + commandline = vssLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests Label commandline generation with a label of more than 31 chars. */ + @Test + public void testLabelCommandLine2() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF, + MSVSS.FLAG_LABEL + LONG_LABEL, + MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSLabel task + MSVSSLABEL vssLabel = new MSVSSLABEL(); + vssLabel.setProject(project); + vssLabel.setComment(SRC_COMMENT); + vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssLabel.setLabel(LONG_LABEL + "blahblah"); + vssLabel.setVsspath(VSS_PROJECT_PATH); + + commandline = vssLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSLabel required attributes. + */ + @Test + public void testLabelExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!"); + expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!"); + } + + /** Tests VSSHistory commandline generation with from label. */ + @Test + public void testHistoryCommandLine1() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL + + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME + + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir() + .getAbsolutePath() + + File.separator + OUTPUT}; + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + + vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + + vssHistory.setFromLabel(SRC_LABEL); + vssHistory.setToLabel(LONG_LABEL + "blahblah"); + vssHistory.setVsspath(VSS_PROJECT_PATH); + vssHistory.setRecursive(false); + vssHistory.setOutput(new File(project.getBaseDir().getAbsolutePath(), OUTPUT)); + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSHistory commandline generation with from date. */ + @Test + public void testHistoryCommandLine2() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE + + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssHistory.setFromDate(DATE2); + vssHistory.setToDate(DATE); + vssHistory.setVsspath(VSS_PROJECT_PATH); + vssHistory.setRecursive(true); + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSHistory commandline generation with date calculation. */ + @Test + public void testHistoryCommandLine3() { + // Set up a Timestamp + Tstamp tstamp = new Tstamp(); + Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + tstamp.setLocation(location); + tstamp.setProject(project); + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("today"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("today"); + + // Get today's date + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + vssHistory.setLogin(VSS_USERNAME); + vssHistory.setToDate(today); + vssHistory.setVsspath(VSS_PROJECT_PATH); + + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME}; + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Tests VSSHistory required attributes. + */ + @Test + public void testHistoryExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!"); + } + + private void expectSpecificBuildException(String target, String failMessage, + String exceptionMessage) { + try { + buildRule.executeTarget(target); + fail(failMessage); + } catch(BuildException ex) { + assertEquals(exceptionMessage, ex.getMessage()); + } + } + + /** Tests CheckIn commandline generation. */ + @Test + public void testCheckinCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME, + MSVSS.FLAG_COMMENT + SRC_COMMENT}; + + // Set up a VSSCheckIn task + MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN(); + vssCheckin.setProject(project); + vssCheckin.setComment(SRC_COMMENT); + vssCheckin.setLogin(VSS_USERNAME); + vssCheckin.setAutoresponse("N"); + vssCheckin.setVsspath(VSS_PROJECT_PATH); + vssCheckin.setWritable(true); + + commandline = vssCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCheckIn required attributes. + */ + @Test + public void testCheckinExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests CheckOut commandline generation. */ + @Test + public void testCheckoutCommandLine() { + String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, + MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME, + FLAG_FILETIME_MODIFIED, FLAG_NO_GET}; + + // Set up a VSSCheckOut task + MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT(); + vssCheckout.setProject(project); + vssCheckout.setLogin(VSS_USERNAME); + vssCheckout.setVsspath(DS_VSS_PROJECT_PATH); + vssCheckout.setRecursive(true); + vssCheckout.setDate(DATE); + vssCheckout.setLabel(SRC_LABEL); + vssCheckout.setSsdir(SS_DIR); + MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); + cmu.setValue(TIME_MODIFIED); + vssCheckout.setFileTimeStamp(cmu); + vssCheckout.setGetLocalCopy(false); + + commandline = vssCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCheckout required attributes. + */ + @Test + public void testCheckoutExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!"); + expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute"); + } + + /** Tests Add commandline generation. */ + @Test + public void testAddCommandLine() { + String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD, + project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, + MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"}; + + // Set up a VSSAdd task + MSVSSADD vssAdd = new MSVSSADD(); + vssAdd.setProject(project); + vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssAdd.setVsspath(DS_VSS_PROJECT_PATH); + vssAdd.setRecursive(true); + vssAdd.setSsdir(SS_DIR); + vssAdd.setWritable(false); + vssAdd.setLocalpath(new Path(project, LOCAL_PATH)); + + commandline = vssAdd.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSAdd required attributes. + */ + @Test + public void testAddExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!"); + } + + /** Tests CP commandline generation. */ + @Test + public void testCpCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN + + VSS_USERNAME}; + + // Set up a VSSCp task + MSVSSCP vssCp = new MSVSSCP(); + vssCp.setProject(project); + vssCp.setLogin(VSS_USERNAME); + vssCp.setVsspath(DS_VSS_PROJECT_PATH); + + commandline = vssCp.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCP required attributes. + */ + @Test + public void testCpExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests Create commandline generation. */ + @Test + public void testCreateCommandLine() { + String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO, + MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME}; + + // Set up a VSSCreate task + MSVSSCREATE vssCreate = new MSVSSCREATE(); + vssCreate.setProject(project); + vssCreate.setComment(SRC_COMMENT); + vssCreate.setLogin(VSS_USERNAME); + vssCreate.setVsspath(DS_VSS_PROJECT_PATH); + vssCreate.setFailOnError(true); + vssCreate.setAutoresponse("N"); + vssCreate.setQuiet(true); + + commandline = vssCreate.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCreate required attributes. + */ + @Test + public void testCreateExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!"); + } + + /** + * Iterate through the generated command line comparing it to reference one. + * @param sTestCmdLine The reference command line; + * @param sGeneratedCmdLine The generated command line; + */ + private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { + int testLength = sTestCmdLine.length; + int genLength = sGeneratedCmdLine.length; + + int genIndex = 0; + int testIndex = 0; + + while (testIndex < testLength) { + try { + if (sGeneratedCmdLine[genIndex].equals("")) { + genIndex++; + continue; + } + assertEquals("arg # " + testIndex, + sTestCmdLine[testIndex], + sGeneratedCmdLine[genIndex]); + testIndex++; + genIndex++; + } catch (ArrayIndexOutOfBoundsException aioob) { + fail("missing arg " + sTestCmdLine[testIndex]); + } + } + + // Count the number of empty strings + int cnt = 0; + for (int i = 0; i < genLength; i++) { + if (sGeneratedCmdLine[i].equals("")) { + cnt++; + } + } + if (genLength - cnt > sTestCmdLine.length) { + // We have extra elements + fail("extra args"); + } + } +} |