Search in sources :

Example 1 with FineGrainedControlClassLoader

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));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with FineGrainedControlClassLoader

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));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with FineGrainedControlClassLoader

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));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with FineGrainedControlClassLoader

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));
}
Also used : FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with FineGrainedControlClassLoader

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);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) System.lineSeparator(java.lang.System.lineSeparator) FunctionExpressionMatcher.expressionMatches(org.mule.tck.junit4.matcher.FunctionExpressionMatcher.expressionMatches) PARENT_ONLY(org.mule.runtime.module.artifact.api.classloader.ParentOnlyLookupStrategy.PARENT_ONLY) URL(java.net.URL) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) PARENT_FIRST(org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST) ClassUtils(org.mule.runtime.core.api.util.ClassUtils) URLClassLoader(java.net.URLClassLoader) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) SmallTest(org.mule.tck.size.SmallTest) TestClassNotFoundException(org.mule.tck.classlaoder.TestClassLoader.TestClassNotFoundException) Method(java.lang.reflect.Method) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) ThrowableMessageMatcher.hasMessage(org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) CompositeClassNotFoundException(org.mule.runtime.module.artifact.api.classloader.exception.CompositeClassNotFoundException) TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) CHILD_FIRST(org.mule.runtime.module.artifact.api.classloader.ChildFirstLookupStrategy.CHILD_FIRST) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Rule(org.junit.Rule) FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) TestClassNotFoundException(org.mule.tck.classlaoder.TestClassLoader.TestClassNotFoundException) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) URLClassLoader(java.net.URLClassLoader) TestClassLoader(org.mule.tck.classlaoder.TestClassLoader) FineGrainedControlClassLoader(org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader) CompositeClassNotFoundException(org.mule.runtime.module.artifact.api.classloader.exception.CompositeClassNotFoundException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

URLClassLoader (java.net.URLClassLoader)8 Test (org.junit.Test)8 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)8 FineGrainedControlClassLoader (org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader)8 SmallTest (org.mule.tck.size.SmallTest)8 TestClassLoader (org.mule.tck.classlaoder.TestClassLoader)4 System.lineSeparator (java.lang.System.lineSeparator)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)3 CoreMatchers.startsWith (org.hamcrest.CoreMatchers.startsWith)3 Matchers.contains (org.hamcrest.Matchers.contains)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Rule (org.junit.Rule)3 ThrowableMessageMatcher.hasMessage (org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage)3 ExpectedException (org.junit.rules.ExpectedException)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.when (org.mockito.Mockito.when)3 ClassUtils (org.mule.runtime.core.api.util.ClassUtils)3