Search in sources :

Example 61 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class ExportedArtifactsCollectorTestCase method mockOperationModel.

private OperationModel mockOperationModel(OutputModel output, OutputModel attributes, ParameterModel... params) {
    OperationModel op = mock(OperationModel.class);
    when(op.getOutput()).thenReturn(output);
    when(op.getOutputAttributes()).thenReturn(attributes);
    if (params != null) {
        mockParameters(op, params);
    }
    return op;
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 62 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class OperationExecutorFactoryWrapperTestCase method mockOperation.

private OperationModel mockOperation(boolean blocking) {
    OperationModel operationModel = mock(OperationModel.class);
    when(operationModel.isBlocking()).thenReturn(blocking);
    return operationModel;
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 63 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel 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 64 with OperationModel

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

Example 65 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel 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));
}
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)

Aggregations

OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)96 Test (org.junit.Test)68 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)27 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)15 SmallTest (org.mule.tck.size.SmallTest)14 Optional (java.util.Optional)13 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)12 MetadataType (org.mule.metadata.api.model.MetadataType)11 List (java.util.List)10 Set (java.util.Set)9 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)9 Optional.empty (java.util.Optional.empty)8 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)8 ObjectType (org.mule.metadata.api.model.ObjectType)7 OutputModel (org.mule.runtime.api.meta.model.OutputModel)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6