Search in sources :

Example 1 with GlobalElementComponentModelModelProperty

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

the class XmlExtensionLoaderTestCase method testModuleGlobalElement.

@Test
public void testModuleGlobalElement() {
    String modulePath = "modules/module-global-element.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-global-element"));
    assertThat(extensionModel.getConfigurationModels().size(), is(1));
    ConfigurationModel configurationModel = extensionModel.getConfigurationModels().get(0);
    assertThat(configurationModel.getName(), is(CONFIG_NAME));
    assertThat(configurationModel.getAllParameterModels().size(), is(2));
    assertThat(configurationModel.getAllParameterModels().get(0).getName(), is("username"));
    Optional<GlobalElementComponentModelModelProperty> globalElementComponentModelModelProperty = configurationModel.getModelProperty(GlobalElementComponentModelModelProperty.class);
    assertThat(globalElementComponentModelModelProperty.isPresent(), is(true));
    assertThat(globalElementComponentModelModelProperty.get().getGlobalElements().size(), is(1));
    assertThat(configurationModel.getOperationModels().size(), is(1));
    Optional<OperationModel> operationModel = configurationModel.getOperationModel("do-something");
    assertThat(operationModel.isPresent(), is(true));
    assertThat(operationModel.get().getAllParameterModels().size(), is(3));
    assertThat(operationModel.get().getAllParameterModels().get(0).getName(), is("somePetName"));
    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 2 with GlobalElementComponentModelModelProperty

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

the class XmlExtensionLoaderDelegate method loadPropertiesFrom.

private Optional<ConfigurationDeclarer> loadPropertiesFrom(ExtensionDeclarer declarer, ComponentModel moduleModel, Set<ExtensionModel> extensions) {
    List<ComponentModel> globalElementsComponentModel = extractGlobalElementsFrom(moduleModel);
    List<ComponentModel> configurationProperties = extractProperties(moduleModel);
    List<ComponentModel> connectionProperties = extractConnectionProperties(moduleModel);
    validateProperties(configurationProperties, connectionProperties);
    if (!configurationProperties.isEmpty() || !connectionProperties.isEmpty() || !globalElementsComponentModel.isEmpty()) {
        declarer.withModelProperty(new NoReconnectionStrategyModelProperty());
        ConfigurationDeclarer configurationDeclarer = declarer.withConfig(CONFIG_NAME);
        configurationDeclarer.withModelProperty(new GlobalElementComponentModelModelProperty(globalElementsComponentModel));
        configurationProperties.stream().forEach(param -> extractProperty(configurationDeclarer, param));
        addConnectionProvider(configurationDeclarer, connectionProperties, globalElementsComponentModel, extensions);
        return of(configurationDeclarer);
    }
    return empty();
}
Also used : NoReconnectionStrategyModelProperty(org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Example 3 with GlobalElementComponentModelModelProperty

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

the class XmlExtensionLoaderTestCase method testModuleWrongBodyContent.

@Test
public void testModuleWrongBodyContent() {
    String modulePath = "validation/module-wrong-body-content.xml";
    if (validateXml) {
        try {
            getExtensionModelFrom(modulePath);
            fail("Should not have reached up to this point, the XML is invalid and the ExtensionModel should not be generated.");
        } catch (MuleRuntimeException e) {
            assertThat(e.getMessage(), containsString("There were '2' error"));
            assertThat(e.getMessage(), containsString("Invalid content was found starting with element 'mule:fake-request-config'"));
            assertThat(e.getMessage(), containsString("Invalid content was found starting with element 'mule:non-existing-operation'"));
        }
    } else {
        ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
        assertThat(extensionModel.getName(), is("module-wrong-body-content"));
        assertThat(extensionModel.getOperationModels().size(), is(0));
        assertThat(extensionModel.getConfigurationModels().size(), is(1));
        ConfigurationModel configurationModel = extensionModel.getConfigurationModels().get(0);
        assertThat(configurationModel.getName(), is(CONFIG_NAME));
        assertThat(configurationModel.getAllParameterModels().size(), is(2));
        Optional<GlobalElementComponentModelModelProperty> globalElementComponentModelModelProperty = configurationModel.getModelProperty(GlobalElementComponentModelModelProperty.class);
        assertThat(globalElementComponentModelModelProperty.isPresent(), is(true));
        assertThat(globalElementComponentModelModelProperty.get().getGlobalElements().size(), is(1));
        Optional<OperationModel> operationModelOptional = configurationModel.getOperationModel("operation-with-non-valid-body");
        assertThat(operationModelOptional.isPresent(), is(true));
        final OperationModel operationModel = operationModelOptional.get();
        assertThat(operationModel.getAllParameterModels().size(), is(0));
        Optional<OperationComponentModelModelProperty> modelProperty = operationModel.getModelProperty(OperationComponentModelModelProperty.class);
        assertThat(modelProperty.isPresent(), is(true));
        assertThat(modelProperty.get().getBodyComponentModel().getInnerComponents().size(), is(1));
        assertThat(operationModel.getOutput().getType().getMetadataFormat(), is(MetadataFormat.JAVA));
        assertThat(operationModel.getOutput().getType(), instanceOf(VoidType.class));
        assertThat(operationModel.getOutputAttributes().getType().getMetadataFormat(), is(MetadataFormat.JAVA));
        assertThat(operationModel.getOutputAttributes().getType(), instanceOf(VoidType.class));
        assertThat(operationModel.getErrorModels().size(), is(0));
    }
}
Also used : VoidType(org.mule.metadata.api.model.VoidType) 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) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) 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 4 with GlobalElementComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty 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 5 with GlobalElementComponentModelModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty 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)

Aggregations

GlobalElementComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty)6 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.Test)4 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)4 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)4 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)4 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)2 ArrayList (java.util.ArrayList)1 VoidType (org.mule.metadata.api.model.VoidType)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ConfigurationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 NoReconnectionStrategyModelProperty (org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty)1