Search in sources :

Example 26 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveTopExceptionWithSameError.

@Test
public void resolveTopExceptionWithSameError() {
    Optional<Error> surfaceError = mockError(TRANSFORMER, TRANSFORMER_EXCEPTION);
    when(event.getError()).thenReturn(surfaceError);
    Exception cause = new MuleFatalException(createStaticMessage(EXPECTED_MESSAGE), new LinkageError("!"));
    MessagingException me = newMessagingException(cause, event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, FATAL);
    assertExceptionMessage(resolved.getMessage(), EXPECTED_MESSAGE);
}
Also used : MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 27 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveExceptionWithCriticalUnderlyingError.

@Test
public void resolveExceptionWithCriticalUnderlyingError() {
    Optional<Error> surfaceError = mockError(CONNECTION, null);
    when(event.getError()).thenReturn(surfaceError);
    MessagingException me = newMessagingException(ERROR, event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, CONNECTION);
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 28 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveWithMultipleErrors.

@Test
public void resolveWithMultipleErrors() {
    Optional<Error> surfaceError = mockError(TRANSFORMER, TRANSFORMER_EXCEPTION);
    when(event.getError()).thenReturn(surfaceError);
    Exception cause = new Exception(new ConnectionException(FATAL_EXCEPTION));
    MessagingException me = newMessagingException(cause, event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, FATAL);
    assertExceptionMessage(resolved.getMessage(), FATAL_EXCEPTION.getMessage());
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 29 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class ErrorBuilderTestCase method givesStringRepresentation.

@Test
public void givesStringRepresentation() {
    ErrorType anyError = ErrorTypeBuilder.builder().namespace("MULE").identifier("ANY").build();
    ErrorType testError = ErrorTypeBuilder.builder().namespace("MULE").identifier("TEST").parentErrorType(anyError).build();
    Error error = builder(new ComposedErrorMessageAwareException(createStaticMessage(EXCEPTION_MESSAGE), testError)).errorType(testError).build();
    assertThat(error.toString(), is("\norg.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation\n" + "{\n" + "  description=message\n" + "  detailedDescription=message\n" + "  errorType=MULE:TEST\n" + "  cause=org.mule.runtime.core.api.message.ErrorBuilderTestCase$ComposedErrorMessageAwareException\n" + "  errorMessage=\n" + "org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation\n" + "{\n" + "  payload=test\n" + "  mediaType=*/*\n" + "  attributes=<not set>\n" + "  attributesMediaType=*/*\n" + "}\n" + "  childErrors=[\n" + "org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation\n" + "{\n" + "  description=unknown description\n" + "  detailedDescription=unknown description\n" + "  errorType=MULE:TEST\n" + "  cause=java.lang.RuntimeException\n" + "  errorMessage=-\n" + "  childErrors=[]\n" + "}, \n" + "org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation\n" + "{\n" + "  description=unknown description\n" + "  detailedDescription=unknown description\n" + "  errorType=MULE:TEST\n" + "  cause=java.io.IOException\n" + "  errorMessage=-\n" + "  childErrors=[]\n" + "}]\n" + "}"));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Error(org.mule.runtime.api.message.Error) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 30 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class ErrorBuilderTestCase method buildError.

@Test
public void buildError() {
    String detailedDescription = "detailed description";
    String description = "description";
    ErrorType errorType = mockErrorType;
    Message errorMessage = of(null);
    IllegalArgumentException exception = new IllegalArgumentException("some message");
    Error error = builder().errorType(errorType).description(description).detailedDescription(detailedDescription).exception(exception).errorMessage(errorMessage).build();
    assertThat(error.getDescription(), is(description));
    assertThat(error.getDetailedDescription(), is(detailedDescription));
    assertThat(error.getCause(), is(exception));
    assertThat(error.getErrorType(), is(errorType));
    assertThat(error.getErrorMessage(), is(errorMessage));
    assertThat(error.getChildErrors(), is(empty()));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Message(org.mule.runtime.api.message.Message) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) SmallTest(org.mule.tck.size.SmallTest) 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