Search in sources :

Example 76 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel 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)

Example 77 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method operationNameClashesWithAnotherOperationName.

@Test
public void operationNameClashesWithAnotherOperationName() {
    exception.expect(IllegalModelDefinitionException.class);
    OperationModel anotherOperationModel = mock(OperationModel.class);
    when(anotherOperationModel.getName()).thenReturn(OPERATION_NAME);
    when(extensionModel.getOperationModels()).thenReturn(asList(operationModel, anotherOperationModel));
    validate();
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 78 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method repeatedChildElementSupportNameAndChildElementSupportDifferenctTypeDifferentOperation.

@Test
public void repeatedChildElementSupportNameAndChildElementSupportDifferenctTypeDifferentOperation() {
    exception.expect(IllegalModelDefinitionException.class);
    OperationModel anotherOperationModel = mock(OperationModel.class);
    when(extensionModel.getOperationModels()).thenReturn(asList(operationModel, anotherOperationModel));
    when(anotherOperationModel.getName()).thenReturn("anotherOperation");
    ParameterModel param = getParameter(UNIQUE_PARAM_NAME + "1", ChildElementTest.class);
    ParameterModel anotherParam = getParameter(UNIQUE_PARAM_NAME + "2", ChildElementTestClone.class);
    when(param.getRole()).thenReturn(BEHAVIOUR);
    when(anotherParam.getRole()).thenReturn(BEHAVIOUR);
    when(operationModel.getAllParameterModels()).thenReturn(asList(param));
    when(anotherOperationModel.getAllParameterModels()).thenReturn(asList(anotherParam));
    mockParameterGroup(operationModel, asList(param));
    mockParameterGroup(anotherOperationModel, asList(anotherParam));
    validate();
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 79 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method repeatedChildElementSupportNameAndChildElementSupportSameTypeDifferentOperation.

@Test
public void repeatedChildElementSupportNameAndChildElementSupportSameTypeDifferentOperation() {
    OperationModel anotherOperationModel = mock(OperationModel.class);
    when(extensionModel.getOperationModels()).thenReturn(asList(operationModel, anotherOperationModel));
    when(anotherOperationModel.getName()).thenReturn("anotherOperation");
    ParameterModel param = getParameter(UNIQUE_PARAM_NAME + "1", ChildElementTest.class);
    ParameterModel anotherParam = getParameter(UNIQUE_PARAM_NAME + "2", ChildElementTest.class);
    when(param.getRole()).thenReturn(BEHAVIOUR);
    when(anotherParam.getRole()).thenReturn(BEHAVIOUR);
    when(operationModel.getAllParameterModels()).thenReturn(asList(param));
    when(anotherOperationModel.getAllParameterModels()).thenReturn(asList(anotherParam));
    mockParameterGroup(operationModel, asList(param));
    mockParameterGroup(anotherOperationModel, asList(anotherParam));
    validate();
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 80 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method repeatedContentParameterNameAndChildElementSupport.

@Test
public void repeatedContentParameterNameAndChildElementSupport() {
    exception.expect(IllegalModelDefinitionException.class);
    OperationModel anotherOperationModel = mock(OperationModel.class);
    when(extensionModel.getOperationModels()).thenReturn(asList(operationModel, anotherOperationModel));
    when(anotherOperationModel.getName()).thenReturn("anotherOperation");
    ParameterModel param = getParameter(REPEATED_NAME, String.class);
    ParameterModel anotherParam = getParameter(UNIQUE_PARAM_NAME, ChildElementTest.class);
    when(param.getRole()).thenReturn(PRIMARY_CONTENT);
    when(anotherParam.getRole()).thenReturn(BEHAVIOUR);
    when(operationModel.getAllParameterModels()).thenReturn(asList(param));
    when(anotherOperationModel.getAllParameterModels()).thenReturn(asList(anotherParam));
    mockParameterGroup(operationModel, asList(param));
    mockParameterGroup(anotherOperationModel, asList(anotherParam));
    validate();
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)96 Test (org.junit.Test)68 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)27 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)15 SmallTest (org.mule.tck.size.SmallTest)14 Optional (java.util.Optional)13 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)12 MetadataType (org.mule.metadata.api.model.MetadataType)11 List (java.util.List)10 Set (java.util.Set)9 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)9 Optional.empty (java.util.Optional.empty)8 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)8 ObjectType (org.mule.metadata.api.model.ObjectType)7 OutputModel (org.mule.runtime.api.meta.model.OutputModel)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6