http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java index 6c05963..c11ba73 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java @@ -1,131 +1,131 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.resources; - -import java.io.File; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.AbstractFileSet; -import org.apache.tools.ant.types.AbstractFileSetTest; -import org.apache.tools.ant.types.Reference; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * This doesn't actually test much, mainly reference handling. - */ -public class MultiRootFileSetTest extends AbstractFileSetTest { - - - protected AbstractFileSet getInstance() { - return new MultiRootFileSet() { - // overriding so set/getDir works as expected by the base test class - private File dir; - public void setDir(File dir) { - if (isReference()) { - throw tooManyAttributes(); - } - this.dir = dir; - } - - public synchronized File getDir(Project p) { - if (isReference()) { - return getRef(p).getDir(p); - } - dieOnCircularReference(); - return dir; - } - }; - } - - @Test - public void testEmptyElementIfIsReferenceAdditionalAttributes() { - MultiRootFileSet f = new MultiRootFileSet(); - f.setProject(getProject()); - f.setBaseDirs("a"); - try { - f.setRefid(new Reference(getProject(), "dummyref")); - fail("Can add reference to multirootfileset " - + " with elements from setBasedirs"); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute " - + "when using refid", be.getMessage()); - } - f = new MultiRootFileSet(); - f.addConfiguredBaseDir(new FileResource(new File("."))); - try { - f.setRefid(new Reference(getProject(), "dummyref")); - fail("Can add reference to multirootfileset" - + " with elements from addConfiguredBaseDir"); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute " - + "when using refid", be.getMessage()); - } - - f = new MultiRootFileSet(); - f.setRefid(new Reference(getProject(), "dummyref")); - try { - f.setBaseDirs("a"); - fail("Can set basedirs in multirootfileset" - + " that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute " - + "when using refid", be.getMessage()); - } - try { - f.setCache(true); - fail("Can set cache in multirootfileset" - + " that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute " - + "when using refid", be.getMessage()); - } - try { - f.setType(MultiRootFileSet.SetType.file); - fail("Can set type in multirootfileset" - + " that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute " - + "when using refid", be.getMessage()); - } - try { - f.addConfiguredBaseDir(new FileResource(new File("."))); - fail("Can add nested basedir in multirootfileset " - + " that is a reference."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using " - + "refid", be.getMessage()); - } - } - - @Test - public void testDirCannotBeSet() { - try { - new MultiRootFileSet().setDir(new File(".")); - fail("Can set dir in a multirootfileset"); - } catch (BuildException e) { - assertTrue(e.getMessage() - .endsWith(" doesn't support the dir attribute")); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.resources; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.AbstractFileSet; +import org.apache.tools.ant.types.AbstractFileSetTest; +import org.apache.tools.ant.types.Reference; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * This doesn't actually test much, mainly reference handling. + */ +public class MultiRootFileSetTest extends AbstractFileSetTest { + + + protected AbstractFileSet getInstance() { + return new MultiRootFileSet() { + // overriding so set/getDir works as expected by the base test class + private File dir; + public void setDir(File dir) { + if (isReference()) { + throw tooManyAttributes(); + } + this.dir = dir; + } + + public synchronized File getDir(Project p) { + if (isReference()) { + return getRef(p).getDir(p); + } + dieOnCircularReference(); + return dir; + } + }; + } + + @Test + public void testEmptyElementIfIsReferenceAdditionalAttributes() { + MultiRootFileSet f = new MultiRootFileSet(); + f.setProject(getProject()); + f.setBaseDirs("a"); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to multirootfileset " + + " with elements from setBasedirs"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + f = new MultiRootFileSet(); + f.addConfiguredBaseDir(new FileResource(new File("."))); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to multirootfileset" + + " with elements from addConfiguredBaseDir"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + + f = new MultiRootFileSet(); + f.setRefid(new Reference(getProject(), "dummyref")); + try { + f.setBaseDirs("a"); + fail("Can set basedirs in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setCache(true); + fail("Can set cache in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setType(MultiRootFileSet.SetType.file); + fail("Can set type in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.addConfiguredBaseDir(new FileResource(new File("."))); + fail("Can add nested basedir in multirootfileset " + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + } + + @Test + public void testDirCannotBeSet() { + try { + new MultiRootFileSet().setDir(new File(".")); + fail("Can set dir in a multirootfileset"); + } catch (BuildException e) { + assertTrue(e.getMessage() + .endsWith(" doesn't support the dir attribute")); + } + } +}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java index f020178..a45e184 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java @@ -1,134 +1,134 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.types.resources; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildFileRule; -import org.apache.tools.ant.types.FilterChain; -import org.apache.tools.ant.types.Reference; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class ResourceListTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() throws Exception { - buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml"); - } - - @After - public void tearDown() throws Exception { - buildRule.executeTarget("tearDown"); - } - - @Test - public void testEmptyElementWithReference() { - ResourceList rl = new ResourceList(); - rl.setEncoding("foo"); - try { - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - fail("Can add reference to ResourceList with encoding attribute set."); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - - rl = new ResourceList(); - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - try { - rl.setEncoding("foo"); - fail("Can set encoding in ResourceList that is a reference"); - } catch (BuildException be) { - assertEquals("You must not specify more than one attribute when using refid", - be.getMessage()); - } - - rl = new ResourceList(); - rl.add(new FileResource(buildRule.getProject(), ".")); - try { - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - fail("Can add reference to ResourceList with nested resource collection."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - - rl = new ResourceList(); - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - try { - rl.add(new FileResource(buildRule.getProject(), ".")); - fail("Can add reference to ResourceList with nested resource collection."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - - rl = new ResourceList(); - rl.addFilterChain(new FilterChain()); - try { - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - fail("Can add reference to ResourceList with nested filter chain."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - - rl = new ResourceList(); - rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); - try { - rl.addFilterChain(new FilterChain()); - fail("Can add reference to ResourceList with nested filter chain."); - } catch (BuildException be) { - assertEquals("You must not specify nested elements when using refid", - be.getMessage()); - } - } - - @Test - public void testCircularReference() throws Exception { - ResourceList rl1 = new ResourceList(); - rl1.setProject(buildRule.getProject()); - rl1.setRefid(new Reference(buildRule.getProject(), "foo")); - - ResourceList rl2 = new ResourceList(); - rl2.setProject(buildRule.getProject()); - buildRule.getProject().addReference("foo", rl2); - - Union u = new Union(); - u.add(rl1); - u.setProject(buildRule.getProject()); - - rl2.add(u); - - try { - rl2.size(); - fail("Can make ResourceList a Reference to itself."); - } catch (BuildException be) { - assertEquals("This data type contains a circular reference.", - be.getMessage()); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.types.resources; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.types.FilterChain; +import org.apache.tools.ant.types.Reference; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class ResourceListTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml"); + } + + @After + public void tearDown() throws Exception { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testEmptyElementWithReference() { + ResourceList rl = new ResourceList(); + rl.setEncoding("foo"); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with encoding attribute set."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.setEncoding("foo"); + fail("Can set encoding in ResourceList that is a reference"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.add(new FileResource(buildRule.getProject(), ".")); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with nested resource collection."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.add(new FileResource(buildRule.getProject(), ".")); + fail("Can add reference to ResourceList with nested resource collection."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.addFilterChain(new FilterChain()); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with nested filter chain."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.addFilterChain(new FilterChain()); + fail("Can add reference to ResourceList with nested filter chain."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReference() throws Exception { + ResourceList rl1 = new ResourceList(); + rl1.setProject(buildRule.getProject()); + rl1.setRefid(new Reference(buildRule.getProject(), "foo")); + + ResourceList rl2 = new ResourceList(); + rl2.setProject(buildRule.getProject()); + buildRule.getProject().addReference("foo", rl2); + + Union u = new Union(); + u.add(rl1); + u.setProject(buildRule.getProject()); + + rl2.add(u); + + try { + rl2.size(); + fail("Can make ResourceList a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java index a9593f0..d0a0fe3 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java @@ -1,54 +1,54 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.types.resources; - -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.apache.tools.ant.FileUtilities.getFileContents; -import static org.junit.Assert.assertEquals; - - -public class TarResourceTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() throws Exception { - buildRule.configureProject("src/etc/testcases/types/resources/tarentry.xml"); - } - - - @After - public void tearDown() throws Exception { - buildRule.executeTarget("tearDown"); - } - - @Test - public void testUncompressSource() throws java.io.IOException { - buildRule.executeTarget("uncompressSource"); - assertEquals(getFileContents(buildRule.getProject().resolveFile("../../asf-logo.gif")), - getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.types.resources; + +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.apache.tools.ant.FileUtilities.getFileContents; +import static org.junit.Assert.assertEquals; + + +public class TarResourceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/types/resources/tarentry.xml"); + } + + + @After + public void tearDown() throws Exception { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testUncompressSource() throws java.io.IOException { + buildRule.executeTarget("uncompressSource"); + assertEquals(getFileContents(buildRule.getProject().resolveFile("../../asf-logo.gif")), + getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java index d5613b2..8862cb1 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java @@ -1,125 +1,125 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.selectors; - -import java.io.File; - - -import org.apache.tools.ant.BuildFileRule; - - -/** - * Base test case for Selectors. Provides a shared test as well as - * a test bed for selecting on, and a helper method for determining - * whether selections are correct. - * - */ -public class BaseSelectorRule extends BuildFileRule { - - private File beddir; - private File mirrordir; - private final String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", - "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", - "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", - "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", - "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; - private File[] files = new File[filenames.length]; - private File[] mirrorfiles = new File[filenames.length]; - - @Override - public void before() throws Throwable { - super.before(); - configureProject("src/etc/testcases/types/selectors.xml"); - executeTarget("setUp"); - - executeTarget("setupfiles"); - executeTarget("mirrorfiles"); - - beddir = new File(super.getProject().getProperty("test.dir")); - mirrordir = new File(super.getProject().getProperty("mirror.dir")); - - for (int x = 0; x < files.length; x++) { - files[x] = new File(beddir,filenames[x]); - mirrorfiles[x] = new File(mirrordir,filenames[x]); - } - } - - @Override - public void after() { - super.after(); - executeTarget("tearDown"); - } - - public File getBeddir() { - return beddir; - } - - public File[] getMirrorFiles() { - return mirrorfiles; - } - - public File[] getFiles() { - return files; - } - - public String[] getFilenames() { - return filenames; - } - - - /** - * This is a helper method that takes a selector and calls its - * isSelected() method on each file in the testbed. It returns - * a string of "T"s amd "F"s - */ - public String selectionString(FileSelector selector) { - return selectionString(beddir,files,selector); - } - - /** - * This is a helper method that takes a selector and calls its - * isSelected() method on each file in the mirror testbed. This - * variation is used for dependency checks and to get around the - * limitations in the touch task when running JDK 1.1. It returns - * a string of "T"s amd "F"s. - */ - public String mirrorSelectionString(FileSelector selector) { - return selectionString(mirrordir,mirrorfiles,selector); - } - - /** - * Worker method for the two convenience methods above. Applies a - * selector on a set of files passed in and returns a string of - * "T"s amd "F"s from applying the selector to each file. - */ - public String selectionString(File basedir, File[] files, FileSelector selector) { - StringBuilder buf = new StringBuilder(); - for (int x = 0; x < files.length; x++) { - if (selector.isSelected(basedir,filenames[x],files[x])) { - buf.append('T'); - } - else { - buf.append('F'); - } - } - return buf.toString(); - } - - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.selectors; + +import java.io.File; + + +import org.apache.tools.ant.BuildFileRule; + + +/** + * Base test case for Selectors. Provides a shared test as well as + * a test bed for selecting on, and a helper method for determining + * whether selections are correct. + * + */ +public class BaseSelectorRule extends BuildFileRule { + + private File beddir; + private File mirrordir; + private final String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", + "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", + "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", + "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", + "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; + private File[] files = new File[filenames.length]; + private File[] mirrorfiles = new File[filenames.length]; + + @Override + public void before() throws Throwable { + super.before(); + configureProject("src/etc/testcases/types/selectors.xml"); + executeTarget("setUp"); + + executeTarget("setupfiles"); + executeTarget("mirrorfiles"); + + beddir = new File(super.getProject().getProperty("test.dir")); + mirrordir = new File(super.getProject().getProperty("mirror.dir")); + + for (int x = 0; x < files.length; x++) { + files[x] = new File(beddir,filenames[x]); + mirrorfiles[x] = new File(mirrordir,filenames[x]); + } + } + + @Override + public void after() { + super.after(); + executeTarget("tearDown"); + } + + public File getBeddir() { + return beddir; + } + + public File[] getMirrorFiles() { + return mirrorfiles; + } + + public File[] getFiles() { + return files; + } + + public String[] getFilenames() { + return filenames; + } + + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the testbed. It returns + * a string of "T"s amd "F"s + */ + public String selectionString(FileSelector selector) { + return selectionString(beddir,files,selector); + } + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the mirror testbed. This + * variation is used for dependency checks and to get around the + * limitations in the touch task when running JDK 1.1. It returns + * a string of "T"s amd "F"s. + */ + public String mirrorSelectionString(FileSelector selector) { + return selectionString(mirrordir,mirrorfiles,selector); + } + + /** + * Worker method for the two convenience methods above. Applies a + * selector on a set of files passed in and returns a string of + * "T"s amd "F"s from applying the selector to each file. + */ + public String selectionString(File basedir, File[] files, FileSelector selector) { + StringBuilder buf = new StringBuilder(); + for (int x = 0; x < files.length; x++) { + if (selector.isSelected(basedir,filenames[x],files[x])) { + buf.append('T'); + } + else { + buf.append('F'); + } + } + return buf.toString(); + } + + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java index 2332778..1cc38d4 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java @@ -1,295 +1,295 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.selectors; - -import java.io.File; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildFileTest; -import org.apache.tools.ant.Project; - -/** - * Base test case for Selectors. Provides a shared test as well as - * a test bed for selecting on, and a helper method for determining - * whether selections are correct. - * - * @deprecated as of 1.9.4. Use {@link org.apache.tools.ant.types.selectors.BaseSelectorRule} instead. - */ -@Deprecated -public abstract class BaseSelectorTest extends BuildFileTest { - - private Project project; - private TaskdefForMakingBed tbed = null; - protected File basedir; - protected File beddir; - protected File mirrordir; - protected String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", - "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", - "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", - "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", - "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; - protected File[] files = new File[filenames.length]; - protected File[] mirrorfiles = new File[filenames.length]; - - public BaseSelectorTest(String name) { - super(name); - } - - public void setUp() { - configureProject("src/etc/testcases/types/selectors.xml"); - executeTarget("setUp"); - beddir = new File(super.getProject().getProperty("test.dir")); - mirrordir = new File(super.getProject().getProperty("mirror.dir")); - basedir = getProjectDir(); - project = new Project(); - project.init(); - project.setBaseDir(basedir); - for (int x = 0; x < files.length; x++) { - files[x] = new File(beddir,filenames[x]); - mirrorfiles[x] = new File(mirrordir,filenames[x]); - } - } - - /** - * Override this in child classes to return a specific Selector - */ - public abstract BaseSelector getInstance(); - - - /** - * Return a preconfigured selector (with a set reference to - * project instance). - * @return the selector - */ - public BaseSelector getSelector() { - BaseSelector selector = getInstance(); - selector.setProject( getProject() ); - return selector; - } - - - public Project getProject() { - return project; - } - - /** - * This is a test that all Selectors derived from BaseSelector can - * use. It calls the setError() method and checks to ensure that a - * BuildException is thrown as a result. - */ - public void testRespondsToError() { - BaseSelector s = getInstance(); - if (s == null) { - return; - } - s.setError("test error"); - try { - s.isSelected(beddir,filenames[0],files[0]); - fail("Cannot cause BuildException when setError() is called"); - } catch (BuildException be) { - assertEquals("test error", - be.getMessage()); - } - } - - - /** - * This is a helper method that takes a selector and calls its - * isSelected() method on each file in the testbed. It returns - * a string of "T"s amd "F"s - */ - public String selectionString(FileSelector selector) { - return selectionString(beddir,files,selector); - } - - /** - * This is a helper method that takes a selector and calls its - * isSelected() method on each file in the mirror testbed. This - * variation is used for dependency checks and to get around the - * limitations in the touch task when running JDK 1.1. It returns - * a string of "T"s amd "F"s. - */ - public String mirrorSelectionString(FileSelector selector) { - return selectionString(mirrordir,mirrorfiles,selector); - } - - /** - * Worker method for the two convenience methods above. Applies a - * selector on a set of files passed in and returns a string of - * "T"s amd "F"s from applying the selector to each file. - */ - public String selectionString(File basedir, File[] files, FileSelector selector) { - StringBuffer buf = new StringBuffer(); - for (int x = 0; x < files.length; x++) { - if (selector.isSelected(basedir,filenames[x],files[x])) { - buf.append('T'); - } - else { - buf.append('F'); - } - } - return buf.toString(); - } - - /** - * Does the selection test for a given selector and prints the - * filenames of the differing files (selected but shouldn't, - * not selected but should). - * @param selector The selector to test - * @param expected The expected result - */ - public void performTests(FileSelector selector, String expected) { - String result = selectionString(selector); - String diff = diff(expected, result); - String resolved = resolve(diff); - assertEquals("Differing files: " + resolved, result, expected); - } - - /** - * Checks which files are selected and shouldn't be or which - * are not selected but should. - * @param expected String containing 'F's and 'T's - * @param result String containing 'F's and 'T's - * @return Difference as String containing '-' (equal) and - * 'X' (difference). - */ - public String diff(String expected, String result) { - int length1 = expected.length(); - int length2 = result.length(); - int min = (length1 > length2) ? length2 : length1; - StringBuffer sb = new StringBuffer(); - for (int i=0; i<min; i++) { - sb.append( - (expected.charAt(i) == result.charAt(i)) - ? "-" - : "X" - ); - } - return sb.toString(); - } - - - /** - * Resolves a diff-String (@see diff()) against the (inherited) filenames- - * and files arrays. - * @param filelist Diff-String - * @return String containing the filenames for all differing files, - * separated with semicolons ';' - */ - public String resolve(String filelist) { - StringBuffer sb = new StringBuffer(); - int min = (filenames.length > filelist.length()) - ? filelist.length() - : filenames.length; - for (int i=0; i<min; i++) { - if ('X'==filelist.charAt(i)) { - sb.append(filenames[i]); - sb.append(";"); - } - } - return sb.toString(); - } - - - /** - * <p>Creates a testbed. We avoid the dreaded "test" word so that we - * don't falsely identify this as a test to be run. The actual - * setting up of the testbed is done in the - * <code>src/etc/testcases/types/selectors.xml</code> build file.</p> - * - * <p>Note that the right way to call this is within a try block, - * with a finally clause that calls cleanupBed(). You place tests of - * the isSelected() method within the try block.</p> - */ - protected void makeBed() { - tbed = new TaskdefForMakingBed("setupfiles"); - tbed.setUp(); - tbed.makeTestbed(); - } - - /** - * Cleans up the testbed by calling a target in the - * <code>src/etc/testcases/types/selectors.xml</code> file. - */ - protected void cleanupBed() { - if (tbed != null) { - tbed.tearDown(); - tbed = null; - } - } - - - /** - * <p>Creates a mirror of the testbed for use in dependency checks.</p> - * - * <p>Note that the right way to call this is within a try block, - * with a finally clause that calls cleanupMirror(). You place tests of - * the isSelected() method within the try block.</p> - */ - protected void makeMirror() { - tbed = new TaskdefForMakingBed("mirrorfiles"); - tbed.setUp(); - tbed.makeMirror(); - } - - /** - * Cleans up the mirror testbed by calling a target in the - * <code>src/etc/testcases/types/selectors.xml</code> file. - */ - protected void cleanupMirror() { - if (tbed != null) { - tbed.deleteMirror(); - tbed = null; - } - } - - private class TaskdefForMakingBed extends BuildFileTest { - - TaskdefForMakingBed(String name) { - super(name); - } - - public void setUp() { - configureProject("src/etc/testcases/types/selectors.xml"); - } - - public void tearDown() { - try { - super.tearDown(); - } catch (Exception exc) { - // ignore - } - } - - public void makeTestbed() { - executeTarget("setupfiles"); - } - - public void makeMirror() { - executeTarget("mirrorfiles"); - } - - public void deleteMirror() { - executeTarget("tearDown"); - } - } - - - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.selectors; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.Project; + +/** + * Base test case for Selectors. Provides a shared test as well as + * a test bed for selecting on, and a helper method for determining + * whether selections are correct. + * + * @deprecated as of 1.9.4. Use {@link org.apache.tools.ant.types.selectors.BaseSelectorRule} instead. + */ +@Deprecated +public abstract class BaseSelectorTest extends BuildFileTest { + + private Project project; + private TaskdefForMakingBed tbed = null; + protected File basedir; + protected File beddir; + protected File mirrordir; + protected String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", + "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", + "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", + "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", + "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; + protected File[] files = new File[filenames.length]; + protected File[] mirrorfiles = new File[filenames.length]; + + public BaseSelectorTest(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/types/selectors.xml"); + executeTarget("setUp"); + beddir = new File(super.getProject().getProperty("test.dir")); + mirrordir = new File(super.getProject().getProperty("mirror.dir")); + basedir = getProjectDir(); + project = new Project(); + project.init(); + project.setBaseDir(basedir); + for (int x = 0; x < files.length; x++) { + files[x] = new File(beddir,filenames[x]); + mirrorfiles[x] = new File(mirrordir,filenames[x]); + } + } + + /** + * Override this in child classes to return a specific Selector + */ + public abstract BaseSelector getInstance(); + + + /** + * Return a preconfigured selector (with a set reference to + * project instance). + * @return the selector + */ + public BaseSelector getSelector() { + BaseSelector selector = getInstance(); + selector.setProject( getProject() ); + return selector; + } + + + public Project getProject() { + return project; + } + + /** + * This is a test that all Selectors derived from BaseSelector can + * use. It calls the setError() method and checks to ensure that a + * BuildException is thrown as a result. + */ + public void testRespondsToError() { + BaseSelector s = getInstance(); + if (s == null) { + return; + } + s.setError("test error"); + try { + s.isSelected(beddir,filenames[0],files[0]); + fail("Cannot cause BuildException when setError() is called"); + } catch (BuildException be) { + assertEquals("test error", + be.getMessage()); + } + } + + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the testbed. It returns + * a string of "T"s amd "F"s + */ + public String selectionString(FileSelector selector) { + return selectionString(beddir,files,selector); + } + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the mirror testbed. This + * variation is used for dependency checks and to get around the + * limitations in the touch task when running JDK 1.1. It returns + * a string of "T"s amd "F"s. + */ + public String mirrorSelectionString(FileSelector selector) { + return selectionString(mirrordir,mirrorfiles,selector); + } + + /** + * Worker method for the two convenience methods above. Applies a + * selector on a set of files passed in and returns a string of + * "T"s amd "F"s from applying the selector to each file. + */ + public String selectionString(File basedir, File[] files, FileSelector selector) { + StringBuffer buf = new StringBuffer(); + for (int x = 0; x < files.length; x++) { + if (selector.isSelected(basedir,filenames[x],files[x])) { + buf.append('T'); + } + else { + buf.append('F'); + } + } + return buf.toString(); + } + + /** + * Does the selection test for a given selector and prints the + * filenames of the differing files (selected but shouldn't, + * not selected but should). + * @param selector The selector to test + * @param expected The expected result + */ + public void performTests(FileSelector selector, String expected) { + String result = selectionString(selector); + String diff = diff(expected, result); + String resolved = resolve(diff); + assertEquals("Differing files: " + resolved, result, expected); + } + + /** + * Checks which files are selected and shouldn't be or which + * are not selected but should. + * @param expected String containing 'F's and 'T's + * @param result String containing 'F's and 'T's + * @return Difference as String containing '-' (equal) and + * 'X' (difference). + */ + public String diff(String expected, String result) { + int length1 = expected.length(); + int length2 = result.length(); + int min = (length1 > length2) ? length2 : length1; + StringBuffer sb = new StringBuffer(); + for (int i=0; i<min; i++) { + sb.append( + (expected.charAt(i) == result.charAt(i)) + ? "-" + : "X" + ); + } + return sb.toString(); + } + + + /** + * Resolves a diff-String (@see diff()) against the (inherited) filenames- + * and files arrays. + * @param filelist Diff-String + * @return String containing the filenames for all differing files, + * separated with semicolons ';' + */ + public String resolve(String filelist) { + StringBuffer sb = new StringBuffer(); + int min = (filenames.length > filelist.length()) + ? filelist.length() + : filenames.length; + for (int i=0; i<min; i++) { + if ('X'==filelist.charAt(i)) { + sb.append(filenames[i]); + sb.append(";"); + } + } + return sb.toString(); + } + + + /** + * <p>Creates a testbed. We avoid the dreaded "test" word so that we + * don't falsely identify this as a test to be run. The actual + * setting up of the testbed is done in the + * <code>src/etc/testcases/types/selectors.xml</code> build file.</p> + * + * <p>Note that the right way to call this is within a try block, + * with a finally clause that calls cleanupBed(). You place tests of + * the isSelected() method within the try block.</p> + */ + protected void makeBed() { + tbed = new TaskdefForMakingBed("setupfiles"); + tbed.setUp(); + tbed.makeTestbed(); + } + + /** + * Cleans up the testbed by calling a target in the + * <code>src/etc/testcases/types/selectors.xml</code> file. + */ + protected void cleanupBed() { + if (tbed != null) { + tbed.tearDown(); + tbed = null; + } + } + + + /** + * <p>Creates a mirror of the testbed for use in dependency checks.</p> + * + * <p>Note that the right way to call this is within a try block, + * with a finally clause that calls cleanupMirror(). You place tests of + * the isSelected() method within the try block.</p> + */ + protected void makeMirror() { + tbed = new TaskdefForMakingBed("mirrorfiles"); + tbed.setUp(); + tbed.makeMirror(); + } + + /** + * Cleans up the mirror testbed by calling a target in the + * <code>src/etc/testcases/types/selectors.xml</code> file. + */ + protected void cleanupMirror() { + if (tbed != null) { + tbed.deleteMirror(); + tbed = null; + } + } + + private class TaskdefForMakingBed extends BuildFileTest { + + TaskdefForMakingBed(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/types/selectors.xml"); + } + + public void tearDown() { + try { + super.tearDown(); + } catch (Exception exc) { + // ignore + } + } + + public void makeTestbed() { + executeTarget("setupfiles"); + } + + public void makeMirror() { + executeTarget("mirrorfiles"); + } + + public void deleteMirror() { + executeTarget("tearDown"); + } + } + + + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java index 41e9c83..6dc8d72 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java @@ -1,56 +1,56 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.selectors; - -import java.io.File; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - - -public class ContainsRegexpTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/types/selectors.xml"); - } - - @Test - public void testContainsRegexp() { - buildRule.executeTarget("containsregexp"); - File dir = new File(buildRule.getOutputDir(), "regexpseltestdest"); - File[] files = dir.listFiles(); - int filecount = files.length; - - if (filecount != 1) { - assertEquals("ContainsRegexp test should have copied 1 file", - 1, files.length); - - } - } - -} - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.selectors; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class ContainsRegexpTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/selectors.xml"); + } + + @Test + public void testContainsRegexp() { + buildRule.executeTarget("containsregexp"); + File dir = new File(buildRule.getOutputDir(), "regexpseltestdest"); + File[] files = dir.listFiles(); + int filecount = files.length; + + if (filecount != 1) { + assertEquals("ContainsRegexp test should have copied 1 file", + 1, files.length); + + } + } + +} + http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java index 9a5a83f..822bf3e 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java @@ -1,114 +1,114 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.selectors; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Parameter; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Tests Contains Selectors. - * - */ -public class ContainsSelectorTest { - - @Rule - public final BaseSelectorRule selectorRule = new BaseSelectorRule(); - - - /** - * Test the code that validates the selector. - */ - @Test - public void testValidate() { - ContainsSelector s = new ContainsSelector(); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("ContainsSelector did not check for required field 'text'"); - } catch (BuildException be1) { - assertEquals("The text attribute is required", be1.getMessage()); - } - - s = new ContainsSelector(); - Parameter param = new Parameter(); - param.setName("garbage in"); - param.setValue("garbage out"); - Parameter[] params = {param}; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("ContainsSelector did not check for valid parameter element"); - } catch (BuildException be2) { - assertEquals("Invalid parameter garbage in", be2.getMessage()); - } - - } - - /** - * Tests to make sure that the selector is selecting files correctly. - */ - @Test - public void testSelectionBehaviour() { - ContainsSelector s; - String results; - - - s = new ContainsSelector(); - s.setText("no such string in test files"); - results = selectorRule.selectionString(s); - assertEquals("TFFFFFFFFFFT", results); - - s = new ContainsSelector(); - s.setText("Apache Ant"); - results = selectorRule.selectionString(s); - assertEquals("TFFFTFFFFFFT", results); - - s = new ContainsSelector(); - s.setText("apache ant"); - s.setCasesensitive(true); - results = selectorRule.selectionString(s); - assertEquals("TFFFFFFFFFFT", results); - - s = new ContainsSelector(); - s.setText("apache ant"); - s.setCasesensitive(false); - results = selectorRule.selectionString(s); - assertEquals("TFFFTFFFFFFT", results); - - s = new ContainsSelector(); - s.setText("ApacheAnt"); - s.setIgnorewhitespace(true); - results = selectorRule.selectionString(s); - assertEquals("TFFFTFFFFFFT", results); - - s = new ContainsSelector(); - s.setText("A p a c h e A n t"); - s.setIgnorewhitespace(true); - results = selectorRule.selectionString(s); - assertEquals("TFFFTFFFFFFT", results); - - - - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Contains Selectors. + * + */ +public class ContainsSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + ContainsSelector s = new ContainsSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("ContainsSelector did not check for required field 'text'"); + } catch (BuildException be1) { + assertEquals("The text attribute is required", be1.getMessage()); + } + + s = new ContainsSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = {param}; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("ContainsSelector did not check for valid parameter element"); + } catch (BuildException be2) { + assertEquals("Invalid parameter garbage in", be2.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + ContainsSelector s; + String results; + + + s = new ContainsSelector(); + s.setText("no such string in test files"); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("Apache Ant"); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("apache ant"); + s.setCasesensitive(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("apache ant"); + s.setCasesensitive(false); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("ApacheAnt"); + s.setIgnorewhitespace(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("A p a c h e A n t"); + s.setIgnorewhitespace(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + + + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java index 6e461ba..43278f4 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java @@ -1,229 +1,229 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.types.selectors; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Parameter; -import org.junit.Assume; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - - -/** - * Tests Date Selectors. - * - */ -public class DateSelectorTest { - - @Rule - public final BaseSelectorRule selectorRule = new BaseSelectorRule(); - - - /** - * Test the code that validates the selector. - */ - @Test - public void testValidate() { - DateSelector s = new DateSelector(); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for required fields"); - } catch (BuildException be1) { - assertEquals("You must provide a datetime or the number of " - + "milliseconds.", be1.getMessage()); - } - - s = new DateSelector(); - s.setDatetime("01/01/1969 01:01 AM"); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for Datetime being in the " - + "allowable range"); - } catch (BuildException be2) { - assertEquals("Date of 01/01/1969 01:01 AM results in negative " - + "milliseconds value relative to epoch (January 1, " - + "1970, 00:00:00 GMT).", be2.getMessage()); - } - - s = new DateSelector(); - s.setDatetime("this is not a date"); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for Datetime being in a " - + "valid format"); - } catch (BuildException be3) { - assertEquals("Date of this is not a date" - + " Cannot be parsed correctly. It should be in" - + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage()); - } - - s = new DateSelector(); - Parameter param = new Parameter(); - param.setName("garbage in"); - param.setValue("garbage out"); - Parameter[] params = new Parameter[1]; - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for valid parameter element"); - } catch (BuildException be4) { - assertEquals("Invalid parameter garbage in", be4.getMessage()); - } - - s = new DateSelector(); - param = new Parameter(); - param.setName("millis"); - param.setValue("garbage out"); - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for valid millis parameter"); - } catch (BuildException be5) { - assertEquals("Invalid millisecond setting garbage out", - be5.getMessage()); - } - - s = new DateSelector(); - param = new Parameter(); - param.setName("granularity"); - param.setValue("garbage out"); - params[0] = param; - s.setParameters(params); - try { - s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); - fail("DateSelector did not check for valid granularity parameter"); - } catch (BuildException be6) { - assertEquals("Invalid granularity setting garbage out", - be6.getMessage()); - } - - } - - /** - * Tests to make sure that the selector is selecting files correctly. - */ - @Test - public void testSelectionBehaviour() { - DateSelector s; - String results; - - DateSelector.TimeComparisons before = new - DateSelector.TimeComparisons(); - before.setValue("before"); - DateSelector.TimeComparisons equal = new - DateSelector.TimeComparisons(); - equal.setValue("equal"); - DateSelector.TimeComparisons after = new - DateSelector.TimeComparisons(); - after.setValue("after"); - - - s = new DateSelector(); - s.setDatetime("10/10/1999 1:45 PM"); - s.setWhen(before); - results = selectorRule.selectionString(s); - assertEquals("TFFFFFFFFFFT", results); - - s = new DateSelector(); - s.setDatetime("10/10/1999 1:45 PM"); - s.setWhen(before); - s.setCheckdirs(true); - results = selectorRule.selectionString(s); - assertEquals("FFFFFFFFFFFF", results); - - s = new DateSelector(); - s.setDatetime("10/10/1999 1:45 PM"); - s.setWhen(after); - results = selectorRule.selectionString(s); - assertEquals("TTTTTTTTTTTT", results); - - s = new DateSelector(); - s.setDatetime("11/21/2001 4:54 AM"); - s.setWhen(before); - results = selectorRule.selectionString(s); - assertEquals("TFTFFFFFFFFT", results); - - s = new DateSelector(); - s.setDatetime("11/21/2001 4:55 AM"); - - long milliseconds = s.getMillis(); - s.setWhen(equal); - results = selectorRule.selectionString(s); - assertEquals("TTFFTFFFTTTT", results); - - s = new DateSelector(); - s.setMillis(milliseconds); - s.setWhen(equal); - results = selectorRule.selectionString(s); - assertEquals("TTFFTFFFTTTT", results); - - s = new DateSelector(); - s.setDatetime("11/21/2001 4:56 AM"); - s.setWhen(after); - results = selectorRule.selectionString(s); - assertEquals("TFFTFTTTFFFT", results); - - s = new DateSelector(); - Parameter param1 = new Parameter(); - Parameter param2 = new Parameter(); - param1.setName("datetime"); - param1.setValue("11/21/2001 4:56 AM"); - param2.setName("when"); - param2.setValue("after"); - Parameter[] params = {param1,param2}; - s.setParameters(params); - results = selectorRule.selectionString(s); - assertEquals("TFFTFTTTFFFT", results); - - s = new DateSelector(); - long testtime = selectorRule.getMirrorFiles()[5].lastModified(); - s.setMillis(testtime); - s.setWhen(after); - s.setGranularity(2); - - // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th - // files don't exist so can't be changed, so don't try and loop over them - for (int i = 1; i <=2; i++) { - Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100))); - } - - - results = selectorRule.mirrorSelectionString(s); - assertEquals("TFFFFTTTTTTT", results); - - s = new DateSelector(); - testtime = selectorRule.getMirrorFiles()[6].lastModified(); - s.setMillis(testtime); - s.setWhen(before); - s.setGranularity(2); - for (int i = 7; i <= 10; i++) { - Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100))); - } - - results = selectorRule.mirrorSelectionString(s); - assertEquals("TTTTTTTFFFFT", results); - - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + * Tests Date Selectors. + * + */ +public class DateSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + DateSelector s = new DateSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("You must provide a datetime or the number of " + + "milliseconds.", be1.getMessage()); + } + + s = new DateSelector(); + s.setDatetime("01/01/1969 01:01 AM"); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for Datetime being in the " + + "allowable range"); + } catch (BuildException be2) { + assertEquals("Date of 01/01/1969 01:01 AM results in negative " + + "milliseconds value relative to epoch (January 1, " + + "1970, 00:00:00 GMT).", be2.getMessage()); + } + + s = new DateSelector(); + s.setDatetime("this is not a date"); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for Datetime being in a " + + "valid format"); + } catch (BuildException be3) { + assertEquals("Date of this is not a date" + + " Cannot be parsed correctly. It should be in" + + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage()); + } + + s = new DateSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = new Parameter[1]; + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid parameter element"); + } catch (BuildException be4) { + assertEquals("Invalid parameter garbage in", be4.getMessage()); + } + + s = new DateSelector(); + param = new Parameter(); + param.setName("millis"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid millis parameter"); + } catch (BuildException be5) { + assertEquals("Invalid millisecond setting garbage out", + be5.getMessage()); + } + + s = new DateSelector(); + param = new Parameter(); + param.setName("granularity"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid granularity parameter"); + } catch (BuildException be6) { + assertEquals("Invalid granularity setting garbage out", + be6.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + DateSelector s; + String results; + + DateSelector.TimeComparisons before = new + DateSelector.TimeComparisons(); + before.setValue("before"); + DateSelector.TimeComparisons equal = new + DateSelector.TimeComparisons(); + equal.setValue("equal"); + DateSelector.TimeComparisons after = new + DateSelector.TimeComparisons(); + after.setValue("after"); + + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(before); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(before); + s.setCheckdirs(true); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(after); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:54 AM"); + s.setWhen(before); + results = selectorRule.selectionString(s); + assertEquals("TFTFFFFFFFFT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:55 AM"); + + long milliseconds = s.getMillis(); + s.setWhen(equal); + results = selectorRule.selectionString(s); + assertEquals("TTFFTFFFTTTT", results); + + s = new DateSelector(); + s.setMillis(milliseconds); + s.setWhen(equal); + results = selectorRule.selectionString(s); + assertEquals("TTFFTFFFTTTT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:56 AM"); + s.setWhen(after); + results = selectorRule.selectionString(s); + assertEquals("TFFTFTTTFFFT", results); + + s = new DateSelector(); + Parameter param1 = new Parameter(); + Parameter param2 = new Parameter(); + param1.setName("datetime"); + param1.setValue("11/21/2001 4:56 AM"); + param2.setName("when"); + param2.setValue("after"); + Parameter[] params = {param1,param2}; + s.setParameters(params); + results = selectorRule.selectionString(s); + assertEquals("TFFTFTTTFFFT", results); + + s = new DateSelector(); + long testtime = selectorRule.getMirrorFiles()[5].lastModified(); + s.setMillis(testtime); + s.setWhen(after); + s.setGranularity(2); + + // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th + // files don't exist so can't be changed, so don't try and loop over them + for (int i = 1; i <=2; i++) { + Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100))); + } + + + results = selectorRule.mirrorSelectionString(s); + assertEquals("TFFFFTTTTTTT", results); + + s = new DateSelector(); + testtime = selectorRule.getMirrorFiles()[6].lastModified(); + s.setMillis(testtime); + s.setWhen(before); + s.setGranularity(2); + for (int i = 7; i <= 10; i++) { + Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100))); + } + + results = selectorRule.mirrorSelectionString(s); + assertEquals("TTTTTTTFFFFT", results); + + } + +}
