| @@ -1,21 +1,21 @@ | |||||
| /* | /* | ||||
| 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. | |||||
| */ | |||||
| * 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. | |||||
| */ | |||||
| public class Alpha { | public class Alpha { | ||||
| public String toString() { | public String toString() { | ||||
| return "alpha"; | |||||
| return "alpha"; | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,25 +1,25 @@ | |||||
| /* | /* | ||||
| 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. | |||||
| */ | |||||
| * 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. | |||||
| */ | |||||
| public class Beta extends Alpha { | public class Beta extends Alpha { | ||||
| public String toString() { | public String toString() { | ||||
| return "beta " + super.toString(); | |||||
| return "beta " + super.toString(); | |||||
| } | } | ||||
| public static void main(String [] args) { | public static void main(String [] args) { | ||||
| Beta myBeta = new Beta(); | |||||
| System.out.println(myBeta.toString()); | |||||
| Beta myBeta = new Beta(); | |||||
| System.out.println(myBeta.toString()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| /* | |||||
| /* | |||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||
| * contributor license agreements. See the NOTICE file distributed with | * contributor license agreements. See the NOTICE file distributed with | ||||
| * this work for additional information regarding copyright ownership. | * this work for additional information regarding copyright ownership. | ||||
| @@ -13,19 +13,19 @@ | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| * | |||||
| * | |||||
| */ | */ | ||||
| /** | /** | ||||
| * this is an assertion tester | * this is an assertion tester | ||||
| * It has a main() entry | * It has a main() entry | ||||
| */ | */ | ||||
| public class AssertionMain { | public class AssertionMain { | ||||
| public static void main(String args[]) { | public static void main(String args[]) { | ||||
| assert true == false : "there exist no facts that are both true and false"; | |||||
| System.out.println("Assertions are disabled"); | |||||
| assert true == false : "there exist no facts that are both true and false"; | |||||
| System.out.println("Assertions are disabled"); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| /* | |||||
| /* | |||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||
| * contributor license agreements. See the NOTICE file distributed with | * contributor license agreements. See the NOTICE file distributed with | ||||
| * this work for additional information regarding copyright ownership. | * this work for additional information regarding copyright ownership. | ||||
| @@ -13,33 +13,33 @@ | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| * | |||||
| * | |||||
| */ | */ | ||||
| import junit.framework.TestCase; | import junit.framework.TestCase; | ||||
| /** | /** | ||||
| * this is an assertion tester for junit | |||||
| * this is an assertion tester for junit | |||||
| */ | */ | ||||
| public class AssertionTest extends TestCase { | public class AssertionTest extends TestCase { | ||||
| public AssertionTest(String name) { | |||||
| super(name); | |||||
| } | |||||
| public void testAssertRaised() { | |||||
| try { | |||||
| assert true == false; | |||||
| fail("expected an assertion"); | |||||
| } catch(AssertionError asserto) { | |||||
| //if we got here, all was well | |||||
| } | |||||
| } | |||||
| public void testAssertNotRaised() { | |||||
| assert(2+2==4); | |||||
| } | |||||
| public AssertionTest(String name) { | |||||
| super(name); | |||||
| } | |||||
| public void testAssertRaised() { | |||||
| try { | |||||
| assert true == false; | |||||
| fail("expected an assertion"); | |||||
| } catch(AssertionError asserto) { | |||||
| //if we got here, all was well | |||||
| } | |||||
| } | |||||
| public void testAssertNotRaised() { | |||||
| assert(2+2==4); | |||||
| } | |||||
| } | } | ||||
| @@ -426,8 +426,8 @@ public class Target implements TaskContainer { | |||||
| try { | try { | ||||
| // use index-based approach to avoid ConcurrentModificationExceptions; | // use index-based approach to avoid ConcurrentModificationExceptions; | ||||
| // also account for growing target children | // also account for growing target children | ||||
| // do not optimize this loop by replacing children.size() by a variable | |||||
| // as children can be added dynamically as in RhinoScriptTest where a target is adding work for itself | |||||
| // do not optimize this loop by replacing children.size() by a variable | |||||
| // as children can be added dynamically as in RhinoScriptTest where a target is adding work for itself | |||||
| for (int i = 0; i < children.size(); i++) { | for (int i = 0; i < children.size(); i++) { | ||||
| Object o = children.get(i); | Object o = children.get(i); | ||||
| if (o instanceof Task) { | if (o instanceof Task) { | ||||
| @@ -745,7 +745,7 @@ public class NetRexxC extends MatchingTask { | |||||
| filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | ||||
| compileList.addElement(destFile.getAbsolutePath()); | compileList.addElement(destFile.getAbsolutePath()); | ||||
| } else if (compile && srcFile.lastModified() > classFile.lastModified()) { | } else if (compile && srcFile.lastModified() > classFile.lastModified()) { | ||||
| // compile case tests against .class file | |||||
| // compile case tests against .class file | |||||
| filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath()); | ||||
| compileList.addElement(destFile.getAbsolutePath()); | compileList.addElement(destFile.getAbsolutePath()); | ||||
| } | } | ||||
| @@ -1039,4 +1039,3 @@ public class NetRexxC extends MatchingTask { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -83,7 +83,7 @@ public class IgnoredTestResult extends TestResult { | |||||
| * @param cause the details of the test and assumption failure. | * @param cause the details of the test and assumption failure. | ||||
| */ | */ | ||||
| public void testAssumptionFailure(Test test, Throwable cause) { | public void testAssumptionFailure(Test test, Throwable cause) { | ||||
| skipped.add(new TestIgnored(test)); | |||||
| skipped.add(new TestIgnored(test)); | |||||
| for (IgnoredTestListener listener : listeners) { | for (IgnoredTestListener listener : listeners) { | ||||
| listener.testAssumptionFailure(test, cause); | listener.testAssumptionFailure(test, cause); | ||||
| } | } | ||||
| @@ -145,10 +145,10 @@ public class JUnitVersionHelper { | |||||
| Class<?> junit4FacadeClass = Class.forName("junit.framework.JUnit4TestCaseFacade"); | Class<?> junit4FacadeClass = Class.forName("junit.framework.JUnit4TestCaseFacade"); | ||||
| if (test != null && test.getClass().isAssignableFrom(junit4FacadeClass)) { | if (test != null && test.getClass().isAssignableFrom(junit4FacadeClass)) { | ||||
| //try and get the message coded as part of the ignore | //try and get the message coded as part of the ignore | ||||
| /* | |||||
| * org.junit.runner.Description contains a getAnnotation(Class) method... but this | |||||
| * wasn't in older versions of JUnit4 so we have to try and do this by reflection | |||||
| */ | |||||
| /* | |||||
| * org.junit.runner.Description contains a getAnnotation(Class) method... but this | |||||
| * wasn't in older versions of JUnit4 so we have to try and do this by reflection | |||||
| */ | |||||
| Class<?> testClass = Class.forName(JUnitVersionHelper.getTestCaseClassName(test)); | Class<?> testClass = Class.forName(JUnitVersionHelper.getTestCaseClassName(test)); | ||||
| Method testMethod = testClass.getMethod(JUnitVersionHelper.getTestCaseName(test)); | Method testMethod = testClass.getMethod(JUnitVersionHelper.getTestCaseName(test)); | ||||
| @@ -36,7 +36,7 @@ public abstract class BaseResourceCollectionWrapper | |||||
| return cacheCollection().iterator(); | return cacheCollection().iterator(); | ||||
| } | } | ||||
| protected int getSize() { | |||||
| protected int getSize() { | |||||
| return cacheCollection().size(); | return cacheCollection().size(); | ||||
| } | } | ||||
| @@ -518,7 +518,7 @@ public final class JavaEnvUtils { | |||||
| case VERSION_1_4: | case VERSION_1_4: | ||||
| tests.addElement("sun.audio.AudioPlayer"); | tests.addElement("sun.audio.AudioPlayer"); | ||||
| if (javaVersionNumber == VERSION_1_4) { | if (javaVersionNumber == VERSION_1_4) { | ||||
| // only for 1.4, not for higher versions which fall through | |||||
| // only for 1.4, not for higher versions which fall through | |||||
| tests.addElement("org.apache.crimson.parser.ContentModel"); | tests.addElement("org.apache.crimson.parser.ContentModel"); | ||||
| tests.addElement("org.apache.xalan.processor.ProcessorImport"); | tests.addElement("org.apache.xalan.processor.ProcessorImport"); | ||||
| tests.addElement("org.apache.xml.utils.URI"); | tests.addElement("org.apache.xml.utils.URI"); | ||||
| @@ -1,26 +1,26 @@ | |||||
| /* | /* | ||||
| 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. | |||||
| */ | |||||
| * 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 task; | package task; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| public class EchoLocation extends Task { | public class EchoLocation extends Task { | ||||
| public void execute() { | |||||
| public void execute() { | |||||
| log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO); | log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO); | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -32,10 +32,10 @@ public class AntAssert { | |||||
| * @param needle the string to search for. | * @param needle the string to search for. | ||||
| * @param haystack the string to search in. | * @param haystack the string to search in. | ||||
| */ | */ | ||||
| public static void assertContains(String message, String needle, String haystack) { | |||||
| String formattedMessage = (message == null ? "" : message + " "); | |||||
| assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||||
| } | |||||
| public static void assertContains(String message, String needle, String haystack) { | |||||
| String formattedMessage = (message == null ? "" : message + " "); | |||||
| assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||||
| } | |||||
| /** | /** | ||||
| * Assert that a string contains the given substring. A default failure message will be used if the target string | * Assert that a string contains the given substring. A default failure message will be used if the target string | ||||
| @@ -43,9 +43,9 @@ public class AntAssert { | |||||
| * @param needle the target string to search for. | * @param needle the target string to search for. | ||||
| * @param haystack the string to search in. | * @param haystack the string to search in. | ||||
| */ | */ | ||||
| public static void assertContains(String needle, String haystack) { | |||||
| assertContains("", needle, haystack); | |||||
| } | |||||
| public static void assertContains(String needle, String haystack) { | |||||
| assertContains("", needle, haystack); | |||||
| } | |||||
| /** | /** | ||||
| * Assert that a string does not contain the given substring. | * Assert that a string does not contain the given substring. | ||||
| @@ -54,8 +54,8 @@ public class AntAssert { | |||||
| * @param haystack the string to search in. | * @param haystack the string to search in. | ||||
| */ | */ | ||||
| public static void assertNotContains(String message, String needle, String haystack) { | public static void assertNotContains(String message, String needle, String haystack) { | ||||
| String formattedMessage = (message == null ? "" : message + " "); | |||||
| assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||||
| String formattedMessage = (message == null ? "" : message + " "); | |||||
| assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -67,6 +67,6 @@ public class AntAssert { | |||||
| public static void assertNotContains(String needle, String haystack) { | public static void assertNotContains(String needle, String haystack) { | ||||
| assertNotContains("", needle, haystack); | assertNotContains("", needle, haystack); | ||||
| } | } | ||||
| } | } | ||||
| @@ -44,7 +44,7 @@ import org.junit.Test; | |||||
| * | * | ||||
| */ | */ | ||||
| public class AntClassLoaderTest { | public class AntClassLoaderTest { | ||||
| @Rule | @Rule | ||||
| public BuildFileRule buildRule = new BuildFileRule(); | public BuildFileRule buildRule = new BuildFileRule(); | ||||
| @@ -62,7 +62,7 @@ public class AntClassLoaderTest { | |||||
| loader.cleanup(); | loader.cleanup(); | ||||
| } | } | ||||
| } | } | ||||
| //test inspired by bug report 37085 | //test inspired by bug report 37085 | ||||
| @Test | @Test | ||||
| public void testJarWithManifestInDirWithSpace() { | public void testJarWithManifestInDirWithSpace() { | ||||
| @@ -75,7 +75,7 @@ public class AntClassLoaderTest { | |||||
| String path = loader.getClasspath(); | String path = loader.getClasspath(); | ||||
| assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testJarWithManifestInNonAsciiDir() { | public void testJarWithManifestInNonAsciiDir() { | ||||
| String mainjarstring = buildRule.getProject().getProperty("main.jar.nonascii"); | String mainjarstring = buildRule.getProject().getProperty("main.jar.nonascii"); | ||||
| @@ -87,7 +87,7 @@ public class AntClassLoaderTest { | |||||
| String path = loader.getClasspath(); | String path = loader.getClasspath(); | ||||
| assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testCleanup() throws BuildException { | public void testCleanup() throws BuildException { | ||||
| Path path = new Path(buildRule.getProject(), "."); | Path path = new Path(buildRule.getProject(), "."); | ||||
| @@ -61,14 +61,14 @@ import org.junit.rules.ExternalResource; | |||||
| */ | */ | ||||
| public class BuildFileRule extends ExternalResource { | public class BuildFileRule extends ExternalResource { | ||||
| private Project project; | |||||
| private Project project; | |||||
| private StringBuffer logBuffer; | private StringBuffer logBuffer; | ||||
| private StringBuffer fullLogBuffer; | private StringBuffer fullLogBuffer; | ||||
| private StringBuffer outputBuffer; | private StringBuffer outputBuffer; | ||||
| private StringBuffer errorBuffer; | private StringBuffer errorBuffer; | ||||
| /** | /** | ||||
| * Tidies up following a test execution. If the currently configured | * Tidies up following a test execution. If the currently configured | ||||
| @@ -313,6 +313,5 @@ public class BuildFileRule extends ExternalResource { | |||||
| public File getOutputDir() { | public File getOutputDir() { | ||||
| return new File(getProject().getProperty("output")); | return new File(getProject().getProperty("output")); | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -29,9 +29,9 @@ import static org.junit.Assert.fail; | |||||
| * Simple tests of build file processing | * Simple tests of build file processing | ||||
| */ | */ | ||||
| public class CaseTest { | public class CaseTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| @@ -53,12 +53,11 @@ public class CaseTest { | |||||
| */ | */ | ||||
| @Test | @Test | ||||
| public void testTaskCase() { | public void testTaskCase() { | ||||
| try { | |||||
| buildRule.executeTarget("taskcase"); | |||||
| fail("Build exception should have been thrown due to case sensitivity of name"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("Task names should be case sensitive", "Problem: failed to create task or type ecHO", ex.getMessage()); | |||||
| } | |||||
| try { | |||||
| buildRule.executeTarget("taskcase"); | |||||
| fail("Build exception should have been thrown due to case sensitivity of name"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("Task names should be case sensitive", "Problem: failed to create task or type ecHO", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -44,9 +44,9 @@ import org.junit.Test; | |||||
| */ | */ | ||||
| public class DirectoryScannerTest { | public class DirectoryScannerTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| // keep track of what operating systems are supported here. | // keep track of what operating systems are supported here. | ||||
| private boolean supportsSymlinks = Os.isFamily("unix"); | private boolean supportsSymlinks = Os.isFamily("unix"); | ||||
| @@ -121,8 +121,8 @@ public class DirectoryScannerTest { | |||||
| @Test | @Test | ||||
| public void testAllowSymlinks() { | public void testAllowSymlinks() { | ||||
| assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||||
| assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||||
| buildRule.getProject().executeTarget("symlink-setup"); | buildRule.getProject().executeTarget("symlink-setup"); | ||||
| DirectoryScanner ds = new DirectoryScanner(); | DirectoryScanner ds = new DirectoryScanner(); | ||||
| @@ -135,7 +135,7 @@ public class DirectoryScannerTest { | |||||
| @Test | @Test | ||||
| public void testProhibitSymlinks() { | public void testProhibitSymlinks() { | ||||
| assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||||
| assumeTrue("Current system does not support Symlinks", supportsSymlinks); | |||||
| buildRule.getProject().executeTarget("symlink-setup"); | buildRule.getProject().executeTarget("symlink-setup"); | ||||
| @@ -244,14 +244,14 @@ public class DirectoryScannerTest { | |||||
| * Only supports test on Linux at the moment because Java has | * Only supports test on Linux at the moment because Java has | ||||
| * no real notion of symlinks built in, so an os-specfic call | * no real notion of symlinks built in, so an os-specfic call | ||||
| * to Runtime.exec() must be made to create a link to test against. | * to Runtime.exec() must be made to create a link to test against. | ||||
| * @throws InterruptedException | |||||
| * @throws InterruptedException | |||||
| */ | */ | ||||
| @Test | @Test | ||||
| public void testSetFollowLinks() throws IOException, InterruptedException { | public void testSetFollowLinks() throws IOException, InterruptedException { | ||||
| if (supportsSymlinks) { | if (supportsSymlinks) { | ||||
| File linkFile = new File(System.getProperty("root"), "src/main/org/apache/tools/ThisIsALink"); | File linkFile = new File(System.getProperty("root"), "src/main/org/apache/tools/ThisIsALink"); | ||||
| System.err.println("link exists pre-test? " + linkFile.exists()); | System.err.println("link exists pre-test? " + linkFile.exists()); | ||||
| try { | try { | ||||
| // add conditions and more commands as soon as the need arises | // add conditions and more commands as soon as the need arises | ||||
| String[] command = new String[] { | String[] command = new String[] { | ||||
| @@ -26,8 +26,8 @@ import org.junit.Test; | |||||
| public class DispatchTaskTest { | public class DispatchTaskTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| @@ -37,10 +37,10 @@ public class DispatchTaskTest { | |||||
| @Test | @Test | ||||
| public void testDisp() { | public void testDisp() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("disp"); | |||||
| fail("BuildException should have been thrown"); | |||||
| buildRule.executeTarget("disp"); | |||||
| fail("BuildException should have been thrown"); | |||||
| } catch(BuildException ex) { | } catch(BuildException ex) { | ||||
| //FIXME the previous method used here ignored the build exception - what are we trying to test | |||||
| //FIXME the previous method used here ignored the build exception - what are we trying to test | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -31,22 +31,22 @@ import org.junit.Test; | |||||
| * Executor tests | * Executor tests | ||||
| */ | */ | ||||
| public class ExecutorTest implements BuildListener { | public class ExecutorTest implements BuildListener { | ||||
| private static final String SINGLE_CHECK | |||||
| private static final String SINGLE_CHECK | |||||
| = "org.apache.tools.ant.helper.SingleCheckExecutor"; | = "org.apache.tools.ant.helper.SingleCheckExecutor"; | ||||
| private static final String IGNORE_DEPS | private static final String IGNORE_DEPS | ||||
| = "org.apache.tools.ant.helper.IgnoreDependenciesExecutor"; | = "org.apache.tools.ant.helper.IgnoreDependenciesExecutor"; | ||||
| private static final Vector<String> TARGET_NAMES; | private static final Vector<String> TARGET_NAMES; | ||||
| static { | static { | ||||
| TARGET_NAMES = new Vector<String>(); | TARGET_NAMES = new Vector<String>(); | ||||
| TARGET_NAMES.add("a"); | TARGET_NAMES.add("a"); | ||||
| TARGET_NAMES.add("b"); | TARGET_NAMES.add("b"); | ||||
| } | } | ||||
| @Rule | @Rule | ||||
| public BuildFileRule buildRule = new BuildFileRule(); | public BuildFileRule buildRule = new BuildFileRule(); | ||||
| private int targetCount; | private int targetCount; | ||||
| /* BuildListener stuff */ | /* BuildListener stuff */ | ||||
| @@ -168,4 +168,3 @@ public class ExecutorTest implements BuildListener { | |||||
| } | } | ||||
| } | } | ||||
| @@ -32,10 +32,10 @@ import org.junit.Test; | |||||
| public class ExtendedTaskdefTest { | public class ExtendedTaskdefTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/core/extended-taskdef.xml"); | buildRule.configureProject("src/etc/testcases/core/extended-taskdef.xml"); | ||||
| } | } | ||||
| @@ -47,22 +47,22 @@ public class ExtendedTaskdefTest { | |||||
| @Test | @Test | ||||
| public void testRun() throws Exception { | public void testRun() throws Exception { | ||||
| try { | |||||
| buildRule.executeTarget("testRun"); | |||||
| fail("BuildException should have been thrown"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||||
| } | |||||
| try { | |||||
| buildRule.executeTarget("testRun"); | |||||
| fail("BuildException should have been thrown"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testRun2() throws Exception { | public void testRun2() throws Exception { | ||||
| try { | |||||
| buildRule.executeTarget("testRun2"); | |||||
| fail("BuildException should have been thrown"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||||
| } | |||||
| try { | |||||
| buildRule.executeTarget("testRun2"); | |||||
| fail("BuildException should have been thrown"); | |||||
| } catch(BuildException ex) { | |||||
| assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -31,9 +31,9 @@ import org.junit.Test; | |||||
| * | * | ||||
| */ | */ | ||||
| public class IncludeTest { | public class IncludeTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| @@ -29,10 +29,10 @@ import org.junit.Test; | |||||
| */ | */ | ||||
| public class LoaderRefTest { | public class LoaderRefTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/core/loaderref/loaderref.xml"); | buildRule.configureProject("src/etc/testcases/core/loaderref/loaderref.xml"); | ||||
| buildRule.executeTarget("setUp"); | buildRule.executeTarget("setUp"); | ||||
| @@ -40,13 +40,12 @@ public class LoaderRefTest { | |||||
| // override allowed on <available> | // override allowed on <available> | ||||
| @Test | @Test | ||||
| public void testBadRef() { | |||||
| try { | |||||
| buildRule.executeTarget("testbadref"); | |||||
| fail("BuildRule should have thrown an exception due to a bad classloader being specified"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("Should fail due to ref not being a class loader", "does not reference a class loader", ex.getMessage()); | |||||
| } | |||||
| public void testBadRef() { | |||||
| try { | |||||
| buildRule.executeTarget("testbadref"); | |||||
| fail("BuildRule should have thrown an exception due to a bad classloader being specified"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("Should fail due to ref not being a class loader", "does not reference a class loader", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -37,12 +37,12 @@ import org.junit.Test; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class TokenFilterTest { | public class TokenFilterTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); | buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); | ||||
| @@ -57,20 +57,20 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testTrimignore() throws IOException { | public void testTrimignore() throws IOException { | ||||
| buildRule.executeTarget("trimignore"); | |||||
| assertContains("Hello-World", buildRule.getLog()); | |||||
| buildRule.executeTarget("trimignore"); | |||||
| assertContains("Hello-World", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testStringTokenizer() throws IOException { | public void testStringTokenizer() throws IOException { | ||||
| buildRule.executeTarget("stringtokenizer"); | |||||
| buildRule.executeTarget("stringtokenizer"); | |||||
| assertContains("#This#is#a#number#of#words#", buildRule.getLog()); | assertContains("#This#is#a#number#of#words#", buildRule.getLog()); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testUnixLineOutput() throws IOException { | public void testUnixLineOutput() throws IOException { | ||||
| buildRule.executeTarget("unixlineoutput"); | |||||
| assertContains("\nThis\nis\na\nnumber\nof\nwords\n", | |||||
| buildRule.executeTarget("unixlineoutput"); | |||||
| assertContains("\nThis\nis\na\nnumber\nof\nwords\n", | |||||
| getFileString(buildRule.getProject().getProperty("output") + "/unixlineoutput")); | getFileString(buildRule.getProject().getProperty("output") + "/unixlineoutput")); | ||||
| } | } | ||||
| @@ -84,7 +84,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testFileTokenizer() throws IOException { | public void testFileTokenizer() throws IOException { | ||||
| buildRule.executeTarget("filetokenizer"); | |||||
| buildRule.executeTarget("filetokenizer"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/filetokenizer"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/filetokenizer"); | ||||
| assertContains(" of words", contents); | assertContains(" of words", contents); | ||||
| assertNotContains(" This is", contents); | assertNotContains(" This is", contents); | ||||
| @@ -92,20 +92,20 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testReplaceString() throws IOException { | public void testReplaceString() throws IOException { | ||||
| buildRule.executeTarget("replacestring"); | |||||
| assertContains("this is the moon", | |||||
| buildRule.executeTarget("replacestring"); | |||||
| assertContains("this is the moon", | |||||
| getFileString(buildRule.getProject().getProperty("output") + "/replacestring")); | getFileString(buildRule.getProject().getProperty("output") + "/replacestring")); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testReplaceStrings() throws IOException { | public void testReplaceStrings() throws IOException { | ||||
| buildRule.executeTarget("replacestrings"); | |||||
| assertContains("bar bar bar", buildRule.getLog()); | |||||
| buildRule.executeTarget("replacestrings"); | |||||
| assertContains("bar bar bar", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testContainsString() throws IOException { | public void testContainsString() throws IOException { | ||||
| buildRule.executeTarget("containsstring"); | |||||
| buildRule.executeTarget("containsstring"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsstring"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsstring"); | ||||
| assertContains("this is a line contains foo", contents); | assertContains("this is a line contains foo", contents); | ||||
| assertNotContains("this line does not", contents); | assertNotContains("this line does not", contents); | ||||
| @@ -114,7 +114,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testReplaceRegex() throws IOException { | public void testReplaceRegex() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", | Assume.assumeTrue("Regex not present", | ||||
| getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| @@ -130,7 +130,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testFilterReplaceRegex() throws IOException { | public void testFilterReplaceRegex() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", | Assume.assumeTrue("Regex not present", | ||||
| getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| @@ -142,7 +142,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testHandleDollerMatch() throws IOException { | public void testHandleDollerMatch() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| buildRule.executeTarget("dollermatch"); | buildRule.executeTarget("dollermatch"); | ||||
| @@ -150,7 +150,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testTrimFile() throws IOException { | public void testTrimFile() throws IOException { | ||||
| buildRule.executeTarget("trimfile"); | |||||
| buildRule.executeTarget("trimfile"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfile"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfile"); | ||||
| assertTrue("no ws at start", contents.startsWith("This is th")); | assertTrue("no ws at start", contents.startsWith("This is th")); | ||||
| assertTrue("no ws at end", contents.endsWith("second line.")); | assertTrue("no ws at end", contents.endsWith("second line.")); | ||||
| @@ -159,7 +159,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testTrimFileByLine() throws IOException { | public void testTrimFileByLine() throws IOException { | ||||
| buildRule.executeTarget("trimfilebyline"); | |||||
| buildRule.executeTarget("trimfilebyline"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfilebyline"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfilebyline"); | ||||
| assertFalse("no ws at start", contents.startsWith("This is th")); | assertFalse("no ws at start", contents.startsWith("This is th")); | ||||
| assertFalse("no ws at end", contents.endsWith("second line.")); | assertFalse("no ws at end", contents.endsWith("second line.")); | ||||
| @@ -169,20 +169,20 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testFilterReplaceString() throws IOException { | public void testFilterReplaceString() throws IOException { | ||||
| buildRule.executeTarget("filterreplacestring"); | |||||
| buildRule.executeTarget("filterreplacestring"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplacestring"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplacestring"); | ||||
| assertContains("This is the moon", contents); | assertContains("This is the moon", contents); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testFilterReplaceStrings() throws IOException { | public void testFilterReplaceStrings() throws IOException { | ||||
| buildRule.executeTarget("filterreplacestrings"); | |||||
| assertContains("bar bar bar", buildRule.getLog()); | |||||
| buildRule.executeTarget("filterreplacestrings"); | |||||
| assertContains("bar bar bar", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testContainsRegex() throws IOException { | public void testContainsRegex() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| //expectFileContains(buildRule.getProject().getProperty("output") + "/replaceregexp", "bye world"); | //expectFileContains(buildRule.getProject().getProperty("output") + "/replaceregexp", "bye world"); | ||||
| @@ -196,7 +196,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testFilterContainsRegex() throws IOException { | public void testFilterContainsRegex() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| buildRule.executeTarget("filtercontainsregex"); | buildRule.executeTarget("filtercontainsregex"); | ||||
| @@ -208,9 +208,9 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testContainsRegex2() throws IOException { | public void testContainsRegex2() throws IOException { | ||||
| buildRule.executeTarget("hasregex"); | |||||
| buildRule.executeTarget("hasregex"); | |||||
| Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); | ||||
| buildRule.executeTarget("containsregex2"); | buildRule.executeTarget("containsregex2"); | ||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"); | ||||
| assertContains("void register_bits();", contents); | assertContains("void register_bits();", contents); | ||||
| @@ -218,7 +218,7 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testDeleteCharacters() throws IOException { | public void testDeleteCharacters() throws IOException { | ||||
| buildRule.executeTarget("deletecharacters"); | |||||
| buildRule.executeTarget("deletecharacters"); | |||||
| String contents = getFileString(buildRule.getProject().getProperty("output") + "/deletechars"); | String contents = getFileString(buildRule.getProject().getProperty("output") + "/deletechars"); | ||||
| assertNotContains("#", contents); | assertNotContains("#", contents); | ||||
| assertNotContains("*", contents); | assertNotContains("*", contents); | ||||
| @@ -227,24 +227,24 @@ public class TokenFilterTest { | |||||
| @Test | @Test | ||||
| public void testScriptFilter() throws IOException { | public void testScriptFilter() throws IOException { | ||||
| Assume.assumeTrue("Project does not have 'testScriptFilter' target", | |||||
| Assume.assumeTrue("Project does not have 'testScriptFilter' target", | |||||
| buildRule.getProject().getTargets().contains("testScriptFilter")); | buildRule.getProject().getTargets().contains("testScriptFilter")); | ||||
| buildRule.executeTarget("scriptfilter"); | |||||
| assertContains("HELLO WORLD", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter")); | |||||
| buildRule.executeTarget("scriptfilter"); | |||||
| assertContains("HELLO WORLD", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testScriptFilter2() throws IOException { | public void testScriptFilter2() throws IOException { | ||||
| Assume.assumeTrue("Project does not have 'testScriptFilter' target", buildRule.getProject().getTargets().contains("testScriptFilter")); | |||||
| Assume.assumeTrue("Project does not have 'testScriptFilter' target", buildRule.getProject().getTargets().contains("testScriptFilter")); | |||||
| buildRule.executeTarget("scriptfilter2"); | buildRule.executeTarget("scriptfilter2"); | ||||
| assertContains("HELLO MOON", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2")); | |||||
| assertContains("HELLO MOON", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testCustomTokenFilter() throws IOException { | public void testCustomTokenFilter() throws IOException { | ||||
| buildRule.executeTarget("customtokenfilter"); | buildRule.executeTarget("customtokenfilter"); | ||||
| assertContains("Hello World", getFileString(buildRule.getProject().getProperty("output") + "/custom")); | |||||
| assertContains("Hello World", getFileString(buildRule.getProject().getProperty("output") + "/custom")); | |||||
| } | } | ||||
| // ------------------------------------------------------ | // ------------------------------------------------------ | ||||
| @@ -32,9 +32,9 @@ import org.junit.Test; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class DirnameTest { | public class DirnameTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| @@ -43,32 +43,32 @@ public class DirnameTest { | |||||
| @Test | @Test | ||||
| public void test1() { | 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()); | |||||
| } | |||||
| 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 | @Test | ||||
| public void test2() { | 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()); | |||||
| } | |||||
| 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 | @Test | ||||
| public void test3() { | 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()); | |||||
| } | |||||
| 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 | @Test | ||||
| @@ -39,10 +39,10 @@ import org.junit.Test; | |||||
| * Unit test for the <exec> task. | * Unit test for the <exec> task. | ||||
| */ | */ | ||||
| public class ExecTaskTest { | public class ExecTaskTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| private static final String BUILD_PATH = "src/etc/testcases/taskdefs/exec/"; | private static final String BUILD_PATH = "src/etc/testcases/taskdefs/exec/"; | ||||
| private static final String BUILD_FILE = BUILD_PATH + "exec.xml"; | private static final String BUILD_FILE = BUILD_PATH + "exec.xml"; | ||||
| private static final int TIME_TO_WAIT = 1; | private static final int TIME_TO_WAIT = 1; | ||||
| @@ -31,7 +31,7 @@ import static org.junit.Assert.fail; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class GzipTest { | public class GzipTest { | ||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @@ -44,41 +44,41 @@ public class GzipTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test4() { | public void test4() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: zipfile must not point to a directory"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: zipfile must not point to a directory"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -39,16 +39,16 @@ import org.junit.Test; | |||||
| public class ImportTest { | public class ImportTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Test | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Test | |||||
| public void testSimpleImport() { | public void testSimpleImport() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/import/import.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/import/import.xml"); | ||||
| assertContains("Before importIn imported topAfter import", buildRule.getLog()); | assertContains("Before importIn imported topAfter import", buildRule.getLog()); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testUnnamedNesting() { | public void testUnnamedNesting() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", | buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", | ||||
| Project.MSG_WARN); | Project.MSG_WARN); | ||||
| @@ -57,17 +57,17 @@ public class ImportTest { | |||||
| log.length() == 0); | log.length() == 0); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testSerial() { | public void testSerial() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); | ||||
| assertContains("Unnamed2.xmlUnnamed1.xml", buildRule.getLog()); | assertContains("Unnamed2.xmlUnnamed1.xml", buildRule.getLog()); | ||||
| assertContains("Expected string was not found in log", | assertContains("Expected string was not found in log", | ||||
| "Skipped already imported file", buildRule.getFullLog()); | |||||
| "Skipped already imported file", buildRule.getFullLog()); | |||||
| } | } | ||||
| // allow this as imported in targets are only tested when a target is run | // allow this as imported in targets are only tested when a target is run | ||||
| @Test | @Test | ||||
| public void testImportInTargetNoEffect() { | |||||
| public void testImportInTargetNoEffect() { | |||||
| buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | ||||
| buildRule.executeTarget("no-import"); | buildRule.executeTarget("no-import"); | ||||
| assertNull(buildRule.getProject().getProperty("foo")); | assertNull(buildRule.getProject().getProperty("foo")); | ||||
| @@ -88,10 +88,10 @@ public class ImportTest { | |||||
| buildRule.configureProject( | buildRule.configureProject( | ||||
| "src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | "src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); | ||||
| try { | try { | ||||
| buildRule.executeTarget("do-import"); | |||||
| fail("Build exception should have been thrown as import only allowed in top level task"); | |||||
| buildRule.executeTarget("do-import"); | |||||
| fail("Build exception should have been thrown as import only allowed in top level task"); | |||||
| } catch(BuildException ex) { | } catch(BuildException ex) { | ||||
| assertContains( "not a top level task", "import only allowed as a top-level task", ex.getMessage()); | |||||
| assertContains( "not a top level task", "import only allowed as a top-level task", ex.getMessage()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -111,7 +111,7 @@ public class ImportTest { | |||||
| "src/etc/testcases/taskdefs/import/same_target.xml"); | "src/etc/testcases/taskdefs/import/same_target.xml"); | ||||
| fail("Expected build exception"); | fail("Expected build exception"); | ||||
| } catch (BuildException ex) { | } catch (BuildException ex) { | ||||
| assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); | |||||
| assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -48,7 +48,7 @@ import static org.junit.Assert.fail; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class JarTest { | public class JarTest { | ||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @@ -56,7 +56,7 @@ public class JarTest { | |||||
| private static String tempDir = "jartmp/"; | private static String tempDir = "jartmp/"; | ||||
| private Reader r1, r2; | private Reader r1, r2; | ||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); | ||||
| @@ -82,31 +82,31 @@ public class JarTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: manifest file does not exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: manifest file does not exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: Unrecognized whenempty attribute: format C: /y"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: Unrecognized whenempty attribute: format C: /y"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| private File getOutputDir() { | private File getOutputDir() { | ||||
| @@ -329,17 +329,17 @@ public class JarTest { | |||||
| public void testIndexJarsPlusJarMarker() { | public void testIndexJarsPlusJarMarker() { | ||||
| buildRule.executeTarget("testIndexJarsPlusJarMarker"); | buildRule.executeTarget("testIndexJarsPlusJarMarker"); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoVersionInfoFail() { | public void testNoVersionInfoFail() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoVersionInfoFail"); | |||||
| fail("BuildException expected: Manifest Implemention information missing."); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("No Implementation-Title set.", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testNoVersionInfoFail"); | |||||
| fail("BuildException expected: Manifest Implemention information missing."); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("No Implementation-Title set.", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoVersionInfoIgnore() { | public void testNoVersionInfoIgnore() { | ||||
| buildRule.executeTarget("testNoVersionInfoIgnore"); | buildRule.executeTarget("testNoVersionInfoIgnore"); | ||||
| @@ -363,7 +363,7 @@ public class JarTest { | |||||
| assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | ||||
| assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testHasVersionInfo() { | public void testHasVersionInfo() { | ||||
| buildRule.executeTarget("testHasVersionInfo"); | buildRule.executeTarget("testHasVersionInfo"); | ||||
| @@ -371,5 +371,5 @@ public class JarTest { | |||||
| assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); | ||||
| assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -37,7 +37,7 @@ public class LoadFileTest { | |||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| @@ -57,11 +57,11 @@ public class LoadFileTest { | |||||
| @Test | @Test | ||||
| public void testNoSourcefileDefined() { | public void testNoSourcefileDefined() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoSourcefileDefined"); | |||||
| fail("BuildException expected: source file not defined"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("testNoSourcefileDefined"); | |||||
| fail("BuildException expected: source file not defined"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @@ -71,11 +71,11 @@ public class LoadFileTest { | |||||
| @Test | @Test | ||||
| public void testNoPropertyDefined() { | public void testNoPropertyDefined() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoPropertyDefined"); | |||||
| fail("BuildException expected: output property not defined"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("testNoPropertyDefined"); | |||||
| fail("BuildException expected: output property not defined"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @@ -85,11 +85,11 @@ public class LoadFileTest { | |||||
| @Test | @Test | ||||
| public void testNoSourcefilefound() { | public void testNoSourcefilefound() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoSourcefilefound"); | |||||
| fail("BuildException expected: File not found"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains(" doesn't exist", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testNoSourcefilefound"); | |||||
| fail("BuildException expected: File not found"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains(" doesn't exist", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -99,7 +99,7 @@ public class LoadFileTest { | |||||
| public void testFailOnError() | public void testFailOnError() | ||||
| throws BuildException { | throws BuildException { | ||||
| buildRule.executeTarget("testFailOnError"); | buildRule.executeTarget("testFailOnError"); | ||||
| assertNull(buildRule.getProject().getProperty("testFailOnError")); | |||||
| assertNull(buildRule.getProject().getProperty("testFailOnError")); | |||||
| } | } | ||||
| @@ -43,114 +43,114 @@ public class MacroDefTest { | |||||
| @Test | @Test | ||||
| public void testSimple() { | public void testSimple() { | ||||
| buildRule.executeTarget("simple"); | buildRule.executeTarget("simple"); | ||||
| assertEquals("Hello World", buildRule.getLog()); | |||||
| assertEquals("Hello World", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testText() { | public void testText() { | ||||
| buildRule.executeTarget("text"); | buildRule.executeTarget("text"); | ||||
| assertEquals("Inner Text", buildRule.getLog()); | |||||
| assertEquals("Inner Text", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDuplicateAttribute() { | public void testDuplicateAttribute() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("duplicate.attribute"); | |||||
| fail("BuildException expected: the attribute text has already been specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("duplicate.attribute"); | |||||
| fail("BuildException expected: the attribute text has already been specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDuplicateElement() { | public void testDuplicateElement() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("duplicate.element"); | |||||
| fail("BuildException expected: the element text has already been specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("duplicate.element"); | |||||
| fail("BuildException expected: the element text has already been specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testUri() { | public void testUri() { | ||||
| buildRule.executeTarget("uri"); | buildRule.executeTarget("uri"); | ||||
| assertEquals("Hello World", buildRule.getLog()); | |||||
| assertEquals("Hello World", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNested() { | public void testNested() { | ||||
| buildRule.executeTarget("nested"); | buildRule.executeTarget("nested"); | ||||
| assertEquals("A nested element", buildRule.getLog()); | |||||
| assertEquals("A nested element", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDouble() { | public void testDouble() { | ||||
| buildRule.executeTarget("double"); | buildRule.executeTarget("double"); | ||||
| assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog()); | |||||
| assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testIgnoreCase() { | public void testIgnoreCase() { | ||||
| buildRule.executeTarget("ignorecase"); | buildRule.executeTarget("ignorecase"); | ||||
| assertEquals("a is ab is b", buildRule.getLog()); | |||||
| assertEquals("a is ab is b", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testIgnoreElementCase() { | public void testIgnoreElementCase() { | ||||
| buildRule.executeTarget("ignore-element-case"); | buildRule.executeTarget("ignore-element-case"); | ||||
| assertEquals("nested elementnested element", buildRule.getLog()); | |||||
| assertEquals("nested elementnested element", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testTextElement() { | public void testTextElement() { | ||||
| buildRule.executeTarget("textelement"); | buildRule.executeTarget("textelement"); | ||||
| assertContains("Hello world", buildRule.getLog()); | |||||
| assertContains("Hello world", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testTextTrim() { | public void testTextTrim() { | ||||
| buildRule.executeTarget("text.trim"); | buildRule.executeTarget("text.trim"); | ||||
| assertContains("[Hello world]", buildRule.getLog()); | |||||
| assertContains("[Hello world]", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDuplicateTextName() { | public void testDuplicateTextName() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("duplicatetextname"); | |||||
| fail("BuildException expected: the name \"text\" is already used as an attribute"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("duplicatetextname"); | |||||
| fail("BuildException expected: the name \"text\" is already used as an attribute"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDuplicateTextName2() { | public void testDuplicateTextName2() { | ||||
| try { | 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 | |||||
| } | |||||
| 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 | @Test | ||||
| public void testEscape() { | public void testEscape() { | ||||
| buildRule.executeTarget("escape"); | buildRule.executeTarget("escape"); | ||||
| assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog()); | |||||
| assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testAttributeDescription() { | public void testAttributeDescription() { | ||||
| buildRule.executeTarget("attribute.description"); | buildRule.executeTarget("attribute.description"); | ||||
| assertEquals("description is hello world", buildRule.getLog()); | |||||
| assertEquals("description is hello world", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testOverrideDefault() { | public void testOverrideDefault() { | ||||
| buildRule.executeTarget("override.default"); | buildRule.executeTarget("override.default"); | ||||
| assertEquals("value is new", buildRule.getLog()); | |||||
| assertEquals("value is new", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testImplicit() { | public void testImplicit() { | ||||
| buildRule.executeTarget("implicit"); | buildRule.executeTarget("implicit"); | ||||
| assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog()); | |||||
| assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testImplicitNotOptional() { | public void testImplicitNotOptional() { | ||||
| @@ -164,7 +164,7 @@ public class MacroDefTest { | |||||
| @Test | @Test | ||||
| public void testImplicitOptional() { | public void testImplicitOptional() { | ||||
| buildRule.executeTarget("implicit.optional"); | buildRule.executeTarget("implicit.optional"); | ||||
| assertEquals("Before implicitAfter implicit", buildRule.getLog()); | |||||
| assertEquals("Before implicitAfter implicit", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testImplicitExplicit() { | public void testImplicitExplicit() { | ||||
| @@ -200,7 +200,6 @@ public class MacroDefTest { | |||||
| @Test | @Test | ||||
| public void testTopLevelText() { | public void testTopLevelText() { | ||||
| buildRule.executeTarget("top-level-text"); | buildRule.executeTarget("top-level-text"); | ||||
| assertContains("Hello World", buildRule.getLog()); | |||||
| assertContains("Hello World", buildRule.getLog()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -46,41 +46,41 @@ public class MakeUrlTest { | |||||
| @Test | @Test | ||||
| public void testEmpty() { | public void testEmpty() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testEmpty"); | |||||
| fail("BuildException expected: missing property"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("property", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testEmpty"); | |||||
| fail("BuildException expected: missing property"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("property", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoProperty() { | public void testNoProperty() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoProperty"); | |||||
| fail("BuildException expected: missing property"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("property", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testNoProperty"); | |||||
| fail("BuildException expected: missing property"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("property", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoFile() { | public void testNoFile() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testNoFile"); | |||||
| fail("BuildException expected: missing file"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("file", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testNoFile"); | |||||
| fail("BuildException expected: missing file"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("file", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testValidation() { | public void testValidation() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testValidation"); | |||||
| fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("file", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("testValidation"); | |||||
| fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("file", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -39,71 +39,71 @@ import org.junit.Test; | |||||
| * Tests <bm:manifestclasspath>. | * Tests <bm:manifestclasspath>. | ||||
| */ | */ | ||||
| public class ManifestClassPathTest { | public class ManifestClassPathTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testBadDirectory() { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("jar.classpath")); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testBadNoProperty() { | public void testBadNoProperty() { | ||||
| try { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("jar.classpath")); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testBadPropertyExists() { | public void testBadPropertyExists() { | ||||
| try { | 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()); | |||||
| } | |||||
| 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"); | assertEquals(buildRule.getProject().getProperty("jar.classpath"), "exists"); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testBadNoJarfile() { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("jar.classpath")); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testBadNoClassPath() { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("jar.classpath")); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testParentLevel1() { | public void testParentLevel1() { | ||||
| buildRule.executeTarget("test-parent-level1"); | buildRule.executeTarget("test-parent-level1"); | ||||
| @@ -118,7 +118,7 @@ public class ManifestClassPathTest { | |||||
| "../resources/dsp-void/"); | "../resources/dsp-void/"); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testParentLevel2() { | public void testParentLevel2() { | ||||
| buildRule.executeTarget("test-parent-level2"); | buildRule.executeTarget("test-parent-level2"); | ||||
| @@ -133,21 +133,21 @@ public class ManifestClassPathTest { | |||||
| "../../resources/dsp-void/"); | "../../resources/dsp-void/"); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testParentLevel2TooDeep() { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("jar.classpath")); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testPseudoTahoeRefid() { | public void testPseudoTahoeRefid() { | ||||
| Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); | Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); | ||||
| buildRule.executeTarget("test-pseudo-tahoe-refid"); | buildRule.executeTarget("test-pseudo-tahoe-refid"); | ||||
| assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + | assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + | ||||
| "classes/dsp-pres/ " + | "classes/dsp-pres/ " + | ||||
| @@ -159,9 +159,9 @@ public class ManifestClassPathTest { | |||||
| @Test | @Test | ||||
| public void testPseudoTahoeNested() { | public void testPseudoTahoeNested() { | ||||
| Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); | |||||
| buildRule.executeTarget("test-pseudo-tahoe-nested"); | |||||
| 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/ " + | assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + | ||||
| "classes/dsp-pres/ " + | "classes/dsp-pres/ " + | ||||
| "classes/dsp-void/ " + | "classes/dsp-void/ " + | ||||
| @@ -186,7 +186,7 @@ public class ManifestClassPathTest { | |||||
| "../../resources/dsp-pres/ " + | "../../resources/dsp-pres/ " + | ||||
| "../../resources/dsp-void/"); | "../../resources/dsp-void/"); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testInternationalGerman() { | public void testInternationalGerman() { | ||||
| buildRule.executeTarget("international-german"); | buildRule.executeTarget("international-german"); | ||||
| @@ -194,10 +194,10 @@ public class ManifestClassPathTest { | |||||
| assertContains("beta alpha", buildRule.getLog()); | assertContains("beta alpha", buildRule.getLog()); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testInternationalHebrew() { | public void testInternationalHebrew() { | ||||
| Assume.assumeFalse("Test with hebrew path not attempted under Windows", Os.isFamily("windows")); | |||||
| Assume.assumeFalse("Test with hebrew path not attempted under Windows", Os.isFamily("windows")); | |||||
| buildRule.executeTarget("international-hebrew"); | buildRule.executeTarget("international-hebrew"); | ||||
| buildRule.executeTarget("run-two-jars"); | buildRule.executeTarget("run-two-jars"); | ||||
| assertContains("beta alpha", buildRule.getLog()); | assertContains("beta alpha", buildRule.getLog()); | ||||
| @@ -212,7 +212,7 @@ public class ManifestClassPathTest { | |||||
| @Test | @Test | ||||
| public void testDifferentWindowsDrive() { | public void testDifferentWindowsDrive() { | ||||
| Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows")); | |||||
| 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 | // 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 C will try to use D | ||||
| // if the temp dir is on D or other will try to use C | // if the temp dir is on D or other will try to use C | ||||
| @@ -233,17 +233,17 @@ public class ManifestClassPathTest { | |||||
| } | } | ||||
| new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); | new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); | ||||
| } catch (java.io.IOException e) { | } catch (java.io.IOException e) { | ||||
| Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e); | |||||
| Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e); | |||||
| } | } | ||||
| buildRule.getProject().setProperty("altDriveLetter", altDriveLetter); | buildRule.getProject().setProperty("altDriveLetter", altDriveLetter); | ||||
| try { | 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()); | |||||
| } | |||||
| 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")); | assertNull(buildRule.getProject().getProperty("cp")); | ||||
| } | } | ||||
| } // END class ManifestClassPathTest | |||||
| } | |||||
| @@ -40,21 +40,21 @@ public class MkdirTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument missing"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: directory already exists as a file"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: directory already exists as a file"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -63,21 +63,21 @@ public class NiceTest { | |||||
| @Test | @Test | ||||
| public void testTooSlow() { | public void testTooSlow() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("too_slow"); | |||||
| fail("BuildException expected: out of range"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("out of the range 1-10", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("too_slow"); | |||||
| fail("BuildException expected: out of range"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("out of the range 1-10", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testTooFast() { | public void testTooFast() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("too_fast"); | |||||
| fail("BuildException expected: out of range"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("out of the range 1-10", ex.getMessage()); | |||||
| } | |||||
| buildRule.executeTarget("too_fast"); | |||||
| fail("BuildException expected: out of range"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("out of the range 1-10", ex.getMessage()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -33,10 +33,10 @@ import static org.junit.Assert.fail; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class PreSetDefTest { | public class PreSetDefTest { | ||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/presetdef.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/presetdef.xml"); | ||||
| @@ -45,55 +45,55 @@ public class PreSetDefTest { | |||||
| @Test | @Test | ||||
| public void testSimple() { | public void testSimple() { | ||||
| buildRule.executeTarget("simple"); | buildRule.executeTarget("simple"); | ||||
| assertEquals("Hello world", buildRule.getLog()); | |||||
| assertEquals("Hello world", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testText() { | public void testText() { | ||||
| buildRule.executeTarget("text"); | buildRule.executeTarget("text"); | ||||
| assertEquals("Inner Text", buildRule.getLog()); | |||||
| assertEquals("Inner Text", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testUri() { | public void testUri() { | ||||
| buildRule.executeTarget("uri"); | buildRule.executeTarget("uri"); | ||||
| assertEquals("Hello world", buildRule.getLog()); | |||||
| assertEquals("Hello world", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDefaultTest() { | public void testDefaultTest() { | ||||
| buildRule.executeTarget("defaulttest"); | buildRule.executeTarget("defaulttest"); | ||||
| assertEquals("attribute is false", buildRule.getLog()); | |||||
| assertEquals("attribute is false", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testDoubleDefault() { | public void testDoubleDefault() { | ||||
| buildRule.executeTarget("doubledefault"); | buildRule.executeTarget("doubledefault"); | ||||
| assertEquals("attribute is falseattribute is true", buildRule.getLog()); | |||||
| assertEquals("attribute is falseattribute is true", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testTextOptional() { | public void testTextOptional() { | ||||
| buildRule.executeTarget("text.optional"); | buildRule.executeTarget("text.optional"); | ||||
| assertEquals("MyTextoverride text", buildRule.getLog()); | |||||
| assertEquals("MyTextoverride text", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testElementOrder() { | public void testElementOrder() { | ||||
| buildRule.executeTarget("element.order"); | buildRule.executeTarget("element.order"); | ||||
| assertEquals("Line 1Line 2", buildRule.getLog()); | |||||
| assertEquals("Line 1Line 2", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testElementOrder2() { | public void testElementOrder2() { | ||||
| buildRule.executeTarget("element.order2"); | buildRule.executeTarget("element.order2"); | ||||
| assertEquals("Line 1Line 2Line 3", buildRule.getLog()); | |||||
| assertEquals("Line 1Line 2Line 3", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testAntTypeTest() { | public void testAntTypeTest() { | ||||
| buildRule.executeTarget("antTypeTest"); | buildRule.executeTarget("antTypeTest"); | ||||
| assertEquals("", buildRule.getLog()); | |||||
| assertEquals("", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -115,13 +115,13 @@ public class PreSetDefTest { | |||||
| assertContains("javac doesn't support the", ex.getMessage()); | assertContains("javac doesn't support the", ex.getMessage()); | ||||
| } | } | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testPresetdefWithNestedElementTwice() { // #38056 | public void testPresetdefWithNestedElementTwice() { // #38056 | ||||
| buildRule.executeTarget("presetdef-with-nested-element-twice"); | buildRule.executeTarget("presetdef-with-nested-element-twice"); | ||||
| buildRule.executeTarget("presetdef-with-nested-element-twice"); | buildRule.executeTarget("presetdef-with-nested-element-twice"); | ||||
| } | } | ||||
| /** | /** | ||||
| * A test class to check default properties | * A test class to check default properties | ||||
| */ | */ | ||||
| @@ -151,4 +151,3 @@ public class PreSetDefTest { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -34,9 +34,9 @@ import org.junit.Test; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class PropertyTest { | public class PropertyTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| /** Utilities used for file operations */ | /** Utilities used for file operations */ | ||||
| private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
| @@ -50,14 +50,14 @@ public class PropertyTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| // should get no output at all | // 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()); | |||||
| buildRule.executeTarget("test1"); | |||||
| assertEquals("System output should have been empty", "", buildRule.getOutput()); | |||||
| assertEquals("System error should have been empty", "", buildRule.getError()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| buildRule.executeTarget("test2"); | |||||
| buildRule.executeTarget("test2"); | |||||
| assertContains("testprop1=aa, testprop3=xxyy, testprop4=aazz", buildRule.getLog()); | assertContains("testprop1=aa, testprop3=xxyy, testprop4=aazz", buildRule.getLog()); | ||||
| } | } | ||||
| @@ -71,21 +71,21 @@ public class PropertyTest { | |||||
| assertTrue("Circular definition not detected - ", | assertTrue("Circular definition not detected - ", | ||||
| e.getMessage().indexOf("was circularly defined") != -1); | e.getMessage().indexOf("was circularly defined") != -1); | ||||
| } | } | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void test4() { | public void test4() { | ||||
| buildRule.executeTarget("test4"); | |||||
| assertContains("http.url is http://localhost:999", buildRule.getLog()); | |||||
| buildRule.executeTarget("test4"); | |||||
| assertContains("http.url is http://localhost:999", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test5() { | public void test5() { | ||||
| String baseDir = buildRule.getProject().getProperty("basedir"); | String baseDir = buildRule.getProject().getProperty("basedir"); | ||||
| String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); | |||||
| String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); | |||||
| buildRule.getProject().setNewProperty("test5.url", uri); | buildRule.getProject().setNewProperty("test5.url", uri); | ||||
| buildRule.executeTarget("test5"); | buildRule.executeTarget("test5"); | ||||
| assertContains("http.url is http://localhost:999", buildRule.getLog()); | assertContains("http.url is http://localhost:999", buildRule.getLog()); | ||||
| } | } | ||||
| @@ -103,7 +103,7 @@ public class PropertyTest { | |||||
| fail("Did not throw exception on invalid use of prefix"); | fail("Did not throw exception on invalid use of prefix"); | ||||
| } | } | ||||
| catch (BuildException e) { | catch (BuildException e) { | ||||
| assertContains("Prefix allowed on non-resource/file load - ", | |||||
| assertContains("Prefix allowed on non-resource/file load - ", | |||||
| "Prefix is only valid", e.getMessage()); | "Prefix is only valid", e.getMessage()); | ||||
| } | } | ||||
| } | } | ||||
| @@ -121,21 +121,21 @@ public class PropertyTest { | |||||
| @Test | @Test | ||||
| public void testThisIsNotACircularReference() { | public void testThisIsNotACircularReference() { | ||||
| buildRule.executeTarget("thisIsNotACircularReference"); | |||||
| buildRule.executeTarget("thisIsNotACircularReference"); | |||||
| assertContains("b is A/A/A", buildRule.getLog()); | assertContains("b is A/A/A", buildRule.getLog()); | ||||
| } | } | ||||
| @Test | @Test | ||||
| public void testXmlProperty() { | public void testXmlProperty() { | ||||
| try { | try { | ||||
| Class.forName("java.lang.Iterable"); | Class.forName("java.lang.Iterable"); | ||||
| } catch (ClassNotFoundException e) { | } catch (ClassNotFoundException e) { | ||||
| Assume.assumeNoException("XML Loading only on Java 5+", e); | |||||
| Assume.assumeNoException("XML Loading only on Java 5+", e); | |||||
| } | } | ||||
| buildRule.executeTarget("testXmlProperty"); | buildRule.executeTarget("testXmlProperty"); | ||||
| assertEquals("ONE", buildRule.getProject().getProperty("xml.one")); | assertEquals("ONE", buildRule.getProject().getProperty("xml.one")); | ||||
| assertEquals("TWO", buildRule.getProject().getProperty("xml.two")); | assertEquals("TWO", buildRule.getProject().getProperty("xml.two")); | ||||
| } | } | ||||
| } | } | ||||
| @@ -41,7 +41,7 @@ import static org.junit.Assume.assumeTrue; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class ReplaceTest { | public class ReplaceTest { | ||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @@ -54,41 +54,41 @@ public class ReplaceTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test4() { | public void test4() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: empty token not allowed"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: empty token not allowed"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -99,21 +99,21 @@ public class ReplaceTest { | |||||
| @Test | @Test | ||||
| public void test6() { | public void test6() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test6"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test6"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test7() { | public void test7() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test7"); | |||||
| fail("BuildException expected: empty token not allowed"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test7"); | |||||
| fail("BuildException expected: empty token not allowed"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -33,9 +33,9 @@ public class SleepTest { | |||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; | private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; | ||||
| private final static int ERROR_RANGE=1000; | |||||
| private final static int ERROR_RANGE=1000; | |||||
| @Before | @Before | ||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject(TASKDEFS_DIR + "sleep.xml"); | buildRule.configureProject(TASKDEFS_DIR + "sleep.xml"); | ||||
| @@ -117,4 +117,3 @@ public class SleepTest { | |||||
| } | } | ||||
| } | } | ||||
| @@ -103,7 +103,7 @@ public class TStampTest { | |||||
| @Test | @Test | ||||
| public void testFormatPrefix() throws Exception { | public void testFormatPrefix() throws Exception { | ||||
| Tstamp.CustomFormat format = tstamp.createFormat(); | |||||
| Tstamp.CustomFormat format = tstamp.createFormat(); | |||||
| format.setProperty("format"); | format.setProperty("format"); | ||||
| format.setPattern("HH:mm:ss z"); | format.setPattern("HH:mm:ss z"); | ||||
| format.setTimezone("GMT"); | format.setTimezone("GMT"); | ||||
| @@ -45,41 +45,41 @@ public class TarTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test4() { | public void test4() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: tar cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: tar cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -96,11 +96,11 @@ public class TarTest { | |||||
| @Test | @Test | ||||
| public void test6() { | public void test6() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test6"); | |||||
| fail("BuildException expected: Invalid value specified for longfile attribute."); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test6"); | |||||
| fail("BuildException expected: Invalid value specified for longfile attribute."); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -172,11 +172,11 @@ public class TarTest { | |||||
| @Test | @Test | ||||
| public void test9() { | public void test9() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test9"); | |||||
| fail("BuildException expected: Invalid value specified for compression attribute."); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test9"); | |||||
| fail("BuildException expected: Invalid value specified for compression attribute."); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -44,41 +44,41 @@ public class TaskdefTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test4() { | public void test4() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: classname specified doesn't exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: classname specified doesn't exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -99,19 +99,19 @@ public class TaskdefTest { | |||||
| @Test | @Test | ||||
| public void test6() { | public void test6() { | ||||
| buildRule.executeTarget("test6"); | buildRule.executeTarget("test6"); | ||||
| assertEquals("simpletask: worked", buildRule.getLog()); | |||||
| assertEquals("simpletask: worked", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test7() { | public void test7() { | ||||
| buildRule.executeTarget("test7"); | buildRule.executeTarget("test7"); | ||||
| assertEquals("worked", buildRule.getLog()); | |||||
| assertEquals("worked", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testGlobal() { | public void testGlobal() { | ||||
| buildRule.executeTarget("testGlobal"); | buildRule.executeTarget("testGlobal"); | ||||
| assertEquals("worked", buildRule.getLog()); | |||||
| assertEquals("worked", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -50,13 +50,13 @@ public class TypeAdapterTest { | |||||
| @Test | @Test | ||||
| public void testTaskAdapter() { | public void testTaskAdapter() { | ||||
| buildRule.executeTarget("taskadapter"); | buildRule.executeTarget("taskadapter"); | ||||
| assertContains("MyExec called", buildRule.getLog()); | |||||
| assertContains("MyExec called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testRunAdapter() { | public void testRunAdapter() { | ||||
| buildRule.executeTarget("runadapter"); | buildRule.executeTarget("runadapter"); | ||||
| assertContains("MyRunnable called", buildRule.getLog()); | |||||
| assertContains("MyRunnable called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -72,19 +72,19 @@ public class TypeAdapterTest { | |||||
| @Test | @Test | ||||
| public void testDelay() { | public void testDelay() { | ||||
| buildRule.executeTarget("delay"); | buildRule.executeTarget("delay"); | ||||
| assertContains("MyTask called", buildRule.getLog()); | |||||
| assertContains("MyTask called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testOnErrorReport() { | public void testOnErrorReport() { | ||||
| buildRule.executeTarget("onerror.report"); | buildRule.executeTarget("onerror.report"); | ||||
| assertContains("MyTaskNotPresent cannot be found", buildRule.getLog()); | |||||
| assertContains("MyTaskNotPresent cannot be found", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testOnErrorIgnore() { | public void testOnErrorIgnore() { | ||||
| buildRule.executeTarget("onerror.ignore"); | buildRule.executeTarget("onerror.ignore"); | ||||
| assertEquals("", buildRule.getLog()); | |||||
| assertEquals("", buildRule.getLog()); | |||||
| } | } | ||||
| public static class MyTask extends Task { | public static class MyTask extends Task { | ||||
| @@ -32,7 +32,7 @@ import static org.junit.Assert.fail; | |||||
| /** | /** | ||||
| */ | */ | ||||
| public class TypedefTest { | public class TypedefTest { | ||||
| @Rule | @Rule | ||||
| public final BuildFileRule buildRule = new BuildFileRule(); | public final BuildFileRule buildRule = new BuildFileRule(); | ||||
| @@ -45,41 +45,41 @@ public class TypedefTest { | |||||
| @Test | @Test | ||||
| public void testEmpty() { | public void testEmpty() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("empty"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("empty"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoName() { | public void testNoName() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("noName"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("noName"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoClassname() { | public void testNoClassname() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("noClassname"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("noClassname"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testClassNotFound() { | public void testClassNotFound() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("classNotFound"); | |||||
| fail("BuildException expected: classname specified doesn't exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("classNotFound"); | |||||
| fail("BuildException expected: classname specified doesn't exist"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -109,28 +109,28 @@ public class TypedefTest { | |||||
| @Test | @Test | ||||
| public void testDoubleNotPresent() { | public void testDoubleNotPresent() { | ||||
| buildRule.executeTarget("double-notpresent"); | buildRule.executeTarget("double-notpresent"); | ||||
| assertContains("hi", buildRule.getLog()); | |||||
| assertContains("hi", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoResourceOnErrorFailAll(){ | 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()); | |||||
| } | |||||
| 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 | @Test | ||||
| public void testNoResourceOnErrorFail(){ | public void testNoResourceOnErrorFail(){ | ||||
| buildRule.executeTarget("noresourcefail"); | |||||
| assertContains("Could not load definitions from resource ", buildRule.getLog()); | |||||
| buildRule.executeTarget("noresourcefail"); | |||||
| assertContains("Could not load definitions from resource ", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoResourceOnErrorNotFail(){ | public void testNoResourceOnErrorNotFail(){ | ||||
| buildRule.executeTarget("noresourcenotfail"); | |||||
| assertContains("Could not load definitions from resource ", buildRule.getLog()); | |||||
| buildRule.executeTarget("noresourcenotfail"); | |||||
| assertContains("Could not load definitions from resource ", buildRule.getLog()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -45,31 +45,31 @@ public class UnzipTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @@ -227,11 +227,11 @@ public class UnzipTest { | |||||
| @Test | @Test | ||||
| public void testTwoMappers() { | public void testTwoMappers() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("testTwoMappers"); | |||||
| fail("BuildException expected: " + Expand.ERROR_MULTIPLE_MAPPERS); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("testTwoMappers"); | |||||
| fail("BuildException expected: " + Expand.ERROR_MULTIPLE_MAPPERS); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -54,24 +54,24 @@ public class UpToDateTest { | |||||
| @Test | @Test | ||||
| public void testFilesetUpToDate() { | public void testFilesetUpToDate() { | ||||
| buildRule.executeTarget("testFilesetUpToDate"); | buildRule.executeTarget("testFilesetUpToDate"); | ||||
| assertEquals("true", buildRule.getProject().getProperty("foo")); | |||||
| assertEquals("true", buildRule.getProject().getProperty("foo")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testFilesetOutOfDate() { | public void testFilesetOutOfDate() { | ||||
| buildRule.executeTarget("testFilesetOutOfDate"); | buildRule.executeTarget("testFilesetOutOfDate"); | ||||
| assertNull(buildRule.getProject().getProperty("foo")); | |||||
| assertNull(buildRule.getProject().getProperty("foo")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testRCUpToDate() { | public void testRCUpToDate() { | ||||
| buildRule.executeTarget("testRCUpToDate"); | buildRule.executeTarget("testRCUpToDate"); | ||||
| assertEquals("true", buildRule.getProject().getProperty("foo")); | |||||
| assertEquals("true", buildRule.getProject().getProperty("foo")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testRCOutOfDate() { | public void testRCOutOfDate() { | ||||
| buildRule.executeTarget("testRCOutOfDate"); | buildRule.executeTarget("testRCOutOfDate"); | ||||
| assertNull(buildRule.getProject().getProperty("foo")); | |||||
| assertNull(buildRule.getProject().getProperty("foo")); | |||||
| } | } | ||||
| } | } | ||||
| @@ -42,19 +42,19 @@ public class XmlnsTest { | |||||
| @Test | @Test | ||||
| public void testXmlns() { | public void testXmlns() { | ||||
| buildRule.executeTarget("xmlns"); | buildRule.executeTarget("xmlns"); | ||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testXmlnsFile() { | public void testXmlnsFile() { | ||||
| buildRule.executeTarget("xmlns.file"); | buildRule.executeTarget("xmlns.file"); | ||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testCore() { | public void testCore() { | ||||
| buildRule.executeTarget("core"); | buildRule.executeTarget("core"); | ||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| assertEquals("MyTask called", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -70,13 +70,13 @@ public class XmlnsTest { | |||||
| @Test | @Test | ||||
| public void testOther() { | public void testOther() { | ||||
| buildRule.executeTarget("other"); | buildRule.executeTarget("other"); | ||||
| assertEquals("a message", buildRule.getLog()); | |||||
| assertEquals("a message", buildRule.getLog()); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNsAttributes() { | public void testNsAttributes() { | ||||
| buildRule.executeTarget("ns.attributes"); | buildRule.executeTarget("ns.attributes"); | ||||
| assertEquals("hello world", buildRule.getLog()); | |||||
| assertEquals("hello world", buildRule.getLog()); | |||||
| } | } | ||||
| public static class MyTask extends Task { | public static class MyTask extends Task { | ||||
| @@ -86,4 +86,3 @@ public class XmlnsTest { | |||||
| } | } | ||||
| } | } | ||||
| @@ -43,10 +43,10 @@ import static org.junit.Assume.assumeTrue; | |||||
| public class ZipTest { | public class ZipTest { | ||||
| @Rule | @Rule | ||||
| public BuildFileRule buildRule = new BuildFileRule(); | public BuildFileRule buildRule = new BuildFileRule(); | ||||
| //instance variable to allow cleanup | //instance variable to allow cleanup | ||||
| ZipFile zfPrefixAddsDir = null; | ZipFile zfPrefixAddsDir = null; | ||||
| @@ -60,42 +60,42 @@ public class ZipTest { | |||||
| @Test | @Test | ||||
| public void test1() { | public void test1() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test1"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test2() { | public void test2() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test2"); | |||||
| fail("BuildException expected: required argument not specified"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void test3() { | public void test3() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: zip cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test3"); | |||||
| fail("BuildException expected: zip cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @Test | @Test | ||||
| @Ignore("Previously commented out") | @Ignore("Previously commented out") | ||||
| public void test4() { | public void test4() { | ||||
| try { | try { | ||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: zip cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| buildRule.executeTarget("test4"); | |||||
| fail("BuildException expected: zip cannot include itself"); | |||||
| } catch (BuildException ex) { | |||||
| //TODO assert value | |||||
| } | |||||
| } | } | ||||
| @After | @After | ||||
| @@ -157,7 +157,7 @@ public class ZipTest { | |||||
| @Test | @Test | ||||
| public void testUpdateIsNecessary() { | public void testUpdateIsNecessary() { | ||||
| buildRule.executeTarget("testUpdateIsNecessary"); | buildRule.executeTarget("testUpdateIsNecessary"); | ||||
| assertContains("Updating", buildRule.getLog()); | |||||
| assertContains("Updating", buildRule.getLog()); | |||||
| } | } | ||||
| // Bugzilla Report 18403 | // Bugzilla Report 18403 | ||||
| @@ -202,7 +202,7 @@ public class ZipTest { | |||||
| @Test | @Test | ||||
| public void testZipEmptyCreate() { | public void testZipEmptyCreate() { | ||||
| buildRule.executeTarget("zipEmptyCreate"); | buildRule.executeTarget("zipEmptyCreate"); | ||||
| assertContains("Note: creating empty", buildRule.getLog()); | |||||
| assertContains("Note: creating empty", buildRule.getLog()); | |||||
| } | } | ||||
| // Bugzilla Report 25513 | // Bugzilla Report 25513 | ||||
| @Test | @Test | ||||
| @@ -1,62 +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); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,216 +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"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| @@ -1,104 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,48 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -1,266 +1,265 @@ | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,60 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -1,200 +1,199 @@ | |||||
| /* | |||||
| * 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)); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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)); | |||||
| } | |||||
| } | |||||
| @@ -1,57 +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)); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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)); | |||||
| } | |||||
| } | |||||
| @@ -1,235 +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"; | |||||
| } | |||||
| /* | |||||
| * 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"; | |||||
| } | |||||
| @@ -1,79 +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 | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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 | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,132 +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 | |||||
| /* | |||||
| * 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 | |||||
| @@ -1,45 +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"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| @@ -1,67 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,71 +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) { | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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) { | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,128 +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"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| @@ -1,71 +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"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| @@ -1,193 +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 | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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 | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,86 +1,85 @@ | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,213 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,87 +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.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; | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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; | |||||
| } | |||||
| } | |||||
| @@ -1,133 +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.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); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,99 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -1,121 +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 | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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 | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,53 +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; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,37 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -63,39 +63,39 @@ import org.w3c.dom.Node; | |||||
| public class JUnitTaskTest { | public class JUnitTaskTest { | ||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| /** | /** | ||||
| * The JUnit setup method. | * The JUnit setup method. | ||||
| */ | */ | ||||
| @Before | |||||
| @Before | |||||
| public void setUp() { | public void setUp() { | ||||
| buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); | buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); | ||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testCrash() { | public void testCrash() { | ||||
| buildRule.executeTarget("crash"); | |||||
| assertEquals("true", buildRule.getProject().getProperty("crashed")); | |||||
| buildRule.executeTarget("crash"); | |||||
| assertEquals("true", buildRule.getProject().getProperty("crashed")); | |||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testNoCrash() { | public void testNoCrash() { | ||||
| buildRule.executeTarget("nocrash"); | |||||
| assertNull(buildRule.getProject().getProperty("crashed")); | |||||
| buildRule.executeTarget("nocrash"); | |||||
| assertNull(buildRule.getProject().getProperty("crashed")); | |||||
| } | } | ||||
| @Test | |||||
| @Test | |||||
| public void testTimeout() { | public void testTimeout() { | ||||
| buildRule.executeTarget("timeout"); | |||||
| assertEquals("true", buildRule.getProject().getProperty("timeout")); | |||||
| buildRule.executeTarget("timeout"); | |||||
| assertEquals("true", buildRule.getProject().getProperty("timeout")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| public void testNoTimeout() { | public void testNoTimeout() { | ||||
| buildRule.executeTarget("notimeout"); | buildRule.executeTarget("notimeout"); | ||||
| assertNull(buildRule.getProject().getProperty("timeout")); | |||||
| assertNull(buildRule.getProject().getProperty("timeout")); | |||||
| } | } | ||||
| @Test | @Test | ||||
| @@ -141,7 +141,7 @@ public class JUnitTaskTest { | |||||
| public void testFailureRecorder() { | public void testFailureRecorder() { | ||||
| if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { | if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { | ||||
| try { | try { | ||||
| Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); | |||||
| Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); | |||||
| Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); | Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); | ||||
| } catch (ClassNotFoundException e) { | } catch (ClassNotFoundException e) { | ||||
| // OK, this is JUnit3, can run test | // OK, this is JUnit3, can run test | ||||
| @@ -154,14 +154,14 @@ public class JUnitTaskTest { | |||||
| // ensure that there is a clean test environment | // ensure that there is a clean test environment | ||||
| assertFalse("Test directory '" + testDir.getAbsolutePath() | assertFalse("Test directory '" + testDir.getAbsolutePath() | ||||
| + "' must not exist before the test preparation.", | |||||
| + "' must not exist before the test preparation.", | |||||
| testDir.exists()); | testDir.exists()); | ||||
| assertFalse("The collector file '" | assertFalse("The collector file '" | ||||
| + collectorFile.getAbsolutePath() | + collectorFile.getAbsolutePath() | ||||
| + "'must not exist before the test preparation.", | |||||
| + "'must not exist before the test preparation.", | |||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| // prepare the test environment | // prepare the test environment | ||||
| buildRule.executeTarget("failureRecorder.prepare"); | buildRule.executeTarget("failureRecorder.prepare"); | ||||
| assertTrue("Test directory '" + testDir.getAbsolutePath() | assertTrue("Test directory '" + testDir.getAbsolutePath() | ||||
| @@ -169,14 +169,14 @@ public class JUnitTaskTest { | |||||
| assertTrue("There should be one class.", | assertTrue("There should be one class.", | ||||
| (new File(testDir, "A.class")).exists()); | (new File(testDir, "A.class")).exists()); | ||||
| assertFalse("The collector file '" | assertFalse("The collector file '" | ||||
| + collectorFile.getAbsolutePath() | |||||
| + collectorFile.getAbsolutePath() | |||||
| + "' should not exist before the 1st run.", | + "' should not exist before the 1st run.", | ||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| // 1st junit run: should do all tests - failing and not failing tests | // 1st junit run: should do all tests - failing and not failing tests | ||||
| buildRule.executeTarget("failureRecorder.runtest"); | buildRule.executeTarget("failureRecorder.runtest"); | ||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| + "' should exist after the 1st run.", | + "' should exist after the 1st run.", | ||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| // the passing test cases | // the passing test cases | ||||
| @@ -202,10 +202,10 @@ public class JUnitTaskTest { | |||||
| buildRule.executeTarget("D.test10"); | buildRule.executeTarget("D.test10"); | ||||
| assertContains("1st run: should run D.test10", buildRule.getOutput()); | assertContains("1st run: should run D.test10", buildRule.getOutput()); | ||||
| // 2nd junit run: should do only failing tests | // 2nd junit run: should do only failing tests | ||||
| buildRule.executeTarget("failureRecorder.runtest"); | buildRule.executeTarget("failureRecorder.runtest"); | ||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| + "' should exist after the 2nd run.", | + "' should exist after the 2nd run.", | ||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| // the passing test cases | // the passing test cases | ||||
| @@ -230,14 +230,14 @@ public class JUnitTaskTest { | |||||
| assertContains("2nd run: should run B.test04", buildRule.getOutput()); | assertContains("2nd run: should run B.test04", buildRule.getOutput()); | ||||
| buildRule.executeTarget("D.test10"); | buildRule.executeTarget("D.test10"); | ||||
| assertContains("2nd run: should run D.test10", buildRule.getOutput()); | assertContains("2nd run: should run D.test10", buildRule.getOutput()); | ||||
| // "fix" errors in class A | // "fix" errors in class A | ||||
| buildRule.executeTarget("failureRecorder.fixing"); | buildRule.executeTarget("failureRecorder.fixing"); | ||||
| // 3rd run: four running tests with two errors | // 3rd run: four running tests with two errors | ||||
| buildRule.executeTarget("failureRecorder.runtest"); | buildRule.executeTarget("failureRecorder.runtest"); | ||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| + "' should exist after the 3rd run.", | + "' should exist after the 3rd run.", | ||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| buildRule.executeTarget("A.test02"); | buildRule.executeTarget("A.test02"); | ||||
| @@ -248,11 +248,11 @@ public class JUnitTaskTest { | |||||
| assertContains("3rd run: should run B.test04", buildRule.getOutput()); | assertContains("3rd run: should run B.test04", buildRule.getOutput()); | ||||
| buildRule.executeTarget("D.test10"); | buildRule.executeTarget("D.test10"); | ||||
| assertContains("3rd run: should run D.test10", buildRule.getOutput()); | assertContains("3rd run: should run D.test10", buildRule.getOutput()); | ||||
| // 4rd run: two running tests with errors | // 4rd run: two running tests with errors | ||||
| buildRule.executeTarget("failureRecorder.runtest"); | buildRule.executeTarget("failureRecorder.runtest"); | ||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| assertTrue("The collector file '" + collectorFile.getAbsolutePath() | |||||
| + "' should exist after the 4th run.", | + "' should exist after the 4th run.", | ||||
| collectorFile.exists()); | collectorFile.exists()); | ||||
| //TODO: these two statements fail | //TODO: these two statements fail | ||||
| @@ -1,111 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -38,7 +38,7 @@ import org.junit.Test; | |||||
| */ | */ | ||||
| public class JUnitTestRunnerTest{ | public class JUnitTestRunnerTest{ | ||||
| // check that a valid method name generates no errors | // check that a valid method name generates no errors | ||||
| @Test | @Test | ||||
| @@ -56,8 +56,8 @@ public class JUnitTestRunnerTest{ | |||||
| String error = runner.getFormatter().getError(); | String error = runner.getFormatter().getError(); | ||||
| // might be FAILURES or ERRORS depending on JUnit version? | // might be FAILURES or ERRORS depending on JUnit version? | ||||
| assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); | assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); | ||||
| } | |||||
| } | |||||
| // check that having no suite generates no errors | // check that having no suite generates no errors | ||||
| @Test | @Test | ||||
| public void testNoSuite(){ | public void testNoSuite(){ | ||||
| @@ -92,7 +92,7 @@ public class JUnitTestRunnerTest{ | |||||
| runner.run(); | runner.run(); | ||||
| // On junit3 this is a FAILURE, on junit4 this is an ERROR | // On junit3 this is a FAILURE, on junit4 this is an ERROR | ||||
| int ret = runner.getRetCode(); | int ret = runner.getRetCode(); | ||||
| if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { | if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { | ||||
| fail("Unexpected result " + ret + " from junit runner"); | fail("Unexpected result " + ret + " from junit runner"); | ||||
| } | } | ||||
| @@ -131,21 +131,21 @@ public class JUnitTestRunnerTest{ | |||||
| } | } | ||||
| protected TestRunner createRunner(Class<?> clazz){ | protected TestRunner createRunner(Class<?> clazz){ | ||||
| return new TestRunner(new JUnitTest(clazz.getName()), null, | |||||
| return new TestRunner(new JUnitTest(clazz.getName()), null, | |||||
| true, true, true); | true, true, true); | ||||
| } | } | ||||
| protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method){ | protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method){ | ||||
| return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, | return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, | ||||
| true, true, true); | true, true, true); | ||||
| } | |||||
| } | |||||
| // the test runner that wrap the dummy formatter that interests us | // the test runner that wrap the dummy formatter that interests us | ||||
| private final static class TestRunner extends JUnitTestRunner { | private final static class TestRunner extends JUnitTestRunner { | ||||
| private ResultFormatter formatter = new ResultFormatter(); | private ResultFormatter formatter = new ResultFormatter(); | ||||
| TestRunner(JUnitTest test, String[] methods, boolean haltonerror, | TestRunner(JUnitTest test, String[] methods, boolean haltonerror, | ||||
| boolean filtertrace, boolean haltonfailure){ | boolean filtertrace, boolean haltonfailure){ | ||||
| super(test, methods, haltonerror, filtertrace, haltonfailure, | |||||
| super(test, methods, haltonerror, filtertrace, haltonfailure, | |||||
| false, false, TestRunner.class.getClassLoader()); | false, false, TestRunner.class.getClassLoader()); | ||||
| // use the classloader that loaded this class otherwise | // use the classloader that loaded this class otherwise | ||||
| // it will not be able to run inner classes if this test | // it will not be able to run inner classes if this test | ||||
| @@ -206,8 +206,8 @@ public class JUnitTestRunnerTest{ | |||||
| // should not be executed | // should not be executed | ||||
| throw new NullPointerException("thrown on purpose"); | throw new NullPointerException("thrown on purpose"); | ||||
| } | } | ||||
| } | |||||
| } | |||||
| public static class InvalidTestCase extends TestCase { | public static class InvalidTestCase extends TestCase { | ||||
| public InvalidTestCase(String name){ | public InvalidTestCase(String name){ | ||||
| super(name); | super(name); | ||||
| @@ -242,4 +242,3 @@ public class JUnitTestRunnerTest{ | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,102 +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";} | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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";} | |||||
| } | |||||
| } | |||||
| @@ -1,30 +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() { | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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() { | |||||
| } | |||||
| } | |||||
| @@ -1,42 +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"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| @@ -1,30 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,42 +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); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,53 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -1,112 +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 | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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 | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,31 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,83 +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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,93 +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()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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()); | |||||
| } | |||||
| } | |||||
| @@ -1,146 +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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,351 +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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,50 +1,49 @@ | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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); | |||||
| } | |||||
| } | |||||
| @@ -1,297 +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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,475 +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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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"); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,248 +1,248 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| import java.io.File; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| 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.fail; | |||||
| /** | |||||
| * Base class for FileSetTest and DirSetTest. | |||||
| * | |||||
| * <p>This doesn't actually test much, mainly reference handling. | |||||
| * | |||||
| */ | |||||
| public abstract class AbstractFileSetTest { | |||||
| private Project project; | |||||
| @Before | |||||
| public void setUp() { | |||||
| project = new Project(); | |||||
| project.setBasedir("."); | |||||
| } | |||||
| protected abstract AbstractFileSet getInstance(); | |||||
| protected final Project getProject() { | |||||
| return project; | |||||
| } | |||||
| @Test | |||||
| public final void testEmptyElementIfIsReference() { | |||||
| AbstractFileSet f = getInstance(); | |||||
| f.setIncludes("**/*.java"); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with elements from setIncludes"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.createPatternSet(); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with nested patternset element."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when " | |||||
| + "using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.createInclude(); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with nested include element."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| try { | |||||
| f.setIncludes("**/*.java"); | |||||
| fail("Can set includes in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setIncludesfile(new File("/a")); | |||||
| fail("Can set includesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setExcludes("**/*.java"); | |||||
| fail("Can set excludes in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setExcludesfile(new File("/a")); | |||||
| fail("Can set excludesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setDir(project.resolveFile(".")); | |||||
| fail("Can set dir in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createInclude(); | |||||
| fail("Can add nested include in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createExclude(); | |||||
| fail("Can add nested exclude in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createIncludesFile(); | |||||
| fail("Can add nested includesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createExcludesFile(); | |||||
| fail("Can add nested excludesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createPatternSet(); | |||||
| fail("Can add nested patternset in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testCircularReferenceCheck() { | |||||
| AbstractFileSet f = getInstance(); | |||||
| project.addReference("dummy", f); | |||||
| f.setRefid(new Reference(getProject(), "dummy")); | |||||
| try { | |||||
| f.getDir(project); | |||||
| fail("Can make " + f.getDataTypeName() | |||||
| + " a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.getDirectoryScanner(project); | |||||
| fail("Can make " + f.getDataTypeName() | |||||
| + " a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 --> dummy1 | |||||
| AbstractFileSet f1 = getInstance(); | |||||
| project.addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(getProject(), "dummy2")); | |||||
| AbstractFileSet f2 = getInstance(); | |||||
| project.addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(getProject(), "dummy3")); | |||||
| AbstractFileSet f3 = getInstance(); | |||||
| project.addReference("dummy3", f3); | |||||
| f3.setRefid(new Reference(getProject(), "dummy1")); | |||||
| try { | |||||
| f1.getDir(project); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f1.getDirectoryScanner(project); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 | |||||
| // (which has the Project's basedir as root). | |||||
| f1 = getInstance(); | |||||
| project.addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(getProject(), "dummy2")); | |||||
| f2 = getInstance(); | |||||
| project.addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(getProject(), "dummy3")); | |||||
| f3 = getInstance(); | |||||
| project.addReference("dummy3", f3); | |||||
| f3.setDir(project.resolveFile(".")); | |||||
| File dir = f1.getDir(project); | |||||
| assertEquals("Dir is basedir", dir, project.getBaseDir()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import java.io.File; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| 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.fail; | |||||
| /** | |||||
| * Base class for FileSetTest and DirSetTest. | |||||
| * | |||||
| * <p>This doesn't actually test much, mainly reference handling. | |||||
| * | |||||
| */ | |||||
| public abstract class AbstractFileSetTest { | |||||
| private Project project; | |||||
| @Before | |||||
| public void setUp() { | |||||
| project = new Project(); | |||||
| project.setBasedir("."); | |||||
| } | |||||
| protected abstract AbstractFileSet getInstance(); | |||||
| protected final Project getProject() { | |||||
| return project; | |||||
| } | |||||
| @Test | |||||
| public final void testEmptyElementIfIsReference() { | |||||
| AbstractFileSet f = getInstance(); | |||||
| f.setIncludes("**/*.java"); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with elements from setIncludes"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.createPatternSet(); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with nested patternset element."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when " | |||||
| + "using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.createInclude(); | |||||
| try { | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| fail("Can add reference to " | |||||
| + f.getDataTypeName() | |||||
| + " with nested include element."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| f = getInstance(); | |||||
| f.setRefid(new Reference(getProject(), "dummyref")); | |||||
| try { | |||||
| f.setIncludes("**/*.java"); | |||||
| fail("Can set includes in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setIncludesfile(new File("/a")); | |||||
| fail("Can set includesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setExcludes("**/*.java"); | |||||
| fail("Can set excludes in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setExcludesfile(new File("/a")); | |||||
| fail("Can set excludesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setDir(project.resolveFile(".")); | |||||
| fail("Can set dir in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute " | |||||
| + "when using refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createInclude(); | |||||
| fail("Can add nested include in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createExclude(); | |||||
| fail("Can add nested exclude in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createIncludesFile(); | |||||
| fail("Can add nested includesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createExcludesFile(); | |||||
| fail("Can add nested excludesfile in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.createPatternSet(); | |||||
| fail("Can add nested patternset in " | |||||
| + f.getDataTypeName() | |||||
| + " that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify nested elements when using " | |||||
| + "refid", be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testCircularReferenceCheck() { | |||||
| AbstractFileSet f = getInstance(); | |||||
| project.addReference("dummy", f); | |||||
| f.setRefid(new Reference(getProject(), "dummy")); | |||||
| try { | |||||
| f.getDir(project); | |||||
| fail("Can make " + f.getDataTypeName() | |||||
| + " a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.getDirectoryScanner(project); | |||||
| fail("Can make " + f.getDataTypeName() | |||||
| + " a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 --> dummy1 | |||||
| AbstractFileSet f1 = getInstance(); | |||||
| project.addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(getProject(), "dummy2")); | |||||
| AbstractFileSet f2 = getInstance(); | |||||
| project.addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(getProject(), "dummy3")); | |||||
| AbstractFileSet f3 = getInstance(); | |||||
| project.addReference("dummy3", f3); | |||||
| f3.setRefid(new Reference(getProject(), "dummy1")); | |||||
| try { | |||||
| f1.getDir(project); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f1.getDirectoryScanner(project); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 | |||||
| // (which has the Project's basedir as root). | |||||
| f1 = getInstance(); | |||||
| project.addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(getProject(), "dummy2")); | |||||
| f2 = getInstance(); | |||||
| project.addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(getProject(), "dummy3")); | |||||
| f3 = getInstance(); | |||||
| project.addReference("dummy3", f3); | |||||
| f3.setDir(project.resolveFile(".")); | |||||
| File dir = f1.getDir(project); | |||||
| assertEquals("Dir is basedir", dir, project.getBaseDir()); | |||||
| } | |||||
| } | |||||
| @@ -1,223 +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.types; | |||||
| import org.apache.tools.ant.AntAssert; | |||||
| 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.taskdefs.condition.Condition; | |||||
| import org.junit.Before; | |||||
| import org.junit.Rule; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.fail; | |||||
| public class AddTypeTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/addtype.xml"); | |||||
| } | |||||
| @Test | |||||
| public void testAddPath() { | |||||
| buildRule.executeTarget("addpath"); | |||||
| } | |||||
| @Test | |||||
| public void testAddCondition() { | |||||
| buildRule.executeTarget("addcondition"); | |||||
| } | |||||
| @Test | |||||
| public void testAddFilter() { | |||||
| buildRule.executeTarget("addfilter"); | |||||
| } | |||||
| @Test | |||||
| public void testAddSelector() { | |||||
| buildRule.executeTarget("addselector"); | |||||
| } | |||||
| @Test | |||||
| public void testNestedA() { | |||||
| buildRule.executeTarget("nested.a"); | |||||
| AntAssert.assertContains("add A called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedB() { | |||||
| buildRule.executeTarget("nested.b"); | |||||
| AntAssert.assertContains( "add B called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedC() { | |||||
| buildRule.executeTarget("nested.c"); | |||||
| AntAssert.assertContains( "add C called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedAB() { | |||||
| try { | |||||
| buildRule.executeTarget("nested.ab"); | |||||
| fail("Build exception expected: Should have got ambiguous"); | |||||
| } catch (BuildException ex) { | |||||
| AntAssert.assertContains("ambiguous", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testConditionType() { | |||||
| buildRule.executeTarget("condition.type"); | |||||
| AntAssert.assertContains( "beforeafter", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionTask() { | |||||
| buildRule.executeTarget("condition.task"); | |||||
| AntAssert.assertContains( "My Condition execution", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionConditionType() { | |||||
| buildRule.executeTarget("condition.condition.type"); | |||||
| AntAssert.assertContains( "My Condition eval", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionConditionTask() { | |||||
| try { | |||||
| buildRule.executeTarget("condition.condition.task"); | |||||
| fail("Build exception expected: Task masking condition"); | |||||
| } catch (BuildException ex) { | |||||
| AntAssert.assertContains("doesn't support the nested", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testAddConfigured() { | |||||
| buildRule.executeTarget("myaddconfigured"); | |||||
| AntAssert.assertContains("value is Value Setexecute: value is Value Set", | |||||
| buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testAddConfiguredValue() { | |||||
| buildRule.executeTarget("myaddconfiguredvalue"); | |||||
| AntAssert.assertContains("value is Value Setexecute: value is Value Set", | |||||
| buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNamespace() { | |||||
| buildRule.executeTarget("namespacetest"); | |||||
| } | |||||
| // The following will be used as types and tasks | |||||
| public static interface A {} | |||||
| public static interface B {} | |||||
| public static interface C extends A {} | |||||
| public static interface AB extends A, B {} | |||||
| public static class AImpl implements A{} | |||||
| public static class BImpl implements B{} | |||||
| public static class CImpl implements C{} | |||||
| public static class ABImpl implements AB{} | |||||
| public static class NestedContainer | |||||
| extends Task | |||||
| { | |||||
| public void add(A el) { | |||||
| log("add A called"); | |||||
| } | |||||
| public void add(B el) { | |||||
| log("add B called"); | |||||
| } | |||||
| public void add(C el) { | |||||
| log("add C called"); | |||||
| } | |||||
| } | |||||
| public static class MyCondition | |||||
| implements Condition | |||||
| { | |||||
| Project project; | |||||
| public void setProject(Project project) { | |||||
| this.project = project; | |||||
| } | |||||
| public boolean eval() { | |||||
| project.log("My Condition eval"); | |||||
| return true; | |||||
| } | |||||
| public void execute() { | |||||
| project.log("My Condition execution"); | |||||
| } | |||||
| } | |||||
| public static class MyValue | |||||
| { | |||||
| private String text = "NOT SET YET"; | |||||
| public void addText(String text) { | |||||
| this.text = text; | |||||
| } | |||||
| public String toString() { | |||||
| return text; | |||||
| } | |||||
| } | |||||
| public static class MyAddConfigured | |||||
| extends Task | |||||
| { | |||||
| MyValue value; | |||||
| public void addConfigured(MyValue value) { | |||||
| log("value is " + value); | |||||
| this.value = value; | |||||
| } | |||||
| public void add(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | |||||
| log("execute: value is " + value); | |||||
| } | |||||
| } | |||||
| public static class MyAddConfiguredValue | |||||
| extends Task | |||||
| { | |||||
| MyValue value; | |||||
| public void addConfiguredValue(MyValue value) { | |||||
| log("value is " + value); | |||||
| this.value = value; | |||||
| } | |||||
| public void addValue(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | |||||
| log("execute: value is " + value); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.AntAssert; | |||||
| 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.taskdefs.condition.Condition; | |||||
| import org.junit.Before; | |||||
| import org.junit.Rule; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.fail; | |||||
| public class AddTypeTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/addtype.xml"); | |||||
| } | |||||
| @Test | |||||
| public void testAddPath() { | |||||
| buildRule.executeTarget("addpath"); | |||||
| } | |||||
| @Test | |||||
| public void testAddCondition() { | |||||
| buildRule.executeTarget("addcondition"); | |||||
| } | |||||
| @Test | |||||
| public void testAddFilter() { | |||||
| buildRule.executeTarget("addfilter"); | |||||
| } | |||||
| @Test | |||||
| public void testAddSelector() { | |||||
| buildRule.executeTarget("addselector"); | |||||
| } | |||||
| @Test | |||||
| public void testNestedA() { | |||||
| buildRule.executeTarget("nested.a"); | |||||
| AntAssert.assertContains("add A called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedB() { | |||||
| buildRule.executeTarget("nested.b"); | |||||
| AntAssert.assertContains( "add B called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedC() { | |||||
| buildRule.executeTarget("nested.c"); | |||||
| AntAssert.assertContains( "add C called", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNestedAB() { | |||||
| try { | |||||
| buildRule.executeTarget("nested.ab"); | |||||
| fail("Build exception expected: Should have got ambiguous"); | |||||
| } catch (BuildException ex) { | |||||
| AntAssert.assertContains("ambiguous", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testConditionType() { | |||||
| buildRule.executeTarget("condition.type"); | |||||
| AntAssert.assertContains( "beforeafter", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionTask() { | |||||
| buildRule.executeTarget("condition.task"); | |||||
| AntAssert.assertContains( "My Condition execution", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionConditionType() { | |||||
| buildRule.executeTarget("condition.condition.type"); | |||||
| AntAssert.assertContains( "My Condition eval", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testConditionConditionTask() { | |||||
| try { | |||||
| buildRule.executeTarget("condition.condition.task"); | |||||
| fail("Build exception expected: Task masking condition"); | |||||
| } catch (BuildException ex) { | |||||
| AntAssert.assertContains("doesn't support the nested", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testAddConfigured() { | |||||
| buildRule.executeTarget("myaddconfigured"); | |||||
| AntAssert.assertContains("value is Value Setexecute: value is Value Set", | |||||
| buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testAddConfiguredValue() { | |||||
| buildRule.executeTarget("myaddconfiguredvalue"); | |||||
| AntAssert.assertContains("value is Value Setexecute: value is Value Set", | |||||
| buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNamespace() { | |||||
| buildRule.executeTarget("namespacetest"); | |||||
| } | |||||
| // The following will be used as types and tasks | |||||
| public static interface A {} | |||||
| public static interface B {} | |||||
| public static interface C extends A {} | |||||
| public static interface AB extends A, B {} | |||||
| public static class AImpl implements A{} | |||||
| public static class BImpl implements B{} | |||||
| public static class CImpl implements C{} | |||||
| public static class ABImpl implements AB{} | |||||
| public static class NestedContainer | |||||
| extends Task | |||||
| { | |||||
| public void add(A el) { | |||||
| log("add A called"); | |||||
| } | |||||
| public void add(B el) { | |||||
| log("add B called"); | |||||
| } | |||||
| public void add(C el) { | |||||
| log("add C called"); | |||||
| } | |||||
| } | |||||
| public static class MyCondition | |||||
| implements Condition | |||||
| { | |||||
| Project project; | |||||
| public void setProject(Project project) { | |||||
| this.project = project; | |||||
| } | |||||
| public boolean eval() { | |||||
| project.log("My Condition eval"); | |||||
| return true; | |||||
| } | |||||
| public void execute() { | |||||
| project.log("My Condition execution"); | |||||
| } | |||||
| } | |||||
| public static class MyValue | |||||
| { | |||||
| private String text = "NOT SET YET"; | |||||
| public void addText(String text) { | |||||
| this.text = text; | |||||
| } | |||||
| public String toString() { | |||||
| return text; | |||||
| } | |||||
| } | |||||
| public static class MyAddConfigured | |||||
| extends Task | |||||
| { | |||||
| MyValue value; | |||||
| public void addConfigured(MyValue value) { | |||||
| log("value is " + value); | |||||
| this.value = value; | |||||
| } | |||||
| public void add(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | |||||
| log("execute: value is " + value); | |||||
| } | |||||
| } | |||||
| public static class MyAddConfiguredValue | |||||
| extends Task | |||||
| { | |||||
| MyValue value; | |||||
| public void addConfiguredValue(MyValue value) { | |||||
| log("value is " + value); | |||||
| this.value = value; | |||||
| } | |||||
| public void addValue(MyValue value) { | |||||
| throw new BuildException("Should not be called"); | |||||
| } | |||||
| public void execute() { | |||||
| log("execute: value is " + value); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,125 +1,123 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.BuildFileRule; | |||||
| 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.fail; | |||||
| /** | |||||
| * test assertion handling | |||||
| */ | |||||
| public class AssertionsTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/assertions.xml"); | |||||
| } | |||||
| /** | |||||
| * runs a test and expects an assertion thrown in forked code | |||||
| * @param target | |||||
| */ | |||||
| private void expectAssertion(String target) { | |||||
| try { | |||||
| buildRule.executeTarget(target); | |||||
| fail("BuildException should have been thrown by assertion fail in task"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testClassname() { | |||||
| expectAssertion("test-classname"); | |||||
| } | |||||
| @Test | |||||
| public void testPackage() { | |||||
| expectAssertion("test-package"); | |||||
| } | |||||
| @Test | |||||
| public void testEmptyAssertions() { | |||||
| buildRule.executeTarget("test-empty-assertions"); | |||||
| } | |||||
| @Test | |||||
| public void testDisable() { | |||||
| buildRule.executeTarget("test-disable"); | |||||
| } | |||||
| @Test | |||||
| public void testOverride() { | |||||
| expectAssertion("test-override"); | |||||
| } | |||||
| @Test | |||||
| public void testOverride2() { | |||||
| buildRule.executeTarget("test-override2"); | |||||
| } | |||||
| @Test | |||||
| public void testReferences() { | |||||
| expectAssertion("test-references"); | |||||
| } | |||||
| @Test | |||||
| public void testMultipleAssertions() { | |||||
| try { | |||||
| buildRule.executeTarget("test-multiple-assertions"); | |||||
| fail("BuildException should have been thrown by assertion fail in task"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testReferenceAbuse() { | |||||
| try { | |||||
| buildRule.executeTarget("test-reference-abuse"); | |||||
| fail("BuildException should have been thrown by reference abuse"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("reference abuse rejected", "You must not specify", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testNofork() { | |||||
| Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus()); | |||||
| buildRule.executeTarget("test-nofork"); | |||||
| assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testJUnit() { | |||||
| buildRule.executeTarget("test-junit"); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.BuildFileRule; | |||||
| 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.fail; | |||||
| /** | |||||
| * test assertion handling | |||||
| */ | |||||
| public class AssertionsTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/assertions.xml"); | |||||
| } | |||||
| /** | |||||
| * runs a test and expects an assertion thrown in forked code | |||||
| * @param target | |||||
| */ | |||||
| private void expectAssertion(String target) { | |||||
| try { | |||||
| buildRule.executeTarget(target); | |||||
| fail("BuildException should have been thrown by assertion fail in task"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testClassname() { | |||||
| expectAssertion("test-classname"); | |||||
| } | |||||
| @Test | |||||
| public void testPackage() { | |||||
| expectAssertion("test-package"); | |||||
| } | |||||
| @Test | |||||
| public void testEmptyAssertions() { | |||||
| buildRule.executeTarget("test-empty-assertions"); | |||||
| } | |||||
| @Test | |||||
| public void testDisable() { | |||||
| buildRule.executeTarget("test-disable"); | |||||
| } | |||||
| @Test | |||||
| public void testOverride() { | |||||
| expectAssertion("test-override"); | |||||
| } | |||||
| @Test | |||||
| public void testOverride2() { | |||||
| buildRule.executeTarget("test-override2"); | |||||
| } | |||||
| @Test | |||||
| public void testReferences() { | |||||
| expectAssertion("test-references"); | |||||
| } | |||||
| @Test | |||||
| public void testMultipleAssertions() { | |||||
| try { | |||||
| buildRule.executeTarget("test-multiple-assertions"); | |||||
| fail("BuildException should have been thrown by assertion fail in task"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testReferenceAbuse() { | |||||
| try { | |||||
| buildRule.executeTarget("test-reference-abuse"); | |||||
| fail("BuildException should have been thrown by reference abuse"); | |||||
| } catch (BuildException ex) { | |||||
| assertContains("reference abuse rejected", "You must not specify", ex.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testNofork() { | |||||
| Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus()); | |||||
| buildRule.executeTarget("test-nofork"); | |||||
| assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testJUnit() { | |||||
| buildRule.executeTarget("test-junit"); | |||||
| } | |||||
| } | |||||
| @@ -1,191 +1,191 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.MagicNames; | |||||
| import org.apache.tools.ant.Project; | |||||
| import org.junit.After; | |||||
| import org.junit.Before; | |||||
| 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.Assert.assertNotNull; | |||||
| import static org.junit.Assert.assertNull; | |||||
| /** | |||||
| * JUnit testcases for org.apache.tools.ant.CommandlineJava | |||||
| * | |||||
| */ | |||||
| public class CommandlineJavaTest { | |||||
| private String cloneVm; | |||||
| private Project project; | |||||
| @Before | |||||
| public void setUp() { | |||||
| project = new Project(); | |||||
| project.setBasedir(System.getProperty("root")); | |||||
| project.setProperty("build.sysclasspath", "ignore"); | |||||
| cloneVm = System.getProperty("ant.build.clonevm"); | |||||
| if (cloneVm != null) { | |||||
| System.setProperty("ant.build.clonevm", "false"); | |||||
| } | |||||
| } | |||||
| @After | |||||
| public void tearDown() { | |||||
| if (cloneVm != null) { | |||||
| System.setProperty("ant.build.clonevm", cloneVm); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testGetCommandline() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||||
| c.setClassname("junit.textui.TestRunner"); | |||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals("no classpath", 4, s.length); | |||||
| /* | |||||
| * After changing CommandlineJava to search for the java | |||||
| * executable, I don't know, how to tests the value returned | |||||
| * here without using the same logic as applied in the class | |||||
| * itself. | |||||
| * | |||||
| * assertTrue("no classpath", "java", s[0]); | |||||
| */ | |||||
| assertEquals("no classpath", "-Djava.compiler=NONE", s[1]); | |||||
| assertEquals("no classpath", "junit.textui.TestRunner", s[2]); | |||||
| assertEquals("no classpath", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", s[3]); | |||||
| try { | |||||
| c.clone(); | |||||
| } catch (NullPointerException ex) { | |||||
| fail("cloning should work without classpath specified"); | |||||
| } | |||||
| c.createClasspath(project).setLocation(project.resolveFile("build.xml")); | |||||
| c.createClasspath(project).setLocation(project.resolveFile( | |||||
| System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar")); | |||||
| s = c.getCommandline(); | |||||
| assertEquals("with classpath", 6, s.length); | |||||
| // assertEquals("with classpath", "java", s[0]); | |||||
| assertEquals("with classpath", "-Djava.compiler=NONE", s[1]); | |||||
| assertEquals("with classpath", "-classpath", s[2]); | |||||
| assertTrue("build.xml contained", | |||||
| s[3].indexOf("build.xml"+java.io.File.pathSeparator) >= 0); | |||||
| assertTrue("ant.jar contained", s[3].endsWith("ant.jar")); | |||||
| assertEquals("with classpath", "junit.textui.TestRunner", s[4]); | |||||
| assertEquals("with classpath", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", s[5]); | |||||
| } | |||||
| @Test | |||||
| public void testJarOption() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("arg1"); | |||||
| c.setJar("myfile.jar"); | |||||
| c.createVmArgument().setValue("-classic"); | |||||
| c.createVmArgument().setValue("-Dx=y"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals("-classic", s[1]); | |||||
| assertEquals("-Dx=y", s[2]); | |||||
| assertEquals("-jar", s[3]); | |||||
| assertEquals("myfile.jar", s[4]); | |||||
| assertEquals("arg1", s[5]); | |||||
| } | |||||
| @Test | |||||
| public void testSysproperties() { | |||||
| String currentClasspath = System.getProperty("java.class.path"); | |||||
| assertNotNull(currentClasspath); | |||||
| assertNull(System.getProperty("key")); | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| Environment.Variable v = new Environment.Variable(); | |||||
| v.setKey("key"); | |||||
| v.setValue("value"); | |||||
| c.addSysproperty(v); | |||||
| project.setProperty("key2", "value2"); | |||||
| PropertySet ps = new PropertySet(); | |||||
| ps.setProject(project); | |||||
| ps.appendName("key2"); | |||||
| c.addSyspropertyset(ps); | |||||
| try { | |||||
| c.setSystemProperties(); | |||||
| String newClasspath = System.getProperty("java.class.path"); | |||||
| assertNotNull(newClasspath); | |||||
| assertEquals(currentClasspath, newClasspath); | |||||
| assertNotNull(System.getProperty("key")); | |||||
| assertEquals("value", System.getProperty("key")); | |||||
| assertTrue(System.getProperties().containsKey("java.class.path")); | |||||
| assertNotNull(System.getProperty("key2")); | |||||
| assertEquals("value2", System.getProperty("key2")); | |||||
| } finally { | |||||
| c.restoreSystemProperties(); | |||||
| } | |||||
| assertNull(System.getProperty("key")); | |||||
| assertNull(System.getProperty("key2")); | |||||
| } | |||||
| @Test | |||||
| public void testAssertions() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||||
| c.setClassname("junit.textui.TestRunner"); | |||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | |||||
| Assertions a = new Assertions(); | |||||
| a.setProject(project); | |||||
| Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion(); | |||||
| ea.setClass("junit.textui.TestRunner"); | |||||
| a.addEnable(ea); | |||||
| c.setAssertions(a); | |||||
| String[] expected = new String[] { | |||||
| null, | |||||
| "-Djava.compiler=NONE", | |||||
| "-ea:junit.textui.TestRunner", | |||||
| "junit.textui.TestRunner", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", | |||||
| }; | |||||
| // only the second iteration would pass because of PR 27218 | |||||
| for (int i = 0; i < 3; i++) { | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(expected.length, s.length); | |||||
| for (int j = 1; j < expected.length; j++) { | |||||
| assertEquals(expected[j], s[j]); | |||||
| } | |||||
| } | |||||
| CommandlineJava c2 = (CommandlineJava) c.clone(); | |||||
| String[] s = c2.getCommandline(); | |||||
| assertEquals(expected.length, s.length); | |||||
| for (int j = 1; j < expected.length; j++) { | |||||
| assertEquals(expected[j], s[j]); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.MagicNames; | |||||
| import org.apache.tools.ant.Project; | |||||
| import org.junit.After; | |||||
| import org.junit.Before; | |||||
| 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.Assert.assertNotNull; | |||||
| import static org.junit.Assert.assertNull; | |||||
| /** | |||||
| * JUnit testcases for org.apache.tools.ant.CommandlineJava | |||||
| * | |||||
| */ | |||||
| public class CommandlineJavaTest { | |||||
| private String cloneVm; | |||||
| private Project project; | |||||
| @Before | |||||
| public void setUp() { | |||||
| project = new Project(); | |||||
| project.setBasedir(System.getProperty("root")); | |||||
| project.setProperty("build.sysclasspath", "ignore"); | |||||
| cloneVm = System.getProperty("ant.build.clonevm"); | |||||
| if (cloneVm != null) { | |||||
| System.setProperty("ant.build.clonevm", "false"); | |||||
| } | |||||
| } | |||||
| @After | |||||
| public void tearDown() { | |||||
| if (cloneVm != null) { | |||||
| System.setProperty("ant.build.clonevm", cloneVm); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testGetCommandline() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||||
| c.setClassname("junit.textui.TestRunner"); | |||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals("no classpath", 4, s.length); | |||||
| /* | |||||
| * After changing CommandlineJava to search for the java | |||||
| * executable, I don't know, how to tests the value returned | |||||
| * here without using the same logic as applied in the class | |||||
| * itself. | |||||
| * | |||||
| * assertTrue("no classpath", "java", s[0]); | |||||
| */ | |||||
| assertEquals("no classpath", "-Djava.compiler=NONE", s[1]); | |||||
| assertEquals("no classpath", "junit.textui.TestRunner", s[2]); | |||||
| assertEquals("no classpath", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", s[3]); | |||||
| try { | |||||
| c.clone(); | |||||
| } catch (NullPointerException ex) { | |||||
| fail("cloning should work without classpath specified"); | |||||
| } | |||||
| c.createClasspath(project).setLocation(project.resolveFile("build.xml")); | |||||
| c.createClasspath(project).setLocation(project.resolveFile( | |||||
| System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar")); | |||||
| s = c.getCommandline(); | |||||
| assertEquals("with classpath", 6, s.length); | |||||
| // assertEquals("with classpath", "java", s[0]); | |||||
| assertEquals("with classpath", "-Djava.compiler=NONE", s[1]); | |||||
| assertEquals("with classpath", "-classpath", s[2]); | |||||
| assertTrue("build.xml contained", | |||||
| s[3].indexOf("build.xml"+java.io.File.pathSeparator) >= 0); | |||||
| assertTrue("ant.jar contained", s[3].endsWith("ant.jar")); | |||||
| assertEquals("with classpath", "junit.textui.TestRunner", s[4]); | |||||
| assertEquals("with classpath", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", s[5]); | |||||
| } | |||||
| @Test | |||||
| public void testJarOption() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("arg1"); | |||||
| c.setJar("myfile.jar"); | |||||
| c.createVmArgument().setValue("-classic"); | |||||
| c.createVmArgument().setValue("-Dx=y"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals("-classic", s[1]); | |||||
| assertEquals("-Dx=y", s[2]); | |||||
| assertEquals("-jar", s[3]); | |||||
| assertEquals("myfile.jar", s[4]); | |||||
| assertEquals("arg1", s[5]); | |||||
| } | |||||
| @Test | |||||
| public void testSysproperties() { | |||||
| String currentClasspath = System.getProperty("java.class.path"); | |||||
| assertNotNull(currentClasspath); | |||||
| assertNull(System.getProperty("key")); | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| Environment.Variable v = new Environment.Variable(); | |||||
| v.setKey("key"); | |||||
| v.setValue("value"); | |||||
| c.addSysproperty(v); | |||||
| project.setProperty("key2", "value2"); | |||||
| PropertySet ps = new PropertySet(); | |||||
| ps.setProject(project); | |||||
| ps.appendName("key2"); | |||||
| c.addSyspropertyset(ps); | |||||
| try { | |||||
| c.setSystemProperties(); | |||||
| String newClasspath = System.getProperty("java.class.path"); | |||||
| assertNotNull(newClasspath); | |||||
| assertEquals(currentClasspath, newClasspath); | |||||
| assertNotNull(System.getProperty("key")); | |||||
| assertEquals("value", System.getProperty("key")); | |||||
| assertTrue(System.getProperties().containsKey("java.class.path")); | |||||
| assertNotNull(System.getProperty("key2")); | |||||
| assertEquals("value2", System.getProperty("key2")); | |||||
| } finally { | |||||
| c.restoreSystemProperties(); | |||||
| } | |||||
| assertNull(System.getProperty("key")); | |||||
| assertNull(System.getProperty("key2")); | |||||
| } | |||||
| @Test | |||||
| public void testAssertions() throws Exception { | |||||
| CommandlineJava c = new CommandlineJava(); | |||||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||||
| c.setClassname("junit.textui.TestRunner"); | |||||
| c.createVmArgument().setValue("-Djava.compiler=NONE"); | |||||
| Assertions a = new Assertions(); | |||||
| a.setProject(project); | |||||
| Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion(); | |||||
| ea.setClass("junit.textui.TestRunner"); | |||||
| a.addEnable(ea); | |||||
| c.setAssertions(a); | |||||
| String[] expected = new String[] { | |||||
| null, | |||||
| "-Djava.compiler=NONE", | |||||
| "-ea:junit.textui.TestRunner", | |||||
| "junit.textui.TestRunner", | |||||
| "org.apache.tools.ant.CommandlineJavaTest", | |||||
| }; | |||||
| // only the second iteration would pass because of PR 27218 | |||||
| for (int i = 0; i < 3; i++) { | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(expected.length, s.length); | |||||
| for (int j = 1; j < expected.length; j++) { | |||||
| assertEquals(expected[j], s[j]); | |||||
| } | |||||
| } | |||||
| CommandlineJava c2 = (CommandlineJava) c.clone(); | |||||
| String[] s = c2.getCommandline(); | |||||
| assertEquals(expected.length, s.length); | |||||
| for (int j = 1; j < expected.length; j++) { | |||||
| assertEquals(expected[j], s[j]); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,180 +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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| import static org.junit.Assert.assertNotNull; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.CommandLine | |||||
| * | |||||
| */ | |||||
| public class CommandlineTest { | |||||
| @Test | |||||
| public void testTokenizer() { | |||||
| String[] s = Commandline.translateCommandline("1 2 3"); | |||||
| assertEquals("Simple case", 3, s.length); | |||||
| for (int i=0; i<3; i++) { | |||||
| assertEquals(""+(i+1), s[i]); | |||||
| } | |||||
| s = Commandline.translateCommandline(""); | |||||
| assertEquals("empty string", 0, s.length); | |||||
| s = Commandline.translateCommandline(null); | |||||
| assertEquals("null", 0, s.length); | |||||
| s = Commandline.translateCommandline("1 \'2\' 3"); | |||||
| assertEquals("Simple case with single quotes", 3, s.length); | |||||
| assertEquals("Single quotes have been stripped", "2", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2\" 3"); | |||||
| assertEquals("Simple case with double quotes", 3, s.length); | |||||
| assertEquals("Double quotes have been stripped", "2", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2 3\" 4"); | |||||
| assertEquals("Case with double quotes and whitespace", 3, s.length); | |||||
| assertEquals("Double quotes stripped, space included", "2 3", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2\'3\" 4"); | |||||
| assertEquals("Case with double quotes around single quote", 3, s.length); | |||||
| assertEquals("Double quotes stripped, single quote included", "2\'3", | |||||
| s[1]); | |||||
| s = Commandline.translateCommandline("1 \'2 3\' 4"); | |||||
| assertEquals("Case with single quotes and whitespace", 3, s.length); | |||||
| assertEquals("Single quotes stripped, space included", "2 3", s[1]); | |||||
| s = Commandline.translateCommandline("1 \'2\"3\' 4"); | |||||
| assertEquals("Case with single quotes around double quote", 3, s.length); | |||||
| assertEquals("Single quotes stripped, double quote included", "2\"3", | |||||
| s[1]); | |||||
| // \ doesn't have a special meaning anymore - this is different from | |||||
| // what the Unix sh does but causes a lot of problems on DOS | |||||
| // based platforms otherwise | |||||
| s = Commandline.translateCommandline("1 2\\ 3 4"); | |||||
| assertEquals("case with quoted whitespace", 4, s.length); | |||||
| assertEquals("backslash included", "2\\", s[1]); | |||||
| // "" should become a single empty argument, same for '' | |||||
| // PR 5906 | |||||
| s = Commandline.translateCommandline("\"\" a"); | |||||
| assertEquals("Doublequoted null arg prepend", 2, s.length); | |||||
| assertEquals("Doublequoted null arg prepend", "", s[0]); | |||||
| assertEquals("Doublequoted null arg prepend", "a", s[1]); | |||||
| s = Commandline.translateCommandline("a \"\""); | |||||
| assertEquals("Doublequoted null arg append", 2, s.length); | |||||
| assertEquals("Doublequoted null arg append", "a", s[0]); | |||||
| assertEquals("Doublequoted null arg append", "", s[1]); | |||||
| s = Commandline.translateCommandline("\"\""); | |||||
| assertEquals("Doublequoted null arg", 1, s.length); | |||||
| assertEquals("Doublequoted null arg", "", s[0]); | |||||
| s = Commandline.translateCommandline("\'\' a"); | |||||
| assertEquals("Singlequoted null arg prepend", 2, s.length); | |||||
| assertEquals("Singlequoted null arg prepend", "", s[0]); | |||||
| assertEquals("Singlequoted null arg prepend", "a", s[1]); | |||||
| s = Commandline.translateCommandline("a \'\'"); | |||||
| assertEquals("Singlequoted null arg append", 2, s.length); | |||||
| assertEquals("Singlequoted null arg append", "a", s[0]); | |||||
| assertEquals("Singlequoted null arg append", "", s[1]); | |||||
| s = Commandline.translateCommandline("\'\'"); | |||||
| assertEquals("Singlequoted null arg", 1, s.length); | |||||
| assertEquals("Singlequoted null arg", "", s[0]); | |||||
| // now to the expected failures | |||||
| try { | |||||
| Commandline.translateCommandline("a \'b c"); | |||||
| fail("unbalanced single quotes undetected"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("unbalanced quotes in a \'b c", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| Commandline.translateCommandline("a \"b c"); | |||||
| fail("unbalanced double quotes undetected"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("unbalanced quotes in a \"b c", be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testToString() { | |||||
| assertEquals("", Commandline.toString(new String[0])); | |||||
| assertEquals("", Commandline.toString(null)); | |||||
| assertEquals("1 2 3", Commandline.toString(new String[] {"1", "2", "3"})); | |||||
| assertEquals("1 \"2 3\"", Commandline.toString(new String[] {"1", "2 3"})); | |||||
| assertEquals("1 \"2\'3\"", Commandline.toString(new String[] {"1", "2\'3"})); | |||||
| assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"})); | |||||
| } | |||||
| @Test | |||||
| public void testAwkCommand() { | |||||
| Commandline c = new Commandline(); | |||||
| c.setExecutable("awk"); | |||||
| c.createArgument().setValue("'NR == 2 { print $NF }'"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertNotNull(s); | |||||
| assertEquals(2, s.length); | |||||
| assertEquals("awk", s[0]); | |||||
| assertEquals("'NR == 2 { print $NF }'", s[1]); | |||||
| } | |||||
| @Test | |||||
| public void testPrefix() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setValue("foo"); | |||||
| a.setPrefix("-f="); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(1, s.length); | |||||
| assertEquals("-f=foo", s[0]); | |||||
| } | |||||
| @Test | |||||
| public void testSuffix() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setValue("foo"); | |||||
| a.setSuffix(",1"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(1, s.length); | |||||
| assertEquals("foo,1", s[0]); | |||||
| } | |||||
| @Test | |||||
| public void testPrefixSuffixLine() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setLine("one two"); | |||||
| a.setPrefix("number "); | |||||
| a.setSuffix("."); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(2, s.length); | |||||
| assertEquals("number one.", s[0]); | |||||
| assertEquals("number two.", s[1]); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| import static org.junit.Assert.assertNotNull; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.CommandLine | |||||
| * | |||||
| */ | |||||
| public class CommandlineTest { | |||||
| @Test | |||||
| public void testTokenizer() { | |||||
| String[] s = Commandline.translateCommandline("1 2 3"); | |||||
| assertEquals("Simple case", 3, s.length); | |||||
| for (int i=0; i<3; i++) { | |||||
| assertEquals(""+(i+1), s[i]); | |||||
| } | |||||
| s = Commandline.translateCommandline(""); | |||||
| assertEquals("empty string", 0, s.length); | |||||
| s = Commandline.translateCommandline(null); | |||||
| assertEquals("null", 0, s.length); | |||||
| s = Commandline.translateCommandline("1 \'2\' 3"); | |||||
| assertEquals("Simple case with single quotes", 3, s.length); | |||||
| assertEquals("Single quotes have been stripped", "2", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2\" 3"); | |||||
| assertEquals("Simple case with double quotes", 3, s.length); | |||||
| assertEquals("Double quotes have been stripped", "2", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2 3\" 4"); | |||||
| assertEquals("Case with double quotes and whitespace", 3, s.length); | |||||
| assertEquals("Double quotes stripped, space included", "2 3", s[1]); | |||||
| s = Commandline.translateCommandline("1 \"2\'3\" 4"); | |||||
| assertEquals("Case with double quotes around single quote", 3, s.length); | |||||
| assertEquals("Double quotes stripped, single quote included", "2\'3", | |||||
| s[1]); | |||||
| s = Commandline.translateCommandline("1 \'2 3\' 4"); | |||||
| assertEquals("Case with single quotes and whitespace", 3, s.length); | |||||
| assertEquals("Single quotes stripped, space included", "2 3", s[1]); | |||||
| s = Commandline.translateCommandline("1 \'2\"3\' 4"); | |||||
| assertEquals("Case with single quotes around double quote", 3, s.length); | |||||
| assertEquals("Single quotes stripped, double quote included", "2\"3", | |||||
| s[1]); | |||||
| // \ doesn't have a special meaning anymore - this is different from | |||||
| // what the Unix sh does but causes a lot of problems on DOS | |||||
| // based platforms otherwise | |||||
| s = Commandline.translateCommandline("1 2\\ 3 4"); | |||||
| assertEquals("case with quoted whitespace", 4, s.length); | |||||
| assertEquals("backslash included", "2\\", s[1]); | |||||
| // "" should become a single empty argument, same for '' | |||||
| // PR 5906 | |||||
| s = Commandline.translateCommandline("\"\" a"); | |||||
| assertEquals("Doublequoted null arg prepend", 2, s.length); | |||||
| assertEquals("Doublequoted null arg prepend", "", s[0]); | |||||
| assertEquals("Doublequoted null arg prepend", "a", s[1]); | |||||
| s = Commandline.translateCommandline("a \"\""); | |||||
| assertEquals("Doublequoted null arg append", 2, s.length); | |||||
| assertEquals("Doublequoted null arg append", "a", s[0]); | |||||
| assertEquals("Doublequoted null arg append", "", s[1]); | |||||
| s = Commandline.translateCommandline("\"\""); | |||||
| assertEquals("Doublequoted null arg", 1, s.length); | |||||
| assertEquals("Doublequoted null arg", "", s[0]); | |||||
| s = Commandline.translateCommandline("\'\' a"); | |||||
| assertEquals("Singlequoted null arg prepend", 2, s.length); | |||||
| assertEquals("Singlequoted null arg prepend", "", s[0]); | |||||
| assertEquals("Singlequoted null arg prepend", "a", s[1]); | |||||
| s = Commandline.translateCommandline("a \'\'"); | |||||
| assertEquals("Singlequoted null arg append", 2, s.length); | |||||
| assertEquals("Singlequoted null arg append", "a", s[0]); | |||||
| assertEquals("Singlequoted null arg append", "", s[1]); | |||||
| s = Commandline.translateCommandline("\'\'"); | |||||
| assertEquals("Singlequoted null arg", 1, s.length); | |||||
| assertEquals("Singlequoted null arg", "", s[0]); | |||||
| // now to the expected failures | |||||
| try { | |||||
| Commandline.translateCommandline("a \'b c"); | |||||
| fail("unbalanced single quotes undetected"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("unbalanced quotes in a \'b c", be.getMessage()); | |||||
| } | |||||
| try { | |||||
| Commandline.translateCommandline("a \"b c"); | |||||
| fail("unbalanced double quotes undetected"); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("unbalanced quotes in a \"b c", be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testToString() { | |||||
| assertEquals("", Commandline.toString(new String[0])); | |||||
| assertEquals("", Commandline.toString(null)); | |||||
| assertEquals("1 2 3", Commandline.toString(new String[] {"1", "2", "3"})); | |||||
| assertEquals("1 \"2 3\"", Commandline.toString(new String[] {"1", "2 3"})); | |||||
| assertEquals("1 \"2\'3\"", Commandline.toString(new String[] {"1", "2\'3"})); | |||||
| assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"})); | |||||
| } | |||||
| @Test | |||||
| public void testAwkCommand() { | |||||
| Commandline c = new Commandline(); | |||||
| c.setExecutable("awk"); | |||||
| c.createArgument().setValue("'NR == 2 { print $NF }'"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertNotNull(s); | |||||
| assertEquals(2, s.length); | |||||
| assertEquals("awk", s[0]); | |||||
| assertEquals("'NR == 2 { print $NF }'", s[1]); | |||||
| } | |||||
| @Test | |||||
| public void testPrefix() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setValue("foo"); | |||||
| a.setPrefix("-f="); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(1, s.length); | |||||
| assertEquals("-f=foo", s[0]); | |||||
| } | |||||
| @Test | |||||
| public void testSuffix() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setValue("foo"); | |||||
| a.setSuffix(",1"); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(1, s.length); | |||||
| assertEquals("foo,1", s[0]); | |||||
| } | |||||
| @Test | |||||
| public void testPrefixSuffixLine() { | |||||
| Commandline c = new Commandline(); | |||||
| Commandline.Argument a = c.createArgument(); | |||||
| a.setLine("one two"); | |||||
| a.setPrefix("number "); | |||||
| a.setSuffix("."); | |||||
| String[] s = c.getCommandline(); | |||||
| assertEquals(2, s.length); | |||||
| assertEquals("number one.", s[0]); | |||||
| assertEquals("number two.", s[1]); | |||||
| } | |||||
| } | |||||
| @@ -1,59 +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.types; | |||||
| import org.apache.tools.ant.BuildFileRule; | |||||
| import org.junit.Rule; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| /** | |||||
| * FilterSet testing | |||||
| * | |||||
| */ | |||||
| public class DescriptionTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Test | |||||
| public void test1() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description1.xml"); | |||||
| assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test2() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description2.xml"); | |||||
| assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test3() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description3.xml"); | |||||
| assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test4() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description4.xml"); | |||||
| assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.BuildFileRule; | |||||
| import org.junit.Rule; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| /** | |||||
| * FilterSet testing | |||||
| * | |||||
| */ | |||||
| public class DescriptionTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Test | |||||
| public void test1() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description1.xml"); | |||||
| assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test2() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description2.xml"); | |||||
| assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test3() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description3.xml"); | |||||
| assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| @Test | |||||
| public void test4() { | |||||
| buildRule.configureProject("src/etc/testcases/types/description4.xml"); | |||||
| assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription()); | |||||
| } | |||||
| } | |||||
| @@ -1,94 +1,94 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| import java.io.File; | |||||
| import java.io.FileOutputStream; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.types.DirSet. | |||||
| * | |||||
| */ | |||||
| public class DirSetTest extends AbstractFileSetTest { | |||||
| protected AbstractFileSet getInstance() { | |||||
| return new DirSet(); | |||||
| } | |||||
| @Test | |||||
| public void testFileSetIsNoDirSet() { | |||||
| DirSet ds = (DirSet) getInstance(); | |||||
| ds.setProject(getProject()); | |||||
| FileSet fs = new FileSet(); | |||||
| fs.setProject(getProject()); | |||||
| getProject().addReference("dummy", fs); | |||||
| ds.setRefid(new Reference(getProject(), "dummy")); | |||||
| try { | |||||
| ds.getDir(getProject()); | |||||
| fail("DirSet created from FileSet reference"); | |||||
| } catch (BuildException e) { | |||||
| assertEquals("dummy doesn\'t denote a DirSet", e.getMessage()); | |||||
| } | |||||
| ds = (DirSet) getInstance(); | |||||
| ds.setProject(getProject()); | |||||
| getProject().addReference("dummy2", ds); | |||||
| fs.setRefid(new Reference(getProject(), "dummy2")); | |||||
| try { | |||||
| fs.getDir(getProject()); | |||||
| fail("FileSet created from DirSet reference"); | |||||
| } catch (BuildException e) { | |||||
| assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage()); | |||||
| } | |||||
| } | |||||
| public void testToString() throws Exception { | |||||
| File tmp = File.createTempFile("DirSetTest", ""); | |||||
| try { | |||||
| tmp.delete(); | |||||
| File a = new File(tmp, "a"); | |||||
| a.mkdirs(); | |||||
| File b = new File(tmp, "b"); | |||||
| File bc = new File(b, "c"); | |||||
| bc.mkdirs(); | |||||
| new FileOutputStream(new File(a, "x")).close(); | |||||
| new FileOutputStream(new File(b, "x")).close(); | |||||
| new FileOutputStream(new File(bc, "x")).close(); | |||||
| DirSet ds = new DirSet(); | |||||
| ds.setProject(getProject()); | |||||
| ds.setDir(tmp); | |||||
| ds.setIncludes("b/"); | |||||
| assertEquals("b;b" + File.separator + "c", ds.toString()); | |||||
| } finally { | |||||
| new File(tmp, "a/x").delete(); | |||||
| new File(tmp, "a").delete(); | |||||
| new File(tmp, "b/c/x").delete(); | |||||
| new File(tmp, "b/c").delete(); | |||||
| new File(tmp, "b/x").delete(); | |||||
| new File(tmp, "b").delete(); | |||||
| tmp.delete(); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import java.io.File; | |||||
| import java.io.FileOutputStream; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.types.DirSet. | |||||
| * | |||||
| */ | |||||
| public class DirSetTest extends AbstractFileSetTest { | |||||
| protected AbstractFileSet getInstance() { | |||||
| return new DirSet(); | |||||
| } | |||||
| @Test | |||||
| public void testFileSetIsNoDirSet() { | |||||
| DirSet ds = (DirSet) getInstance(); | |||||
| ds.setProject(getProject()); | |||||
| FileSet fs = new FileSet(); | |||||
| fs.setProject(getProject()); | |||||
| getProject().addReference("dummy", fs); | |||||
| ds.setRefid(new Reference(getProject(), "dummy")); | |||||
| try { | |||||
| ds.getDir(getProject()); | |||||
| fail("DirSet created from FileSet reference"); | |||||
| } catch (BuildException e) { | |||||
| assertEquals("dummy doesn\'t denote a DirSet", e.getMessage()); | |||||
| } | |||||
| ds = (DirSet) getInstance(); | |||||
| ds.setProject(getProject()); | |||||
| getProject().addReference("dummy2", ds); | |||||
| fs.setRefid(new Reference(getProject(), "dummy2")); | |||||
| try { | |||||
| fs.getDir(getProject()); | |||||
| fail("FileSet created from DirSet reference"); | |||||
| } catch (BuildException e) { | |||||
| assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage()); | |||||
| } | |||||
| } | |||||
| public void testToString() throws Exception { | |||||
| File tmp = File.createTempFile("DirSetTest", ""); | |||||
| try { | |||||
| tmp.delete(); | |||||
| File a = new File(tmp, "a"); | |||||
| a.mkdirs(); | |||||
| File b = new File(tmp, "b"); | |||||
| File bc = new File(b, "c"); | |||||
| bc.mkdirs(); | |||||
| new FileOutputStream(new File(a, "x")).close(); | |||||
| new FileOutputStream(new File(b, "x")).close(); | |||||
| new FileOutputStream(new File(bc, "x")).close(); | |||||
| DirSet ds = new DirSet(); | |||||
| ds.setProject(getProject()); | |||||
| ds.setDir(tmp); | |||||
| ds.setIncludes("b/"); | |||||
| assertEquals("b;b" + File.separator + "c", ds.toString()); | |||||
| } finally { | |||||
| new File(tmp, "a/x").delete(); | |||||
| new File(tmp, "a").delete(); | |||||
| new File(tmp, "b/c/x").delete(); | |||||
| new File(tmp, "b/c").delete(); | |||||
| new File(tmp, "b/x").delete(); | |||||
| new File(tmp, "b").delete(); | |||||
| tmp.delete(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,106 +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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.assertTrue; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute. | |||||
| */ | |||||
| public class EnumeratedAttributeTest { | |||||
| private static String[] expected = {"a", "b", "c"}; | |||||
| @Test | |||||
| public void testContains() { | |||||
| EnumeratedAttribute t1 = new TestNormal(); | |||||
| for (int i=0; i<expected.length; i++) { | |||||
| assertTrue(expected[i]+" is in TestNormal", | |||||
| t1.containsValue(expected[i])); | |||||
| assertTrue(expected[i].toUpperCase()+" is in TestNormal", | |||||
| !t1.containsValue(expected[i].toUpperCase())); | |||||
| } | |||||
| assertTrue("TestNormal doesn\'t have \"d\" attribute", | |||||
| !t1.containsValue("d")); | |||||
| assertTrue("TestNull doesn\'t have \"d\" attribute and doesn\'t die", | |||||
| !(new TestNull()).containsValue("d")); | |||||
| } | |||||
| @Test | |||||
| public void testFactory() { | |||||
| Factory ea = (Factory)EnumeratedAttribute.getInstance(Factory.class, "one"); | |||||
| assertEquals("Factory did not set the right value.", ea.getValue(), "one"); | |||||
| try { | |||||
| EnumeratedAttribute.getInstance(Factory.class, "illegal"); | |||||
| fail("Factory should fail when trying to set an illegal value."); | |||||
| } catch (BuildException be) { | |||||
| // was expected | |||||
| //TODO assert exception message | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testExceptions() { | |||||
| EnumeratedAttribute t1 = new TestNormal(); | |||||
| for (int i=0; i<expected.length; i++) { | |||||
| try { | |||||
| t1.setValue(expected[i]); | |||||
| } catch (BuildException be) { | |||||
| fail("unexpected exception for value "+expected[i]); | |||||
| } | |||||
| } | |||||
| try { | |||||
| t1.setValue("d"); | |||||
| fail("expected exception for value \"d\""); | |||||
| } catch (BuildException be) { | |||||
| //TODO assert build exception | |||||
| } | |||||
| try { | |||||
| (new TestNull()).setValue("d"); | |||||
| fail("expected exception for value \"d\" in TestNull"); | |||||
| } catch (BuildException be) { | |||||
| //TODO assert exception message | |||||
| } | |||||
| } | |||||
| public static class TestNormal extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return expected; | |||||
| } | |||||
| } | |||||
| public static class TestNull extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public static class Factory extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return new String[] { "one", "two", "three" }; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.assertTrue; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute. | |||||
| */ | |||||
| public class EnumeratedAttributeTest { | |||||
| private static String[] expected = {"a", "b", "c"}; | |||||
| @Test | |||||
| public void testContains() { | |||||
| EnumeratedAttribute t1 = new TestNormal(); | |||||
| for (int i=0; i<expected.length; i++) { | |||||
| assertTrue(expected[i]+" is in TestNormal", | |||||
| t1.containsValue(expected[i])); | |||||
| assertTrue(expected[i].toUpperCase()+" is in TestNormal", | |||||
| !t1.containsValue(expected[i].toUpperCase())); | |||||
| } | |||||
| assertTrue("TestNormal doesn\'t have \"d\" attribute", | |||||
| !t1.containsValue("d")); | |||||
| assertTrue("TestNull doesn\'t have \"d\" attribute and doesn\'t die", | |||||
| !(new TestNull()).containsValue("d")); | |||||
| } | |||||
| @Test | |||||
| public void testFactory() { | |||||
| Factory ea = (Factory)EnumeratedAttribute.getInstance(Factory.class, "one"); | |||||
| assertEquals("Factory did not set the right value.", ea.getValue(), "one"); | |||||
| try { | |||||
| EnumeratedAttribute.getInstance(Factory.class, "illegal"); | |||||
| fail("Factory should fail when trying to set an illegal value."); | |||||
| } catch (BuildException be) { | |||||
| // was expected | |||||
| //TODO assert exception message | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testExceptions() { | |||||
| EnumeratedAttribute t1 = new TestNormal(); | |||||
| for (int i=0; i<expected.length; i++) { | |||||
| try { | |||||
| t1.setValue(expected[i]); | |||||
| } catch (BuildException be) { | |||||
| fail("unexpected exception for value "+expected[i]); | |||||
| } | |||||
| } | |||||
| try { | |||||
| t1.setValue("d"); | |||||
| fail("expected exception for value \"d\""); | |||||
| } catch (BuildException be) { | |||||
| //TODO assert build exception | |||||
| } | |||||
| try { | |||||
| (new TestNull()).setValue("d"); | |||||
| fail("expected exception for value \"d\" in TestNull"); | |||||
| } catch (BuildException be) { | |||||
| //TODO assert exception message | |||||
| } | |||||
| } | |||||
| public static class TestNormal extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return expected; | |||||
| } | |||||
| } | |||||
| public static class TestNull extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public static class Factory extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return new String[] { "one", "two", "three" }; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,163 +1,163 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| 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.File; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * Some tests for filelist. | |||||
| */ | |||||
| public class FileListTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/filelist.xml"); | |||||
| } | |||||
| @Test | |||||
| public void testEmptyElementIfIsReference() { | |||||
| FileList f = new FileList(); | |||||
| f.setDir(buildRule.getProject().resolveFile(".")); | |||||
| try { | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| fail("Can add reference to FileList with directory attribute set."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| f = new FileList(); | |||||
| f.setFiles("foo.xml,c/d/bar.xml"); | |||||
| try { | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| fail("Can add reference to FileList with file attribute set."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| f = new FileList(); | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| try { | |||||
| f.setFiles("a/b/foo.java"); | |||||
| fail("Can set files in FileList that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setDir(buildRule.getProject().resolveFile(".")); | |||||
| fail("Can set dir in FileList that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testCircularReferenceCheck() { | |||||
| FileList f = new FileList(); | |||||
| buildRule.getProject().addReference("dummy", f); | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummy")); | |||||
| try { | |||||
| f.getDir(buildRule.getProject()); | |||||
| fail("Can make FileList a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.getFiles(buildRule.getProject()); | |||||
| fail("Can make FileList a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 --> dummy1 | |||||
| FileList f1 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); | |||||
| FileList f2 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); | |||||
| FileList f3 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy3", f3); | |||||
| f3.setRefid(new Reference(buildRule.getProject(), "dummy1")); | |||||
| try { | |||||
| f1.getDir(buildRule.getProject()); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f1.getFiles(buildRule.getProject()); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 | |||||
| // (which has the Project's basedir as root). | |||||
| f1 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); | |||||
| f2 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); | |||||
| f3 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy3", f3); | |||||
| f3.setDir(buildRule.getProject().resolveFile(".")); | |||||
| File dir = f1.getDir(buildRule.getProject()); | |||||
| assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir()); | |||||
| } | |||||
| @Test | |||||
| public void testSimple() { | |||||
| buildRule.executeTarget("simple"); | |||||
| assertEquals("/abc/a", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testDouble() { | |||||
| buildRule.executeTarget("double"); | |||||
| assertEquals("/abc/a:/abc/b", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNested() { | |||||
| buildRule.executeTarget("nested"); | |||||
| assertEquals("/abc/a:/abc/b", buildRule.getLog()); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| 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.File; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * Some tests for filelist. | |||||
| */ | |||||
| public class FileListTest { | |||||
| @Rule | |||||
| public BuildFileRule buildRule = new BuildFileRule(); | |||||
| @Before | |||||
| public void setUp() { | |||||
| buildRule.configureProject("src/etc/testcases/types/filelist.xml"); | |||||
| } | |||||
| @Test | |||||
| public void testEmptyElementIfIsReference() { | |||||
| FileList f = new FileList(); | |||||
| f.setDir(buildRule.getProject().resolveFile(".")); | |||||
| try { | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| fail("Can add reference to FileList with directory attribute set."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| f = new FileList(); | |||||
| f.setFiles("foo.xml,c/d/bar.xml"); | |||||
| try { | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| fail("Can add reference to FileList with file attribute set."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| f = new FileList(); | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummyref")); | |||||
| try { | |||||
| f.setFiles("a/b/foo.java"); | |||||
| fail("Can set files in FileList that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.setDir(buildRule.getProject().resolveFile(".")); | |||||
| fail("Can set dir in FileList that is a reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("You must not specify more than one attribute when using refid", | |||||
| be.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testCircularReferenceCheck() { | |||||
| FileList f = new FileList(); | |||||
| buildRule.getProject().addReference("dummy", f); | |||||
| f.setRefid(new Reference(buildRule.getProject(), "dummy")); | |||||
| try { | |||||
| f.getDir(buildRule.getProject()); | |||||
| fail("Can make FileList a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f.getFiles(buildRule.getProject()); | |||||
| fail("Can make FileList a Reference to itself."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 --> dummy1 | |||||
| FileList f1 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); | |||||
| FileList f2 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); | |||||
| FileList f3 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy3", f3); | |||||
| f3.setRefid(new Reference(buildRule.getProject(), "dummy1")); | |||||
| try { | |||||
| f1.getDir(buildRule.getProject()); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| try { | |||||
| f1.getFiles(buildRule.getProject()); | |||||
| fail("Can make circular reference."); | |||||
| } catch (BuildException be) { | |||||
| assertEquals("This data type contains a circular reference.", | |||||
| be.getMessage()); | |||||
| } | |||||
| // dummy1 --> dummy2 --> dummy3 | |||||
| // (which has the Project's basedir as root). | |||||
| f1 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy1", f1); | |||||
| f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); | |||||
| f2 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy2", f2); | |||||
| f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); | |||||
| f3 = new FileList(); | |||||
| buildRule.getProject().addReference("dummy3", f3); | |||||
| f3.setDir(buildRule.getProject().resolveFile(".")); | |||||
| File dir = f1.getDir(buildRule.getProject()); | |||||
| assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir()); | |||||
| } | |||||
| @Test | |||||
| public void testSimple() { | |||||
| buildRule.executeTarget("simple"); | |||||
| assertEquals("/abc/a", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testDouble() { | |||||
| buildRule.executeTarget("double"); | |||||
| assertEquals("/abc/a:/abc/b", buildRule.getLog()); | |||||
| } | |||||
| @Test | |||||
| public void testNested() { | |||||
| buildRule.executeTarget("nested"); | |||||
| assertEquals("/abc/a:/abc/b", buildRule.getLog()); | |||||
| } | |||||
| } | |||||
| @@ -1,36 +1,36 @@ | |||||
| /* | |||||
| * 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.types; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.types.FileSet. | |||||
| * | |||||
| * <p>This doesn't actually test much, mainly reference handling. | |||||
| * | |||||
| */ | |||||
| public class FileSetTest extends AbstractFileSetTest { | |||||
| protected AbstractFileSet getInstance() { | |||||
| return new FileSet(); | |||||
| } | |||||
| } | |||||
| /* | |||||
| * 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.types; | |||||
| /** | |||||
| * JUnit 3 testcases for org.apache.tools.ant.types.FileSet. | |||||
| * | |||||
| * <p>This doesn't actually test much, mainly reference handling. | |||||
| * | |||||
| */ | |||||
| public class FileSetTest extends AbstractFileSetTest { | |||||
| protected AbstractFileSet getInstance() { | |||||
| return new FileSet(); | |||||
| } | |||||
| } | |||||