Search in sources :

Example 21 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class MuleClassLoaderLookupPolicyProviderTestCase method extendsPolicy.

@Test
public void extendsPolicy() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), emptySet());
    final ClassLoaderLookupPolicy extendedPolicy = lookupPolicy.extend(singletonMap(FOO_PACKAGE, PARENT_FIRST));
    assertThat(extendedPolicy.getClassLookupStrategy(FOO_CLASS), sameInstance(PARENT_FIRST));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 22 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class MuleClassLoaderLookupPolicyProviderTestCase method maintainsOriginalLookupStrategy.

@Test
public void maintainsOriginalLookupStrategy() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(singletonMap(FOO_PACKAGE, new ContainerOnlyLookupStrategy(getClass().getClassLoader())), emptySet());
    final ClassLoaderLookupPolicy extendedPolicy = lookupPolicy.extend(singletonMap(FOO_PACKAGE, PARENT_FIRST));
    assertThat(extendedPolicy.getClassLookupStrategy(FOO_CLASS), instanceOf(ContainerOnlyLookupStrategy.class));
    assertThat(extendedPolicy.getClassLookupStrategy(FOO_CLASS).getClassLoaders(getClass().getClassLoader()), contains(getClass().getClassLoader()));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 23 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class MuleClassLoaderLookupPolicyProviderTestCase method normalizesLookupStrategies.

@Test
public void normalizesLookupStrategies() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(singletonMap(FOO_PACKAGE, new ContainerOnlyLookupStrategy(getClass().getClassLoader())), emptySet());
    final ClassLoaderLookupPolicy extendedPolicy = lookupPolicy.extend(singletonMap(FOO_PACKAGE_PREFIX, PARENT_FIRST));
    assertThat(extendedPolicy.getClassLookupStrategy(FOO_CLASS), instanceOf(ContainerOnlyLookupStrategy.class));
    assertThat(extendedPolicy.getClassLookupStrategy(FOO_CLASS).getClassLoaders(getClass().getClassLoader()), contains(getClass().getClassLoader()));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 24 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class MuleClassLoaderLookupPolicyProviderTestCase method cannotExtendPolicyWithSystemPackage.

@Test
public void cannotExtendPolicyWithSystemPackage() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), singleton(SYSTEM_PACKAGE));
    final String overrideClassName = Object.class.getName();
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage(invalidLookupPolicyOverrideError(overrideClassName, PARENT_FIRST));
    lookupPolicy.extend(singletonMap(overrideClassName, PARENT_FIRST));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 25 with ClassLoaderLookupPolicy

use of org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy in project mule by mulesoft.

the class MuleClassLoaderLookupPolicyProviderTestCase method usesParentOnlyForSystemPackage.

@Test
public void usesParentOnlyForSystemPackage() throws Exception {
    ClassLoaderLookupPolicy lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), singleton(SYSTEM_PACKAGE));
    assertThat(lookupPolicy.getClassLookupStrategy(Object.class.getName()), sameInstance(PARENT_ONLY));
    lookupPolicy = new MuleClassLoaderLookupPolicy(emptyMap(), singleton(JAVA_PACKAGE));
    assertThat(lookupPolicy.getClassLookupStrategy(Object.class.getName()), sameInstance(PARENT_ONLY));
}
Also used : ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)32 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)16 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)12 URLClassLoader (java.net.URLClassLoader)8 FineGrainedControlClassLoader (org.mule.runtime.module.artifact.api.classloader.FineGrainedControlClassLoader)8 URL (java.net.URL)6 HashMap (java.util.HashMap)5 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)5 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)5 PARENT_FIRST (org.mule.runtime.module.artifact.api.classloader.ParentFirstLookupStrategy.PARENT_FIRST)5 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MuleModule (org.mule.runtime.container.api.MuleModule)4 ArtifactClassLoaderFilter (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFilter)4 ArtifactDescriptor (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor)4 TestClassLoader (org.mule.tck.classlaoder.TestClassLoader)4 System.lineSeparator (java.lang.System.lineSeparator)3