use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.
the class DefaultApplicationPolicyInstanceTestCase method correctArtifactTypeForPolicies.
@Test
@Issue("MULE-14289")
@Ignore("MULE-14289: The discovered ArtifactConfigurationProcessor is not compatible with the provided mocks.")
public void correctArtifactTypeForPolicies() throws InitialisationException {
MuleContextListener muleContextListener = mock(MuleContextListener.class);
ArgumentCaptor<MuleContext> muleContextCaptor = ArgumentCaptor.forClass(MuleContext.class);
PolicyTemplate policyTemplate = mock(PolicyTemplate.class, RETURNS_DEEP_STUBS);
when(policyTemplate.getArtifactClassLoader().getClassLoader()).thenReturn(this.getClass().getClassLoader());
Application application = mock(Application.class, RETURNS_DEEP_STUBS);
Registry registry = application.getRegistry();
doReturn(of(mockContextWithServices())).when(registry).lookupByType(MuleContext.class);
doReturn(of(mock(ExtensionManager.class))).when(registry).lookupByName(OBJECT_EXTENSION_MANAGER);
PolicyParametrization parameterization = mock(PolicyParametrization.class, RETURNS_DEEP_STUBS);
when(parameterization.getId()).thenReturn("policyId");
DefaultApplicationPolicyInstance applicationPolicyInstance = new DefaultApplicationPolicyInstance(application, policyTemplate, parameterization, mock(ServiceRepository.class), mock(ClassLoaderRepository.class), emptyList(), mock(ExtensionModelLoaderRepository.class), muleContextListener);
applicationPolicyInstance.initialise();
verify(muleContextListener).onCreation(muleContextCaptor.capture());
assertThat(muleContextCaptor.getValue().getArtifactType(), is(POLICY));
}
use of org.mule.runtime.deployment.model.api.application.Application 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.application.Application 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.Application in project mule by mulesoft.
the class CompositeArtifactExtensionManagerFactoryTestCase method createsCompositeExtensionManager.
@Test
public void createsCompositeExtensionManager() throws Exception {
Application application = mock(Application.class, RETURNS_DEEP_STUBS);
ExtensionManager applicationExtensionManager = mock(ExtensionManager.class);
when(application.getRegistry().lookupByName(MuleProperties.OBJECT_EXTENSION_MANAGER)).thenReturn(of(applicationExtensionManager));
ExtensionModelLoaderRepository extensionModelLoaderRepository = mock(ExtensionModelLoaderRepository.class);
ExtensionManagerFactory extensionManagerFactory = mock(ExtensionManagerFactory.class);
CompositeArtifactExtensionManagerFactory factory = new CompositeArtifactExtensionManagerFactory(application, extensionModelLoaderRepository, emptyList(), extensionManagerFactory);
ExtensionManager policyExtensionManager = mock(ExtensionManager.class);
MuleContext muleContext = mock(MuleContext.class);
when(extensionManagerFactory.create(muleContext)).thenReturn(policyExtensionManager);
ExtensionManager extensionManager = factory.create(muleContext);
assertThat(extensionManager, instanceOf(CompositeArtifactExtensionManager.class));
CompositeArtifactExtensionManager compositeArtifactExtensionManager = (CompositeArtifactExtensionManager) extensionManager;
assertThat(compositeArtifactExtensionManager.getParentExtensionManager(), equalTo(applicationExtensionManager));
assertThat(compositeArtifactExtensionManager.getChildExtensionManager(), equalTo(policyExtensionManager));
}
use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.
the class ApplicationDeploymentTestCase method appHomePropertyIsPresent.
@Test
public void appHomePropertyIsPresent() throws Exception {
final ApplicationFileBuilder globalPropertyAppFileBuilder = new ApplicationFileBuilder("property-app").definedBy("app-properties-config.xml");
addExplodedAppFromBuilder(globalPropertyAppFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, globalPropertyAppFileBuilder.getId());
final Application app = findApp(globalPropertyAppFileBuilder.getId(), 1);
Optional<ConfigurationProperties> configurationProperties = app.getRegistry().lookupByType(ConfigurationProperties.class);
assertThat(configurationProperties.isPresent(), is(true));
String appHome = configurationProperties.get().resolveStringProperty("appHome").orElseThrow(() -> new RuntimeException("Could not find property appHome"));
assertThat(new File(appHome).exists(), is(true));
}
Aggregations