use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method appliesApplicationPolicyDuplicatingPluginOnDomain.
@Test
public void appliesApplicationPolicyDuplicatingPluginOnDomain() throws Exception {
addPackedDomainFromBuilder(exceptionThrowingPluginImportingDomain);
policyManager.registerPolicyTemplate(exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin).dependingOn(exceptionThrowingPluginImportingDomain);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
policyManager.addPolicy(applicationFileBuilder.getId(), exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactId(), new PolicyParametrization(EXCEPTION_POLICY_NAME, s -> true, 1, emptyMap(), getResourceFile("/exceptionThrowingPolicy.xml"), emptyList()));
try {
executeApplicationFlow("main");
fail("Flow execution was expected to throw an exception");
} catch (MuleRuntimeException expected) {
assertThat(expected.getCause().getCause().getClass().getName(), is(equalTo("org.exception.CustomException")));
}
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method removesApplicationPolicy.
@Test
public void removesApplicationPolicy() throws Exception {
policyManager.registerPolicyTemplate(fooPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
policyManager.addPolicy(applicationFileBuilder.getId(), fooPolicyFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, parameters -> true, 1, singletonMap(POLICY_PROPERTY_KEY, POLICY_PROPERTY_VALUE), getResourceFile("/fooPolicy.xml"), emptyList()));
executeApplicationFlow("main");
assertThat(invocationCount, equalTo(1));
policyManager.removePolicy(applicationFileBuilder.getId(), FOO_POLICY_ID);
executeApplicationFlow("main");
assertThat("Policy is still applied on the application", invocationCount, equalTo(1));
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method appliesPolicyThatUsesPolicyClassOnExpression.
@Test
public void appliesPolicyThatUsesPolicyClassOnExpression() throws Exception {
ArtifactPluginFileBuilder simpleExtensionPlugin = createSingleExtensionPlugin();
policyManager.registerPolicyTemplate(policyWithPluginAndResource().getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_SIMPLE_EXTENSION_CONFIG, simpleExtensionPlugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingPluginFileBuilder.getArtifactId(), new PolicyParametrization(BAR_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/policy-using-policy-class-in-expression.xml"), emptyList()));
executeApplicationFlow("main");
assertThat(invocationCount, equalTo(1));
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method doApplicationPolicyExecutionTest.
private void doApplicationPolicyExecutionTest(PolicyPointcut pointcut, int expectedPolicyInvocations, Object expectedPolicyParametrization) throws Exception {
policyManager.registerPolicyTemplate(fooPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
policyManager.addPolicy(applicationFileBuilder.getId(), fooPolicyFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, pointcut, 1, singletonMap(POLICY_PROPERTY_KEY, POLICY_PROPERTY_VALUE), getResourceFile("/fooPolicy.xml"), emptyList()));
executeApplicationFlow("main");
assertThat(invocationCount, equalTo(expectedPolicyInvocations));
assertThat(policyParametrization, equalTo(expectedPolicyParametrization));
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method appliesApplicationPolicyDuplicatingExtensionPlugin.
@Test
public void appliesApplicationPolicyDuplicatingExtensionPlugin() throws Exception {
policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
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");
}
Aggregations