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