use of org.mule.runtime.api.event.EventContext in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateMultipleEvents.
@Test
public void testAggregateMultipleEvents() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
router.setListener(sensingMessageProcessor);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = 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(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).build();
CoreEvent event2 = InternalEvent.builder(executionContext).message(message2).build();
CoreEvent event3 = InternalEvent.builder(executionContext).message(message3).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent resultEvent = router.process(event3);
assertNotNull(sensingMessageProcessor.event);
assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
Message nextMessage = sensingMessageProcessor.event.getMessage();
assertNotNull(nextMessage);
assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
List<InternalMessage> list = (List<InternalMessage>) nextMessage.getPayload().getValue();
assertEquals(3, list.size());
String[] results = new String[3];
list.stream().map(msg -> msg.getPayload().getValue()).collect(toList()).toArray(results);
// Need to sort result because of MULE-5998
Arrays.sort(results);
assertEquals("test event A", results[0]);
assertEquals("test event B", results[1]);
assertEquals("test event C", results[2]);
}
use of org.mule.runtime.api.event.EventContext in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateSingleEvent.
@Test
public void testAggregateSingleEvent() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
router.setListener(sensingMessageProcessor);
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = of("test event A");
CoreEvent event1 = InternalEvent.builder(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 1))).build();
CoreEvent resultEvent = router.process(event1);
assertNotNull(sensingMessageProcessor.event);
assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
Message nextMessage = sensingMessageProcessor.event.getMessage();
assertNotNull(nextMessage);
assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
List<InternalMessage> payload = (List<InternalMessage>) nextMessage.getPayload().getValue();
assertEquals(1, payload.size());
assertEquals("test event A", payload.get(0).getPayload().getValue());
}
Aggregations