use of org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader in project mule by mulesoft.
the class DefaultDomainFactoryTestCase method createDefaultDomain.
@Test
public void createDefaultDomain() throws IOException {
final MuleApplicationClassLoader domainArtifactClassLoader = mock(MuleApplicationClassLoader.class);
when(domainArtifactClassLoader.getArtifactId()).thenReturn(DEFAULT_DOMAIN_NAME);
DomainClassLoaderBuilder domainClassLoaderBuilderMock = mock(DomainClassLoaderBuilder.class);
when(domainClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.setArtifactId(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.addArtifactPluginDescriptors(new ArtifactPluginDescriptor[0])).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.build()).thenReturn(domainArtifactClassLoader);
when(domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(domainClassLoaderBuilderMock);
Domain domain = domainFactory.createArtifact(new File(DEFAULT_DOMAIN_NAME), empty());
assertThat(domain.getArtifactName(), is(DEFAULT_DOMAIN_NAME));
assertThat(domain.getDescriptor(), instanceOf(EmptyDomainDescriptor.class));
assertThat(domain.getArtifactClassLoader(), is(domainArtifactClassLoader));
}
use of org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader 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.deployment.model.internal.application.MuleApplicationClassLoader in project mule by mulesoft.
the class DefaultMuleApplicationStatusTestCase method doSetUp.
@Override
protected void doSetUp() throws Exception {
MuleApplicationClassLoader parentArtifactClassLoader = mock(MuleApplicationClassLoader.class);
mockArtifactContext = mock(ArtifactContext.class);
when(mockArtifactContext.getMuleContext()).thenReturn(muleContext);
when(mockArtifactContext.getRegistry()).thenReturn(new DefaultRegistry(muleContext));
application = new DefaultMuleApplication(null, parentArtifactClassLoader, emptyList(), null, mock(ServiceRepository.class), mock(ExtensionModelLoaderRepository.class), appLocation, null, null);
application.setArtifactContext(mockArtifactContext);
muleContext.getInjector().inject(this);
}
use of org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader in project mule by mulesoft.
the class DefaultDomainFactoryTestCase method createCustomDomain.
@Test
public void createCustomDomain() throws IOException {
String domainName = "custom-domain";
final DomainDescriptor descriptor = new DomainDescriptor(domainName);
when(domainDescriptorFactory.create(any(), any())).thenReturn(descriptor);
final MuleApplicationClassLoader domainArtifactClassLoader = mock(MuleApplicationClassLoader.class);
when(domainArtifactClassLoader.getArtifactId()).thenReturn(domainName);
DomainClassLoaderBuilder domainClassLoaderBuilderMock = mock(DomainClassLoaderBuilder.class);
when(domainClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.setArtifactId(any())).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(domainClassLoaderBuilderMock);
when(domainClassLoaderBuilderMock.build()).thenReturn(domainArtifactClassLoader);
when(domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(domainClassLoaderBuilderMock);
Domain domain = domainFactory.createArtifact(new File(domainName), empty());
assertThat(domain.getArtifactName(), is(domainName));
assertThat(domain.getDescriptor(), is(descriptor));
assertThat(domain.getArtifactClassLoader(), is(domainArtifactClassLoader));
}
use of org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader in project mule by mulesoft.
the class IsolatedClassLoaderFactory method createApplicationArtifactClassLoader.
/**
* Creates an {@link ArtifactClassLoader} for the application.
*
* @param parent the parent class loader to be assigned to the new one created here
* @param childClassLoaderLookupPolicy look policy to be used
* @param artifactsUrlClassification the url classifications to get plugins urls
* @param pluginsArtifactClassLoaders the classloaders of the plugins used by the application
* @return the {@link ArtifactClassLoader} to be used for running the test
*/
protected ArtifactClassLoader createApplicationArtifactClassLoader(ClassLoader parent, ClassLoaderLookupPolicy childClassLoaderLookupPolicy, ArtifactsUrlClassification artifactsUrlClassification, List<ArtifactClassLoader> pluginsArtifactClassLoaders) {
List<URL> applicationUrls = new ArrayList<>();
applicationUrls.addAll(artifactsUrlClassification.getApplicationLibUrls());
applicationUrls.addAll(artifactsUrlClassification.getApplicationSharedLibUrls());
logClassLoaderUrls("APP", applicationUrls);
return new MuleApplicationClassLoader(APP_NAME, new ArtifactDescriptor(APP_NAME), parent, new DefaultNativeLibraryFinderFactory().create(APP_NAME, applicationUrls.toArray(new URL[applicationUrls.size()])), applicationUrls, childClassLoaderLookupPolicy, pluginsArtifactClassLoaders);
}
Aggregations