use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method loadModuleExtension.
private void loadModuleExtension(ExtensionDeclarer declarer, URL resource, Document moduleDocument, Set<ExtensionModel> extensions, boolean comesFromTNS) {
final ComponentModel moduleModel = getModuleComponentModel(resource, moduleDocument);
if (!moduleModel.getIdentifier().equals(MODULE_IDENTIFIER)) {
throw new MuleRuntimeException(createStaticMessage(format("The root element of a module must be '%s', but found '%s'", MODULE_IDENTIFIER.toString(), moduleModel.getIdentifier().toString())));
}
final String name = moduleModel.getParameters().get(MODULE_NAME);
// TODO(fernandezlautaro): MULE-11010 remove version from ExtensionModel
final String version = "4.0.0";
final String category = moduleModel.getParameters().get(CATEGORY);
final String vendor = moduleModel.getParameters().get(VENDOR);
final XmlDslModel xmlDslModel = getXmlDslModel(moduleModel, name, version);
final String description = getDescription(moduleModel);
final String xmlnsTnsValue = moduleModel.getParameters().get(XMLNS_TNS);
if (xmlnsTnsValue != null && !xmlDslModel.getNamespace().equals(xmlnsTnsValue)) {
throw new MuleRuntimeException(createStaticMessage(format("The %s attribute value of the module must be '%s', but found '%s'", XMLNS_TNS, xmlDslModel.getNamespace(), xmlnsTnsValue)));
}
fillDeclarer(declarer, name, version, category, vendor, xmlDslModel, description);
declarer.withModelProperty(getXmlExtensionModelProperty(moduleModel, xmlDslModel));
DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
// loading public operations
final Optional<ConfigurationDeclarer> configurationDeclarer = loadPropertiesFrom(declarer, moduleModel, extensions);
final HasOperationDeclarer hasOperationDeclarer = configurationDeclarer.isPresent() ? configurationDeclarer.get() : declarer;
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PUBLIC);
// loading private operations
if (comesFromTNS) {
// when parsing for the TNS, we need the <operation/>s to be part of the extension model to validate the XML properly
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
} else {
// when parsing for the macro expansion, the <operation/>s will be left in the PrivateOperationsModelProperty model property
final ExtensionDeclarer temporalDeclarer = new ExtensionDeclarer();
fillDeclarer(temporalDeclarer, name, version, category, vendor, xmlDslModel, description);
loadOperationsFrom(temporalDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
final ExtensionModel result = createExtensionModel(temporalDeclarer);
declarer.withModelProperty(new PrivateOperationsModelProperty(result.getOperationModels()));
}
final CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(directedGraph);
final Set<String> cycles = cycleDetector.findCycles();
if (!cycles.isEmpty()) {
throw new MuleRuntimeException(createStaticMessage(format(CYCLIC_OPERATIONS_ERROR, new TreeSet(cycles))));
}
}
use of org.mule.runtime.api.meta.model.ExtensionModel 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.api.meta.model.ExtensionModel 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));
}
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class XmlExtensionLoaderTestCase method testModuleCallingOperationsWithinModule.
@Test
public void testModuleCallingOperationsWithinModule() {
String modulePath = "modules/module-calling-operations-within-module.xml";
ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
assertThat(extensionModel.getName(), is("module-calling-operations-within-module"));
assertThat(extensionModel.getConfigurationModels().size(), is(0));
assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
assertThat(extensionModel.getOperationModels().size(), is(11));
}
use of org.mule.runtime.api.meta.model.ExtensionModel 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));
}
Aggregations