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"));
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations