use of org.mule.runtime.api.meta.model.connection.ConnectionProviderModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method testeableConnectionProvider.
@Test
public void testeableConnectionProvider() throws Exception {
ExtensionModel extensionModel = createExtension(VeganExtension.class);
ConnectionProviderModel connectionProviderModel = extensionModel.getConfigurationModel(BANANA).map(c -> c.getConnectionProviders().get(0)).get();
assertThat(connectionProviderModel.supportsConnectivityTesting(), is(true));
}
use of org.mule.runtime.api.meta.model.connection.ConnectionProviderModel 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;
}
use of org.mule.runtime.api.meta.model.connection.ConnectionProviderModel 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;
}
use of org.mule.runtime.api.meta.model.connection.ConnectionProviderModel in project mule by mulesoft.
the class NameClashModelValidatorTestCase method connectionProviderNameClashesWithAnotherConnectionProviderName.
@Test
public void connectionProviderNameClashesWithAnotherConnectionProviderName() {
exception.expect(IllegalModelDefinitionException.class);
ConnectionProviderModel anotherConnectionProviderModel = mock(ConnectionProviderModel.class);
when(anotherConnectionProviderModel.getName()).thenReturn(CONNECTION_PROVIDER_NAME);
when(extensionModel.getConnectionProviders()).thenReturn(asList(connectionProviderModel, anotherConnectionProviderModel));
validate();
}
Aggregations