Search in sources :

Example 6 with Component

use of org.mule.runtime.api.component.Component in project mule by mulesoft.

the class ComponentInvocationHandlerTestCase method overridesAbstractAnnotated.

@Test
public void overridesAbstractAnnotated() throws Exception {
    Class<Component> clazz = addAnnotationsToClass(ExtendsAnnotated.class);
    Method method = clazz.getMethod("setSomething", Object.class);
    assertThat(method.getAnnotation(Inject.class), not(nullValue()));
}
Also used : Inject(javax.inject.Inject) Method(java.lang.reflect.Method) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 7 with Component

use of org.mule.runtime.api.component.Component in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method collectionAccessPayloadChangedMULE7506.

@Test
public void collectionAccessPayloadChangedMULE7506() throws Exception {
    PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(new String[] { "1", "2" })).build();
    assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null));
    event = PrivilegedEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value(singletonList("1")).build()).build();
    assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) Component(org.mule.runtime.api.component.Component) Test(org.junit.Test)

Example 8 with Component

use of org.mule.runtime.api.component.Component in project mule by mulesoft.

the class FirstSuccessfulTestCase method createFirstSuccessfulRouter.

private FirstSuccessful createFirstSuccessfulRouter(Processor... processors) throws Exception {
    FirstSuccessful fs = new FirstSuccessful();
    fs.setAnnotations(getAppleFlowComponentLocationAnnotations());
    final FlowConstruct flow = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
    when(flow.getMuleContext()).thenReturn(muleContext);
    when(((Component) flow).getLocation()).thenReturn(TEST_CONNECTOR_LOCATION);
    fs.setMuleContext(muleContext);
    fs.setRoutes(asList(processors));
    return fs;
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Component(org.mule.runtime.api.component.Component)

Example 9 with Component

use of org.mule.runtime.api.component.Component in project mule by mulesoft.

the class DefaultPolicyManager method createOperationPolicy.

@Override
public OperationPolicy createOperationPolicy(Component operation, CoreEvent event, Map<String, Object> operationParameters, OperationExecutionFunction operationExecutionFunction) {
    PolicyPointcutParameters operationPointcutParameters = policyPointcutParametersManager.createOperationPointcutParameters(operation, event, operationParameters);
    List<Policy> parameterizedPolicies = policyProvider.findOperationParameterizedPolicies(operationPointcutParameters);
    if (parameterizedPolicies.isEmpty()) {
        return (operationEvent) -> operationExecutionFunction.execute(operationParameters, operationEvent);
    }
    return new CompositeOperationPolicy(parameterizedPolicies, lookupOperationParametersTransformer(operation.getLocation().getComponentIdentifier().getIdentifier()), operationPolicyProcessorFactory, () -> operationParameters, operationExecutionFunction, streamingManager);
}
Also used : Policy(org.mule.runtime.core.api.policy.Policy) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Processor(org.mule.runtime.core.api.processor.Processor) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Inject(javax.inject.Inject) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MessageProcessors.process(org.mule.runtime.core.privileged.processor.MessageProcessors.process) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message.of(org.mule.runtime.api.message.Message.of) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) Either.right(org.mule.runtime.core.api.functional.Either.right) Either(org.mule.runtime.core.api.functional.Either) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) List(java.util.List) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 10 with Component

use of org.mule.runtime.api.component.Component 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));
}
Also used : Optional.empty(java.util.Optional.empty) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Predicate(java.util.function.Predicate) Optional.of(java.util.Optional.of) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Function(java.util.function.Function) String.format(java.lang.String.format) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Aggregations

Component (org.mule.runtime.api.component.Component)39 Test (org.junit.Test)15 Map (java.util.Map)12 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)12 SmallTest (org.mule.tck.size.SmallTest)11 Optional (java.util.Optional)9 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 List (java.util.List)8 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)8 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 HashMap (java.util.HashMap)6 String.format (java.lang.String.format)5 Optional.empty (java.util.Optional.empty)5 Optional.of (java.util.Optional.of)5 Set (java.util.Set)5 Inject (javax.inject.Inject)5 Arrays.asList (java.util.Arrays.asList)4 Collection (java.util.Collection)4