|
|
@@ -19,115 +19,112 @@ package org.apache.tools.ant.taskdefs; |
|
|
|
|
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
|
import org.apache.tools.ant.BuildFileRule; |
|
|
|
import org.hamcrest.Matcher; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.experimental.runners.Enclosed; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runners.Parameterized; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.both; |
|
|
|
import static org.hamcrest.Matchers.containsString; |
|
|
|
import static org.hamcrest.Matchers.endsWith; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
|
|
|
|
@RunWith(Enclosed.class) |
|
|
|
public class MakeUrlTest { |
|
|
|
|
|
|
|
@Rule |
|
|
|
public final BuildFileRule buildRule = new BuildFileRule(); |
|
|
|
|
|
|
|
@Rule |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testEmpty() { |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
thrown.expectMessage("No property defined"); |
|
|
|
buildRule.executeTarget("testEmpty"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNoProperty() { |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
thrown.expectMessage("No property defined"); |
|
|
|
buildRule.executeTarget("testNoProperty"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNoFile() { |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
thrown.expectMessage("No files defined"); |
|
|
|
buildRule.executeTarget("testNoFile"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testValidation() { |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
thrown.expectMessage("A source file is missing"); |
|
|
|
buildRule.executeTarget("testValidation"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testWorks() { |
|
|
|
buildRule.executeTarget("testWorks"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testWorks"), |
|
|
|
both(containsString("file:")).and(containsString("/foo"))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testIllegalChars() { |
|
|
|
buildRule.executeTarget("testIllegalChars"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testIllegalChars"), |
|
|
|
both(containsString("file:")).and(containsString("fo%20o%25"))); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* test that we can round trip by opening a url that exists |
|
|
|
* |
|
|
|
* @throws IOException if something goes wrong |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testRoundTrip() throws IOException { |
|
|
|
buildRule.executeTarget("testRoundTrip"); |
|
|
|
String property = buildRule.getProject().getProperty("testRoundTrip"); |
|
|
|
assertThat(property, containsString("file:")); |
|
|
|
URL url = new URL(property); |
|
|
|
InputStream instream = url.openStream(); |
|
|
|
instream.close(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testIllegalCombinations() { |
|
|
|
buildRule.executeTarget("testIllegalCombinations"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testIllegalCombinations"), |
|
|
|
both(containsString("/foo")).and(containsString(".xml"))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFileset() { |
|
|
|
buildRule.executeTarget("testFileset"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testFileset"), |
|
|
|
both(containsString(".xml ")).and(endsWith(".xml"))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFilesetSeparator() { |
|
|
|
buildRule.executeTarget("testFilesetSeparator"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testFilesetSeparator"), |
|
|
|
both(containsString(".xml\",\"")).and(endsWith(".xml"))); |
|
|
|
@RunWith(Parameterized.class) |
|
|
|
public static class InvalidArgumentTest { |
|
|
|
|
|
|
|
@Rule |
|
|
|
public final BuildFileRule buildRule = new BuildFileRule(); |
|
|
|
|
|
|
|
@Rule |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); |
|
|
|
} |
|
|
|
|
|
|
|
@Parameterized.Parameters(name = "{0}") |
|
|
|
public static Collection<Object[]> targets() { |
|
|
|
return Arrays.asList(new Object[][]{ |
|
|
|
{"testEmpty", "No property defined"}, |
|
|
|
{"testNoProperty", "No property defined"}, |
|
|
|
{"testNoFile", "No files defined"}, |
|
|
|
{"testValidation", "A source file is missing"} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Parameterized.Parameter |
|
|
|
public String targetName; |
|
|
|
|
|
|
|
@Parameterized.Parameter(1) |
|
|
|
public String message; |
|
|
|
|
|
|
|
@Test |
|
|
|
public void test() { |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
thrown.expectMessage(message); |
|
|
|
buildRule.executeTarget(targetName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testPath() { |
|
|
|
buildRule.executeTarget("testPath"); |
|
|
|
assertThat(buildRule.getProject().getProperty("testPath"), containsString("makeurl.xml")); |
|
|
|
@RunWith(Parameterized.class) |
|
|
|
public static class ValidArgumentTest { |
|
|
|
|
|
|
|
@Rule |
|
|
|
public final BuildFileRule buildRule = new BuildFileRule(); |
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); |
|
|
|
} |
|
|
|
|
|
|
|
@Parameterized.Parameters(name = "{0}") |
|
|
|
public static Collection<Object[]> targets() { |
|
|
|
return Arrays.asList(new Object[][]{ |
|
|
|
{"testWorks", both(containsString("file:")).and(containsString("/foo"))}, |
|
|
|
{"testIllegalChars", both(containsString("file:")).and(containsString("fo%20o%25"))}, |
|
|
|
{"testRoundTrip", containsString("file:")}, |
|
|
|
{"testIllegalCombinations", both(containsString("/foo")).and(containsString(".xml"))}, |
|
|
|
{"testFileset", both(containsString(".xml ")).and(endsWith(".xml"))}, |
|
|
|
{"testFilesetSeparator", both(containsString(".xml\",\"")).and(endsWith(".xml"))}, |
|
|
|
{"testPath", containsString("makeurl.xml")} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Parameterized.Parameter |
|
|
|
public String targetName; |
|
|
|
|
|
|
|
@Parameterized.Parameter(1) |
|
|
|
public Matcher<String> matcher; |
|
|
|
|
|
|
|
@Test |
|
|
|
public void test() throws IOException { |
|
|
|
buildRule.executeTarget(targetName); |
|
|
|
String property = buildRule.getProject().getProperty(targetName); |
|
|
|
assertNotNull("property not set", property); |
|
|
|
assertThat(property, matcher); |
|
|
|
|
|
|
|
if (targetName.equals("testRoundTrip")) { |
|
|
|
// test that we can round trip by opening a url that exists |
|
|
|
URL url = new URL(property); |
|
|
|
InputStream instream = url.openStream(); |
|
|
|
instream.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |