FileDocCategorySizeDatePackage
AntClassLoaderDelegationTest.javaAPI DocApache Ant 1.704942Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant

AntClassLoaderDelegationTest

public class AntClassLoaderDelegationTest extends TestCase
Test case for ant class loader

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Instance of a utility class to use for file operations.
private org.apache.tools.ant.Project
p
private static final String
TEST_RESOURCE
Sample resource present in build/testcases/
Constructors Summary
public AntClassLoaderDelegationTest(String name)


       
        super(name);
    
Methods Summary
private static java.util.Listenum2List(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 voidsetUp()

        p = new Project();
        p.init();
    
public voidtestFindIsolateResources()

        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 voidtestFindResources()

    
         
        // 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)));