use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class ExecutableComponentTestCase method testExecuteWithEvent.
@Test
public void testExecuteWithEvent() throws Exception {
Event response = executableComponent.execute(testEvent()).get();
assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage));
assertThat(response.getMessage(), equalTo(responseMessage));
assertThat(componentInEvent.get().getContext(), not(equalTo(response.getContext())));
assertThat(((BaseEventContext) componentInEvent.get().getContext()).isTerminated(), is(true));
assertThat(((BaseEventContext) response.getContext()).isTerminated(), is(false));
BaseEventContext childContext = (BaseEventContext) componentInEvent.get().getContext();
assertThat(childContext.isTerminated(), is(true));
BaseEventContext parentContext = (BaseEventContext) testEvent().getContext();
assertThat(parentContext.isTerminated(), is(false));
((BaseEventContext) testEvent().getContext()).success();
assertThat(parentContext.isTerminated(), is(true));
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class ExecutableComponentTestCase method testExecuteWithInputEvent.
@Test
public void testExecuteWithInputEvent() throws Exception {
ExecutionResult executionResult = executableComponent.execute(InputEvent.create().message(requestMessage)).get();
Event response = executionResult.getEvent();
assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage));
assertThat(response.getMessage(), equalTo(responseMessage));
assertThat(componentInEvent.get().getContext(), equalTo(response.getContext()));
BaseEventContext eventContext = (BaseEventContext) componentInEvent.get().getContext();
assertThat(eventContext.isTerminated(), is(false));
executionResult.complete();
assertThat(eventContext.isTerminated(), is(true));
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<Event> execute(Event event) {
CoreEvent internalEvent;
BaseEventContext child = createChildEventContext(event.getContext());
if (event instanceof CoreEvent) {
internalEvent = builder(child, (CoreEvent) event).build();
} else {
internalEvent = CoreEvent.builder(createEventContext(null)).message(event.getMessage()).error(event.getError().orElse(null)).variables(event.getVariables()).build();
}
return from(MessageProcessors.process(internalEvent, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).map(r -> builder(event.getContext(), r).build()).cast(Event.class).toFuture();
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class RoutersExecutionTestCase method stereotypedRoutes.
@Test
public void stereotypedRoutes() throws Exception {
Event routeEvent = flowRunner("stereotypedRoutes").run();
Ricin ricin = ((List<Ricin>) routeEvent.getMessage().getPayload().getValue()).get(0);
assertThat(ricin.getDestination().getVictim(), is("bye bye, someName"));
}
use of org.mule.runtime.api.event.Event in project mule by mulesoft.
the class ProcessorChainExecutorTestCase method testDoProcessOnErrorGenericException.
@Test
public void testDoProcessOnErrorGenericException() throws InterruptedException {
when(chain.apply(any())).thenReturn(error(new RuntimeException()));
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(TEST_PAYLOAD));
}
Aggregations