use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AbstractSplitterTestCase method simpleSplitter.
@Test
public void simpleSplitter() throws Exception {
TestSplitter splitter = new TestSplitter(false);
MultipleEventSensingMessageProcessor listener = new MultipleEventSensingMessageProcessor();
splitter.setListener(listener);
splitter.setMuleContext(muleContext);
Apple apple = new Apple();
Banana banana = new Banana();
Orange orange = new Orange();
FruitBowl fruitBowl = new FruitBowl();
fruitBowl.addFruit(apple);
fruitBowl.addFruit(banana);
fruitBowl.addFruit(orange);
final CoreEvent inEvent = eventBuilder(muleContext).message(of(fruitBowl)).build();
CoreEvent resultEvent = splitter.process(inEvent);
assertThat(listener.events, hasSize(3));
assertThat(listener.events.get(0).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
assertThat(listener.events.get(1).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
assertThat(listener.events.get(2).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
assertThat(resultEvent.getMessage().getPayload().getValue(), instanceOf(List.class));
assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()), hasSize(3));
assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(0).getPayload().getValue(), instanceOf(Fruit.class));
assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(1).getPayload().getValue(), instanceOf(Fruit.class));
assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(2).getPayload().getValue(), instanceOf(Fruit.class));
}
use of org.mule.runtime.core.api.event.CoreEvent 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.core.api.event.CoreEvent in project mule by mulesoft.
the class ChoiceRouterTestCase method testNoMatchingNorDefaultRoute.
@Test
public void testNoMatchingNorDefaultRoute() throws Exception {
choiceRouter.addRoute(payloadZapExpression(), newChain(empty(), new TestMessageProcessor("bar")));
CoreEvent inputEvent = fooEvent();
assertThat(process(choiceRouter, inputEvent), is(inputEvent));
}
use of org.mule.runtime.core.api.event.CoreEvent 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));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class ChoiceRouterTestCase method testNoRoute.
@Test
public void testNoRoute() throws Exception {
CoreEvent inputEvent = fooEvent();
assertThat(process(choiceRouter, inputEvent), is(inputEvent));
}
Aggregations