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