http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java index 2f351d4..0b301f9 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -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); + } +}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java index 6e318ad..40472de 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java @@ -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()); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java index 62ba085..cde44d0 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java @@ -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)); + } + + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java index 3138e3a..1e8acc9 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java @@ -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)); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/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 a403673..d74c798 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/0ed7f4ab/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 0f7aff7..cd7a431 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/0ed7f4ab/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 ad5973c..d043b59 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/0ed7f4ab/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 d3ec1a3..41803de 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/0ed7f4ab/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 d05cf0c..3ca428e 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); + } + +}
