Search in sources :

Example 1 with ElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ElementDeclarer in project mule by mulesoft.

the class DeclarationElementModelFactoryTestCase method testGlobalParameterDeclarationToElement.

@Test
public void testGlobalParameterDeclarationToElement() {
    ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
    final ParameterObjectValue.Builder value = newObjectValue().withParameter(BEHAVIOUR_NAME, "additional").withParameter(CONTENT_NAME, "#[{field: value}]");
    getId(complexType).ifPresent(value::ofType);
    TopLevelParameterDeclaration declaration = ext.newGlobalParameter(SOURCE_NAME).withRefName("globalParameter").withValue(value.build()).getDeclaration();
    DslElementModel<MetadataType> element = create(declaration);
    assertThat(element.getModel(), is(complexType));
    assertThat(element.getContainedElements().size(), is(2));
    assertThat(element.findElement(BEHAVIOUR_NAME).isPresent(), is(true));
    assertThat(element.findElement("myCamelCaseName").get().getValue().get(), is("#[{field: value}]"));
    assertThat(element.getConfiguration().get().getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) TopLevelParameterDeclaration(org.mule.runtime.app.declaration.api.TopLevelParameterDeclaration) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) Test(org.junit.Test)

Example 2 with ElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ElementDeclarer in project mule by mulesoft.

the class DeclarationElementModelFactoryTestCase method testOperationDeclarationToElement.

