use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method bindFoo.
private Foo bindFoo(final String values) throws Exception {
Properties properties = PropertiesLoaderUtils.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method testBindWithDelimitedPrefixUsingDifferentDelimiter.
@Test
public void testBindWithDelimitedPrefixUsingDifferentDelimiter() throws Exception {
this.targetName = "env.foo";
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.<String, Object>singletonMap("ENV_FOO_NAME", "blah")));
propertySources.addLast(new RandomValuePropertySource("random"));
this.ignoreUnknownFields = false;
setupFactory();
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
Foo foo = this.factory.getObject();
assertThat(foo.name).isEqualTo("blah");
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class EnableConfigurationPropertiesTests method removeSystemProperties.
/**
* Strict tests need a known set of properties so we remove system items which may be
* environment specific.
*/
private void removeSystemProperties() {
MutablePropertySources sources = this.context.getEnvironment().getPropertySources();
sources.remove("systemProperties");
sources.remove("systemEnvironment");
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class RelaxedPropertyResolverTests method testPropertySource.
@Test
public void testPropertySource() throws Exception {
Properties properties;
PropertiesPropertySource propertySource;
String propertyPrefix = "spring.datasource.";
String propertyName = "password";
String fullPropertyName = propertyPrefix + propertyName;
StandardEnvironment environment = new StandardEnvironment();
MutablePropertySources sources = environment.getPropertySources();
properties = new Properties();
properties.put(fullPropertyName, "systemPassword");
propertySource = new PropertiesPropertySource("system", properties);
sources.addLast(propertySource);
properties = new Properties();
properties.put(fullPropertyName, "propertiesPassword");
propertySource = new PropertiesPropertySource("properties", properties);
sources.addLast(propertySource);
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, propertyPrefix);
String directProperty = propertyResolver.getProperty(propertyName);
Map<String, Object> subProperties = propertyResolver.getSubProperties("");
String subProperty = (String) subProperties.get(propertyName);
assertThat(subProperty).isEqualTo(directProperty);
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method matchingPropertySource.
private Condition<ConfigurableEnvironment> matchingPropertySource(final String sourceName) {
return new Condition<ConfigurableEnvironment>("environment containing property source " + sourceName) {
@Override
public boolean matches(ConfigurableEnvironment value) {
MutablePropertySources sources = new MutablePropertySources(value.getPropertySources());
ConfigurationPropertySources.finishAndRelocate(sources);
return sources.contains(sourceName);
}
};
}
Aggregations