Examples of PathableClassLoader


Examples of org.apache.commons.logging.PathableClassLoader

* Simulates the case when TCCL is badly set and cannot load JCL.
*/
public class BadTCCLTestCase extends TestCase {

    public static Test suite() throws Exception {
        PathableClassLoader contextClassLoader = new PathableClassLoader(null);
        contextClassLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
        PathableTestSuite suite = new PathableTestSuite(BadTCCLTestCase.class, contextClassLoader);
        return suite;
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

        // Determine the URL to this .class file, so that we can then
        // append the priority dirs to it. For tidiness, load this
        // class through a dummy loader though this is not absolutely
        // necessary...
        PathableClassLoader dummy = new PathableClassLoader(null);
        dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
        dummy.addLogicalLib("testclasses");
        dummy.addLogicalLib("commons-logging");
       
        String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
        URL baseUrl = dummy.findResource(thisClassPath);

        // Now set up the desired classloader hierarchy. Everything goes into
        // the parent classpath, but we exclude the custom Log class.
        //
        // We then create a tccl classloader that can see the custom
        // Log class. Therefore if that class can be found, then the
        // TCCL must have been used to load it.
        PathableClassLoader emptyLoader = new PathableClassLoader(null);
       
        PathableClassLoader parentLoader = new PathableClassLoader(null);
        parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
        parentLoader.addLogicalLib("commons-logging");
        parentLoader.addLogicalLib("testclasses");
        // hack to ensure that the testcase classloader can't see
        // the custom MyLog
        parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
       
        URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
        parentLoader.addURL(propsEnableUrl);

        PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
        tcclLoader.addLogicalLib("testclasses");

        Class testClass = parentLoader.loadClass(thisClass.getName());
        return new PathableTestSuite(testClass, tcclLoader);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

        // Determine the URL to this .class file, so that we can then
        // append the priority dirs to it. For tidiness, load this
        // class through a dummy loader though this is not absolutely
        // necessary...
        PathableClassLoader dummy = new PathableClassLoader(null);
        dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
        dummy.addLogicalLib("testclasses");
        dummy.addLogicalLib("commons-logging");
       
        String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
        URL baseUrl = dummy.findResource(thisClassPath);

        // Now set up the desired classloader hierarchy. Everything goes into
        // the parent classpath, but we exclude the custom Log class.
        //
        // We then create a tccl classloader that can see the custom
        // Log class. Therefore if that class can be found, then the
        // TCCL must have been used to load it.
        PathableClassLoader emptyLoader = new PathableClassLoader(null);
       
        PathableClassLoader parentLoader = new PathableClassLoader(null);
        parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
        parentLoader.addLogicalLib("commons-logging");
        parentLoader.addLogicalLib("testclasses");
        // hack to ensure that the testcase classloader can't see
        // the custom MyLogFactoryImpl
        parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
       
        URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
        parentLoader.addURL(propsEnableUrl);

        PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
        tcclLoader.addLogicalLib("testclasses");

        Class testClass = parentLoader.loadClass(thisClass.getName());
        return new PathableTestSuite(testClass, tcclLoader);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

        Class thisClass = ParentFirstTestCase.class;
        ClassLoader thisClassLoader = thisClass.getClassLoader();

        // Make the parent a direct child of the bootloader to hide all
        // other classes in the system classpath
        PathableClassLoader parent = new PathableClassLoader(null);
       
        // Make the junit classes visible as a special case, as junit
        // won't be able to call this class at all without this. The
        // junit classes must be visible from the classloader that loaded
        // this class, so use that as the source for future access to classes
        // from the junit package.
        parent.useExplicitLoader("junit.", thisClassLoader);
       
        // make the commons-logging.jar classes visible via the parent
        parent.addLogicalLib("commons-logging");
       
        // create a child classloader to load the test case through
        PathableClassLoader child = new PathableClassLoader(parent);
       
        // obviously, the child classloader needs to have the test classes
        // in its path!
        child.addLogicalLib("testclasses");
        child.addLogicalLib("commons-logging-adapters");
       
        // create a third classloader to be the context classloader.
        PathableClassLoader context = new PathableClassLoader(child);

        // reload this class via the child classloader
        Class testClass = child.loadClass(thisClass.getName());
       
        // and return our custom TestSuite class
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

        //
        // Having the test loaded via a loader above the tccl emulates the situation
        // where a web.xml file specifies ServletContextCleaner as a listener, and
        // that class is deployed via a shared classloader.

        PathableClassLoader parent = new PathableClassLoader(null);
        parent.useExplicitLoader("junit.", Test.class.getClassLoader());
        parent.addLogicalLib("commons-logging");
        parent.addLogicalLib("servlet-api");

        PathableClassLoader child = new PathableClassLoader(parent);
        child.setParentFirst(false);
        child.addLogicalLib("commons-logging");
        child.addLogicalLib("testclasses");

        PathableClassLoader tccl = new PathableClassLoader(child);
        tccl.setParentFirst(false);
        tccl.addLogicalLib("commons-logging");

        Class testClass = child.loadClass(BasicServletTestCase.class.getName());
        return new PathableTestSuite(testClass, tccl);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

     */
    public static Test suite() throws Exception {
        Class thisClass = GeneralTestCase.class;
        ClassLoader thisClassLoader = thisClass.getClassLoader();
       
        PathableClassLoader loader = new PathableClassLoader(null);
        loader.useExplicitLoader("junit.", thisClassLoader);
        loader.addLogicalLib("testclasses");

        // reload this class via the child classloader
        Class testClass = loader.loadClass(thisClass.getName());
       
        // and return our custom TestSuite class
        return new PathableTestSuite(testClass, loader);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

        Class thisClass = ChildFirstTestCase.class;
        ClassLoader thisClassLoader = thisClass.getClassLoader();
       
        // Make the parent a direct child of the bootloader to hide all
        // other classes in the system classpath
        PathableClassLoader parent = new PathableClassLoader(null);
        parent.setParentFirst(false);
       
        // Make the junit classes visible as a special case, as junit
        // won't be able to call this class at all without this. The
        // junit classes must be visible from the classloader that loaded
        // this class, so use that as the source for future access to classes
        // from the junit package.
        parent.useExplicitLoader("junit.", thisClassLoader);
       
        // Make the commons-logging.jar classes visible via the parent
        parent.addLogicalLib("commons-logging");
       
        // Create a child classloader to load the test case through
        PathableClassLoader child = new PathableClassLoader(parent);
        child.setParentFirst(false);
       
        // Obviously, the child classloader needs to have the test classes
        // in its path!
        child.addLogicalLib("testclasses");
        child.addLogicalLib("commons-logging-adapters");
       
        // Create a third classloader to be the context classloader.
        PathableClassLoader context = new PathableClassLoader(child);
        context.setParentFirst(false);

        // reload this class via the child classloader
        Class testClass = child.loadClass(thisClass.getName());
       
        // and return our custom TestSuite class
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

    /**
     * Return the tests included in this test suite.
     */
    public static Test suite() throws Exception {
        PathableClassLoader loader = new PathableClassLoader(null);
        loader.useExplicitLoader("junit.", Test.class.getClassLoader());
        loader.addLogicalLib("testclasses");
        loader.addLogicalLib("commons-logging");
       
        Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
        return new PathableTestSuite(testClass, loader);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

    /**
     * Return the tests included in this test suite.
     */
    public static Test suite() throws Exception {
        PathableClassLoader cl = new PathableClassLoader(null);
        cl.useExplicitLoader("junit.", Test.class.getClassLoader());

        // the TestHandler class must be accessable from the System classloader
        // in order for java.util.logging.LogManager.readConfiguration to
        // be able to instantiate it. And this test case must see the same
        // class in order to be able to access its data. Yes this is ugly
        // but the whole jdk14 API is a ******* mess anyway.
        ClassLoader scl = ClassLoader.getSystemClassLoader();
        loadTestHandler(HANDLER_NAME, scl);
        cl.useExplicitLoader(HANDLER_NAME, scl);
        cl.addLogicalLib("commons-logging");
        cl.addLogicalLib("testclasses");
       
        Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
        return new PathableTestSuite(testClass, cl);
    }
View Full Code Here

Examples of org.apache.commons.logging.PathableClassLoader

    /**
     * Return the tests included in this test suite.
     */
    public static Test suite() throws Exception {
        PathableClassLoader parent = new PathableClassLoader(null);
        parent.useExplicitLoader("junit.", Test.class.getClassLoader());

        // the TestHandler class must be accessable from the System classloader
        // in order for java.util.logging.LogManager.readConfiguration to
        // be able to instantiate it. And this test case must see the same
        // class in order to be able to access its data. Yes this is ugly
        // but the whole jdk14 API is a ******* mess anyway.
        ClassLoader scl = ClassLoader.getSystemClassLoader();
        loadTestHandler(HANDLER_NAME, scl);
        parent.useExplicitLoader(HANDLER_NAME, scl);
        parent.addLogicalLib("commons-logging");

        PathableClassLoader child = new PathableClassLoader(parent);
        child.addLogicalLib("testclasses");
       
        Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
        return new PathableTestSuite(testClass, child);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.