Search in sources :

Example 96 with ParameterModel

use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.

the class ExportedArtifactsCollectorTestCase method mockParameterModel.

private ParameterModel mockParameterModel(Type type) {
    ParameterModel pm = mock(ParameterModel.class);
    when(pm.getType()).thenReturn(loader.load(type));
    return pm;
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel)

Example 97 with ParameterModel

use of org.mule.runtime.api.meta.model.parameter.ParameterModel 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)

Example 98 with ParameterModel

use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.

the class XmlExtensionLoaderTestCase method testModuleJsonCustomTypes.

@Test
public void testModuleJsonCustomTypes() throws IOException {
    String modulePath = "modules/module-json-custom-types.xml";
    ExtensionModel extensionModel = getExtensionModelFrom(modulePath);
    assertThat(extensionModel.getName(), is("module-json-custom-types"));
    assertThat(extensionModel.getConfigurationModels().size(), is(0));
    assertThat(extensionModel.getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent(), is(false));
    assertThat(extensionModel.getOperationModels().size(), is(8));
    Optional<OperationModel> operationModel = extensionModel.getOperationModel("operation-with-custom-types");
    assertThat(operationModel.isPresent(), is(true));
    final OperationModel operation = operationModel.get();
    assertThat(operation.getAllParameterModels().size(), is(3));
    final ParameterModel parameterValueModel = operation.getAllParameterModels().get(0);
    assertThat(parameterValueModel.getName(), is("value"));
    assertThat(operation.getAllParameterModels().get(1).getName(), is(TARGET_PARAMETER_NAME));
    assertThat(operation.getAllParameterModels().get(2).getName(), is(TARGET_VALUE_PARAMETER_NAME));
    assertThat(parameterValueModel.getType().getMetadataFormat(), is(MetadataFormat.JSON));
    assertThat(parameterValueModel.getType(), instanceOf(ObjectType.class));
    assertThat(((ObjectType) parameterValueModel.getType()).getFields().size(), is(2));
    assertThat(operation.getOutput().getType().getMetadataFormat(), is(MetadataFormat.JSON));
    assertThat(operation.getOutput().getType(), instanceOf(ObjectType.class));
    assertThat(((ObjectType) operation.getOutput().getType()).getFields().size(), is(3));
    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 99 with ParameterModel

use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method withInputXmlStaticType.

@Test
public void withInputXmlStaticType() throws Exception {
    OperationModel o = getOperation("xmlInput");
    ParameterModel param = o.getAllParameterModels().get(0);
    assertXmlOrder(param);
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 100 with ParameterModel

use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method withInputJsonType.

@Test
public void withInputJsonType() throws Exception {
    OperationModel o = getOperation("jsonInputStream");
    ParameterModel param = o.getAllParameterModels().get(0);
    assertJsonPerson(param);
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Aggregations

ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)133 Test (org.junit.Test)91 SmallTest (org.mule.tck.size.SmallTest)68 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)21 List (java.util.List)19 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)19 Optional (java.util.Optional)16 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 Collectors.toList (java.util.stream.Collectors.toList)13 ObjectType (org.mule.metadata.api.model.ObjectType)13 String.format (java.lang.String.format)12 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)12 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)12 ExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory)12 StringType (org.mule.metadata.api.model.StringType)11 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)10 ArrayType (org.mule.metadata.api.model.ArrayType)10 MetadataType (org.mule.metadata.api.model.MetadataType)10 Map (java.util.Map)9