ConfigFileApplicationListenerTests.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:spring-boot-concourse 作者:
@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<String>();
    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]");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号