git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1585935 13f79535-47bb-0310-9956-ffa450edef68master
@@ -18,15 +18,20 @@ | |||
<project name="selectors-test" basedir="." default="setupfiles"> | |||
<import file="../buildfiletest-base.xml"/> | |||
<target name="setUp"> | |||
<mkdir dir="${output}"/> | |||
</target> | |||
<property name="etc.dir" value=".."/> | |||
<property name="test.dir" | |||
value="selectortest"/> | |||
value="${output}/selectortest"/> | |||
<property name="testregexpsrc.dir" | |||
value="regexpseltestsrc"/> | |||
value="${output}/regexpseltestsrc"/> | |||
<property name="testregexpdest.dir" | |||
value="regexpseltestdest"/> | |||
value="${output}/regexpseltestdest"/> | |||
<property name="mirror.dir" | |||
value="selectortest2"/> | |||
value="${output}/selectortest2"/> | |||
<target name="setupfiles"> | |||
<mkdir dir="${test.dir}" /> | |||
@@ -75,10 +80,6 @@ | |||
datetime="05/10/2002 2:29 AM"/> | |||
</target> | |||
<target name="cleanup"> | |||
<delete dir="${test.dir}" /> | |||
</target> | |||
<target name="mirrorfiles"> | |||
<mkdir dir="${mirror.dir}" /> | |||
<mkdir dir="${mirror.dir}/zip" /> | |||
@@ -98,15 +99,6 @@ | |||
<touch file="${mirror.dir}/tar/bz2/asf-logo-huge.tar.bz2"/> | |||
</target> | |||
<target name="cleanup.mirrorfiles"> | |||
<delete dir="${mirror.dir}" /> | |||
</target> | |||
<target name="cleanupregexp"> | |||
<delete dir="${testregexpsrc.dir}" /> | |||
<delete dir="${testregexpdest.dir}" /> | |||
</target> | |||
<target name="containsregexp"> | |||
<mkdir dir="${testregexpsrc.dir}" /> | |||
<mkdir dir="${testregexpdest.dir}" /> | |||
@@ -407,12 +407,12 @@ public class ModifiedSelector extends BaseExtendSelector | |||
clazz = Class.forName(classname); | |||
} | |||
T rv = clazz.asSubclass(type).newInstance(); | |||
Object rv = clazz.newInstance(); | |||
if (!type.isInstance(rv)) { | |||
throw new BuildException("Specified class (" + classname + ") " + msg); | |||
} | |||
return rv; | |||
return (T) rv; | |||
} catch (ClassNotFoundException e) { | |||
throw new BuildException("Specified class (" + classname + ") not found."); | |||
} catch (Exception e) { | |||
@@ -32,16 +32,13 @@ import org.apache.tools.ant.Project; | |||
* whether selections are correct. | |||
* | |||
*/ | |||
public abstract class BaseSelectorTest extends TestCase { | |||
public abstract class BaseSelectorTest extends BuildFileTest { | |||
private Project project; | |||
private TaskdefForMakingBed tbed = null; | |||
protected String basedirname = "src/etc/testcases/types"; | |||
protected String beddirname = basedirname + "/selectortest"; | |||
protected String mirrordirname = basedirname + "/selectortest2"; | |||
protected File basedir = new File(System.getProperty("root"), basedirname); | |||
protected File beddir = new File(System.getProperty("root"), beddirname); | |||
protected File mirrordir = new File(System.getProperty("root"), mirrordirname); | |||
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", | |||
@@ -55,6 +52,11 @@ public abstract class BaseSelectorTest extends TestCase { | |||
} | |||
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); | |||
@@ -227,7 +229,7 @@ public abstract class BaseSelectorTest extends TestCase { | |||
*/ | |||
protected void cleanupBed() { | |||
if (tbed != null) { | |||
tbed.tearDown(); | |||
tbed.tearDown(); | |||
tbed = null; | |||
} | |||
} | |||
@@ -268,7 +270,11 @@ public abstract class BaseSelectorTest extends TestCase { | |||
} | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
try { | |||
super.tearDown(); | |||
} catch (Exception exc) { | |||
// ignore | |||
} | |||
} | |||
public void makeTestbed() { | |||
@@ -280,7 +286,7 @@ public abstract class BaseSelectorTest extends TestCase { | |||
} | |||
public void deleteMirror() { | |||
executeTarget("cleanup.mirrorfiles"); | |||
executeTarget("tearDown"); | |||
} | |||
} | |||
@@ -60,7 +60,11 @@ public class ContainsRegexpTest extends TestCase { | |||
} | |||
public void tearDown() { | |||
executeTarget("cleanupregexp"); | |||
try { | |||
super.tearDown(); | |||
} catch (Exception exc) { | |||
// ignore | |||
} | |||
} | |||
public void test() { | |||
@@ -70,7 +74,7 @@ public class ContainsRegexpTest extends TestCase { | |||
executeTarget("containsregexp"); | |||
dir = new File(getProjectDir() + "/regexpseltestdest/"); | |||
dir = new File(getOutputDir(), "regexpseltestdest"); | |||
files = dir.listFiles(); | |||
filecount = files.length; | |||
@@ -138,13 +138,13 @@ public class DependSelectorTest extends BaseSelectorTest { | |||
makeMirror(); | |||
s = (DependSelector)getInstance(); | |||
File testdir = getProject().resolveFile("selectortest2"); | |||
File testdir = new File(getOutputDir(), "selectortest2"); | |||
s.setTargetdir(testdir); | |||
results = selectionString(s); | |||
assertEquals("FFFTTFFFFFFF", results); | |||
s = (DependSelector)getInstance(); | |||
testdir = getProject().resolveFile("selectortest2/tar/bz2"); | |||
testdir = new File(getOutputDir(), "selectortest2/tar/bz2"); | |||
s.setTargetdir(testdir); | |||
m = s.createMapper(); | |||
m.setType(glob); | |||
@@ -192,6 +192,9 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
public void testCustomClasses() { | |||
if (getProject().getProperty("ant.home") == null) { | |||
return; | |||
} | |||
BFT bft = new BFT(); | |||
bft.setUp(); | |||
try { | |||
@@ -287,6 +290,7 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
*/ | |||
private String getAlgoName(String classname) { | |||
ModifiedSelector sel = new ModifiedSelector(); | |||
sel.setProject(getProject()); | |||
// add the test classes to its classpath | |||
sel.addClasspath(testclasses); | |||
sel.setAlgorithmClass(classname); | |||
@@ -422,7 +426,7 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
* A cache must return a stored value and a valid iterator. | |||
* After calling the delete() the cache must be empty. | |||
* | |||
* @param algo configured test object | |||
* @param cache configured test object | |||
*/ | |||
protected void doTest(Cache cache) { | |||
assertTrue("Cache not proper configured.", cache.isValid()); | |||
@@ -609,6 +613,9 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
bft.deleteCachefile(); | |||
} | |||
public void testResourceSelectorScenarioSimple() { | |||
if (getProject().getProperty("ant.home") == null) { | |||
return; | |||
} | |||
BFT bft = new BFT("modifiedselector"); | |||
bft.doTarget("modifiedselectortest-scenario-resourceSimple"); | |||
bft.doTarget("modifiedselectortest-scenario-clean"); | |||
@@ -618,7 +625,7 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
* Test the interface semantic of Comparators. | |||
* This method does some common test for comparator implementations. | |||
* | |||
* @param algo configured test object | |||
* @param comp configured test object | |||
*/ | |||
protected void doTest(Comparator comp) { | |||
Object o1 = new String("string1"); | |||
@@ -827,16 +834,25 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
public void testScenarioCoreSelectorDefaults() { | |||
if (getProject().getProperty("ant.home") == null) { | |||
return; | |||
} | |||
doScenarioTest("modifiedselectortest-scenario-coreselector-defaults", "cache.properties"); | |||
} | |||
public void testScenarioCoreSelectorSettings() { | |||
if (getProject().getProperty("ant.home") == null) { | |||
return; | |||
} | |||
doScenarioTest("modifiedselectortest-scenario-coreselector-settings", "core.cache.properties"); | |||
} | |||
public void testScenarioCustomSelectorSettings() { | |||
if (getProject().getProperty("ant.home") == null) { | |||
return; | |||
} | |||
doScenarioTest("modifiedselectortest-scenario-customselector-settings", "core.cache.properties"); | |||
} | |||
@@ -851,9 +867,9 @@ public class ModifiedSelectorTest extends BaseSelectorTest { | |||
bft.doTarget(target); | |||
// the directories to check | |||
File to1 = new File(basedir, "selectortest/to-1"); | |||
File to2 = new File(basedir, "selectortest/to-2"); | |||
File to3 = new File(basedir, "selectortest/to-3"); | |||
File to1 = new File(getOutputDir(), "selectortest/to-1"); | |||
File to2 = new File(getOutputDir(), "selectortest/to-2"); | |||
File to3 = new File(getOutputDir(), "selectortest/to-3"); | |||
// do the checks | |||
assertTrue("Cache file not created.", cachefile.exists()); | |||
@@ -128,7 +128,7 @@ public class PresentSelectorTest extends BaseSelectorTest { | |||
makeMirror(); | |||
s = (PresentSelector)getInstance(); | |||
subdir = getProject().resolveFile("selectortest2"); | |||
subdir = new File(getOutputDir(), "selectortest2"); | |||
s.setTargetdir(subdir); | |||
results = mirrorSelectionString(s); | |||
assertEquals("TTTFFTTTTTTT", results); | |||