Search in sources :

Example 11 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters 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());
}
Also used : HashMap(java.util.HashMap) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 12 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method createSourceParametersWhenOneFactorySupportsIdentifier.

@Test
public void createSourceParametersWhenOneFactorySupportsIdentifier() {
    SourcePolicyPointcutParametersFactory factory = mockSourceFactory(true);
    sourcePointcutFactories.add(factory);
    PolicyPointcutParameters parameters = parametersManager.createSourcePointcutParameters(component, event);
    assertThat(parameters.getComponent(), is(component));
    assertThat(parameters.getSourceParameters(), empty());
    verify(factory).supportsSourceIdentifier(identifier);
    verify(factory).createPolicyPointcutParameters(component, event.getMessage().getAttributes());
    verify(eventContext).onTerminated(any());
}
Also used : SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 13 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method createSourceParametersWhenOneFactoryDoesNotSupportsIdentifier.

@Test
public void createSourceParametersWhenOneFactoryDoesNotSupportsIdentifier() {
    SourcePolicyPointcutParametersFactory factory = mockSourceFactory(false);
    sourcePointcutFactories.add(factory);
    PolicyPointcutParameters parameters = parametersManager.createSourcePointcutParameters(component, event);
    assertThat(parameters.getComponent(), is(component));
    assertThat(parameters.getSourceParameters(), empty());
    verify(factory).supportsSourceIdentifier(identifier);
    verify(factory, never()).createPolicyPointcutParameters(component, event.getMessage().getAttributes());
    verify(eventContext).onTerminated(any());
}
Also used : SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 14 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters 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());
}
Also used : HashMap(java.util.HashMap) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 15 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method mockOperationFactory.

private OperationPolicyPointcutParametersFactory mockOperationFactory(boolean supportsIdentifier, PolicyPointcutParameters sourceParameters) {
    OperationPolicyPointcutParametersFactory factory = mock(OperationPolicyPointcutParametersFactory.class);
    when(factory.supportsOperationIdentifier(identifier)).thenReturn(supportsIdentifier);
    PolicyPointcutParameters parameters = new PolicyPointcutParameters(component, sourceParameters);
    when(factory.createPolicyPointcutParameters(any())).thenReturn(parameters);
    return factory;
}
Also used : OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Aggregations

PolicyPointcutParameters (org.mule.runtime.policy.api.PolicyPointcutParameters)17 Test (org.junit.Test)11 OperationPolicyPointcutParametersFactory (org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory)10 SourcePolicyPointcutParametersFactory (org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory)8 HashMap (java.util.HashMap)7 Collection (java.util.Collection)4 Map (java.util.Map)4 Optional (java.util.Optional)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Component (org.mule.runtime.api.component.Component)4 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)4 String.format (java.lang.String.format)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Inject (javax.inject.Inject)2