use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenEmptyFactoryAndEmptySourceParameters.
@Test
public void createOperationParametersWhenEmptyFactoryAndEmptySourceParameters() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), empty());
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class DefaultPolicyManager method createSourcePolicyInstance.
@Override
public SourcePolicy createSourcePolicyInstance(Component source, CoreEvent sourceEvent, Processor flowExecutionProcessor, MessageSourceResponseParametersProcessor messageSourceResponseParametersProcessor) {
PolicyPointcutParameters sourcePointcutParameters = policyPointcutParametersManager.createSourcePointcutParameters(source, sourceEvent);
List<Policy> parameterizedPolicies = policyProvider.findSourceParameterizedPolicies(sourcePointcutParameters);
if (parameterizedPolicies.isEmpty()) {
return event -> from(process(event, flowExecutionProcessor)).defaultIfEmpty(CoreEvent.builder(sourceEvent).message(of(null)).build()).<Either<SourcePolicyFailureResult, SourcePolicySuccessResult>>map(flowExecutionResult -> right(new SourcePolicySuccessResult(flowExecutionResult, () -> messageSourceResponseParametersProcessor.getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResult), messageSourceResponseParametersProcessor))).onErrorResume(Exception.class, e -> {
MessagingException messagingException = e instanceof MessagingException ? (MessagingException) e : new MessagingException(event, e, (Component) flowExecutionProcessor);
return just(Either.left(new SourcePolicyFailureResult(messagingException, () -> messageSourceResponseParametersProcessor.getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent()))));
});
}
return new CompositeSourcePolicy(parameterizedPolicies, lookupSourceParametersTransformer(source.getLocation().getComponentIdentifier().getIdentifier()), sourcePolicyProcessorFactory, flowExecutionProcessor, messageSourceResponseParametersProcessor);
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManager method createSourcePointcutParameters.
/**
* Creates {@link PolicyPointcutParameters} for a specific source. The created parameters is also stored so it can be used in
* case a matching policy also defines an operation part.
*
* @param source the source component to which policies will be applied
* @param event the event which will execute the source policies
* @return the created {@link PolicyPointcutParameters}
*/
public PolicyPointcutParameters createSourcePointcutParameters(Component source, CoreEvent event) {
ComponentIdentifier sourceIdentifier = source.getLocation().getComponentIdentifier().getIdentifier();
PolicyPointcutParameters sourcePointcutParameters = createPointcutParameters(source, SourcePolicyPointcutParametersFactory.class, sourcePointcutFactories, factory -> factory.supportsSourceIdentifier(sourceIdentifier), factory -> factory.createPolicyPointcutParameters(source, event.getMessage().getAttributes())).orElse(new PolicyPointcutParameters(source));
String correlationId = event.getContext().getCorrelationId();
sourceParametersMap.put(correlationId, sourcePointcutParameters);
((BaseEventContext) event.getContext()).getRootContext().onTerminated((e, t) -> sourceParametersMap.remove(correlationId));
return sourcePointcutParameters;
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createSourceParametersWhenOneFactorySupportsIdentifierAndOneNot.
@Test
public void createSourceParametersWhenOneFactorySupportsIdentifierAndOneNot() {
SourcePolicyPointcutParametersFactory factory1 = mockSourceFactory(true);
SourcePolicyPointcutParametersFactory factory2 = mockSourceFactory(false);
sourcePointcutFactories.add(factory1);
sourcePointcutFactories.add(factory2);
PolicyPointcutParameters parameters = parametersManager.createSourcePointcutParameters(component, event);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), empty());
verify(factory1).supportsSourceIdentifier(identifier);
verify(factory1).createPolicyPointcutParameters(component, event.getMessage().getAttributes());
verify(factory2).supportsSourceIdentifier(identifier);
verify(factory2, never()).createPolicyPointcutParameters(component, event.getMessage().getAttributes());
verify(eventContext).onTerminated(any());
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenEmptyFactory.
@Test
public void createOperationParametersWhenEmptyFactory() {
Map<String, Object> operationParameters = new HashMap<>();
sourcePointcutFactories.add(mockSourceFactory(true));
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
}
Aggregations