use of org.mule.runtime.api.component.execution.ExecutionResult in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<ExecutionResult> execute(InputEvent inputEvent) {
CompletableFuture completableFuture = new CompletableFuture();
CoreEvent.Builder builder = CoreEvent.builder(createEventContext(of(completableFuture)));
CoreEvent event = builder.message(inputEvent.getMessage()).error(inputEvent.getError().orElse(null)).variables(inputEvent.getVariables()).build();
return from(MessageProcessors.process(event, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).<ExecutionResult>map(result -> new ExecutionResultImplementation(result, completableFuture)).toFuture();
}
use of org.mule.runtime.api.component.execution.ExecutionResult 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));
}
Aggregations