Search in sources :

Example 1 with ErrorModel

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

the class SoapModelLoaderDelegate method declare.

/**
 * {@inheritDoc}
 */
public ExtensionDeclarer declare(ExtensionLoadingContext context) {
    final SoapExtensionTypeWrapper<?> extension = getSoapExtensionType(this.extensionType, typeLoader);
    List<MessageDispatcherProviderTypeWrapper> customTransportProviders = extension.getDispatcherProviders();
    ExtensionDeclarer extensionDeclarer = getExtensionDeclarer(context);
    declareSubtypes(extensionDeclarer, customTransportProviders);
    Set<ErrorModel> soapErrors = getSoapErrors(extensionDeclarer);
    soapErrors.forEach(extensionDeclarer::withErrorModel);
    ConfigurationDeclarer configDeclarer = getConfigDeclarer(extensionDeclarer, extension, soapErrors);
    extension.getSoapServiceProviders().forEach(provider -> serviceProviderDeclarer.declare(configDeclarer, provider, !customTransportProviders.isEmpty()));
    return extensionDeclarer;
}
Also used : MessageDispatcherProviderTypeWrapper(org.mule.runtime.module.extension.soap.internal.loader.type.runtime.MessageDispatcherProviderTypeWrapper) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel)

Example 2 with ErrorModel

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

the class ErrorsModelFactory method toErrorModel.

/**
 * @param errorTypeDefinition
 * @param errorModelMap
 * @return
 */
private ErrorModel toErrorModel(ErrorTypeDefinition<?> errorTypeDefinition, Map<String, ErrorModel> errorModelMap) {
    if (errorModelMap.containsKey(toIdentifier(errorTypeDefinition))) {
        return errorModelMap.get(toIdentifier(errorTypeDefinition));
    } else {
        ErrorModelBuilder builder = newError(errorTypeDefinition.getType(), getErrorNamespace(errorTypeDefinition));
        builder.withParent(toErrorModel(errorTypeDefinition.getParent().orElse(ANY), errorModelMap));
        ErrorModel errorModel = builder.build();
        errorModelMap.put(toIdentifier(errorTypeDefinition), errorModel);
        return errorModel;
    }
}
Also used : ErrorModelBuilder(org.mule.runtime.api.meta.model.error.ErrorModelBuilder) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel)

Example 3 with ErrorModel

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

the class ExtensionErrorsRegistrantTestCase method operationTriesToAddInternalErrorType.

@Test
public void operationTriesToAddInternalErrorType() {
    ErrorTypeRepository repository = mock(ErrorTypeRepository.class);
    when(repository.getErrorType(any())).then((e) -> typeRepository.getErrorType(((ComponentIdentifier) e.getArguments()[0])));
    ErrorModel internalRepeatedError = ErrorModelBuilder.newError(SOURCE_RESPONSE_GENERATE).build();
    when(operationWithError.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    when(extensionModel.getOperationModels()).thenReturn(singletonList(operationWithError));
    when(extensionModel.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    ErrorTypeLocator mockTypeLocator = mock(ErrorTypeLocator.class);
    errorsRegistrant = new ExtensionErrorsRegistrant(typeRepository, mockTypeLocator);
    errorsRegistrant.registerErrors(extensionModel);
    verify(repository, times(0)).addErrorType(any(), any());
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with ErrorModel

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

the class ErrorsDeclarationEnricherTestCase method extensionErrorsInheritFromMuleErrors.

@Test
public void extensionErrorsInheritFromMuleErrors() {
    extensionModel = loadExtension(HeisenbergExtension.class);
    OperationModel cureCancer = getNamedObject(extensionModel.getOperationModels(), "cureCancer");
    assertThat(cureCancer.getErrorModels(), hasItem(hasProperty(TYPE, is(HEALTH.getType()))));
    Optional<ErrorModel> healthError = extensionModel.getErrorModels().stream().filter(errorModel -> errorModel.getType().equals(HEALTH.getType())).findFirst();
    assertThat(healthError.isPresent(), is(true));
    Optional<ErrorModel> optConnectivityError = healthError.get().getParent();
    assertThat(optConnectivityError.isPresent(), is(true));
    ErrorModel connectivityError = optConnectivityError.get();
    assertThat(connectivityError.getType(), is(CONNECTIVITY_ERROR_IDENTIFIER));
    assertThat(connectivityError.getNamespace(), is(HEISENBERG));
    Optional<ErrorModel> optMuleConnectivityError = connectivityError.getParent();
    assertThat(optMuleConnectivityError.isPresent(), is(true));
    ErrorModel muleConnectivityError = optMuleConnectivityError.get();
    assertThat(muleConnectivityError.getType(), is(CONNECTIVITY_ERROR_IDENTIFIER));
    assertThat(muleConnectivityError.getNamespace(), is(MULE_NAMESPACE));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Optional.empty(java.util.Optional.empty) HEALTH(org.mule.test.heisenberg.extension.HeisenbergErrors.HEALTH) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Operations(org.mule.runtime.extension.api.annotation.Operations) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Extension(org.mule.runtime.extension.api.annotation.Extension) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) EXTENSION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.EXTENSION) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CONNECTIVITY_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER) ExpectedException.none(org.junit.rules.ExpectedException.none) EnricherTestUtils.getNamedObject(org.mule.runtime.module.extension.internal.loader.enricher.EnricherTestUtils.getNamedObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) Set(java.util.Set) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Test(org.junit.Test) OPERATION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.OPERATION) ANY(org.mule.runtime.extension.api.error.MuleErrors.ANY) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) Rule(org.junit.Rule) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) 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 5 with ErrorModel

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

the class ErrorsDeclarationEnricherTestCase method operationThrowsOverridesExtensionThrows.

@Test
public void operationThrowsOverridesExtensionThrows() {
    extensionModel = loadExtension(HeisenbergWithOperationThrows.class);
    OperationModel someOperation = extensionModel.getOperationModel("someOperation").get();
    Optional<ErrorModel> operationError = someOperation.getErrorModels().stream().filter(errorModel -> errorModel.getType().equals(OPERATION.getType())).findFirst();
    assertThat(operationError.isPresent(), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Optional.empty(java.util.Optional.empty) HEALTH(org.mule.test.heisenberg.extension.HeisenbergErrors.HEALTH) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Operations(org.mule.runtime.extension.api.annotation.Operations) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Extension(org.mule.runtime.extension.api.annotation.Extension) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) EXTENSION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.EXTENSION) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CONNECTIVITY_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER) ExpectedException.none(org.junit.rules.ExpectedException.none) EnricherTestUtils.getNamedObject(org.mule.runtime.module.extension.internal.loader.enricher.EnricherTestUtils.getNamedObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) Set(java.util.Set) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Test(org.junit.Test) OPERATION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.OPERATION) ANY(org.mule.runtime.extension.api.error.MuleErrors.ANY) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) Rule(org.junit.Rule) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

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