use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentOnlyLookupAndFails.
@Test
public void usesParentOnlyLookupAndFails() throws Exception {
ClassLoader parent = mock(ClassLoader.class);
final ClassNotFoundException thrownException = new ClassNotFoundException("ERROR");
when(parent.loadClass(TEST_CLASS_NAME)).thenThrow(thrownException);
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_ONLY);
expected.expect(CompositeClassNotFoundException.class);
expected.expectMessage(startsWith("Cannot load class '" + TEST_CLASS_NAME + "': [" + lineSeparator() + "\t" + "ERROR]"));
expected.expect(expressionMatches((e) -> ((CompositeClassNotFoundException) e).getExceptions(), contains(sameInstance(thrownException))));
FineGrainedControlClassLoader ext = new FineGrainedControlClassLoader(new URL[] { getChildFileResource() }, parent, lookupPolicy);
ext.loadClass(TEST_CLASS_NAME);
}
use of org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader in project mule by mulesoft.
the class FineGrainedControlClassLoaderTestCase method usesParentFirstThenChildLookup.
@Test
public void usesParentFirstThenChildLookup() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(PARENT_FIRST);
when(lookupPolicy.getClassLookupStrategy(Object.class.getName())).thenReturn(PARENT_FIRST);
when(lookupPolicy.getClassLookupStrategy(String.class.getName())).thenReturn(PARENT_FIRST);
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 usesChildFirstThenParentLookupAndFails.
@Test
public void usesChildFirstThenParentLookupAndFails() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(TEST_CLASS_NAME)).thenReturn(CHILD_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(expressionMatches((e) -> ((TestClassNotFoundException) e).getClassLoader(), is((ClassLoader) ext)), hasMessage(is(TEST_CLASS_NAME)))));
invokeTestClassMethod(ext);
}
Aggregations