Search in sources :

Example 1 with MessageProcessorChain

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

the class SplitAggregateScopeTestCase 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 = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    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(List.class));
    assertThat(List.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
    List<Message> resultList = (List<Message>) typedValue.getValue();
    assertThat(resultList, 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 2 with MessageProcessorChain

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

the class SplitAggregateScopeTestCase method defaultTarget.

@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
    CoreEvent original = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
    List<Message> resultList = (List<Message>) result.getMessage().getPayload().getValue();
    assertThat(resultList, 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 3 with MessageProcessorChain

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

the class ScatterGatherRouterTestCase method consumablePayload.

@Test
@Description("Consumable payloads are not supported.")
public void consumablePayload() throws Exception {
    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();
    expectedException.expect(instanceOf(MuleRuntimeException.class));
    router.process(CoreEvent.builder(testEvent()).message(Message.of(new StringBufferInputStream(TEST_PAYLOAD))).build());
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) StringBufferInputStream(java.io.StringBufferInputStream) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 4 with MessageProcessorChain

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

the class SplitAggregateScopeTestCase 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 = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    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(List.class));
    List<Message> resultList = (List<Message>) ((Message) result.getVariables().get(variableName).getValue()).getPayload().getValue();
    assertThat(resultList, 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 5 with MessageProcessorChain

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

the class ChoiceRouterTestCase method testAddAndDeleteRoute.

@Test
public void testAddAndDeleteRoute() throws Exception {
    MessageProcessorChain mp = newChain(empty(), new TestMessageProcessor("bar"));
    choiceRouter.addRoute(payloadZapExpression(), mp);
    choiceRouter.removeRoute(mp);
    choiceRouter.setRouterStatistics(new RouterStatistics(TYPE_OUTBOUND));
    choiceRouter.setMuleContext(muleContext);
    choiceRouter.initialise();
    CoreEvent inputEvent = zapEvent();
    assertThat(process(choiceRouter, inputEvent), is(inputEvent));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RouterStatistics(org.mule.runtime.core.api.management.stats.RouterStatistics) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) 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