use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class SourceAdapter method setConnection.
private void setConnection() throws MuleException {
if (!connectionSetter.isPresent()) {
return;
}
FieldSetter<Object, ConnectionProvider> setter = connectionSetter.get();
ConfigurationInstance config = configurationInstance.orElseThrow(() -> new DefaultMuleException(createStaticMessage("Message Source on root component '%s' requires a connection but it doesn't point to any configuration. Please review your " + "application", component.getLocation().getRootContainerName())));
if (!config.getConnectionProvider().isPresent()) {
throw new DefaultMuleException(createStaticMessage(format("Message Source on root component '%s' requires a connection, but points to config '%s' which doesn't specify any. " + "Please review your application", component.getLocation().getRootContainerName(), config.getName())));
}
ConnectionProvider<Object> connectionProvider = new SourceConnectionProvider(connectionManager, config);
setter.set(sourceInvokationTarget.get(), connectionProvider);
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class DefaultExtensionManagerTestCase method getOperationExecutorThroughImplicitConfigurationConcurrently.
@Test
public void getOperationExecutorThroughImplicitConfigurationConcurrently() throws Exception {
final int threadCount = 2;
final CountDownLatch joinerLatch = new CountDownLatch(threadCount);
MuleRegistry registry = muleContext.getRegistry();
when(extension1ConfigurationModel.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty());
doAnswer(invocation -> {
registerIntoMockContext(muleContext, getImplicitConfigurationProviderName(extensionModel1, extension1ConfigurationModel), extension1ConfigurationProvider);
new Thread(() -> extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event)).start();
joinerLatch.countDown();
return null;
}).when(registry).registerObject(anyString(), anyObject());
Optional<ConfigurationInstance> configurationInstance = extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event);
joinerLatch.countDown();
assertThat(configurationInstance.isPresent(), is(true));
assertThat(joinerLatch.await(5, TimeUnit.SECONDS), is(true));
assertThat(configurationInstance.get().getValue(), is(sameInstance(configInstance)));
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class ConfigurationInstanceFactoryTestCase method createFromEvent.
@Test
public void createFromEvent() throws Exception {
ConfigurationInstance configurationInstance = factory.createConfiguration(CONFIG_NAME, event, connectionProviderValueResolver);
assertConfiguration(configurationInstance);
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method failsToObtainMissingConfigurationFromModel.
@Test
public void failsToObtainMissingConfigurationFromModel() 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.getConfiguration(childExtension, operationModel, event)).thenReturn(empty());
when(childExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
expectedException.expect(IllegalArgumentException.class);
extensionManager.getConfiguration(childExtension, operationModel, event);
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method returnsConfigurationFromModel.
@Test
public void returnsConfigurationFromModel() 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.getConfiguration(childExtension, operationModel, event)).thenReturn(ofNullable(configurationInstance));
when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
Optional<ConfigurationInstance> configuration = extensionManager.getConfiguration(childExtension, operationModel, event);
assertThat(configuration.isPresent(), is(true));
assertThat(configuration.get(), is(configurationInstance));
}
Aggregations