Search in sources :

Example 21 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class DeclarationElementModelFactoryTestCase method testSourceDeclarationToElement.

@Test
public void testSourceDeclarationToElement() {
    ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
    SourceElementDeclaration declaration = ext.newSource(SOURCE_NAME).withConfig(CONFIGURATION_NAME).withParameterGroup(newParameterGroup().withParameter(BEHAVIOUR_NAME, "additional").withParameter(CONTENT_NAME, "#[{field: value}]").getDeclaration()).getDeclaration();
    DslElementModel<SourceModel> element = create(declaration);
    assertThat(element.getModel(), is(source));
    assertThat(element.getContainedElements().size(), is(2));
    assertThat(element.findElement(BEHAVIOUR_NAME).isPresent(), is(true));
    assertThat(element.findElement(CONTENT_NAME).get().getConfiguration().get().getValue().get(), is("#[{field: value}]"));
    assertThat(element.getConfiguration().get().getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) SourceElementDeclaration(org.mule.runtime.app.declaration.api.SourceElementDeclaration) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) Test(org.junit.Test)

Example 22 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class MetadataMediator method getTypedModel.

/**
 * Returns a {@link ComponentModel} with its types resolved.
 *
 * @param inputMetadataDescriptor {@link InputMetadataDescriptor} describes the input parameters of the component
 * @param outputMetadataDescriptor {@link OutputMetadataDescriptor} describes the component output
 * @return model with its types resolved by the metadata resolution process
 */
private T getTypedModel(InputMetadataDescriptor inputMetadataDescriptor, OutputMetadataDescriptor outputMetadataDescriptor) {
    Reference<T> typedModel = new Reference<>();
    component.accept(new ComponentModelVisitor() {

        @Override
        public void visit(ConstructModel constructModel) {
            typedModel.set((T) new ImmutableConstructModel(constructModel.getName(), constructModel.getDescription(), resolveParameterGroupModelType(constructModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), constructModel.getNestedComponents(), constructModel.allowsTopLevelDeclaration(), constructModel.getDisplayModel().orElse(null), constructModel.getErrorModels(), constructModel.getStereotype(), constructModel.getModelProperties()));
        }

        @Override
        public void visit(OperationModel operationModel) {
            OutputModel typedOutputModel = resolveOutputModelType(operationModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
            OutputModel typedAttributesModel = resolveOutputModelType(operationModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
            typedModel.set((T) new ImmutableOperationModel(operationModel.getName(), operationModel.getDescription(), resolveParameterGroupModelType(operationModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), operationModel.getNestedComponents(), typedOutputModel, typedAttributesModel, operationModel.isBlocking(), operationModel.getExecutionType(), operationModel.requiresConnection(), operationModel.isTransactional(), operationModel.supportsStreaming(), operationModel.getDisplayModel().orElse(null), operationModel.getErrorModels(), operationModel.getStereotype(), operationModel.getModelProperties(), operationModel.getNotificationModels()));
        }

        @Override
        public void visit(SourceModel sourceModel) {
            OutputModel typedOutputModel = resolveOutputModelType(sourceModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
            OutputModel typedAttributesModel = resolveOutputModelType(sourceModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
            typedModel.set((T) new ImmutableSourceModel(sourceModel.getName(), sourceModel.getDescription(), sourceModel.hasResponse(), true, resolveParameterGroupModelType(sourceModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), sourceModel.getNestedComponents(), typedOutputModel, typedAttributesModel, resolveSourceCallbackType(sourceModel.getSuccessCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getErrorCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getTerminateCallback(), inputMetadataDescriptor.getAllParameters()), sourceModel.requiresConnection(), sourceModel.isTransactional(), sourceModel.supportsStreaming(), sourceModel.getDisplayModel().orElse(null), sourceModel.getStereotype(), sourceModel.getErrorModels(), sourceModel.getModelProperties(), sourceModel.getNotificationModels()));
        }
    });
    return typedModel.get();
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ImmutableConstructModel(org.mule.runtime.extension.api.model.construct.ImmutableConstructModel) ImmutableOperationModel(org.mule.runtime.extension.api.model.operation.ImmutableOperationModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) Reference(org.mule.runtime.api.util.Reference) ComponentModelVisitor(org.mule.runtime.api.meta.model.ComponentModelVisitor) ImmutableConstructModel(org.mule.runtime.extension.api.model.construct.ImmutableConstructModel) ImmutableOutputModel(org.mule.runtime.extension.api.model.ImmutableOutputModel) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ImmutableOperationModel(org.mule.runtime.extension.api.model.operation.ImmutableOperationModel)

Example 23 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method sourceOnSuccessCustomType.

@Test
public void sourceOnSuccessCustomType() {
    SourceModel s = getSource("custom-static-metadata");
    assertXmlOrder(s.getSuccessCallback().get().getAllParameterModels().get(0));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Test(org.junit.Test)

Example 24 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method sourceOnErrorCustomType.

@Test
public void sourceOnErrorCustomType() {
    SourceModel s = getSource("custom-static-metadata");
    assertJsonPerson(s.getErrorCallback().get().getAllParameterModels().get(0));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Test(org.junit.Test)

Example 25 with SourceModel

use of org.mule.runtime.api.meta.model.source.SourceModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method sourceNameClashesWithSourceName.

@Test
public void sourceNameClashesWithSourceName() {
    exception.expect(IllegalModelDefinitionException.class);
    SourceModel anotherSourceModel = mock(SourceModel.class);
    when(anotherSourceModel.getName()).thenReturn(SOURCE_NAME);
    when(anotherSourceModel.getErrorCallback()).thenReturn(empty());
    when(anotherSourceModel.getSuccessCallback()).thenReturn(empty());
    when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel, anotherSourceModel));
    validate();
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)25 Test (org.junit.Test)14 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)13 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)12 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)9 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)8 SmallTest (org.mule.tck.size.SmallTest)8 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)7 List (java.util.List)6 Optional (java.util.Optional)6 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)6 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)6 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)6 Collectors.toList (java.util.stream.Collectors.toList)5 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)5 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)5 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)5 Reference (org.mule.runtime.api.util.Reference)5 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)4 ObjectType (org.mule.metadata.api.model.ObjectType)4