http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java index 7056ca9..a403673 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java @@ -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 = "[email protected]", - NEW_EMAIL = "[email protected]", - 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 = "[email protected]", + NEW_EMAIL = "[email protected]", + 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"; +}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java index cd7a431..0f7aff7 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java @@ -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 + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java index b6c09a5..ad5973c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java @@ -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 http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java index 41803de..d3ec1a3 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java @@ -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"); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java index 35576dc..d05cf0c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java @@ -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); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java index ac4462d..e69ffb4 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java @@ -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) { + } + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java index 667c890..5914001 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java @@ -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"); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java index 02281eb..1444141 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java @@ -1,129 +1,129 @@ -package org.apache.tools.ant.taskdefs.optional; - -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.security.Permission; - -import junit.framework.AssertionFailedError; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.XSLTLiaison; -import org.apache.tools.ant.taskdefs.XSLTLogger; -import org.apache.tools.ant.util.JAXPUtils; -import org.junit.After; -import org.junit.Assume; -import org.junit.Test; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * TraX XSLTLiaison testcase - */ -public class TraXLiaisonTest extends AbstractXSLTLiaisonTest - implements XSLTLogger { - - - @After - public void tearDown() { - File f = new File("xalan2-redirect-out.tmp"); - if (f.exists()) { - f.delete(); - } - } - - public XSLTLiaison createLiaison() throws Exception { - TraXLiaison l = new TraXLiaison(); - l.setLogger(this); - return l; - } - - @Test - public void testXalan2Redirect() throws Exception { - try { - getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect"); - } catch (Exception exc) { - Assume.assumeNoException("xalan redirect is not on the classpath", exc); - } - File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl"); - liaison.setStylesheet(xsl); - File out = new File("xalan2-redirect-out-dummy.tmp"); - File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); - ClassLoader orig = Thread.currentThread().getContextClassLoader(); - try { - liaison.addParam("xalan-version", "2"); - // Use the JRE's Xerces, not lib/optional/xerces.jar: - Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { - public InputStream getResourceAsStream(String name) { - if (name.startsWith("META-INF/services/")) { - // work around JAXP #6723276 in JDK 6 - return new ByteArrayInputStream(new byte[0]); - } - return super.getResourceAsStream(name); - } - }); - // Tickle #52382: - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); - liaison.transform(in, out); - } finally { - out.delete(); - Thread.currentThread().setContextClassLoader(orig); - System.setSecurityManager(null); - } - } - - @Test - public void testMultipleTransform() throws Exception { - File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); - liaison.setStylesheet(xsl); - liaison.addParam("param", "value"); - File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); - // test for 10 consecutives transform - for (int i = 0; i < 50; i++){ - File out = new File("xsltliaison" + i + ".tmp"); - try { - liaison.transform(in, out); - } catch (Exception e){ - throw new BuildException("failed in transform " + i, e); - } finally { - out.delete(); - } - } - } - - @Test - public void testSystemId(){ - File file = null; - if ( File.separatorChar == '\\' ){ - file = new File("d:\\jdk"); - } else { - file = new File("/user/local/bin"); - } - String systemid = JAXPUtils.getSystemId(file); - assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); - assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); - } - - public void log(String message) { - throw new AssertionFailedError("Liaison sent message: "+message); - } - -} +package org.apache.tools.ant.taskdefs.optional; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.security.Permission; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.taskdefs.XSLTLogger; +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * TraX XSLTLiaison testcase + */ +public class TraXLiaisonTest extends AbstractXSLTLiaisonTest + implements XSLTLogger { + + + @After + public void tearDown() { + File f = new File("xalan2-redirect-out.tmp"); + if (f.exists()) { + f.delete(); + } + } + + public XSLTLiaison createLiaison() throws Exception { + TraXLiaison l = new TraXLiaison(); + l.setLogger(this); + return l; + } + + @Test + public void testXalan2Redirect() throws Exception { + try { + getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect"); + } catch (Exception exc) { + Assume.assumeNoException("xalan redirect is not on the classpath", exc); + } + File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl"); + liaison.setStylesheet(xsl); + File out = new File("xalan2-redirect-out-dummy.tmp"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + ClassLoader orig = Thread.currentThread().getContextClassLoader(); + try { + liaison.addParam("xalan-version", "2"); + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + // work around JAXP #6723276 in JDK 6 + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + // Tickle #52382: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + liaison.transform(in, out); + } finally { + out.delete(); + Thread.currentThread().setContextClassLoader(orig); + System.setSecurityManager(null); + } + } + + @Test + public void testMultipleTransform() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + liaison.setStylesheet(xsl); + liaison.addParam("param", "value"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); + // test for 10 consecutives transform + for (int i = 0; i < 50; i++){ + File out = new File("xsltliaison" + i + ".tmp"); + try { + liaison.transform(in, out); + } catch (Exception e){ + throw new BuildException("failed in transform " + i, e); + } finally { + out.delete(); + } + } + } + + @Test + public void testSystemId(){ + File file = null; + if ( File.separatorChar == '\\' ){ + file = new File("d:\\jdk"); + } else { + file = new File("/user/local/bin"); + } + String systemid = JAXPUtils.getSystemId(file); + assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); + assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + } + + public void log(String message) { + throw new AssertionFailedError("Liaison sent message: "+message); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java index c9948bb..02b11a3 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java @@ -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"); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java index 58f7a4b..869031f 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java @@ -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 + } + } + +}
