Search in sources :

Example 6 with OperationComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty in project mule by mulesoft.

the class XmlExtensionLoaderTestCase method testModuleProperties.

@Test
public void testModuleProperties() {
    String modulePath = "modules/module-properties.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-properties"));
    assertThat(extensionModel.getConfigurationModels().size(), is(1));
    ConfigurationModel configurationModel = extensionModel.getConfigurationModels().get(0);
    assertThat(configurationModel.getName(), is(CONFIG_NAME));
    assertThat(configurationModel.getAllParameterModels().size(), is(5));
    assertThat(configurationModel.getAllParameterModels().get(0).getName(), is("configParam"));
    assertThat(configurationModel.getAllParameterModels().get(1).getName(), is("defaultConfigParam"));
    Optional<GlobalElementComponentModelModelProperty> globalElementComponentModelModelProperty = configurationModel.getModelProperty(GlobalElementComponentModelModelProperty.class);
    assertThat(globalElementComponentModelModelProperty.isPresent(), is(true));
    assertThat(globalElementComponentModelModelProperty.get().getGlobalElements().size(), is(0));
    assertThat(configurationModel.getOperationModels().size(), is(7));
    Optional<OperationModel> operationModel = configurationModel.getOperationModel("set-payload-add-param-and-property-values");
    assertThat(operationModel.isPresent(), is(true));
    assertThat(operationModel.get().getAllParameterModels().size(), is(3));
    assertThat(operationModel.get().getAllParameterModels().get(0).getName(), is("value1"));
    assertThat(operationModel.get().getAllParameterModels().get(1).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(operationModel.get().getAllParameterModels().get(2).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    Optional<OperationComponentModelModelProperty> modelProperty = operationModel.get().getModelProperty(OperationComponentModelModelProperty.class);
    assertThat(modelProperty.isPresent(), is(true));
    assertThat(modelProperty.get().getBodyComponentModel().getInnerComponents().size(), is(1));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Matchers.containsString(org.hamcrest.Matchers.containsString) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 7 with OperationComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty in project mule by mulesoft.

the class XmlExtensionLoaderTestCase method testModuleDocumentation.

@Test
public void testModuleDocumentation() throws IOException {
    String modulePath = "modules/module-documentation.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-documentation"));
    assertThat(extensionModel.getDescription(), is("Documentation for the connector"));
    assertThat(extensionModel.getConfigurationModels().size(), is(1));
    ConfigurationModel configurationModel = extensionModel.getConfigurationModels().get(0);
    assertThat(configurationModel.getName(), is(CONFIG_NAME));
    final List<ParameterModel> configurationParameterModels = configurationModel.getAllParameterModels();
    assertThat(configurationParameterModels.size(), is(5));
    assertThat(configurationParameterModels.get(0).getName(), is("aPropertyWithDoc"));
    assertThat(configurationParameterModels.get(0).getDescription(), is("Documentation for the property"));
    assertThat(configurationParameterModels.get(1).getName(), is("aHiddenPropertyWithDoc"));
    assertThat(configurationParameterModels.get(1).getDescription(), is("Documentation for the hidden property"));
    assertThat(configurationParameterModels.get(1).getLayoutModel().isPresent(), is(true));
    assertThat(configurationParameterModels.get(1).getLayoutModel().get().isPassword(), is(true));
    assertThat(configurationParameterModels.get(2).getName(), is("aPropertyDisplayModel"));
    assertThat(configurationParameterModels.get(2).getDescription(), is(""));
    assertThat(configurationParameterModels.get(2).getDisplayModel().isPresent(), is(true));
    assertThat(configurationParameterModels.get(2).getDisplayModel().get().getDisplayName(), is("A pretty name property"));
    assertThat(configurationParameterModels.get(2).getDisplayModel().get().getSummary(), is("a summary tooltip property"));
    assertThat(configurationParameterModels.get(2).getDisplayModel().get().getExample(), is("SOME_PROPERTY_SAMPLE_DATA"));
    assertThat(configurationParameterModels.get(3).getName(), is("aPropertyWithPlacement"));
    assertThat(configurationParameterModels.get(3).getDescription(), is(""));
    assertThat(configurationParameterModels.get(3).getLayoutModel().isPresent(), is(true));
    assertThat(configurationParameterModels.get(3).getLayoutModel().get().getTabName().get(), is("Not General Property"));
    assertThat(configurationParameterModels.get(3).getLayoutModel().get().getOrder().get(), is(42));
    Optional<GlobalElementComponentModelModelProperty> globalElementComponentModelModelProperty = configurationModel.getModelProperty(GlobalElementComponentModelModelProperty.class);
    assertThat(globalElementComponentModelModelProperty.isPresent(), is(true));
    assertThat(globalElementComponentModelModelProperty.get().getGlobalElements().size(), is(0));
    assertThat(configurationModel.getOperationModels().size(), is(1));
    Optional<OperationModel> operationModelOptional = configurationModel.getOperationModel("operation-with-doc");
    assertThat(operationModelOptional.isPresent(), is(true));
    final OperationModel operationModel = operationModelOptional.get();
    assertThat(operationModel.getDescription(), is("Documentation for the operation"));
    assertThat(operationModel.getDisplayModel().isPresent(), is(true));
    assertThat(operationModel.getDisplayModel().get().getDisplayName(), is("A pretty name for the operation"));
    assertThat(operationModel.getDisplayModel().get().getSummary(), is("a summary tooltip operation"));
    assertThat(operationModel.getDisplayModel().get().getExample(), is("SOME_OPERATION_SAMPLE_DATA"));
    final List<ParameterModel> allParameterModels = operationModel.getAllParameterModels();
    assertThat(allParameterModels.size(), is(6));
    assertThat(allParameterModels.get(0).getName(), is("paramWithDoc"));
    assertThat(allParameterModels.get(0).getDescription(), is("Documentation for the parameter"));
    assertThat(allParameterModels.get(0).getLayoutModel().get().getTabName().get(), is(Placement.DEFAULT_TAB));
    assertThat(allParameterModels.get(0).getLayoutModel().get().getOrder().isPresent(), is(false));
    assertThat(allParameterModels.get(1).getName(), is("hiddenParamWithDoc"));
    assertThat(allParameterModels.get(1).getDescription(), is("Documentation for the hidden parameter"));
    assertThat(allParameterModels.get(1).getLayoutModel().isPresent(), is(true));
    assertThat(allParameterModels.get(1).getLayoutModel().get().isPassword(), is(true));
    assertThat(allParameterModels.get(2).getName(), is("paramDisplayModel"));
    assertThat(allParameterModels.get(2).getDescription(), is(""));
    assertThat(allParameterModels.get(2).getDisplayModel().isPresent(), is(true));
    assertThat(allParameterModels.get(2).getDisplayModel().get().getDisplayName(), is("A pretty name parameter"));
    assertThat(allParameterModels.get(2).getDisplayModel().get().getSummary(), is("a summary tooltip parameter"));
    assertThat(allParameterModels.get(2).getDisplayModel().get().getExample(), is("SOME_PARAMETER_SAMPLE_DATA"));
    assertThat(allParameterModels.get(3).getName(), is("paramWithPlacement"));
    assertThat(allParameterModels.get(3).getDescription(), is(""));
    assertThat(allParameterModels.get(3).getLayoutModel().isPresent(), is(true));
    assertThat(allParameterModels.get(3).getLayoutModel().get().getTabName().get(), is("Not General Parameter"));
    assertThat(allParameterModels.get(3).getLayoutModel().get().getOrder().get(), is(17));
    assertThat(allParameterModels.get(4).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(allParameterModels.get(4).getDescription(), is(TARGET_PARAMETER_DESCRIPTION));
    assertThat(allParameterModels.get(5).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    assertThat(allParameterModels.get(5).getDescription(), is(TARGET_VALUE_PARAMETER_DESCRIPTION));
    assertThat(operationModel.getOutput().getDescription(), is("Documentation for the output"));
    assertThat(operationModel.getOutputAttributes().getDescription(), is("Documentation for the output attributes"));
    assertThat(operationModel.getErrorModels().size(), is(2));
    assertThat(operationModel.getErrorModels(), containsInAnyOrder(ErrorModelBuilder.newError("CUSTOM_ERROR_HERE", extensionModel.getXmlDslModel().getPrefix().toUpperCase()).withParent(ErrorModelBuilder.newError(ANY).build()).build(), ErrorModelBuilder.newError("ANOTHER_CUSTOM_ERROR_HERE", extensionModel.getXmlDslModel().getPrefix().toUpperCase()).withParent(ErrorModelBuilder.newError(ANY).build()).build()));
    Optional<OperationComponentModelModelProperty> modelProperty = operationModel.getModelProperty(OperationComponentModelModelProperty.class);
    assertThat(modelProperty.isPresent(), is(true));
    assertThat(modelProperty.get().getBodyComponentModel().getInnerComponents().size(), is(2));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Matchers.containsString(org.hamcrest.Matchers.containsString) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 8 with OperationComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty in project mule by mulesoft.

the class XmlExtensionLoaderTestCase method testModuleJsonCustomTypes.

@Test
public void testModuleJsonCustomTypes() throws IOException {
    String modulePath = "modules/module-json-custom-types.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-json-custom-types"));
    assertThat(extensionModel.getConfigurationModels().size(), is(0));
    assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
    assertThat(extensionModel.getOperationModels().size(), is(8));
    Optional<OperationModel> operationModel = extensionModel.getOperationModel("operation-with-custom-types");
    assertThat(operationModel.isPresent(), is(true));
    final OperationModel operation = operationModel.get();
    assertThat(operation.getAllParameterModels().size(), is(3));
    final ParameterModel parameterValueModel = operation.getAllParameterModels().get(0);
    assertThat(parameterValueModel.getName(), is("value"));
    assertThat(operation.getAllParameterModels().get(1).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(operation.getAllParameterModels().get(2).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    assertThat(parameterValueModel.getType().getMetadataFormat(), is(MetadataFormat.JSON));
    assertThat(parameterValueModel.getType(), instanceOf(ObjectType.class));
    assertThat(((ObjectType) parameterValueModel.getType()).getFields().size(), is(2));
    assertThat(operation.getOutput().getType().getMetadataFormat(), is(MetadataFormat.JSON));
    assertThat(operation.getOutput().getType(), instanceOf(ObjectType.class));
    assertThat(((ObjectType) operation.getOutput().getType()).getFields().size(), is(3));
    Optional<OperationComponentModelModelProperty> modelProperty = operation.getModelProperty(OperationComponentModelModelProperty.class);
    assertThat(modelProperty.isPresent(), is(true));
    assertThat(modelProperty.get().getBodyComponentModel().getInnerComponents().size(), is(1));
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Matchers.containsString(org.hamcrest.Matchers.containsString) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 9 with OperationComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty in project mule by mulesoft.

the class MacroExpansionModuleModel method createModuleOperationChain.

/**
 * Takes a one liner call to any given message processor, expand it to creating a "module-operation-chain" scope which has the
 * set of properties, the set of parameters and the list of message processors to execute.
 *
 * @param operationRefModel message processor that will be replaced by a scope element named "module-operation-chain".
 * @param operationModel operation that provides both the <parameter/>s and content of the <body/>
 * @param moduleGlobalElementsNames collection with the global components names (such as <http:config name="a"../>, <file:config
 *        name="b"../>, <file:matcher name="c"../> and so on) that are contained within the <module/> that will be macro
 *        expanded
 * @param configRefParentTnsName parent reference to the global element if exists (it might not be global elements in the
 *        current module). Useful when replacing {@link #TNS_PREFIX} operations, as the references to the global elements will
 *        be those of the rootest element of the operations consumed by the app.
 * @param containerName name of the container that contains the operation to be macro expanded. Not null nor empty.
 * @return a new component model that represents the old placeholder but expanded with the content of the <body/>
 */
private ComponentModel createModuleOperationChain(ComponentModel operationRefModel, OperationModel operationModel, Set<String> moduleGlobalElementsNames, Optional<String> configRefParentTnsName, String containerName) {
    final OperationComponentModelModelProperty operationComponentModelModelProperty = operationModel.getModelProperty(OperationComponentModelModelProperty.class).get();
    final ComponentModel operationModuleComponentModel = operationComponentModelModelProperty.getBodyComponentModel();
    List<ComponentModel> bodyProcessors = operationModuleComponentModel.getInnerComponents();
    Optional<String> configRefName = referencesOperationsWithinModule(operationRefModel) ? configRefParentTnsName : Optional.ofNullable(operationRefModel.getParameters().get(MODULE_OPERATION_CONFIG_REF));
    ComponentModel.Builder processorChainBuilder = new ComponentModel.Builder();
    processorChainBuilder.setIdentifier(builder().namespace(CORE_PREFIX).name("module-operation-chain").build());
    processorChainBuilder.addParameter("moduleName", extensionModel.getXmlDslModel().getPrefix(), false);
    processorChainBuilder.addParameter("moduleOperation", operationModel.getName(), false);
    Map<String, String> propertiesMap = extractProperties(configRefName);
    Map<String, String> parametersMap = extractParameters(operationRefModel, operationModel.getAllParameterModels());
    ComponentModel propertiesComponentModel = getParameterChild(propertiesMap, "module-operation-properties", "module-operation-property-entry");
    ComponentModel parametersComponentModel = getParameterChild(parametersMap, "module-operation-parameters", "module-operation-parameter-entry");
    processorChainBuilder.addChildComponentModel(propertiesComponentModel);
    processorChainBuilder.addChildComponentModel(parametersComponentModel);
    for (ComponentModel bodyProcessor : bodyProcessors) {
        ComponentModel childMPcomponentModel = lookForTNSOperation(bodyProcessor).map(tnsOperation -> createModuleOperationChain(bodyProcessor, tnsOperation, moduleGlobalElementsNames, configRefName, containerName)).orElseGet(() -> copyOperationComponentModel(bodyProcessor, configRefName, moduleGlobalElementsNames, getLiteralParameters(propertiesMap, parametersMap), containerName));
        processorChainBuilder.addChildComponentModel(childMPcomponentModel);
    }
    copyErrorMappings(operationRefModel, processorChainBuilder);
    for (Map.Entry<String, Object> customAttributeEntry : operationRefModel.getCustomAttributes().entrySet()) {
        processorChainBuilder.addCustomAttribute(customAttributeEntry.getKey(), customAttributeEntry.getValue());
    }
    processorChainBuilder.addCustomAttribute(ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME, containerName);
    ComponentModel processorChainModel = processorChainBuilder.build();
    for (ComponentModel processorChainModelChild : processorChainModel.getInnerComponents()) {
        processorChainModelChild.setParent(processorChainModel);
    }
    operationRefModel.getConfigFileName().ifPresent(processorChainBuilder::setConfigFileName);
    operationRefModel.getLineNumber().ifPresent(processorChainBuilder::setLineNumber);
    processorChainBuilder.addCustomAttribute(ORIGINAL_IDENTIFIER, operationRefModel.getIdentifier());
    return processorChainModel;
}
Also used : IntStream(java.util.stream.IntStream) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) CommonBeanDefinitionCreator(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator) MODULE_OPERATION_CHAIN(org.mule.runtime.config.internal.model.ApplicationModel.MODULE_OPERATION_CHAIN) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) NAME_ATTRIBUTE(org.mule.runtime.config.internal.model.ApplicationModel.NAME_ATTRIBUTE) Collectors.toSet(java.util.stream.Collectors.toSet) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) Collections.emptyMap(java.util.Collections.emptyMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) VARS(org.mule.runtime.api.el.BindingContextUtils.VARS) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) MODULE_CONFIG_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONFIG_GLOBAL_ELEMENT_NAME) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Aggregations

OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)9 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)8 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 Test (org.junit.Test)7 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)5 GlobalElementComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty)5 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)4 ObjectType (org.mule.metadata.api.model.ObjectType)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)2 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1