@Test
public void testOperationDeclarationToElement() {
    ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
    OperationElementDeclaration declaration = ext.newOperation(OPERATION_NAME).withConfig(CONFIGURATION_NAME).withParameterGroup(newParameterGroup().withParameter(CONTENT_NAME, "#[{field: value}]").withParameter(BEHAVIOUR_NAME, "additional").getDeclaration()).getDeclaration();
    DslElementModel<OperationModel> element = create(declaration);
    assertThat(element.getModel(), is(operation));
    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 : OperationElementDeclaration(org.mule.runtime.app.declaration.api.OperationElementDeclaration) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 3 with ElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ElementDeclarer in project mule by mulesoft.

the class DeclarationElementModelFactoryTestCase method testConfigDeclarationToElement.

@Test
public void testConfigDeclarationToElement() {
    ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
    ConfigurationElementDeclaration declaration = ext.newConfiguration(CONFIGURATION_NAME).withRefName("sample").withConnection(ext.newConnection(CONNECTION_PROVIDER_NAME).withParameterGroup(newParameterGroup().withParameter(CONTENT_NAME, "#[{field: value}]").withParameter(BEHAVIOUR_NAME, "additional").withParameter(LIST_NAME, newListValue().withValue("additional").build()).getDeclaration()).getDeclaration()).getDeclaration();
    DslElementModel<ConfigurationModel> element = create(declaration);
    assertThat(element.getModel(), is(configuration));
    assertThat(element.getContainedElements().size(), is(1));
    DslElementModel connectionElement = element.getContainedElements().get(0);
    assertThat(connectionElement.getContainedElements().size(), is(3));
    assertThat(element.findElement(LIST_NAME).isPresent(), is(true));
    DslElementModel<Object> listModel = element.findElement(LIST_NAME).get();
    assertThat(listModel.getContainedElements().size(), is(1));
    assertThat(listModel.getContainedElements().get(0).getDsl().getElementName(), is("list-name-item"));
    DslElementModel<Object> itemModel = listModel.getContainedElements().get(0);
    assertThat(itemModel.getContainedElements().get(0).getDsl().getAttributeName(), is(VALUE_ATTRIBUTE_NAME));
    assertThat(itemModel.getContainedElements().get(0).getValue().get(), is("additional"));
    assertThat(element.findElement(CONNECTION_PROVIDER_NAME).isPresent(), is(true));
    assertThat(element.findElement(CONTENT_NAME).get().getConfiguration().get().getValue().get(), is("#[{field: value}]"));
    assertThat(((ComponentConfiguration) connectionElement.getConfiguration().get()).getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
Also used : ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) Test(org.junit.Test)

Example 4 with ElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ElementDeclarer 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 5 with ElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ElementDeclarer in project mule by mulesoft.

the class DefaultXmlArtifactDeclarationLoader method declareAsConnectionProvider.

private boolean declareAsConnectionProvider(ExtensionModel ownerExtension, ConfigurationModel model, ConfigurationElementDeclarer configurationDeclarer, ConfigLine config, ElementDeclarer extensionElementsDeclarer) {
    final DslSyntaxResolver dsl = resolvers.get(getNamespace(config));
    Optional<ConnectionProviderModel> connectionProvider = model.getConnectionProviders().stream().filter(cp -> dsl.resolve(cp).getElementName().equals(config.getIdentifier())).findFirst();
    if (!connectionProvider.isPresent()) {
        connectionProvider = ownerExtension.getConnectionProviders().stream().filter(cp -> dsl.resolve(cp).getElementName().equals(config.getIdentifier())).findFirst();
    }
    if (!connectionProvider.isPresent()) {
        return true;
    }
    ConnectionProviderModel providerModel = connectionProvider.get();
    ConnectionElementDeclarer connectionDeclarer = extensionElementsDeclarer.newConnection(providerModel.getName());
    declareParameterizedComponent(providerModel, dsl.resolve(providerModel), connectionDeclarer, config.getConfigAttributes(), config.getChildren());
    configurationDeclarer.withConnection(connectionDeclarer.getDeclaration());
    return false;
}
Also used : Arrays(java.util.Arrays) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) TLS_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TLS_PARAMETER_NAME) MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) EXPIRATION_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.EXPIRATION_POLICY_ELEMENT_IDENTIFIER) REDELIVERY_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.REDELIVERY_POLICY_ELEMENT_IDENTIFIER) ArrayType(org.mule.metadata.api.model.ArrayType) Document(org.w3c.dom.Document) Map(java.util.Map) ParameterSimpleValue(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue) ParameterGroupElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer) MetadataTypeUtils.getLocalPart(org.mule.metadata.api.utils.MetadataTypeUtils.getLocalPart) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) RECONNECT_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_ELEMENT_IDENTIFIER) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) ElementDeclarer.newObjectValue(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newObjectValue) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) POOLING_PROFILE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.POOLING_PROFILE_PARAMETER_NAME) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) NON_REPEATABLE_BYTE_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.NON_REPEATABLE_BYTE_STREAM_ALIAS) XmlArtifactDeclarationLoader(org.mule.runtime.config.internal.dsl.model.XmlArtifactDeclarationLoader) ExtensionModelUtils.isInfrastructure(org.mule.runtime.extension.api.util.ExtensionModelUtils.isInfrastructure) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) CONFIG_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.CONFIG_ATTRIBUTE_NAME) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS) RouteElementDeclaration(org.mule.runtime.app.declaration.api.RouteElementDeclaration) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ParameterSimpleValue.cdata(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.cdata) ConfigurationElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConfigurationElementDeclarer) ParameterListValue(org.mule.runtime.app.declaration.api.fluent.ParameterListValue) ParameterSimpleValue.plain(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.plain) EXPIRATION_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.EXPIRATION_POLICY_PARAMETER_NAME) ConnectionElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConnectionElementDeclarer) ElementDeclarer.newListValue(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newListValue) XmlConfigurationDocumentLoader.noValidationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.noValidationDocumentLoader) ConstructElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConstructElementDeclarer) GlobalElementDeclaration(org.mule.runtime.app.declaration.api.GlobalElementDeclaration) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ParameterValue(org.mule.runtime.app.declaration.api.ParameterValue) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) RECONNECTION_CONFIG_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_CONFIG_PARAMETER_NAME) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) STREAMING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.STREAMING_STRATEGY_PARAMETER_NAME) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) Reference(org.mule.runtime.api.util.Reference) ParameterizedBuilder(org.mule.runtime.app.declaration.api.fluent.ParameterizedBuilder) ComponentElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer) ElementDeclarer.forExtension(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.forExtension) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) TLS_REVOCATION_CHECK_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.TLS_REVOCATION_CHECK_ELEMENT_IDENTIFIER) RECONNECT_FOREVER_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_FOREVER_ELEMENT_IDENTIFIER) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) HasNestedComponentDeclarer(org.mule.runtime.app.declaration.api.fluent.HasNestedComponentDeclarer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComposableModel(org.mule.runtime.api.meta.model.ComposableModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Collectors.toMap(java.util.stream.Collectors.toMap) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ArtifactDeclarer(org.mule.runtime.app.declaration.api.fluent.ArtifactDeclarer) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) TLS_CONTEXT_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.TLS_CONTEXT_ELEMENT_IDENTIFIER) REDELIVERY_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.REDELIVERY_POLICY_PARAMETER_NAME) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) CONNECTION(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.CONNECTION) RECONNECTION_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_STRATEGY_PARAMETER_NAME) NAME_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.NAME_ATTRIBUTE_NAME) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) Optional(java.util.Optional) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) POOLING_PROFILE_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.POOLING_PROFILE_ELEMENT_IDENTIFIER) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) RouteElementDeclarer(org.mule.runtime.app.declaration.api.fluent.RouteElementDeclarer) HashMap(java.util.HashMap) Function(java.util.function.Function) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) ElementDeclarer.newParameterGroup(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newParameterGroup) ParameterizedElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterizedElementDeclarer) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) TopLevelParameterDeclarer(org.mule.runtime.app.declaration.api.fluent.TopLevelParameterDeclarer) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) IS_CDATA(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.IS_CDATA) ComponentElementDeclaration(org.mule.runtime.app.declaration.api.ComponentElementDeclaration) ExtensibleTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ExtensibleTypeAnnotation) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) InputStream(java.io.InputStream) ConnectionElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConnectionElementDeclarer) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)

Aggregations

ElementDeclarer (org.mule.runtime.app.declaration.api.fluent.ElementDeclarer)8 MetadataType (org.mule.metadata.api.model.MetadataType)5 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)5 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)5 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 InputStream (java.io.InputStream)4 Arrays (java.util.Arrays)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 Collectors.toList (java.util.stream.Collectors.toList)4 Collectors.toMap (java.util.stream.Collectors.toMap)4 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)4 ArrayType (org.mule.metadata.api.model.ArrayType)4 ObjectType (org.mule.metadata.api.model.ObjectType)4