Search in sources :

Example 21 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class DefaultExtensionModelFactoryTestCase method exportedLibraries.

@Test
public void exportedLibraries() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    assertExternalLibraries(extensionModel);
    new IdempotentExtensionWalker() {

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            assertExternalLibraries(model);
        }

        @Override
        protected void onConnectionProvider(ConnectionProviderModel model) {
            assertExternalLibraries(model);
        }
    }.walk(extensionModel);
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 22 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class ConfigurationModelValidator method validateInjectedConfigType.

private void validateInjectedConfigType(HasOperationModels owner, OperationModel operationModel, ProblemsReporter problemsReporter) {
    if (owner instanceof ConfigurationModel) {
        Class<?> configType = getConfigurationFactory((ConfigurationModel) owner).getObjectType();
        Optional<Class<?>> operationConfigParameterType = operationModel.getModelProperty(ConfigTypeModelProperty.class).map(modelProperty -> modelProperty.getConfigType());
        if (operationConfigParameterType.isPresent() && !operationConfigParameterType.get().isAssignableFrom(configType)) {
            problemsReporter.addError(new Problem(operationModel, format("Operation '%s' requires a configuration of type '%s'. However, the operation is " + "reachable from configuration '%s' of incompatible type '%s'.", operationModel.getName(), operationConfigParameterType.get().getName(), ((ConfigurationModel) owner).getName(), configType.getName())));
        }
    }
}
Also used : ConfigTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConfigTypeModelProperty) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Problem(org.mule.runtime.extension.api.loader.Problem)

Example 23 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class DeclarationElementModelFactoryTestCase method testConfigNoParams.

@Test
public void testConfigNoParams() {
    ConfigurationElementDeclaration declaration = ElementDeclarer.forExtension(EXTENSION_NAME).newConfiguration(CONFIGURATION_NAME).withRefName("sample").getDeclaration();
    DslElementModel<ConfigurationModel> element = create(declaration);
    assertThat(element.getModel(), is(configuration));
    assertThat(element.getContainedElements().isEmpty(), is(true));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) Test(org.junit.Test)

Example 24 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel 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 25 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method findTestConnectionGlobalElementFrom.

/**
 * Goes over all {@code globalElementsComponentModel} looking for the configuration and connection elements (parent and child),
 * where if present looks for the {@link ExtensionModel}s validating if the element is in fact a {@link ConnectionProvider}.
 * It heavily relies on the {@link DslSyntaxResolver}, as many elements in the XML do not match to the names of the model.
 *
 * @param globalElementsComponentModel global elements of the smart connector
 * @param extensions set of extensions used to generate the current {@link ExtensionModel}
 * @return a {@link ComponentModel} of the global element to do test connection, empty otherwise.
 */
private Optional<ComponentModel> findTestConnectionGlobalElementFrom(List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
    Optional<ComponentModel> testConnectionGlobalElement;
    final DslResolvingContext dslResolvingContext = DslResolvingContext.getDefault(extensions);
    final Set<ComponentModel> testConnectionComponentModels = new HashSet<>();
    for (ComponentModel globalElementComponentModel : globalElementsComponentModel) {
        for (ComponentModel connectionProviderChildElement : globalElementComponentModel.getInnerComponents()) {
            final String globalElementConfigurationModelName = globalElementComponentModel.getIdentifier().getName();
            final String childConnectionProviderName = connectionProviderChildElement.getIdentifier().getName();
            for (ExtensionModel extensionModel : extensions) {
                final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, dslResolvingContext);
                for (ConfigurationModel configurationModel : extensionModel.getConfigurationModels()) {
                    if (dslSyntaxResolver.resolve(configurationModel).getElementName().equals(globalElementConfigurationModelName)) {
                        for (ConnectionProviderModel connectionProviderModel : configurationModel.getConnectionProviders()) {
                            if (dslSyntaxResolver.resolve(connectionProviderModel).getElementName().equals(childConnectionProviderName)) {
                                testConnectionComponentModels.add(globalElementComponentModel);
                            }
                        }
                    }
                }
            }
        }
    }
    if (testConnectionComponentModels.size() > 1) {
        throw new MuleRuntimeException(createStaticMessage(format("There are [%d] global elements that can be potentially used for test connection when it should be just one. Mark any of them with the attribute [%s=\"true\"], offended global elements are: [%s]", testConnectionComponentModels.size(), MODULE_CONNECTION_MARKER_ATTRIBUTE, testConnectionComponentModels.stream().map(ComponentModel::getNameAttribute).sorted().collect(Collectors.joining(", ")))));
    }
    testConnectionGlobalElement = testConnectionComponentModels.stream().findFirst();
    return testConnectionGlobalElement;
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) HashSet(java.util.HashSet)

Aggregations

ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)35 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)19 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)16 Test (org.junit.Test)15 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)13 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)11 Optional (java.util.Optional)9 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)9 List (java.util.List)8 Set (java.util.Set)7 ObjectType (org.mule.metadata.api.model.ObjectType)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)7 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 MetadataType (org.mule.metadata.api.model.MetadataType)6