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();
}
Aggregations