use of org.mule.runtime.deployment.model.api.application.ApplicationDescriptor in project mule by mulesoft.
the class DefaultApplicationFactoryTestCase method applicationDeployFailDueToDomainNotDeployed.
@Test
public void applicationDeployFailDueToDomainNotDeployed() throws Exception {
final ApplicationDescriptor descriptor = new ApplicationDescriptor(APP_NAME);
descriptor.setClassLoaderModel(createClassLoaderModelWithDomain());
when(applicationDescriptorFactory.create(any(), any())).thenReturn(descriptor);
expectedException.expect(DeploymentException.class);
applicationFactory.createArtifact(new File(APP_NAME), empty());
}
use of org.mule.runtime.deployment.model.api.application.ApplicationDescriptor 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.api.application.ApplicationDescriptor in project mule by mulesoft.
the class DefaultMuleApplicationStatusTestCase method nullDeploymentClassLoaderAfterDispose.
@Test
public void nullDeploymentClassLoaderAfterDispose() {
ApplicationDescriptor descriptor = mock(ApplicationDescriptor.class);
when(descriptor.getConfigResources()).thenReturn(emptySet());
DefaultMuleApplication application = new DefaultMuleApplication(descriptor, mock(MuleApplicationClassLoader.class), emptyList(), null, null, null, appLocation, null, null);
application.install();
assertThat(application.deploymentClassLoader, is(notNullValue()));
application.dispose();
assertThat(application.deploymentClassLoader, is(nullValue()));
}
use of org.mule.runtime.deployment.model.api.application.ApplicationDescriptor in project mule by mulesoft.
the class PropertyOverridesTestCase method testOverrides.
@Test
public void testOverrides() throws Exception {
File tempProps = File.createTempFile("property", "overrides");
InputStream input = getClass().getClassLoader().getResourceAsStream("overridden.properties");
FileOutputStream output = new FileOutputStream(tempProps);
copy(input, output);
input.close();
output.close();
ApplicationDescriptor descriptor = new ApplicationDescriptor("app");
ApplicationDescriptorFactory applicationDescriptorFactory = new ApplicationDescriptorFactory(new ArtifactPluginDescriptorLoader(new ArtifactPluginDescriptorFactory()), new ServiceRegistryDescriptorLoaderRepository(new SpiServiceRegistry()), ArtifactDescriptorValidatorBuilder.builder());
applicationDescriptorFactory.setApplicationProperties(descriptor, tempProps);
Map<String, String> appProps = descriptor.getAppProperties();
assertEquals("state", appProps.get("texas"));
assertEquals("country", appProps.get("peru"));
assertEquals("austin", appProps.get("texas.capital"));
assertEquals("4", appProps.get("peru.capital.numberOfletters"));
assertEquals("runtime", appProps.get("mule"));
assertEquals("ipaas", appProps.get("mule.ion"));
try {
setSystemProperties();
descriptor = new ApplicationDescriptor("app");
applicationDescriptorFactory.setApplicationProperties(descriptor, tempProps);
appProps = descriptor.getAppProperties();
assertEquals("state", appProps.get("texas"));
assertEquals("nation", appProps.get("peru"));
assertEquals("austin", appProps.get("texas.capital"));
assertEquals("4", appProps.get("peru.capital.numberOfletters"));
assertEquals("wayCool", appProps.get("mule"));
assertEquals("ipaas", appProps.get("mule.ion"));
assertEquals("evenCooler", appProps.get("mule.mmc"));
descriptor = new ApplicationDescriptor("app");
applicationDescriptorFactory.setApplicationProperties(descriptor, new File("nonexistent.nonexistent"));
appProps = descriptor.getAppProperties();
assertNull(appProps.get("texas"));
assertEquals("nation", appProps.get("peru"));
assertNull(appProps.get("texas.capital"));
assertNull(appProps.get("peru.capital.numberOfletters"));
assertEquals("wayCool", appProps.get("mule"));
assertNull(appProps.get("mule.ion"));
assertEquals("evenCooler", appProps.get("mule.mmc"));
} finally {
resetSystemProperties();
}
}
use of org.mule.runtime.deployment.model.api.application.ApplicationDescriptor 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());
}
Aggregations