Package org.apache.commons.logging

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-api");

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

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


        // 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. We'll put JCL
        // in the container path, the testcase in a webapp path, and
        // both config files into the webapp path too.
        PathableClassLoader containerLoader = new PathableClassLoader(null);
        containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
        containerLoader.addLogicalLib("commons-logging");

        PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
        webappLoader.addLogicalLib("testclasses");

        URL pri20URL = new URL(baseUrl, "priority20/");
        webappLoader.addURL(pri20URL);

        URL pri10URL = new URL(baseUrl, "priority10/");
        webappLoader.addURL(pri10URL);

        // load the test class via webapp loader, and use the webapp loader
        // as the tccl loader too.
        Class testClass = webappLoader.loadClass(thisClass.getName());
        return new PathableTestSuite(testClass, webappLoader);
    }
View Full Code Here

        // 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. We'll put a config
        // file of priority=10 in the container path, and ones of both
        // "no priority" and priority=20 in the webapp path.
        //
        // A second properties file with priority=20 is also added,
        // so we can check that the first one in the classpath is
        // used.
        PathableClassLoader containerLoader = new PathableClassLoader(null);
        containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
        containerLoader.addLogicalLib("commons-logging");

        URL pri10URL = new URL(baseUrl, "priority10/");
        containerLoader.addURL(pri10URL);

        PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
        webappLoader.setParentFirst(true);
        webappLoader.addLogicalLib("testclasses");

        URL noPriorityURL = new URL(baseUrl, "nopriority/");
        webappLoader.addURL(noPriorityURL);

        URL pri20URL = new URL(baseUrl, "priority20/");
        webappLoader.addURL(pri20URL);

        URL pri20aURL = new URL(baseUrl, "priority20a/");
        webappLoader.addURL(pri20aURL);

        // load the test class via webapp loader, and use the webapp loader
        // as the tccl loader too.
        Class testClass = webappLoader.loadClass(thisClass.getName());
        return new PathableTestSuite(testClass, webappLoader);
    }
View Full Code Here

    /**
     * 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

* 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

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

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

    /**
     * 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

    /**
     * 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

    /**
     * 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());
        parent.addLogicalLib("commons-logging");
        parent.addLogicalLib("log4j12");

        PathableClassLoader child = new PathableClassLoader(parent);
        child.addLogicalLib("testclasses");

        Class testClass = child.loadClass(
            "org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
        return new PathableTestSuite(testClass, child);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.logging.PathableClassLoader

Copyright © 2018 www.massapicom. 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.