use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesChildFirstLookup.
@Test
public void usesChildFirstLookup() throws Exception {
URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(CHILD_FIRST);
when(lookupPolicy.getClassLookupStrategy(Object.class.getName())).thenReturn(PARENT_ONLY);
when(lookupPolicy.getClassLookupStrategy(String.class.getName())).thenReturn(PARENT_ONLY);
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
assertEquals(EXPECTED_CHILD_MESSAGE, invokeTestClassMethod(ext));
}
use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesChildFirstThenParentLookup.
@Test
public void usesChildFirstThenParentLookup() throws Exception {
URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[0], parent, lookupPolicy);
assertEquals(EXPECTED_PARENT_MESSAGE, invokeTestClassMethod(ext));
}
use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentOnlyLookup.
@Test
public void usesParentOnlyLookup() throws Exception {
URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_ONLY);
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
assertEquals(EXPECTED_PARENT_MESSAGE, invokeTestClassMethod(ext));
}
use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentFirstLookup.
@Test
public void usesParentFirstLookup() throws Exception {
URLClassLoader parent = new URLClassLoader(new URL[] { getParentResource() }, Thread.currentThread().getContextClassLoader());
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
assertEquals(EXPECTED_PARENT_MESSAGE, invokeTestClassMethod(ext));
}
use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentFirstAndChildLookupAndFails.
@Test
public void usesParentFirstAndChildLookupAndFails() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
expected.expect(CompositeClassNotFoundException.class);
expected.expectMessage(startsWith("Cannot load class '" + TEST_CLASS_NAME + "': ["));
FineGrainedControlClassLoader ext = buildFineGrainedControlClassLoader(parent, lookupPolicy);
expected.expect(expressionMatches((e) -> ((CompositeClassNotFoundException) e).getExceptions(), contains(hasMessage(is(TEST_CLASS_NAME)), expressionMatches((e) -> ((TestClassNotFoundException) e).getClassLoader(), is((ClassLoader) ext)))));
invokeTestClassMethod(ext);
}
Aggregations