use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.
the class DefaultPolicyTemplateFactoryTestCase method createApplication.
private Application createApplication(RegionClassLoader regionClassLoader) {
ApplicationDescriptor appDescriptor = mock(ApplicationDescriptor.class);
when(appDescriptor.getPlugins()).thenReturn(emptySet());
Application application = mock(Application.class);
when(application.getRegionClassLoader()).thenReturn(regionClassLoader);
when(application.getDescriptor()).thenReturn(appDescriptor);
final Domain domain = mock(Domain.class);
when(domain.getDescriptor()).thenReturn(new DomainDescriptor("testDomain"));
when(application.getDomain()).thenReturn(domain);
return application;
}
use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor 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.api.domain.DomainDescriptor in project mule by mulesoft.
the class ToolingApplicationClassLoaderBuilder method getParentLookupPolicy.
@Override
protected ClassLoaderLookupPolicy getParentLookupPolicy(ArtifactClassLoader parentClassLoader) {
if (!usesCustomDomain) {
return super.getParentLookupPolicy(parentClassLoader);
}
Map<String, LookupStrategy> lookupStrategies = new HashMap<>();
DomainDescriptor descriptor = parentClassLoader.getArtifactDescriptor();
descriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
for (ArtifactPluginDescriptor artifactPluginDescriptor : descriptor.getPlugins()) {
artifactPluginDescriptor.getClassLoaderModel().getExportedPackages().forEach(p -> lookupStrategies.put(p, PARENT_FIRST));
}
return parentClassLoader.getClassLoaderLookupPolicy().extend(lookupStrategies);
}
use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.
the class MuleApplicationClassLoaderTestCase method createAppClassLoader.
@Before
public void createAppClassLoader() throws Exception {
// Create directories structure
previousMuleHome = System.setProperty(MULE_HOME_DIRECTORY_PROPERTY, tempMuleHome.getRoot().getAbsolutePath());
final List<URL> urls = new LinkedList<>();
appFolder = getAppFolder(APP_NAME);
assertThat(appFolder.mkdirs(), is(true));
// Add isolated resources in classes dir
FileUtils.stringToFile(new File(appFolder, RESOURCE_IN_CLASSES_AND_JAR).getAbsolutePath(), "Some text");
FileUtils.stringToFile(new File(appFolder, RESOURCE_JUST_IN_CLASSES).getAbsolutePath(), "Some text");
urls.add(appFolder.toURI().toURL());
// Add jar file with resources in lib dir
File libDir = getAppLibFolder(APP_NAME);
assertThat(libDir.mkdirs(), is(true));
URL resourceSrcJarFile = currentThread().getContextClassLoader().getResource("test-jar-with-resources.jar");
assertNotNull(resourceSrcJarFile);
File srcJarFile = new File(resourceSrcJarFile.toURI());
jarFile = new File(libDir, "test-jar-with-resources.jar");
FileUtils.copyFile(srcJarFile, jarFile, false);
urls.add(jarFile.toURI().toURL());
// Add isolated resources in domain dir
domainDir = MuleFoldersUtil.getDomainFolder(DOMAIN_NAME);
assertThat(domainDir.mkdirs(), is(true));
FileUtils.stringToFile(new File(domainDir, RESOURCE_JUST_IN_DOMAIN).getAbsolutePath(), "Some text");
mockStatic(MuleArtifactClassLoader.class);
// Create app class loader
domainCL = new MuleSharedDomainClassLoader(new DomainDescriptor(DOMAIN_NAME), currentThread().getContextClassLoader(), mock(ClassLoaderLookupPolicy.class), emptyList(), emptyList());
final ApplicationDescriptor applicationDescriptor = new ApplicationDescriptor(APP_NAME);
ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder(applicationDescriptor.getClassLoaderModel()).containing(getAppFolder(APP_NAME).toURI().toURL()).build();
applicationDescriptor.setClassLoaderModel(classLoaderModel);
appCL = new MuleApplicationClassLoader(APP_NAME, applicationDescriptor, domainCL, null, urls, mock(ClassLoaderLookupPolicy.class), emptyList());
}
use of org.mule.runtime.deployment.model.api.domain.DomainDescriptor in project mule by mulesoft.
the class DomainClassLoaderFactoryTestCase method createClassLoaderUsingDefaultDomain.
@Test
public void createClassLoaderUsingDefaultDomain() {
createDomainDir(MULE_DOMAIN_FOLDER, DEFAULT_DOMAIN_NAME);
DomainDescriptor descriptor = getTestDescriptor(DEFAULT_DOMAIN_NAME);
final String artifactId = getDomainId(DEFAULT_DOMAIN_NAME);
assertThat(new DomainClassLoaderFactory(getClass().getClassLoader()).create(artifactId, containerClassLoader, descriptor, emptyList()).getArtifactId(), is(artifactId));
}
Aggregations