Search in sources :

Example 36 with ArtifactClassLoader

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

the class DefaultApplicationFactoryTestCase method createsApplication.

@Test
public void createsApplication() throws Exception {
    final ApplicationDescriptor descriptor = new ApplicationDescriptor(APP_NAME);
    descriptor.setClassLoaderModel(createClassLoaderModelWithDomain());
    final File[] resourceFiles = new File[] { new File("mule-config.xml") };
    when(applicationDescriptorFactory.create(any(), any())).thenReturn(descriptor);
    final ArtifactPluginDescriptor coreArtifactPluginDescriptor = new ArtifactPluginDescriptor(FAKE_ARTIFACT_PLUGIN);
    coreArtifactPluginDescriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().build());
    final ArtifactPlugin appPlugin = mock(ArtifactPlugin.class);
    final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
    when(appPlugin.getArtifactClassLoader()).thenReturn(artifactClassLoader);
    when(artifactClassLoader.getArtifactId()).thenReturn(FAKE_ARTIFACT_PLUGIN);
    when(appPlugin.getDescriptor()).thenReturn(coreArtifactPluginDescriptor);
    final Domain domain = createDomain(DOMAIN_NAME);
    final ClassLoaderLookupPolicy sharedLibLookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(domain.getArtifactClassLoader().getClassLoaderLookupPolicy().extend(anyMap())).thenReturn(sharedLibLookupPolicy);
    final MuleApplicationClassLoader applicationArtifactClassLoader = mock(MuleApplicationClassLoader.class);
    when(applicationArtifactClassLoader.getArtifactId()).thenReturn(APP_ID);
    ApplicationClassLoaderBuilder applicationClassLoaderBuilderMock = mock(ApplicationClassLoaderBuilder.class);
    when(applicationClassLoaderBuilderMock.setDomain(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactId(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.build()).thenReturn(applicationArtifactClassLoader);
    when(applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(applicationClassLoaderBuilderMock);
    List<ArtifactClassLoader> pluginClassLoaders = new ArrayList<>();
    pluginClassLoaders.add(artifactClassLoader);
    when(applicationArtifactClassLoader.getArtifactPluginClassLoaders()).thenReturn(pluginClassLoaders);
    final Application application = applicationFactory.createArtifact(new File(APP_NAME), empty());
    assertThat(application.getDomain(), is(domain));
    assertThat(application.getArtifactClassLoader(), is(applicationArtifactClassLoader));
    assertThat(application.getDescriptor(), is(descriptor));
    assertThat(application.getArtifactName(), is(APP_NAME));
    assertThat(application.getResourceFiles(), is(resourceFiles));
    verify(domainRepository, times(2)).getDomain(DOMAIN_ARTIFACT_FILE_NAME);
    verify(applicationClassLoaderBuilderMock).setDomain(domain);
    verify(applicationClassLoaderBuilderMock).addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]));
    verify(applicationClassLoaderBuilderMock).setArtifactDescriptor(descriptor);
    verify(applicationClassLoaderBuilderMock).setArtifactId(APP_NAME);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ApplicationClassLoaderBuilder(org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArrayList(java.util.ArrayList) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) Domain(org.mule.runtime.deployment.model.api.domain.Domain) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) File(java.io.File) Application(org.mule.runtime.deployment.model.api.application.Application) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin) Test(org.junit.Test)

Example 37 with ArtifactClassLoader

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

the class DefaultArtifactClassLoaderManagerTestCase method registersArtifactClassLoader.

@Test
public void registersArtifactClassLoader() throws Exception {
    ArtifactClassLoader artifactClassLoader = getArtifactClassLoader();
    manager.register(artifactClassLoader);
    assertThat(manager.find(ARTIFACT_ID).get(), is(artifactClassLoader.getClassLoader()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 38 with ArtifactClassLoader

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

the class DefaultArtifactClassLoaderManagerTestCase method unregistersArtifactClassLoader.

@Test
public void unregistersArtifactClassLoader() throws Exception {
    ArtifactClassLoader artifactClassLoader = getArtifactClassLoader();
    manager.register(artifactClassLoader);
    assertThat(manager.unregister(ARTIFACT_ID), is(artifactClassLoader));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 39 with ArtifactClassLoader

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

the class DefaultArtifactClassLoaderManagerTestCase method getArtifactClassLoader.

private ArtifactClassLoader getArtifactClassLoader() {
    ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
    when(artifactClassLoader.getArtifactId()).thenReturn(ARTIFACT_ID);
    ClassLoader expectedClassLoader = getClass().getClassLoader();
    when(artifactClassLoader.getClassLoader()).thenReturn(expectedClassLoader);
    return artifactClassLoader;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)

Example 40 with ArtifactClassLoader

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

the class DefaultClassLoaderManager method find.

@Override
public Optional<ClassLoader> find(String classLoaderId) {
    checkClassLoaderId(classLoaderId);
    ArtifactClassLoader artifactClassLoader = artifactClassLoaders.get(classLoaderId);
    return of(artifactClassLoader.getClassLoader());
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)

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