Search in sources :

Example 6 with ApplicationDescriptor

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());
}
Also used : File(java.io.File) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) Test(org.junit.Test)

Example 7 with ApplicationDescriptor

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);
}
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 8 with ApplicationDescriptor

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()));
}
Also used : MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) Test(org.junit.Test)

Example 9 with ApplicationDescriptor

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();
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ArtifactPluginDescriptorLoader(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorLoader) ArtifactPluginDescriptorFactory(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorFactory) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) File(java.io.File) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) ServiceRegistryDescriptorLoaderRepository(org.mule.runtime.module.deployment.impl.internal.artifact.ServiceRegistryDescriptorLoaderRepository) Test(org.junit.Test)

Example 10 with ApplicationDescriptor

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());
}
Also used : File(java.io.File) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) URL(java.net.URL) LinkedList(java.util.LinkedList) MuleSharedDomainClassLoader(org.mule.runtime.deployment.model.internal.domain.MuleSharedDomainClassLoader) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Before(org.junit.Before)

Aggregations

ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)12 File (java.io.File)6 Test (org.junit.Test)5 Application (org.mule.runtime.deployment.model.api.application.Application)3 Domain (org.mule.runtime.deployment.model.api.domain.Domain)3 Before (org.junit.Before)2 DomainDescriptor (org.mule.runtime.deployment.model.api.domain.DomainDescriptor)2 MuleApplicationClassLoader (org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader)2 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)2 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1 MavenClientProvider (org.mule.maven.client.api.MavenClientProvider)1 MuleApplicationModel (org.mule.runtime.api.deployment.meta.MuleApplicationModel)1