Search in sources :

Example 11 with Error

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"));
}
Also used : Error(org.mule.runtime.api.message.Error) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 12 with Error

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);
        }
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) SourceResult.responseError(org.mule.runtime.extension.api.runtime.source.SourceResult.responseError) SourceResult.invocationError(org.mule.runtime.extension.api.runtime.source.SourceResult.invocationError) Error(org.mule.runtime.api.message.Error)

Example 13 with Error

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;
}
Also used : Error(org.mule.runtime.api.message.Error)

Example 14 with Error

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)));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 15 with Error

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());
}
Also used : Optional(java.util.Optional) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Error (org.mule.runtime.api.message.Error)30 Test (org.junit.Test)18 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)11 SmallTest (org.mule.tck.size.SmallTest)11 MuleException (org.mule.runtime.api.exception.MuleException)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 ErrorType (org.mule.runtime.api.message.ErrorType)7 Optional (java.util.Optional)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)5 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)5 Component (org.mule.runtime.api.component.Component)4 TypedValue (org.mule.runtime.api.metadata.TypedValue)4 Message (org.mule.runtime.api.message.Message)3 ExceptionUtils.isUnknownMuleError (org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError)3 ErrorMapping (org.mule.runtime.core.internal.exception.ErrorMapping)3 List (java.util.List)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2