Search in sources :

Example 6 with ErrorModel

use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.

the class ErrorsDeclarationEnricherTestCase method operationsWithConnectionsThrowsConnectivityError.

@Test
public void operationsWithConnectionsThrowsConnectivityError() {
    extensionModel = loadExtension(HeisenbergExtension.class);
    OperationModel callSaul = getNamedObject(extensionModel.getConfigurationModel("config").get().getOperationModels(), "callSaul");
    Set<ErrorModel> errorTypesIdentifiers = callSaul.getErrorModels();
    assertThat(errorTypesIdentifiers, hasItem(hasProperty(TYPE, is(CONNECTIVITY_ERROR_IDENTIFIER))));
}
Also used : ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 7 with ErrorModel

use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.

the class ErrorsDeclarationEnricherTestCase method orphanErrorsUsesAnyAsParent.

@Test
public void orphanErrorsUsesAnyAsParent() {
    extensionModel = loadExtension(HeisenbergWithOrphanErrors.class);
    ErrorModel errorModel = extensionModel.getErrorModels().stream().filter(error -> error.getType().equals("HEALTH")).findFirst().get();
    assertThat(errorModel.getNamespace(), is(HEISENBERG));
    Optional<ErrorModel> anyExtensionError = errorModel.getParent();
    assertThat(anyExtensionError.isPresent(), is(true));
    assertThat(anyExtensionError.get().getType(), is(ANY.getType()));
    assertThat(anyExtensionError.get().getNamespace(), is(MULE_NAMESPACE));
}
Also used : ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) Test(org.junit.Test)

Example 8 with ErrorModel

use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareErrors.

private void declareErrors(ExtensionDeclarer extensionDeclarer) {
    final ErrorModel criticalError = newError(CRITICAL).handleable(false).build();
    final ErrorModel overloadError = newError(OVERLOAD).withParent(criticalError).build();
    final ErrorModel securityError = newError(SECURITY).withParent(anyError).build();
    final ErrorModel sourceError = newError(SOURCE).withParent(anyError).build();
    final ErrorModel sourceResponseError = newError(SOURCE_RESPONSE).withParent(anyError).build();
    final ErrorModel serverSecurityError = newError(SERVER_SECURITY).withParent(securityError).build();
    extensionDeclarer.withErrorModel(anyError);
    extensionDeclarer.withErrorModel(newError(EXPRESSION).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(TRANSFORMATION).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(CONNECTIVITY).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(RETRY_EXHAUSTED).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(REDELIVERY_EXHAUSTED).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(STREAM_MAXIMUM_SIZE_EXCEEDED).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(TIMEOUT).withParent(anyError).build());
    extensionDeclarer.withErrorModel(newError(UNKNOWN).handleable(false).withParent(anyError).build());
    extensionDeclarer.withErrorModel(routingError);
    extensionDeclarer.withErrorModel(compositeRoutingError);
    extensionDeclarer.withErrorModel(validationError);
    extensionDeclarer.withErrorModel(duplicateMessageError);
    extensionDeclarer.withErrorModel(securityError);
    extensionDeclarer.withErrorModel(serverSecurityError);
    extensionDeclarer.withErrorModel(newError(CLIENT_SECURITY).withParent(securityError).build());
    extensionDeclarer.withErrorModel(newError(NOT_PERMITTED).withParent(securityError).build());
    extensionDeclarer.withErrorModel(sourceError);
    extensionDeclarer.withErrorModel(sourceResponseError);
    extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_GENERATE).handleable(false).withParent(sourceError).build());
    extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_SEND).handleable(false).withParent(sourceError).build());
    extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_GENERATE).withParent(sourceResponseError).build());
    extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_SEND).handleable(false).withParent(sourceResponseError).build());
    extensionDeclarer.withErrorModel(criticalError);
    extensionDeclarer.withErrorModel(overloadError);
    extensionDeclarer.withErrorModel(newError(FLOW_BACK_PRESSURE).handleable(false).withParent(overloadError).build());
    extensionDeclarer.withErrorModel(newError(FATAL).handleable(false).withParent(criticalError).build());
}
Also used : ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel)

