use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method appliesApplicationPolicyIncludingPlugin.
@Test
public void appliesApplicationPolicyIncludingPlugin() throws Exception {
ArtifactPluginFileBuilder simpleExtensionPlugin = createSingleExtensionPlugin();
policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.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(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.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 appliesApplicationPolicyWithNotificationListener.
@Test
public void appliesApplicationPolicyWithNotificationListener() throws Exception {
policyManager.registerPolicyTemplate(fooPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
List<Integer> notificationListenerActionIds = new ArrayList<>();
PolicyNotificationListener<PolicyNotification> notificationListener = notification -> notificationListenerActionIds.add(notification.getAction().getActionId());
policyManager.addPolicy(applicationFileBuilder.getId(), fooPolicyFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, pointparameters -> true, 1, singletonMap(POLICY_PROPERTY_KEY, POLICY_PROPERTY_VALUE), getResourceFile("/fooPolicy.xml"), singletonList(notificationListener)));
executeApplicationFlow("main");
assertThat(invocationCount, equalTo(1));
new PollingProber(POLICY_NOTIFICATION_TIMEOUT, 100).check(new JUnitProbe() {
@Override
protected boolean test() throws Exception {
assertThat(notificationListenerActionIds, hasSize(4));
assertThat(notificationListenerActionIds, hasItems(PROCESS_START, BEFORE_NEXT, AFTER_NEXT, PROCESS_END));
return true;
}
});
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class DomainDeploymentTestCase method appliesApplicationPolicyWithPluginDependingOnDomainPlugin.
@Test
public void appliesApplicationPolicyWithPluginDependingOnDomainPlugin() throws Exception {
installEchoService();
installFooService();
policyManager.registerPolicyTemplate(policyIncludingDependantPluginFileBuilder.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));
}
use of org.mule.runtime.core.api.policy.PolicyParametrization in project mule by mulesoft.
the class TestPolicyManager method addPolicy.
/**
* Adds a parameterized policy
*
* @param appName application where the policy must be applied. Non empty.
* @param policyTemplateName template that must be used to instantiate the parametrized policy. Non empty.
* @param policyParametrization parametrization to instantiate the policy. Non null.
*/
public void addPolicy(String appName, String policyTemplateName, PolicyParametrization policyParametrization) throws PolicyRegistrationException {
checkArgument(!isEmpty(appName), "appName cannot be empty");
checkArgument(!isEmpty(policyTemplateName), "policyTemplateName cannot be empty");
checkArgument(policyParametrization != null, "policyParametrization cannot be ull");
Optional<PolicyTemplateDescriptor> policyTemplateDescriptor = policyTemplateDescriptors.stream().filter(template -> template.getName().equals(policyTemplateName)).findFirst();
if (!policyTemplateDescriptor.isPresent()) {
throw new IllegalStateException("Cannot find policy template descriptor with name: " + policyTemplateName);
}
Application application = deploymentService.findApplication(appName);
ApplicationPolicyManager policyManager = application.getPolicyManager();
policyManager.addPolicy(policyTemplateDescriptor.get(), policyParametrization);
}
Aggregations