Search in sources :

Example 11 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class DefaultArchiveDeployerTestCase method ignoresErrorsWhileRemovingArtifactDataFolder.

@Test
public void ignoresErrorsWhileRemovingArtifactDataFolder() throws Exception {
    AbstractDeployableArtifactFactory artifactFactory = mock(AbstractDeployableArtifactFactory.class);
    ArtifactDeployer artifactDeployer = mock(ArtifactDeployer.class);
    DefaultArchiveDeployer<Application> deployer = new DefaultArchiveDeployer(artifactDeployer, artifactFactory, new ObservableList(), null, null);
    deployer.setDeploymentListener(mock(DeploymentListener.class));
    deployer.deployArtifact(createMockApplication(), empty());
    mockStatic(FileUtils.class);
    PowerMockito.doThrow(new IOException()).when(FileUtils.class);
    deleteDirectory(Matchers.eq(getAppDataFolder(ARTIFACT_ID)));
    deployer.undeployArtifact(ARTIFACT_ID);
}
Also used : ObservableList(org.mule.runtime.module.deployment.internal.util.ObservableList) AbstractDeployableArtifactFactory(org.mule.runtime.module.deployment.impl.internal.artifact.AbstractDeployableArtifactFactory) IOException(java.io.IOException) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) Application(org.mule.runtime.deployment.model.api.application.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class DefaultMuleDeployerTestCase method disposesAppOnDeployFailure.

@Test
public void disposesAppOnDeployFailure() throws Exception {
    DefaultArtifactDeployer deployer = new DefaultArtifactDeployer();
    Application app = mock(Application.class);
    doThrow(new IllegalStateException()).when(app).init();
    try {
        deployer.deploy(app);
        fail("Deployment is supposed to fail");
    } catch (DeploymentException expected) {
    }
    verify(app, times(1)).dispose();
}
Also used : DeploymentException(org.mule.runtime.deployment.model.api.DeploymentException) Application(org.mule.runtime.deployment.model.api.application.Application) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 13 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class DomainDeploymentTestCase method failsToApplyApplicationPolicyWithDomainPluginVersionMismatch.

@Test
public void failsToApplyApplicationPolicyWithDomainPluginVersionMismatch() throws Exception {
    installEchoService();
    installFooService();
    policyManager.registerPolicyTemplate(policyIncludingHelloPluginV2FileBuilder.getArtifactFile());
    DomainFileBuilder domainFileBuilder = new DomainFileBuilder("dummy-domain-bundle").definedBy("empty-domain-config.xml").dependingOn(helloExtensionV1Plugin);
    ApplicationFileBuilder applicationFileBuilder = new ApplicationFileBuilder("dummyWithHelloExtension").definedBy(APP_WITH_EXTENSION_PLUGIN_CONFIG).dependingOn(domainFileBuilder);
    addPackedDomainFromBuilder(domainFileBuilder);
    addPackedAppFromBuilder(applicationFileBuilder);
    startDeployment();
    assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
    try {
        policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingHelloPluginV2FileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
        fail("Policy application should have failed");
    } catch (PolicyRegistrationException expected) {
    }
}
Also used : URL(java.net.URL) Assert.assertNotSame(org.junit.Assert.assertNotSame) DEFAULT_CONFIGURATION_RESOURCE(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_CONFIGURATION_RESOURCE) URISyntaxException(java.net.URISyntaxException) Matchers.not(org.hamcrest.Matchers.not) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) DESTROYED(org.mule.runtime.deployment.model.api.application.ApplicationStatus.DESTROYED) ByteArrayInputStream(java.io.ByteArrayInputStream) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) URI(java.net.URI) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) CompilerUtils(org.mule.tck.util.CompilerUtils) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ApplicationStatus(org.mule.runtime.deployment.model.api.application.ApplicationStatus) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) EXPORTED_CLASS_PACKAGES_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_CLASS_PACKAGES_PROPERTY) DomainClassLoaderFactory(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderFactory) FileUtils.forceDelete(org.apache.commons.io.FileUtils.forceDelete) FileUtils.touch(org.apache.commons.io.FileUtils.touch) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IOUtils(org.mule.runtime.core.api.util.IOUtils) Application(org.mule.runtime.deployment.model.api.application.Application) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Ignore(org.junit.Ignore) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Paths(java.nio.file.Paths) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DEFAULT_DOMAIN_NAME(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_DOMAIN_NAME) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Mockito.reset(org.mockito.Mockito.reset) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 14 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class DomainDeploymentTestCase method deploysDomain.

private void deploysDomain() {
    assertDeploymentSuccess(domainDeploymentListener, dummyDomainBundleFileBuilder.getId());
    assertDomainDir(NONE, new String[] { DEFAULT_DOMAIN_NAME, dummyDomainBundleFileBuilder.getId() }, true);
    final Domain domain = findADomain(dummyDomainBundleFileBuilder.getId());
    assertNotNull(domain);
    assertNotNull(domain.getRegistry());
    assertApplicationDeploymentSuccess(applicationDeploymentListener, dummyAppDescriptorFileBuilder.getId());
    assertAppsDir(NONE, new String[] { dummyAppDescriptorFileBuilder.getId() }, true);
    final Application app = findApp(dummyAppDescriptorFileBuilder.getId(), 1);
    assertNotNull(app);
}
Also used : Domain(org.mule.runtime.deployment.model.api.domain.Domain) Application(org.mule.runtime.deployment.model.api.application.Application)

Example 15 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class TestPolicyManager method removePolicy.

/**
 * Removes a parameterized policy
 *
 * @param appName application where the policy is applied. Non empty.
 * @param policyId identifies the policy parametrization. Non empty.
 * @return true if the poclicy was removed, false if the policy is not applied in the application.
 * @throws IllegalArgumentException if the application does not exists or there is an invalid parameter value.
 */
public boolean removePolicy(String appName, String policyId) {
    checkArgument(!isEmpty(appName), "appName cannot be empty");
    checkArgument(!isEmpty(policyId), "policyId cannot be empty");
    Application application = deploymentService.findApplication(appName);
    if (application == null) {
        throw new IllegalArgumentException("Cannot find application named: " + appName);
    }
    return application.getPolicyManager().removePolicy(policyId);
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application)

Aggregations

Application (org.mule.runtime.deployment.model.api.application.Application)35 Test (org.junit.Test)19 File (java.io.File)7 Domain (org.mule.runtime.deployment.model.api.domain.Domain)6 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)4 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)4 PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)3 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)3 DeploymentListener (org.mule.runtime.module.deployment.api.DeploymentListener)3 URI (java.net.URI)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)2