use of org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory in project mule by mulesoft.
the class PolicyPointcutParametersManager method createOperationPointcutParameters.
/**
* Creates {@link PolicyPointcutParameters} for a specific operation. Stored parameters from the source are included in the
* newly created parameters to be able to correlate parameters from both source and operation.
*
* @param operation the operation component to which policies will be applied
* @param event the event which will execute the operation policies
* @param operationParameters a map containing the parameters of the operation
* @return the created {@link PolicyPointcutParameters}
*/
public PolicyPointcutParameters createOperationPointcutParameters(Component operation, CoreEvent event, Map<String, Object> operationParameters) {
ComponentIdentifier operationIdentifier = operation.getLocation().getComponentIdentifier().getIdentifier();
PolicyPointcutParameters sourceParameters = sourceParametersMap.get(event.getContext().getCorrelationId());
OperationPolicyPointcutParametersParameters parameters = new OperationPolicyPointcutParametersParameters(operation, operationParameters, sourceParameters);
Function<OperationPolicyPointcutParametersFactory, PolicyPointcutParameters> creationFunction = factory -> {
try {
return factory.createPolicyPointcutParameters(parameters);
} catch (AbstractMethodError error) {
return factory.createPolicyPointcutParameters(parameters.getOperation(), parameters.getOperationParameters());
}
};
return createPointcutParameters(operation, OperationPolicyPointcutParametersFactory.class, operationPointcutFactories, factory -> factory.supportsOperationIdentifier(operationIdentifier), creationFunction).orElse(new PolicyPointcutParameters(operation, sourceParameters));
}
use of org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenOneFactorySupportsIdentifier.
@Test
public void createOperationParametersWhenOneFactorySupportsIdentifier() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
operationPointcutFactories.add(factory);
sourcePointcutFactories.add(mockSourceFactory(true));
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
verify(factory).supportsOperationIdentifier(identifier);
verify(factory).createPolicyPointcutParameters(any());
}
use of org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersFallbacksToDeprecatedMethod.
@Test
public void createOperationParametersFallbacksToDeprecatedMethod() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
PolicyPointcutParameters parameters = mock(PolicyPointcutParameters.class);
when(factory.createPolicyPointcutParameters(any())).thenThrow(new AbstractMethodError());
when(factory.createPolicyPointcutParameters(component, operationParameters)).thenReturn(parameters);
operationPointcutFactories.add(factory);
PolicyPointcutParameters returnedParameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(returnedParameters, is(parameters));
verify(factory).supportsOperationIdentifier(identifier);
verify(factory).createPolicyPointcutParameters(any());
verify(factory).createPolicyPointcutParameters(component, operationParameters);
}
use of org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenOneFactoryDoesNotSupportsIdentifier.
@Test
public void createOperationParametersWhenOneFactoryDoesNotSupportsIdentifier() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory = mockOperationFactory(false, sourceParameters);
operationPointcutFactories.add(factory);
sourcePointcutFactories.add(mockSourceFactory(true));
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
verify(factory).supportsOperationIdentifier(identifier);
verify(factory, never()).createPolicyPointcutParameters(any());
}
use of org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenOneFactorySupportsIdentifierAndOneNot.
@Test
public void createOperationParametersWhenOneFactorySupportsIdentifierAndOneNot() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory1 = mockOperationFactory(true, sourceParameters);
OperationPolicyPointcutParametersFactory factory2 = mockOperationFactory(false, sourceParameters);
operationPointcutFactories.add(factory1);
operationPointcutFactories.add(factory2);
sourcePointcutFactories.add(mockSourceFactory(true));
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
verify(factory1).supportsOperationIdentifier(identifier);
verify(factory1).createPolicyPointcutParameters(any());
verify(factory2).supportsOperationIdentifier(identifier);
verify(factory2, never()).createPolicyPointcutParameters(any());
}
Aggregations