use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class DevToolsHomePropertiesPostProcessorTests method ignoresMissingHomeProperties.
@Test
public void ignoresMissingHomeProperties() throws Exception {
ConfigurableEnvironment environment = new MockEnvironment();
MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor();
postProcessor.postProcessEnvironment(environment, null);
assertThat(environment.getProperty("abc")).isNull();
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class ConfigurationPropertiesBindingPostProcessor method deducePropertySources.
private PropertySources deducePropertySources() {
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
if (configurer != null) {
// Flatten the sources into a single list so they can be iterated
return new FlatPropertySources(configurer.getAppliedPropertySources());
}
if (this.environment instanceof ConfigurableEnvironment) {
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
return new FlatPropertySources(propertySources);
}
// empty, so not very useful, but fulfils the contract
logger.warn("Unable to obtain PropertySources from " + "PropertySourcesPlaceholderConfigurer or Environment");
return new MutablePropertySources();
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class SpringApplicationBuilderTests method propertiesWithRepeatSeparator.
@Test
public void propertiesWithRepeatSeparator() throws Exception {
SpringApplicationBuilder application = new SpringApplicationBuilder().sources(ExampleConfig.class).contextClass(StaticApplicationContext.class).properties("one=c:\\logging.file", "two=a:b", "three:c:\\logging.file", "four:a:b");
this.context = application.run();
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.getProperty("one")).isEqualTo("c:\\logging.file");
assertThat(environment.getProperty("two")).isEqualTo("a:b");
assertThat(environment.getProperty("three")).isEqualTo("c:\\logging.file");
assertThat(environment.getProperty("four")).isEqualTo("a:b");
}
use of org.springframework.core.env.ConfigurableEnvironment 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);
}
};
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method activateProfileFromProfileSpecificProperties.
@Test
public void activateProfileFromProfileSpecificProperties() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.profiles.active=includeprofile");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment).has(matchingProfile("includeprofile"));
assertThat(environment).has(matchingProfile("specific"));
assertThat(environment).has(matchingProfile("morespecific"));
assertThat(environment).has(matchingProfile("yetmorespecific"));
assertThat(environment).doesNotHave(matchingProfile("missing"));
}
Aggregations