use of org.springframework.boot.env.EnumerableCompositePropertySource in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method yamlSetsProfiles.
@Test
public void yamlSetsProfiles() throws Exception {
this.initializer.setSearchNames("testsetprofiles");
this.initializer.postProcessEnvironment(this.environment, this.application);
assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
String property = this.environment.getProperty("my.property");
assertThat(this.environment.getActiveProfiles()).contains("dev");
assertThat(property).isEqualTo("fromdevprofile");
ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment.getPropertySources().get(ConfigFileApplicationListener.APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource.getSource();
assertThat(sources).hasSize(2);
List<String> names = new ArrayList<>();
for (org.springframework.core.env.PropertySource<?> source : sources) {
if (source instanceof EnumerableCompositePropertySource) {
for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source).getSource()) {
names.add(nested.getName());
}
} else {
names.add(source.getName());
}
}
assertThat(names).contains("applicationConfig: [classpath:/testsetprofiles.yml]#dev", "applicationConfig: [classpath:/testsetprofiles.yml]");
}
Aggregations