Search in sources :

Example 21 with MessageProcessorChain

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

the class ScatterGatherRouterTestCase method defaultTarget.

@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
    CoreEvent original = testEvent();
    MessageProcessorChain route1 = newChain(empty(), event -> event);
    MessageProcessorChain route2 = newChain(empty(), event -> event);
    router.setRoutes(asList(route1, route2));
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMap = (Map) result.getMessage().getPayload().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 22 with MessageProcessorChain

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

the class ScatterGatherRouterTestCase method customTargetMessage.

@Test
@Description("When a custom target is configured the router result is set in a variable and the input event is output.")
public void customTargetMessage() 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);
    router.setTargetValue("#[message]");
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage(), equalTo(original.getMessage()));
    assertThat(((Message) result.getVariables().get(variableName).getValue()).getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMap = (Map) ((Message) result.getVariables().get(variableName).getValue()).getPayload().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)

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