use of org.mule.runtime.api.meta.model.ExtensionModel 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.api.meta.model.ExtensionModel in project mule by mulesoft.
the class XmlExtensionLoaderTestCase method getExtensionModelFrom.
/**
* If {@link #validateXml} is true, the XML of the smart connector must be validated when reading it. False otherwise. Useful to
* simulate the {@link ExtensionModel} generation of a connector that has malformed message processors in the <body/> element.
*
* @param modulePath relative path to the XML connector.
* @return an {@link ExtensionModel}
*/
private ExtensionModel getExtensionModelFrom(String modulePath) {
Map<String, Object> parameters = new HashMap<>();
parameters.put(RESOURCE_XML, modulePath);
parameters.put(XmlExtensionModelLoader.VALIDATE_XML, validateXml);
final ExtensionModel extensionModel = new XmlExtensionModelLoader().loadExtensionModel(getClass().getClassLoader(), getDefault(getDependencyExtensions()), parameters);
assertNoReconnectionIsAdded(extensionModel);
return extensionModel;
}
use of org.mule.runtime.api.meta.model.ExtensionModel 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.api.meta.model.ExtensionModel in project mule by mulesoft.
the class XmlExtensionLoaderWithDeclarationTestCase method assertModule.
private void assertModule(Optional<String> declarationPath, DeclarationOperation declaresOutput, DeclarationOperation declaresAttributes, DeclarationOperation declaresOutputAndAttributes, DeclarationOperation declaresNothing) {
final ExtensionModel extensionModel = getExtensionModelFrom(declarationPath);
assertThat(extensionModel.getName(), is("module-declarer-datasense"));
assertThat(extensionModel.getConfigurationModels().size(), is(0));
assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
assertThat(extensionModel.getOperationModels().size(), is(4));
assertOperation("op-declares-output", extensionModel, declaresOutput, format(DOC_OUTPUT_FORMAT, "op-declares-output"), "");
assertOperation("op-declares-attributes", extensionModel, declaresAttributes, "", format(DOC_OUTPUT_ATTRIBUTE_FORMAT, "op-declares-attributes"));
assertOperation("op-declares-output-and-attributes", extensionModel, declaresOutputAndAttributes, format(DOC_OUTPUT_FORMAT, "op-declares-output-and-attributes"), format(DOC_OUTPUT_ATTRIBUTE_FORMAT, "op-declares-output-and-attributes"));
assertOperation("op-declares-nothing", extensionModel, declaresNothing, "", "");
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DefaultModelValidatorTestCase method getDependencyExtensions.
private Set<ExtensionModel> getDependencyExtensions() {
ExtensionModel petstore = loadExtension(PetStoreConnector.class, emptySet());
ExtensionModel heisenberg = loadExtension(HeisenbergExtension.class, emptySet());
return ImmutableSet.<ExtensionModel>builder().add(petstore, heisenberg).build();
}
Aggregations