Search in sources :

Example 1 with OperationModel

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

the class CoreExtensionModelTestCase method idempotentMessageValidator.

@Test
public void idempotentMessageValidator() {
    final OperationModel filterModel = coreExtensionModel.getOperationModel("idempotentMessageValidator").get();
    assertThat(filterModel.getStereotype(), is(PROCESSOR));
    assertOutputSameAsInput(filterModel);
    assertThat(filterModel.getAllParameterModels(), hasSize(4));
    assertThat(filterModel.getAllParameterModels().get(0).getName(), is("idExpression"));
    assertThat(filterModel.getAllParameterModels().get(0).getExpressionSupport(), is(SUPPORTED));
    assertThat(filterModel.getAllParameterModels().get(0).getType(), instanceOf(DefaultStringType.class));
    assertThat(filterModel.getAllParameterModels().get(0).isRequired(), is(false));
    assertThat(filterModel.getAllParameterModels().get(1).getName(), is("valueExpression"));
    assertThat(filterModel.getAllParameterModels().get(1).getExpressionSupport(), is(SUPPORTED));
    assertThat(filterModel.getAllParameterModels().get(1).getType(), instanceOf(DefaultStringType.class));
    assertThat(filterModel.getAllParameterModels().get(1).isRequired(), is(false));
    assertThat(filterModel.getAllParameterModels().get(2).getName(), is("storePrefix"));
    assertThat(filterModel.getAllParameterModels().get(2).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(filterModel.getAllParameterModels().get(2).getType(), instanceOf(DefaultStringType.class));
    assertThat(filterModel.getAllParameterModels().get(2).isRequired(), is(false));
    assertThat(filterModel.getAllParameterModels().get(3).getName(), is("objectStore"));
    assertThat(filterModel.getAllParameterModels().get(3).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(filterModel.getAllParameterModels().get(3).getType(), instanceOf(DefaultObjectType.class));
    assertThat(filterModel.getAllParameterModels().get(3).isRequired(), is(false));
    assertThat(filterModel.getAllParameterModels().get(3).getAllowedStereotypes().size(), is(1));
    assertThat(filterModel.getAllParameterModels().get(3).getAllowedStereotypes().get(0), is(OBJECT_STORE));
}
Also used : DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 2 with OperationModel

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

the class CoreExtensionModelTestCase method logger.

@Test
public void logger() {
    final OperationModel loggerModel = coreExtensionModel.getOperationModel("logger").get();
    assertThat(loggerModel.getStereotype(), is(PROCESSOR));
    assertThat(loggerModel.getErrorModels(), empty());
    assertThat(loggerModel.getExecutionType(), is(CPU_LITE));
    assertOutputSameAsInput(loggerModel);
    final List<ParameterModel> paramModels = loggerModel.getAllParameterModels();
    assertThat(paramModels, hasSize(3));
    assertThat(paramModels.get(0).getName(), is("message"));
    assertThat(paramModels.get(0).getExpressionSupport(), is(SUPPORTED));
    assertThat(paramModels.get(0).getType(), instanceOf(StringType.class));
    assertThat(paramModels.get(0).isRequired(), is(false));
    assertThat(paramModels.get(1).getName(), is("level"));
    assertThat(paramModels.get(1).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(paramModels.get(1).getType(), instanceOf(DefaultStringType.class));
    assertThat(paramModels.get(1).isRequired(), is(false));
    assertThat(paramModels.get(2).getName(), is("category"));
    assertThat(paramModels.get(2).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(paramModels.get(2).getType(), instanceOf(StringType.class));
    assertThat(paramModels.get(2).isRequired(), is(false));
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) StringType(org.mule.metadata.api.model.StringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 3 with OperationModel

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

the class CoreExtensionModelTestCase method raiseError.

@Test
public void raiseError() {
    final OperationModel raiseErrorModel = coreExtensionModel.getOperationModel("raiseError").get();
    assertThat(raiseErrorModel.getStereotype(), is(PROCESSOR));
    assertThat(raiseErrorModel.getErrorModels(), empty());
    assertThat(raiseErrorModel.getExecutionType(), is(CPU_LITE));
    assertOutputSameAsInput(raiseErrorModel);
    final List<ParameterModel> paramModels = raiseErrorModel.getAllParameterModels();
    assertThat(paramModels, hasSize(2));
    assertThat(paramModels.get(0).getName(), is("type"));
    assertThat(paramModels.get(0).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(paramModels.get(0).getType(), instanceOf(DefaultStringType.class));
    assertThat(paramModels.get(0).isRequired(), is(true));
    assertThat(paramModels.get(1).getName(), is("description"));
    assertThat(paramModels.get(1).getExpressionSupport(), is(SUPPORTED));
    assertThat(paramModels.get(1).getType(), instanceOf(StringType.class));
    assertThat(paramModels.get(1).isRequired(), is(false));
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) StringType(org.mule.metadata.api.model.StringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 4 with OperationModel

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

the class ExportedPackagesValidatorTestCase method setUpInvalidExtension.

private void setUpInvalidExtension() {
    OutputModel appleList = mockOutputModel(InternalTestClass.class);
    OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(InternalTestClass.class));
    withMethod(firstOperation, getApiMethods(InternalTestClass.class).stream().filter(m -> m.getName().equals("someOperation")).findFirst());
    ParameterModel parameter = mockParameterModel(Shape.class);
    OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
    }.getType());
    OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
    withMethod(secondOperation, empty());
    when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
    visitableMock(firstOperation, secondOperation);
}
Also used : InternalTestClass(org.mule.test.module.extension.internal.InternalTestClass) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) TypeToken(com.google.common.reflect.TypeToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Result(org.mule.runtime.extension.api.runtime.operation.Result)

Example 5 with OperationModel

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

the class DefaultExtensionBuildingDefinitionProvider method registerExtensionParsers.

private void registerExtensionParsers(ExtensionModel extensionModel) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    final ExtensionParsingContext parsingContext = createParsingContext(extensionModel);
    final Builder definitionBuilder = new Builder().withNamespace(xmlDslModel.getPrefix());
    final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, DslResolvingContext.getDefault(extensions));
    if (extensionModel.getModelProperty(CustomBuildingDefinitionProviderModelProperty.class).isPresent()) {
        return;
    }
    if (extensionModel.getModelProperty(XmlExtensionModelProperty.class).isPresent()) {
        registerXmlExtensionParsers(definitionBuilder, extensionModel, dslSyntaxResolver);
    } else {
        final ClassLoader extensionClassLoader = getClassLoader(extensionModel);
        withContextClassLoader(extensionClassLoader, () -> {
            ReflectionCache reflectionCache = new ReflectionCache();
            new IdempotentExtensionWalker() {

                @Override
                public void onConfiguration(ConfigurationModel model) {
                    parseWith(new ConfigurationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onConstruct(ConstructModel model) {
                    parseWith(new ConstructDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onOperation(OperationModel model) {
                    parseWith(new OperationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onConnectionProvider(ConnectionProviderModel model) {
                    parseWith(new ConnectionProviderDefinitionParser(definitionBuilder, model, extensionModel, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onSource(SourceModel model) {
                    parseWith(new SourceDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onParameter(ParameterGroupModel groupModel, ParameterModel model) {
                    registerTopLevelParameter(model.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
                }
            }.walk(extensionModel);
            registerExportedTypesTopLevelParsers(extensionModel, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
            registerSubTypes(definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
        });
    }
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) CustomBuildingDefinitionProviderModelProperty(org.mule.runtime.core.internal.extension.CustomBuildingDefinitionProviderModelProperty) ConnectionProviderDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.connection.ConnectionProviderDefinitionParser) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ConstructDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.construct.ConstructDefinitionParser) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) SourceDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.source.SourceDefinitionParser) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.config.ConfigurationDefinitionParser) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) OperationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationDefinitionParser)

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