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));
}
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));
}
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);
}
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));
}
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));
}
}
Aggregations