Example 9 with ErrorModel

use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.

the class ModuleExceptionHandlerTestCase method handleThrowingChildErrorsFromTheOneDeclared.

@Test
public void handleThrowingChildErrorsFromTheOneDeclared() {
    Set<ErrorModel> errors = new HashSet<>();
    ErrorModel parent = newError(PARENT.getType(), ERROR_NAMESPACE).build();
    ErrorModel child = newError(CHILD.getType(), ERROR_NAMESPACE).withParent(parent).build();
    errors.add(parent);
    ErrorType parentErrorType = typeRepository.addErrorType(getIdentifier(parent), typeRepository.getAnyErrorType());
    typeRepository.addErrorType(getIdentifier(child), parentErrorType);
    when(operationModel.getErrorModels()).thenReturn(errors);
    ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
    ModuleException moduleException = new ModuleException(CHILD, new RuntimeException());
    Throwable throwable = handler.processException(moduleException);
    assertThat(throwable, is(instanceOf(TypedException.class)));
    ErrorType errorType = ((TypedException) throwable).getErrorType();
    assertThat(errorType.getIdentifier(), is(CHILD.getType()));
    assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE));
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ErrorType(org.mule.runtime.api.message.ErrorType) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) ModuleException(org.mule.runtime.extension.api.exception.ModuleException) TypedException(org.mule.runtime.api.exception.TypedException) HashSet(java.util.HashSet) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 10 with ErrorModel

use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.

the class ExtensionErrorsRegistrant method registerErrors.

/**
 * Registers the found {@link ErrorModel} from each {@link OperationModel} into the {@link ErrorTypeRepository} and creates an
 * {@link ExceptionMapper} for each {@link OperationModel} that declares {@link ErrorModel}s.
 *
 * @param extensionModel from where get the {@link ErrorModel} from each {@link OperationModel}
 */
void registerErrors(ExtensionModel extensionModel) {
    Set<ErrorModel> errorTypes = extensionModel.getErrorModels();
    String extensionNamespace = extensionModel.getXmlDslModel().getPrefix();
    String errorExtensionNamespace = MuleExtensionUtils.getExtensionsNamespace(extensionModel);
    DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
    ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
    ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
    errorTypes.forEach(errorModel -> getErrorType(errorModel, extensionModel));
    ExtensionWalker extensionWalker = new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel model) {
            registerErrors(model);
        }

        @Override
        protected void onConstruct(ConstructModel model) {
            registerErrors(model);
        }

        private void registerErrors(ComponentModel model) {
            if (!errorTypes.isEmpty()) {
                ExceptionMapper.Builder builder = ExceptionMapper.builder();
                builder.addExceptionMapping(ConnectionException.class, getErrorType(connectivityErrorModel, extensionModel));
                builder.addExceptionMapping(RetryPolicyExhaustedException.class, getErrorType(retryExhaustedError, extensionModel));
                String elementName = syntaxResolver.resolve(model).getElementName();
                errorTypeLocator.addComponentExceptionMapper(createIdentifier(elementName, extensionNamespace), builder.build());
            }
        }
    };
    extensionWalker.walk(extensionModel);
}
Also used : ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ExceptionMapper(org.mule.runtime.core.api.exception.ExceptionMapper) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) SingleExtensionImportTypesStrategy(org.mule.runtime.extension.api.dsl.syntax.resolver.SingleExtensionImportTypesStrategy) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Aggregations

ErrorModel (org.mule.runtime.api.meta.model.error.ErrorModel)12 Test (org.junit.Test)7 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)5 Collections.singleton (java.util.Collections.singleton)3 Optional (java.util.Optional)3 Optional.empty (java.util.Optional.empty)3 Set (java.util.Set)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)3 Rule (org.junit.Rule)3 ExpectedException (org.junit.rules.ExpectedException)3 ExpectedException.none (org.junit.rules.ExpectedException.none)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 CONNECTIVITY_ERROR_IDENTIFIER (org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER)3 Extension (org.mule.runtime.extension.api.annotation.Extension)3 Operations (org.mule.runtime.extension.api.annotation.Operations)3 ErrorTypeProvider (org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider)3