AntClassLoaderDelegationTestpublic class AntClassLoaderDelegationTest extends TestCase Test case for ant class loader |
Fields Summary |
---|
private static final org.apache.tools.ant.util.FileUtils | FILE_UTILSInstance of a utility class to use for file operations. | private org.apache.tools.ant.Project | p | private static final String | TEST_RESOURCESample resource present in build/testcases/ |
Constructors Summary |
---|
public AntClassLoaderDelegationTest(String name)
super(name);
|
Methods Summary |
---|
private static java.util.List | enum2List(java.util.Enumeration e)
// JDK 1.4: return Collections.list(e);
List l = new ArrayList();
while (e.hasMoreElements()) {
l.add(e.nextElement());
}
return l;
| public void | setUp()
p = new Project();
p.init();
| public void | testFindIsolateResources()
String buildTestcases = System.getProperty("build.tests");
assertNotNull("defined ${build.tests}", buildTestcases);
assertTrue("have a dir " + buildTestcases,
new File(buildTestcases).isDirectory());
Path path = new Path(p, buildTestcases + "/org");
// A special parent loader which is not the system class loader:
ClassLoader parent = new ParentLoader();
URL urlFromPath = new URL(
FILE_UTILS.toURI(buildTestcases) + "org/" + TEST_RESOURCE);
AntClassLoader acl = new AntClassLoader(parent, p, path, false);
acl.setIsolated(true);
assertEquals("correct resources (reverse delegation order)",
Arrays.asList(new URL[] {urlFromPath}),
enum2List(acl.getResources(TEST_RESOURCE)));
| public void | testFindResources()
// This path should contain the class files for these testcases:
String buildTestcases = System.getProperty("build.tests");
assertNotNull("defined ${build.tests}", buildTestcases);
assertTrue("have a dir " + buildTestcases,
new File(buildTestcases).isDirectory());
Path path = new Path(p, buildTestcases + "/org");
// A special parent loader which is not the system class loader:
ClassLoader parent = new ParentLoader();
// An AntClassLoader which is supposed to delegate to
// the parent and then to the disk path:
ClassLoader acl = new AntClassLoader(parent, p, path, true);
// The intended result URLs:
URL urlFromPath = new URL(
FILE_UTILS.toURI(buildTestcases) + "org/" + TEST_RESOURCE);
URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE);
assertEquals("correct resources (regular delegation order)",
Arrays.asList(new URL[] {urlFromParent, urlFromPath}),
enum2List(acl.getResources(TEST_RESOURCE)));
acl = new AntClassLoader(parent, p, path, false);
assertEquals("correct resources (reverse delegation order)",
Arrays.asList(new URL[] {urlFromPath, urlFromParent}),
enum2List(acl.getResources(TEST_RESOURCE)));
|
|