use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsParentConfigurationProviderFromProviderName.
@Test
public void returnsParentConfigurationProviderFromProviderName() throws Exception {
ExtensionModel parentExtension = mock(ExtensionModel.class);
Set<ExtensionModel> parentExtensions = singleton(parentExtension);
when(parentExtensionManager.getExtensions()).thenReturn(parentExtensions);
when(childExtensionManager.getExtensions()).thenReturn(emptySet());
CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
ConfigurationProvider parentConfigurationProvider = mock(ConfigurationProvider.class);
when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(parentConfigurationProvider));
when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
Optional<ConfigurationProvider> configurationProvider = extensionManager.getConfigurationProvider(PROVIDER_NAME);
assertThat(configurationProvider.get(), is(parentConfigurationProvider));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsParentConfigurationProviderFromModel.
@Test
public void returnsParentConfigurationProviderFromModel() throws Exception {
ExtensionModel parentExtension = mock(ExtensionModel.class);
Set<ExtensionModel> parentExtensions = singleton(parentExtension);
when(parentExtensionManager.getExtensions()).thenReturn(parentExtensions);
when(childExtensionManager.getExtensions()).thenReturn(emptySet());
CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
ConfigurationProvider parentConfigurationProvider = mock(ConfigurationProvider.class);
when(parentExtensionManager.getConfigurationProvider(parentExtension, operationModel)).thenReturn(of(parentConfigurationProvider));
when(childExtensionManager.getConfigurationProvider(parentExtension, operationModel)).thenReturn(empty());
Optional<ConfigurationProvider> configurationProvider = extensionManager.getConfigurationProvider(parentExtension, operationModel);
assertThat(configurationProvider.get(), is(parentConfigurationProvider));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsChildConfigurationProviderFromModel.
@Test
public void returnsChildConfigurationProviderFromModel() throws Exception {
ExtensionModel childExtension = mock(ExtensionModel.class);
Set<ExtensionModel> childExtensions = singleton(childExtension);
when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
when(childExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(of(childConfigurationProvider));
when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
Optional<ConfigurationProvider> configurationProvider = extensionManager.getConfigurationProvider(childExtension, operationModel);
assertThat(configurationProvider.get(), is(childConfigurationProvider));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsConfigurationFromProviderName.
@Test
public void returnsConfigurationFromProviderName() throws Exception {
ExtensionModel childExtension = mock(ExtensionModel.class);
Set<ExtensionModel> childExtensions = singleton(childExtension);
when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
CoreEvent event = mock(CoreEvent.class);
ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(childConfigurationProvider));
when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
ConfigurationInstance configuration = extensionManager.getConfiguration(PROVIDER_NAME, event);
assertThat(configuration, is(configurationInstance));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.
the class ExtensionComponent method getMetadataContext.
private MetadataContext getMetadataContext() throws MetadataResolvingException {
CoreEvent fakeEvent = null;
try {
fakeEvent = getInitialiserEvent(muleContext);
Optional<ConfigurationInstance> configuration = getConfiguration(fakeEvent);
if (configuration.isPresent()) {
ConfigurationProvider configurationProvider = findConfigurationProvider().orElseThrow(() -> new MetadataResolvingException("Failed to create the required configuration for Metadata retrieval", INVALID_CONFIGURATION));
if (configurationProvider instanceof DynamicConfigurationProvider) {
throw new MetadataResolvingException("Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION);
}
}
String cacheId = configuration.map(ConfigurationInstance::getName).orElseGet(() -> extensionModel.getName() + "|" + componentModel.getName());
return new DefaultMetadataContext(() -> configuration, connectionManager, metadataService.getMetadataCache(cacheId), typeLoader);
} finally {
if (fakeEvent != null) {
((BaseEventContext) fakeEvent.getContext()).success();
}
}
}
Aggregations