Search in sources :

Example 1 with OperationComponentModelModelProperty

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

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

the class XmlExtensionLoaderTestCase method testModuleXsdCustomTypes.

@Test
public void testModuleXsdCustomTypes() throws IOException {
    String modulePath = "modules/module-xsd-custom-types.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-xsd-custom-types"));
    assertThat(extensionModel.getConfigurationModels().size(), is(0));
    assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
    assertThat(extensionModel.getOperationModels().size(), is(4));
    Optional<OperationModel> operationModel = extensionModel.getOperationModel("operation-with-custom-types");
    assertThat(operationModel.isPresent(), is(true));
    final OperationModel operation = operationModel.get();
    assertThat(operation.getAllParameterModels().size(), is(4));
    assertThat(operation.getAllParameterModels().get(2).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(operation.getAllParameterModels().get(3).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    final ParameterModel firstParameterValueModel = operation.getAllParameterModels().get(0);
    assertThat(firstParameterValueModel.getName(), is("value"));
    assertThat(firstParameterValueModel.getType().getMetadataFormat(), is(MetadataFormat.XML));
    assertThat(firstParameterValueModel.getType(), instanceOf(ObjectType.class));
    final ObjectType firstInputParameterObjectType = (ObjectType) firstParameterValueModel.getType();
    assertThat(firstInputParameterObjectType.getFields().size(), is(1));
    assertThat(firstInputParameterObjectType.getFieldByName("User").isPresent(), is(true));
    final ParameterModel secondParameterValueModel = operation.getAllParameterModels().get(1);
    assertThat(secondParameterValueModel.getName(), is("value2"));
    assertThat(secondParameterValueModel.getType().getMetadataFormat(), is(MetadataFormat.XML));
    assertThat(secondParameterValueModel.getType(), instanceOf(ObjectType.class));
    final ObjectType secondInputParameterObjectType = (ObjectType) secondParameterValueModel.getType();
    assertThat(secondInputParameterObjectType.getFields().size(), is(1));
    assertThat(secondInputParameterObjectType.getFieldByName("Root").isPresent(), is(true));
    assertThat(operation.getOutput().getType().getMetadataFormat(), is(MetadataFormat.XML));
    assertThat(operation.getOutput().getType(), instanceOf(ObjectType.class));
    final ObjectType outputObjectType = (ObjectType) operation.getOutput().getType();
    assertThat(outputObjectType.getFields().size(), is(1));
    assertThat(outputObjectType.getFieldByName("Root0").isPresent(), is(true));
    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 3 with OperationComponentModelModelProperty

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

the class XmlExtensionLoaderDelegate method extractOperationExtension.

private void extractOperationExtension(HasOperationDeclarer declarer, ComponentModel operationModel, DirectedGraph<String, DefaultEdge> directedGraph, XmlDslModel xmlDslModel) {
    String operationName = operationModel.getNameAttribute();
    OperationDeclarer operationDeclarer = declarer.withOperation(operationName);
    ComponentModel bodyComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_BODY_IDENTIFIER)).findFirst().orElseThrow(() -> new IllegalArgumentException(format("The operation '%s' is missing the <body> statement", operationName)));
    directedGraph.addVertex(operationName);
    fillGraphWithTnsReferences(directedGraph, operationName, bodyComponentModel.getInnerComponents());
    operationDeclarer.withModelProperty(new OperationComponentModelModelProperty(operationModel, bodyComponentModel));
    operationDeclarer.describedAs(getDescription(operationModel));
    operationDeclarer.getDeclaration().setDisplayModel(getDisplayModel(operationModel));
    extractOperationParameters(operationDeclarer, operationModel);
    extractOutputType(operationDeclarer.withOutput(), OPERATION_OUTPUT_IDENTIFIER, operationModel, getDeclarationOutputFor(operationName));
    extractOutputType(operationDeclarer.withOutputAttributes(), OPERATION_OUTPUT_ATTRIBUTES_IDENTIFIER, operationModel, getDeclarationOutputAttributesFor(operationName));
    declareErrorModels(operationDeclarer, xmlDslModel, operationName, operationModel);
}
Also used : HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)

Example 4 with OperationComponentModelModelProperty

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

the class XmlExtensionLoaderTestCase method testModuleSimple.

@Test
public void testModuleSimple() {
    String modulePath = "modules/module-simple.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-simple"));
    assertThat(extensionModel.getConfigurationModels().size(), is(0));
    assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
    assertThat(extensionModel.getOperationModels().size(), is(11));
    Optional<OperationModel> operationModelOptional = extensionModel.getOperationModel("set-payload-concat-params-values");
    assertThat(operationModelOptional.isPresent(), is(true));
    final OperationModel operationModel = operationModelOptional.get();
    assertThat(operationModel.getAllParameterModels().size(), is(4));
    assertThat(operationModel.getAllParameterModels().get(0).getName(), is("value1"));
    assertThat(operationModel.getAllParameterModels().get(1).getName(), is("value2"));
    assertThat(operationModel.getAllParameterModels().get(2).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(operationModel.getAllParameterModels().get(3).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    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(StringType.class));
    assertThat(operationModel.getOutputAttributes().getType().getMetadataFormat(), is(MetadataFormat.JAVA));
    assertThat(operationModel.getOutputAttributes().getType(), instanceOf(StringType.class));
    assertThat(operationModel.getErrorModels().size(), is(0));
}
Also used : StringType(org.mule.metadata.api.model.StringType) 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 OperationComponentModelModelProperty

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

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