Search in sources :

Example 11 with PolicyParametrization

use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.

the class ApplicationPolicyDeploymentTestCase method failsToApplyApplicationPolicyWithPluginVersionMismatch.

@Test
public void failsToApplyApplicationPolicyWithPluginVersionMismatch() throws Exception {
    policyManager.registerPolicyTemplate(policyIncludingHelloPluginV2FileBuilder.getArtifactFile());
    ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
    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 : URISyntaxException(java.net.URISyntaxException) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) Matchers.hasItems(org.hamcrest.Matchers.hasItems) PollingProber(org.mule.tck.probe.PollingProber) Collections.singletonList(java.util.Collections.singletonList) BEFORE_NEXT(org.mule.runtime.api.notification.PolicyNotification.BEFORE_NEXT) PROCESS_END(org.mule.runtime.api.notification.PolicyNotification.PROCESS_END) TestPolicyProcessor.policyParametrization(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.policyParametrization) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) AbstractSecurityProvider(org.mule.runtime.core.api.security.AbstractSecurityProvider) Assert.fail(org.junit.Assert.fail) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) JUnitProbe(org.mule.tck.probe.JUnitProbe) AFTER_NEXT(org.mule.runtime.api.notification.PolicyNotification.AFTER_NEXT) PolicyPointcut(org.mule.runtime.core.api.policy.PolicyPointcut) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) EXPORTED_RESOURCE_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_RESOURCE_PROPERTY) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) Collections.emptyList(java.util.Collections.emptyList) PolicyNotification(org.mule.runtime.api.notification.PolicyNotification) PolicyNotificationListener(org.mule.runtime.api.notification.PolicyNotificationListener) 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) JAVA_LOADER_ID(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.JAVA_LOADER_ID) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MULE(org.mule.runtime.api.deployment.meta.Product.MULE) PROCESS_START(org.mule.runtime.api.notification.PolicyNotification.PROCESS_START) MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) EXPORTED_RESOURCES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_RESOURCES) BeforeClass(org.junit.BeforeClass) MulePolicyModel(org.mule.runtime.api.deployment.meta.MulePolicyModel) ArrayList(java.util.ArrayList) PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID(org.mule.runtime.module.deployment.impl.internal.policy.PropertiesBundleDescriptorLoader.PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) SecurityException(org.mule.runtime.api.security.SecurityException) XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) Test(org.junit.Test) File(java.io.File) BOOTSTRAP_PROPERTIES(org.mule.runtime.core.internal.config.bootstrap.ClassLoaderRegistryBootstrapDiscoverer.BOOTSTRAP_PROPERTIES) Authentication(org.mule.runtime.api.security.Authentication) EXPORTED_PACKAGES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_PACKAGES) RESOURCE_XML(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader.RESOURCE_XML) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) Product(org.mule.runtime.api.deployment.meta.Product) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 12 with PolicyParametrization

use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.

the class DomainDeploymentTestCase method appliesApplicationPolicyDuplicatingDomainPlugin.

@Test
public void appliesApplicationPolicyDuplicatingDomainPlugin() throws Exception {
    installEchoService();
    installFooService();
    policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.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());
    policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingPluginFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
    executeApplicationFlow("main");
    assertThat(invocationCount, equalTo(1));
}
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) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 13 with PolicyParametrization

use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.

the class DomainDeploymentTestCase method appliesApplicationPolicyUsingDomainPlugin.

@Test
public void appliesApplicationPolicyUsingDomainPlugin() throws Exception {
    installEchoService();
    installFooService();
    policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.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());
    policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingPluginFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
    executeApplicationFlow("main");
    assertThat(invocationCount, equalTo(1));
}
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) 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 PolicyParametrization

use of org.mule.runtime.core.api.policy.PolicyParametrization 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 15 with PolicyParametrization

use of org.mule.runtime.core.api.policy.PolicyParametrization 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));
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ClassLoaderRepository(org.mule.runtime.module.artifact.api.classloader.ClassLoaderRepository) ExtensionModelLoaderRepository(org.mule.runtime.module.extension.internal.loader.ExtensionModelLoaderRepository) MuleContextListener(org.mule.runtime.core.api.context.notification.MuleContextListener) Registry(org.mule.runtime.api.artifact.Registry) ServiceRepository(org.mule.runtime.api.service.ServiceRepository) Application(org.mule.runtime.deployment.model.api.application.Application) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Ignore(org.junit.Ignore) Issue(io.qameta.allure.Issue) Test(org.junit.Test)

Aggregations

PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)24 Test (org.junit.Test)21 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)21 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)21 File (java.io.File)20 ArtifactPluginFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder)20 URISyntaxException (java.net.URISyntaxException)19 Collections.emptyList (java.util.Collections.emptyList)19 Collections.emptyMap (java.util.Collections.emptyMap)19 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)19 Matchers.equalTo (org.hamcrest.Matchers.equalTo)19 Is.is (org.hamcrest.core.Is.is)19 Assert.fail (org.junit.Assert.fail)19 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 JarFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder)19 TestPolicyProcessor.invocationCount (org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount)19 CompilerUtils (org.mule.tck.util.CompilerUtils)19 ArrayList (java.util.ArrayList)17 List (java.util.List)17 Arrays.asList (java.util.Arrays.asList)15