use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class ResequencerTestCase method testMessageResequencer.
@Test
public void testMessageResequencer() throws Exception {
MuleSession session = new DefaultMuleSession();
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
TestEventResequencer router = new TestEventResequencer(3);
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event2));
assertNull(router.process(event3));
CoreEvent resultEvent = router.process(event1);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
assertTrue(getPayloadAsString(resultMessage).equals("test event A") || getPayloadAsString(resultMessage).equals("test event B") || getPayloadAsString(resultMessage).equals("test event C"));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateMessageCollections.
@Test
public void testAggregateMessageCollections() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = of("test event A");
Message message2 = of("test event B");
Message message3 = of("test event C");
Message message4 = of("test event D");
List<Message> list = new ArrayList<>();
List<Message> list2 = new ArrayList<>();
list.add(message1);
list.add(message2);
list2.add(message3);
list2.add(message4);
Message messageCollection1 = Message.of(list);
Message messageCollection2 = Message.of(list2);
CoreEvent event1 = InternalEvent.builder(executionContext).message(messageCollection1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
CoreEvent event2 = InternalEvent.builder(executionContext).message(messageCollection2).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
assertNull(router.process(event1));
CoreEvent resultEvent = router.process(event2);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
List<InternalMessage> payload = (List<InternalMessage>) resultMessage.getPayload().getValue();
assertEquals(2, payload.size());
assertEquals("test event A", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(0).getPayload().getValue());
assertEquals("test event B", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(1).getPayload().getValue());
assertEquals("test event C", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(0).getPayload().getValue());
assertEquals("test event D", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(1).getPayload().getValue());
}
use of org.mule.runtime.api.message.Message 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));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class AggregatorTestCase method testMessageAggregator.
@Test
public void testMessageAggregator() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
MuleSession session = new DefaultMuleSession();
TestEventAggregator router = new TestEventAggregator(3);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent result = router.process(event3);
assertNotNull(result);
PrivilegedEvent privilegedResult = (PrivilegedEvent) result;
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event A"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event B"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event C"));
assertTrue(privilegedResult.getMessageAsString(muleContext).matches("test event [A,B,C] test event [A,B,C] test event [A,B,C] "));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultRouterResultsHandlerTestCase method aggregateMultipleEventsAllButOneNull.
@Test
public void aggregateMultipleEventsAllButOneNull() {
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
CoreEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key", "value").build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).addVariable("key2", "value2").build();
List<CoreEvent> events = new ArrayList<>();
events.add(null);
events.add(event2);
CoreEvent result = resultsHandler.aggregateResults(events, event1);
assertSame(event2, result);
// Because same event instance is returned rather than MessageCollection
// don't copy invocation properties
assertThat(result.getVariables().keySet(), not(hasItem("key1")));
assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
}
Aggregations