Search in sources :

Example 11 with ArtifactClassLoader

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

the class DefaultRegionPluginClassLoadersFactoryTestCase method createsPluginWithPrivilegedContainerAccess.

@Test
public void createsPluginWithPrivilegedContainerAccess() throws Exception {
    MuleModule privilegedModule = mock(MuleModule.class);
    when(privilegedModule.getPrivilegedArtifacts()).thenReturn(singleton(PLUGIN_ARTIFACT_ID1));
    when(privilegedModule.getPrivilegedExportedPackages()).thenReturn(singleton(PRIVILEGED_PACKAGE));
    when(moduleRepository.getModules()).thenReturn(singletonList(privilegedModule));
    List<ArtifactPluginDescriptor> artifactPluginDescriptors = singletonList(plugin1Descriptor);
    ArgumentCaptor<Map> mapArgumentCaptor = forClass(Map.class);
    when(regionOwnerLookupPolicy.extend(mapArgumentCaptor.capture())).thenReturn(pluginLookupPolicy);
    List<ArtifactClassLoader> pluginClassLoaders = factory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionOwnerLookupPolicy);
    assertThat(pluginClassLoaders, contains(pluginClassLoader1));
    Map<String, LookupStrategy> value = mapArgumentCaptor.getValue();
    assertThat(value, hasEntry(equalTo(PRIVILEGED_PACKAGE), instanceOf(ContainerOnlyLookupStrategy.class)));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Map(java.util.Map) DelegateOnlyLookupStrategy(org.mule.runtime.module.artifact.api.classloader.DelegateOnlyLookupStrategy) ContainerOnlyLookupStrategy(org.mule.runtime.container.internal.ContainerOnlyLookupStrategy) LookupStrategy(org.mule.runtime.module.artifact.api.classloader.LookupStrategy) MuleModule(org.mule.runtime.container.api.MuleModule) Test(org.junit.Test)

Example 12 with ArtifactClassLoader

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

the class ArtifactBootstrapRegistryConfigurationBuilderTestCase method createBootstrapServiceDiscovererContextBuilder.

private ArtifactBootstrapServiceDiscovererConfigurationBuilder createBootstrapServiceDiscovererContextBuilder() {
    try {
        ArtifactPlugin plugin1 = mock(ArtifactPlugin.class);
        final ArtifactClassLoader pluginClassLoader1 = mock(ArtifactClassLoader.class);
        when(plugin1.getArtifactClassLoader()).thenReturn(pluginClassLoader1);
        final List<ArtifactPlugin> artifactPlugins = new ArrayList<>();
        artifactPlugins.add(plugin1);
        final List<URL> urls = new ArrayList<>();
        urls.add(this.getClass().getResource("/plugin1-bootstrap.properties"));
        urls.add(this.getClass().getResource("/plugin2-bootstrap.properties"));
        when(pluginClassLoader1.findResources(BOOTSTRAP_PROPERTIES)).thenReturn(new EnumerationAdapter<>(urls));
        return new ArtifactBootstrapServiceDiscovererConfigurationBuilder(artifactPlugins);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 13 with ArtifactClassLoader

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

the class DefaultArtifactClassLoaderManagerTestCase method getIdForNonRegisteredArtifactClassLoader.

@Test
public void getIdForNonRegisteredArtifactClassLoader() {
    ArtifactClassLoader artifactClassLoader = getArtifactClassLoader();
    assertThat(manager.getId(artifactClassLoader.getClassLoader()), is(Optional.empty()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 14 with ArtifactClassLoader

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

the class DefaultArtifactClassLoaderManagerTestCase method getIdForRegisteredArtifactClassLoader.

@Test
public void getIdForRegisteredArtifactClassLoader() {
    ArtifactClassLoader artifactClassLoader = getArtifactClassLoader();
    manager.register(artifactClassLoader);
    assertThat(manager.getId(artifactClassLoader.getClassLoader()), is(Optional.of(ARTIFACT_ID)));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 15 with ArtifactClassLoader

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

the class DefaultPolicyTemplateFactoryTestCase method createRegionClassLoader.

private RegionClassLoader createRegionClassLoader() {
    ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
    RegionClassLoader regionClassLoader = new RegionClassLoader(descriptor.getName(), descriptor, this.getClass().getClassLoader(), lookupPolicy);
    // Adds the owner of the region
    ArtifactClassLoader regionOwnerClassLoader = mock(ArtifactClassLoader.class);
    regionClassLoader.addClassLoader(regionOwnerClassLoader, NULL_CLASSLOADER_FILTER);
    return regionClassLoader;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) RegionClassLoader(org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)

Aggregations

ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)58 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)17 URL (java.net.URL)12 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)12 Pair (org.mule.runtime.api.util.Pair)10 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)10 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)10 Service (org.mule.runtime.api.service.Service)8 SmallTest (org.mule.tck.size.SmallTest)8 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)7 Map (java.util.Map)6 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)6 File (java.io.File)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)5 HashSet (java.util.HashSet)4