Search in sources :

Example 1 with NestableElementModel

use of org.mule.runtime.api.meta.model.nested.NestableElementModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method async.

@Test
public void async() {
    final ConstructModel asyncModel = coreExtensionModel.getConstructModel("async").get();
    assertThat(asyncModel.getNestedComponents(), hasSize(1));
    NestableElementModel processors = asyncModel.getNestedComponents().get(0);
    assertThat(processors, instanceOf(NestedChainModel.class));
    assertThat(processors.isRequired(), is(true));
    assertThat(asyncModel.getAllParameterModels(), hasSize(2));
    assertThat(asyncModel.getAllParameterModels().get(0).getName(), is("name"));
    assertThat(asyncModel.getAllParameterModels().get(0).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(asyncModel.getAllParameterModels().get(0).getType(), instanceOf(DefaultStringType.class));
    assertThat(asyncModel.getAllParameterModels().get(0).isRequired(), is(false));
    assertThat(asyncModel.getAllParameterModels().get(1).getName(), is("maxConcurrency"));
    assertThat(asyncModel.getAllParameterModels().get(1).getType(), instanceOf(DefaultNumberType.class));
    assertThat(asyncModel.getAllParameterModels().get(1).isRequired(), is(false));
}
Also used : ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Example 2 with NestableElementModel

use of org.mule.runtime.api.meta.model.nested.NestableElementModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method foreach.

@Test
public void foreach() {
    final ConstructModel foreach = coreExtensionModel.getConstructModel("foreach").get();
    assertThat(foreach.getNestedComponents().size(), is(1));
    NestableElementModel processorsChain = foreach.getNestedComponents().get(0);
    assertThat(processorsChain, instanceOf(NestedChainModel.class));
    assertThat(processorsChain.isRequired(), is(true));
    assertThat(foreach.getAllParameterModels(), hasSize(4));
    ParameterModel collection = foreach.getAllParameterModels().get(0);
    assertThat(collection.getName(), is("collection"));
    assertThat(collection.getExpressionSupport(), is(REQUIRED));
    assertThat(collection.getType(), instanceOf(ArrayType.class));
    assertThat(collection.getType().getAnnotation(ClassInformationAnnotation.class).map(ClassInformationAnnotation::getClassname).orElse(""), is(Iterable.class.getName()));
    assertThat(collection.isRequired(), is(false));
    ParameterModel batchSize = foreach.getAllParameterModels().get(1);
    assertThat(batchSize.getName(), is("batchSize"));
    assertThat(batchSize.getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(batchSize.getType(), instanceOf(DefaultNumberType.class));
    assertThat(batchSize.isRequired(), is(false));
    ParameterModel rootMessageName = foreach.getAllParameterModels().get(2);
    assertThat(rootMessageName.getName(), is("rootMessageVariableName"));
    assertThat(rootMessageName.getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(rootMessageName.getType(), instanceOf(DefaultStringType.class));
    assertThat(rootMessageName.isRequired(), is(false));
    ParameterModel counter = foreach.getAllParameterModels().get(3);
    assertThat(counter.getName(), is("counterVariableName"));
    assertThat(counter.getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(counter.getType(), instanceOf(DefaultStringType.class));
    assertThat(counter.isRequired(), is(false));
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Example 3 with NestableElementModel

use of org.mule.runtime.api.meta.model.nested.NestableElementModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method splitAggregate.

@Test
public void splitAggregate() {
    final ConstructModel splitAggregate = coreExtensionModel.getConstructModel("splitAggregate").get();
    NestableElementModel processorsChain = splitAggregate.getNestedComponents().get(0);
    assertThat(processorsChain, instanceOf(NestedChainModel.class));
    assertThat(processorsChain.isRequired(), is(true));
    assertThat(splitAggregate.getAllParameterModels(), hasSize(5));
    assertThat(splitAggregate.getAllParameterModels().get(0).getName(), is("collection"));
    assertThat(splitAggregate.getAllParameterModels().get(0).getExpressionSupport(), is(REQUIRED));
    assertThat(splitAggregate.getAllParameterModels().get(0).getType(), instanceOf(DefaultStringType.class));
    assertThat(splitAggregate.getAllParameterModels().get(0).isRequired(), is(false));
    assertThat(splitAggregate.getAllParameterModels().get(1).getName(), is("timeout"));
    assertThat(splitAggregate.getAllParameterModels().get(1).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(splitAggregate.getAllParameterModels().get(1).getType(), instanceOf(DefaultNumberType.class));
    assertThat(splitAggregate.getAllParameterModels().get(1).isRequired(), is(false));
    assertThat(splitAggregate.getAllParameterModels().get(2).getName(), is("maxConcurrency"));
    assertThat(splitAggregate.getAllParameterModels().get(2).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(splitAggregate.getAllParameterModels().get(2).getType(), instanceOf(DefaultNumberType.class));
    assertThat(splitAggregate.getAllParameterModels().get(2).isRequired(), is(false));
    assertThat(splitAggregate.getAllParameterModels().get(3).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(splitAggregate.getAllParameterModels().get(3).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(splitAggregate.getAllParameterModels().get(3).getType(), instanceOf(DefaultStringType.class));
    assertThat(splitAggregate.getAllParameterModels().get(3).isRequired(), is(false));
    assertThat(splitAggregate.getAllParameterModels().get(4).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    assertThat(splitAggregate.getAllParameterModels().get(4).getExpressionSupport(), is(REQUIRED));
    assertThat(splitAggregate.getAllParameterModels().get(4).getType(), instanceOf(StringType.class));
    assertThat(splitAggregate.getAllParameterModels().get(4).isRequired(), is(false));
}
Also used : ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) StringType(org.mule.metadata.api.model.StringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Example 4 with NestableElementModel

use of org.mule.runtime.api.meta.model.nested.NestableElementModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method flow.

@Test
public void flow() {
    final ConstructModel flow = coreExtensionModel.getConstructModel("flow").get();
    assertThat(flow.getStereotype().getType(), is(FLOW.getType()));
    assertThat(flow.allowsTopLevelDeclaration(), is(true));
    final List<ParameterModel> paramModels = flow.getAllParameterModels();
    assertThat(paramModels, hasSize(2));
    ParameterModel initialState = paramModels.get(0);
    assertThat(initialState.getName(), is("initialState"));
    assertThat(initialState.getDefaultValue(), is("started"));
    ParameterModel maxConcurrency = paramModels.get(1);
    assertThat(maxConcurrency.getName(), is("maxConcurrency"));
    List<? extends NestableElementModel> nestedComponents = flow.getNestedComponents();
    assertThat(nestedComponents, hasSize(3));
    NestableElementModel source = nestedComponents.get(0);
    assertThat(source.getName(), is("source"));
    assertThat(source.isRequired(), is(false));
    assertThat(source, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) source).getAllowedStereotypes(), contains(SOURCE));
    NestableElementModel chain = nestedComponents.get(1);
    assertThat(chain.getName(), is("processors"));
    assertThat(chain.isRequired(), is(true));
    assertThat(chain, instanceOf(NestedChainModel.class));
    assertThat(((NestedChainModel) chain).getAllowedStereotypes().stream().anyMatch(s -> s.getType().equals(PROCESSOR.getType())), is(true));
    NestableElementModel errorHandler = nestedComponents.get(2);
    assertThat(errorHandler.getName(), is("errorHandler"));
    assertThat(errorHandler.isRequired(), is(false));
    assertThat(errorHandler, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) errorHandler).getAllowedStereotypes(), contains(ERROR_HANDLER));
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ErrorModelBuilder.newError(org.mule.runtime.api.meta.model.error.ErrorModelBuilder.newError) DefaultAnyType(org.mule.metadata.api.model.impl.DefaultAnyType) VoidType(org.mule.metadata.api.model.VoidType) Assert.assertThat(org.junit.Assert.assertThat) CPU_LITE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_LITE) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) IsCollectionContaining.hasItem(org.hamcrest.core.IsCollectionContaining.hasItem) ArrayType(org.mule.metadata.api.model.ArrayType) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) ON_ERROR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ON_ERROR) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ObjectType(org.mule.metadata.api.model.ObjectType) REQUIRED(org.mule.runtime.api.meta.ExpressionSupport.REQUIRED) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) MuleManifest.getVendorName(org.mule.runtime.core.api.config.MuleManifest.getVendorName) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) StringType(org.mule.metadata.api.model.StringType) Matchers.contains(org.hamcrest.Matchers.contains) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FLOW(org.mule.runtime.extension.api.stereotype.MuleStereotypes.FLOW) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) TRANSFORMATION(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.TRANSFORMATION) SOURCE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.SOURCE) COMMUNITY(org.mule.runtime.api.meta.Category.COMMUNITY) OBJECT_STORE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE) Iterator(java.util.Iterator) ERROR_HANDLER(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ERROR_HANDLER) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DefaultBooleanType(org.mule.metadata.api.model.impl.DefaultBooleanType) Test(org.junit.Test) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MULE_VERSION(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_VERSION) MuleExtensionModelProvider.getExtensionModel(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.getExtensionModel) PROCESSOR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.PROCESSOR) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) MULE_NAME(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_NAME) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SubTypesModel(org.mule.runtime.api.meta.model.SubTypesModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Example 5 with NestableElementModel

use of org.mule.runtime.api.meta.model.nested.NestableElementModel in project mule by mulesoft.

the class AbstractComponentDefinitionParser method doParse.

@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
    Builder finalBuilder = definitionBuilder.withIdentifier(operationDsl.getElementName()).withTypeDefinition(fromType(getMessageProcessorType())).withObjectFactoryType(getMessageProcessorFactoryType()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(componentModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromReferenceObject(Registry.class).build()).withConstructorParameterDefinition(fromReferenceObject(PolicyManager.class).build()).withSetterParameterDefinition(TARGET_PARAMETER_NAME, fromSimpleParameter(TARGET_PARAMETER_NAME).build()).withSetterParameterDefinition(TARGET_VALUE_PARAMETER_NAME, fromSimpleParameter(TARGET_VALUE_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build());
    Optional<? extends NestableElementModel> nestedChain = componentModel.getNestedComponents().stream().filter(c -> c instanceof NestedChainModel).findFirst();
    if (nestedChain.isPresent()) {
        // TODO MULE-13483: improve parsers to support things like [source, chainOfProcessors, errorHandler]
        // or [chainOfProcessors, errorHandler]
        finalBuilder = finalBuilder.withSetterParameterDefinition("nestedProcessors", fromChildCollectionConfiguration(Processor.class).build());
        parseParameters(componentModel.getAllParameterModels());
    } else {
        List<ParameterGroupModel> inlineGroups = getInlineGroups(componentModel);
        parseParameters(getFlatParameters(inlineGroups, componentModel.getAllParameterModels()));
        for (ParameterGroupModel group : inlineGroups) {
            parseInlineParameterGroup(group);
        }
        // TODO MULE-13483
        parseNestedComponents(componentModel.getNestedComponents());
    }
    return finalBuilder;
}
Also used : ExtensionDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.ExtensionDefinitionParser) Builder.fromReferenceObject(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromReferenceObject) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) CONFIG_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.CONFIG_ATTRIBUTE_NAME) ExtensionParsingContext(org.mule.runtime.module.extension.internal.config.dsl.ExtensionParsingContext) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) Builder.fromChildConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildConfiguration) Builder.fromSimpleReferenceParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleReferenceParameter) Processor(org.mule.runtime.core.api.processor.Processor) Builder.fromFixedValue(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromFixedValue) Builder.fromSimpleParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleParameter) OperationMessageProcessorObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationMessageProcessorObjectFactory) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) MuleContext(org.mule.runtime.core.api.MuleContext) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) Registry(org.mule.runtime.api.artifact.Registry) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) Builder.fromChildCollectionConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildCollectionConfiguration) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ComponentMessageProcessorObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.ComponentMessageProcessorObjectFactory) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ComponentMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Optional(java.util.Optional) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) MuleContext(org.mule.runtime.core.api.MuleContext) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) Processor(org.mule.runtime.core.api.processor.Processor) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) ComponentMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)

Aggregations

NestableElementModel (org.mule.runtime.api.meta.model.nested.NestableElementModel)6 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)5 NestedChainModel (org.mule.runtime.api.meta.model.nested.NestedChainModel)5 Test (org.junit.Test)4 DefaultNumberType (org.mule.metadata.api.model.impl.DefaultNumberType)4 DefaultStringType (org.mule.metadata.api.model.impl.DefaultStringType)4 List (java.util.List)3 Optional (java.util.Optional)3 ArrayType (org.mule.metadata.api.model.ArrayType)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)3 Iterator (java.util.Iterator)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 StringType (org.mule.metadata.api.model.StringType)2 NestedRouteModel (org.mule.runtime.api.meta.model.nested.NestedRouteModel)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)2 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)2 TARGET_PARAMETER_NAME (org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME)2 TARGET_VALUE_PARAMETER_NAME (org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME)2