use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class ProcessorChainExecutorTestCase method testDoProcessOnErrorMessagingException.
@Test
public void testDoProcessOnErrorMessagingException() throws InterruptedException, MuleException {
final String ERROR_PAYLOAD = "ERROR_PAYLOAD";
when(chain.apply(any())).thenReturn(error(new MessagingException(createStaticMessage(""), getEventBuilder().message(of(ERROR_PAYLOAD)).build())));
ImmutableProcessorChainExecutor chainExecutor = new ImmutableProcessorChainExecutor(coreEvent, chain);
AtomicInteger successCalls = new AtomicInteger(0);
AtomicInteger errorCalls = new AtomicInteger(0);
Reference<Event> errorEvent = new Reference<>();
doProcessAndWait(chainExecutor, r -> successCalls.incrementAndGet(), (t, r) -> {
errorCalls.incrementAndGet();
errorEvent.set(((EventedResult) r).getEvent());
});
assertThat(successCalls.get(), is(0));
assertThat(errorCalls.get(), is(1));
assertThat(errorEvent.get().getMessage().getPayload().getValue(), is(ERROR_PAYLOAD));
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class NonBlockingOperationsTestCase method voidNonBlockingOperation.
@Test
public void voidNonBlockingOperation() throws Exception {
IronMan ironMan = getIronMan("ironMan");
final String payload = "take me to the avengers tower";
Event event = flowRunner("computeFlightPlan").withPayload(payload).run();
assertThat(event.getMessage().getPayload().getValue().toString(), equalTo(payload));
new PollingProber().probe(1000, 1000, () -> FLIGHT_PLAN.equals(ironMan.getFlightPlan()));
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class ScatterGatherRouterTestCase 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 = testEvent();
MessageProcessorChain route1 = newChain(empty(), event -> event);
MessageProcessorChain route2 = newChain(empty(), event -> event);
router.setRoutes(asList(route1, route2));
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(Map.class));
assertThat(Map.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
Map<String, Message> resultMap = (Map<String, Message>) typedValue.getValue();
assertThat(resultMap.values(), hasSize(2));
}
use of org.mule.runtime.api.event.Event 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));
}
use of org.mule.runtime.api.event.Event 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));
}
Aggregations