use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy 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.ClassLoaderLookupPolicy 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.ClassLoaderLookupPolicy 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.ClassLoaderLookupPolicy in project mule by mulesoft.
the class MuleClassLoaderLookupPolicyProviderTestCase method usesChildFirstForNoConfiguredPackage.
@Test
public void usesChildFirstForNoConfiguredPackage() throws Exception {
ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), emptySet());
assertThat(lookupPolicy.getClassLookupStrategy(FOO_CLASS), sameInstance(CHILD_FIRST));
}
use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.
the class ContainerClassLoaderFactory method createContainerClassLoader.
/**
* Creates the classLoader to represent the Mule container.
*
* @param parentClassLoader parent classLoader. Can be null.
* @return a non null {@link ArtifactClassLoader} containing container code that can be used as parent classloader for other
* mule artifacts.
*/
public ArtifactClassLoader createContainerClassLoader(final ClassLoader parentClassLoader) {
final List<MuleModule> muleModules = moduleRepository.getModules();
final ClassLoaderLookupPolicy containerLookupPolicy = getContainerClassLoaderLookupPolicy(parentClassLoader, muleModules);
return createArtifactClassLoader(parentClassLoader, muleModules, containerLookupPolicy, new ArtifactDescriptor("mule"));
}
Aggregations