use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class HeisenbergMessageSourceTestCase method failureInFlowCallsOnErrorDirectlyAndFailsHandlingIt.
@Test
public void failureInFlowCallsOnErrorDirectlyAndFailsHandlingIt() throws Exception {
startFlow("failureInFlowCallsOnErrorDirectlyAndFailsHandlingIt");
probe(TIMEOUT_MILLIS, POLL_DELAY_MILLIS, () -> assertState(false, false, true));
assertThat(HeisenbergSource.terminateStatus, is(ERROR_INVOKE));
Optional<Error> optionalError = HeisenbergSource.error;
assertThat(optionalError, is(not(empty())));
assertThat(optionalError.get().getErrorType(), is(errorType(SOURCE_ERROR_RESPONSE_GENERATE)));
MuleException me = (MuleException) unwrap(optionalError.get().getCause());
assertThat((String) me.getInfo().get(INFO_LOCATION_KEY), containsString("failureInFlowCallsOnErrorDirectlyAndFailsHandlingIt/source"));
assertThat((String) me.getInfo().get(INFO_SOURCE_XML_KEY), containsString("heisenberg:success-info"));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class SourceResultArgumentResolver method resolve.
@Override
public LazyValue<SourceResult> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
Error error = errorArgumentResolver.resolve(executionContext).get();
SourceCallbackContext callbackContext = callbackContextArgumentResolver.resolve(executionContext).get();
if (error == null) {
return success(callbackContext);
} else {
String errorIdentifier = error.getErrorType().getIdentifier();
return isErrorGeneratingErrorResponse(errorIdentifier) ? invocationError(error, callbackContext) : responseError(error, callbackContext);
}
});
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class MuleTestUtils method createErrorMock.
/**
* Creates an {@link Error} mock that will return the provided exception when calling {@link Error#getCause()}
*
* @param exception the exception to use to create the mock
* @return a mocked {@link Error}
*/
public static Error createErrorMock(Exception exception) {
Error errorMock = mock(Error.class);
when(errorMock.getCause()).thenReturn(exception);
return errorMock;
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method childErrorsErrorBinding.
@Test
public void childErrorsErrorBinding() throws Exception {
String childErrorMessage = "error";
String otherChildErrorMessage = "oops";
ErrorType errorType = mock(ErrorType.class);
Error error = mock(Error.class);
when(error.getChildErrors()).thenReturn(asList(ErrorBuilder.builder(new IOException(childErrorMessage)).errorType(errorType).build(), ErrorBuilder.builder(new DefaultMuleException(otherChildErrorMessage)).errorType(errorType).build()));
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "error.childErrors reduce ((child, acc = '') -> acc ++ child.cause.message)";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(format("%s%s", childErrorMessage, otherChildErrorMessage)));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method errorMessageContainsDataweaveExceptionCauseMessage.
@Test
public void errorMessageContainsDataweaveExceptionCauseMessage() throws Exception {
Error error = mock(Error.class);
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expressionThatThrowsException = "payload + 'foo'";
expectedEx.expect(ExpressionRuntimeException.class);
expectedEx.expectMessage(containsString("You called the function '+' with these arguments"));
expectedEx.expectMessage(containsString("evaluating expression: \"" + expressionThatThrowsException));
expressionLanguage.evaluate(expressionThatThrowsException, event, BindingContext.builder().build());
}
Aggregations