use of org.mule.runtime.api.component.ConfigurationProperties in project mule by mulesoft.
the class ApplicationModel method createConfigurationAttributeResolver.
private void createConfigurationAttributeResolver(ArtifactConfig artifactConfig, Optional<ConfigurationProperties> parentConfigurationProperties, Map<String, String> deploymentProperties) {
EnvironmentPropertiesConfigurationProvider environmentPropertiesConfigurationProvider = new EnvironmentPropertiesConfigurationProvider();
ConfigurationPropertiesProvider globalPropertiesConfigurationAttributeProvider = createProviderFromGlobalProperties(artifactConfig);
DefaultConfigurationPropertiesResolver localResolver = new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(empty(), environmentPropertiesConfigurationProvider)), globalPropertiesConfigurationAttributeProvider)), environmentPropertiesConfigurationProvider);
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = getConfigurationPropertiesProvidersFromComponents(artifactConfig, localResolver);
FileConfigurationPropertiesProvider externalPropertiesConfigurationProvider = new FileConfigurationPropertiesProvider(externalResourceProvider, "External files");
Optional<ConfigurationPropertiesResolver> parentConfigurationPropertiesResolver = of(localResolver);
if (parentConfigurationProperties.isPresent()) {
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(empty(), new ConfigurationPropertiesProvider() {
@Override
public Optional<ConfigurationProperty> getConfigurationProperty(String configurationAttributeKey) {
return parentConfigurationProperties.get().resolveProperty(configurationAttributeKey).map(value -> new DefaultConfigurationProperty(parentConfigurationProperties, configurationAttributeKey, value));
}
@Override
public String getDescription() {
return "Domain properties";
}
}));
}
if (!configConfigurationPropertiesProviders.isEmpty()) {
CompositeConfigurationPropertiesProvider configurationAttributesProvider = new CompositeConfigurationPropertiesProvider(configConfigurationPropertiesProviders);
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, configurationAttributesProvider));
}
DefaultConfigurationPropertiesResolver globalPropertiesConfigurationPropertiesResolver = new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, globalPropertiesConfigurationAttributeProvider);
DefaultConfigurationPropertiesResolver systemPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(globalPropertiesConfigurationPropertiesResolver), environmentPropertiesConfigurationProvider);
DefaultConfigurationPropertiesResolver externalPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(systemPropertiesResolver), externalPropertiesConfigurationProvider);
if (deploymentProperties.isEmpty()) {
this.configurationProperties = new PropertiesResolverConfigurationProperties(externalPropertiesResolver);
} else {
this.configurationProperties = new PropertiesResolverConfigurationProperties(new DefaultConfigurationPropertiesResolver(of(externalPropertiesResolver), new MapConfigurationPropertiesProvider(deploymentProperties, "Deployment properties")));
}
}
use of org.mule.runtime.api.component.ConfigurationProperties in project mule by mulesoft.
the class MuleContextUtils method mockContextWithServices.
/**
* Creates and configures a mock {@link MuleContext} to return testing services implementations.
*
* @return the created {@code muleContext}.
*/
public static MuleContextWithRegistries mockContextWithServices() {
final MuleContextWithRegistries muleContext = mockMuleContext();
SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
when(muleContext.getSchedulerService()).thenReturn(schedulerService);
ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
final MuleRegistry registry = muleContext.getRegistry();
NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
ConfigurationProperties configProps = mock(ConfigurationProperties.class);
when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
try {
when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
Map<Class, Object> injectableObjects = new HashMap<>();
injectableObjects.put(MuleContext.class, muleContext);
injectableObjects.put(SchedulerService.class, schedulerService);
injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
injectableObjects.put(ConfigurationProperties.class, configProps);
// Ensure injection of consistent mock objects
when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
} catch (RegistrationException e1) {
throw new MuleRuntimeException(e1);
}
return muleContext;
}
use of org.mule.runtime.api.component.ConfigurationProperties in project mule by mulesoft.
the class ApplicationDeploymentTestCase method appHomePropertyIsPresent.
@Test
public void appHomePropertyIsPresent() throws Exception {
final ApplicationFileBuilder globalPropertyAppFileBuilder = new ApplicationFileBuilder("property-app").definedBy("app-properties-config.xml");
addExplodedAppFromBuilder(globalPropertyAppFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, globalPropertyAppFileBuilder.getId());
final Application app = findApp(globalPropertyAppFileBuilder.getId(), 1);
Optional<ConfigurationProperties> configurationProperties = app.getRegistry().lookupByType(ConfigurationProperties.class);
assertThat(configurationProperties.isPresent(), is(true));
String appHome = configurationProperties.get().resolveStringProperty("appHome").orElseThrow(() -> new RuntimeException("Could not find property appHome"));
assertThat(new File(appHome).exists(), is(true));
}
Aggregations