Search in sources :

Example 31 with ErrorType

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

the class ExtensionErrorsRegistrant method getErrorType.

private ErrorType getErrorType(ErrorModel errorModel, ExtensionModel extensionModel) {
    ComponentIdentifier identifier = createIdentifier(errorModel.getType(), errorModel.getNamespace());
    Optional<ErrorType> optionalError = errorTypeRepository.getErrorType(identifier);
    return optionalError.orElseGet(() -> createErrorType(errorModel, identifier, extensionModel));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier)

Example 32 with ErrorType

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

the class ExtensionErrorsRegistrantTestCase method lookupErrorsForOperation.

@Test
public void lookupErrorsForOperation() {
    when(extensionModel.getErrorModels()).thenReturn(singleton(extensionConnectivityError));
    errorsRegistrant.registerErrors(extensionModel);
    ErrorType errorType = typeLocator.lookupComponentErrorType(OPERATION_IDENTIFIER, ConnectionException.class);
    assertThat(errorType.getIdentifier(), is(CONNECTIVITY_ERROR_IDENTIFIER));
    assertThat(errorType.getNamespace(), is(EXTENSION_PREFIX.toUpperCase()));
    ErrorType muleConnectivityError = errorType.getParentErrorType();
    assertThat(muleConnectivityError.getNamespace(), is(MULE_CONNECTIVITY_ERROR.getNamespace()));
    assertThat(muleConnectivityError.getIdentifier(), is(MULE_CONNECTIVITY_ERROR.getType()));
    ErrorType anyErrorType = muleConnectivityError.getParentErrorType();
    assertThat(anyErrorType.getNamespace(), is(MULE));
    assertThat(anyErrorType.getIdentifier(), is(ANY));
    assertThat(anyErrorType.getParentErrorType(), is(nullValue()));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 33 with ErrorType

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

the class ExtensionErrorsRegistrantTestCase method registerErrorTypes.

@Test
public void registerErrorTypes() {
    when(extensionModel.getErrorModels()).thenReturn(singleton(oauthExtensionConnectivityError));
    errorsRegistrant.registerErrors(extensionModel);
    Optional<ErrorType> optionalOAuthType = typeRepository.lookupErrorType(builder().name(OAUTH_TEST_CONNECTIVITY_ERROR_TYPE).namespace(EXTENSION_PREFIX).build());
    Optional<ErrorType> optionalConnectivityType = typeRepository.lookupErrorType(builder().name(TEST_CONNECTIVITY_ERROR_TYPE).namespace(EXTENSION_PREFIX).build());
    assertThat(optionalOAuthType.isPresent(), is(true));
    assertThat(optionalConnectivityType.isPresent(), is(true));
    ErrorType parentErrorType = optionalOAuthType.get().getParentErrorType();
    assertThat(parentErrorType, is(optionalConnectivityType.get()));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 34 with ErrorType

use of org.mule.runtime.api.message.ErrorType 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 35 with ErrorType

use of org.mule.runtime.api.message.ErrorType 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

ErrorType (org.mule.runtime.api.message.ErrorType)35 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)9 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)8 Error (org.mule.runtime.api.message.Error)7 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)6 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)6 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)6 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)5 Optional (java.util.Optional)4 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)4 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Component (org.mule.runtime.api.component.Component)3 TypedException (org.mule.runtime.api.exception.TypedException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 HashSet (java.util.HashSet)2