Search in sources :

Example 1 with ParentClassLoaderFinder

use of org.apache.openejb.core.ParentClassLoaderFinder in project tomee by apache.

the class URLClassLoaderFirstTest method loadFromAppIfNotInContainer.

@Test
public void loadFromAppIfNotInContainer() throws Exception {
    assertTrue(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));
    final URLClassLoader parent = new URLClassLoader(new URL[0]) {

        @Override
        public URL getResource(final String name) {
            if ("javax/wsdl/WSDLException.class".equals(name)) {
                return null;
            }
            return super.getResource(name);
        }
    };
    final URLClassLoader tmpLoader = new URLClassLoaderFirst(new URL[] { JarLocation.jarLocation(WSDLException.class).toURI().toURL() }, parent);
    SystemInstance.init(new Properties());
    SystemInstance.get().setComponent(ParentClassLoaderFinder.class, new ParentClassLoaderFinder() {

        @Override
        public ClassLoader getParentClassLoader(final ClassLoader fallback) {
            return parent;
        }
    });
    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(tmpLoader);
    try {
        assertFalse(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));
    } finally {
        Thread.currentThread().setContextClassLoader(old);
        SystemInstance.reset();
    }
    assertTrue(URLClassLoaderFirst.shouldSkip("javax.wsdl.WSDLException"));
    SystemInstance.reset();
}
Also used : ParentClassLoaderFinder(org.apache.openejb.core.ParentClassLoaderFinder) WSDLException(javax.wsdl.WSDLException) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

URLClassLoader (java.net.URLClassLoader)1 Properties (java.util.Properties)1 WSDLException (javax.wsdl.WSDLException)1 ParentClassLoaderFinder (org.apache.openejb.core.ParentClassLoaderFinder)1 Test (org.junit.Test)1