Search in sources :

Example 16 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class ModuleOperationMessageProcessorChainFactoryBean method doGetObject.

@Override
public MessageProcessorChain doGetObject() throws Exception {
    MessageProcessorChainBuilder builder = getBuilderInstance();
    for (Object processor : processors) {
        if (processor instanceof Processor) {
            builder.chain((Processor) processor);
        } else {
            throw new IllegalArgumentException(format("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured. Found a %s", processor.getClass().getName()));
        }
    }
    final MessageProcessorChain messageProcessorChain = newLazyProcessorChainBuilder((ModuleOperationMessageProcessorChainBuilder) builder, muleContext, () -> getProcessingStrategy(locator, getRootContainerLocation()).orElse(null));
    messageProcessorChain.setAnnotations(getAnnotations());
    messageProcessorChain.setMuleContext(muleContext);
    return messageProcessorChain;
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Processor(org.mule.runtime.core.api.processor.Processor) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder)

Example 17 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class FlowRefFactoryBeanTestCase method createStaticFlowRefFactoryBean.

private FlowRefFactoryBean createStaticFlowRefFactoryBean(Processor target, Object targetBuilder) throws InitialisationException {
    doReturn(false).when(expressionManager).isExpression(anyString());
    if (targetBuilder != null) {
        when(applicationContext.getBean(eq(STATIC_REFERENCED_FLOW))).thenReturn(targetBuilder);
    } else {
        when(applicationContext.getBean(eq(STATIC_REFERENCED_FLOW))).thenReturn(target);
    }
    if (target instanceof MessageProcessorChain) {
        Processor processor = ((MessageProcessorChain) target).getMessageProcessors().get(0);
        when(processor.apply(any())).thenAnswer(successAnswer());
    } else {
        when(target.apply(any())).thenAnswer(successAnswer());
    }
    return createFlowRefFactoryBean(STATIC_REFERENCED_FLOW);
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Processor(org.mule.runtime.core.api.processor.Processor)

Example 18 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class MessageProcessorsTestCase method createChain.

private Processor createChain(ReactiveProcessor processor) throws InitialisationException {
    MessageProcessorChain chain = newChain(Optional.empty(), new ReactiveProcessorToProcessorAdaptor(processor));
    chain.setMuleContext(muleContext);
    return chain;
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)

Example 19 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class ScatterGatherRouterTestCase method customTargetDefaultPayload.

@Test
@Description("When a custom target is configured the router result is set in a variable and the input event is output.")
public void customTargetDefaultPayload() throws Exception {
    final String variableName = "foo";
    CoreEvent original = testEvent();
    MessageProcessorChain route1 = newChain(empty(), event -> event);
    MessageProcessorChain route2 = newChain(empty(), event -> event);
    router.setRoutes(asList(route1, route2));
    router.setTarget(variableName);
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage(), equalTo(original.getMessage()));
    final TypedValue<?> typedValue = result.getVariables().get(variableName);
    assertThat(typedValue.getValue(), instanceOf(Map.class));
    assertThat(Map.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
    Map<String, Message> resultMap = (Map<String, Message>) typedValue.getValue();
    assertThat(resultMap.values(), hasSize(2));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 20 with MessageProcessorChain

use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.

the class ScatterGatherRouterTestCase method routingPairs.

@Test
@Description("RoutingPairs are created for each route configured. Each RoutingPair has the same input event.")
public void routingPairs() throws Exception {
    CoreEvent event = mock(CoreEvent.class);
    MessageProcessorChain route1 = mock(MessageProcessorChain.class);
    MessageProcessorChain route2 = mock(MessageProcessorChain.class);
    MessageProcessorChain route3 = mock(MessageProcessorChain.class);
    router.setRoutes(asList(route1, route2, route3));
    List<RoutingPair> routingPairs = from(router.getRoutingPairs(event)).collectList().block();
    assertThat(routingPairs, hasSize(3));
    assertThat(routingPairs.get(0), equalTo(of(event, route1)));
    assertThat(routingPairs.get(1), equalTo(of(event, route2)));
    assertThat(routingPairs.get(2), equalTo(of(event, route3)));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)22 Test (org.junit.Test)14 Description (io.qameta.allure.Description)11 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)11 Message (org.mule.runtime.api.message.Message)7 Event (org.mule.runtime.api.event.Event)6 Processor (org.mule.runtime.core.api.processor.Processor)5 ArrayList (java.util.ArrayList)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Collections.singletonMap (java.util.Collections.singletonMap)3 Map (java.util.Map)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)2 DefaultMessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)2 MessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder)2 TestMessageProcessor (org.mule.tck.testmodels.mule.TestMessageProcessor)2 StringBufferInputStream (java.io.StringBufferInputStream)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1