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);
}
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()));
}
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));
}
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;
}
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());
}
Aggregations