use of org.mule.runtime.deployment.model.api.application.ApplicationPolicyManager 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