Search in sources :

Example 1 with ConfigurableEnvironment

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();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 2 with ConfigurableEnvironment

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();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 3 with ConfigurableEnvironment

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");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 4 with ConfigurableEnvironment

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);
        }
    };
}
Also used : Condition(org.assertj.core.api.Condition) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 5 with ConfigurableEnvironment

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"));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Aggregations

ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)54 Test (org.junit.Test)27 StandardEnvironment (org.springframework.core.env.StandardEnvironment)18 MutablePropertySources (org.springframework.core.env.MutablePropertySources)10 SpringApplication (org.springframework.boot.SpringApplication)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 MockEnvironment (org.springframework.mock.env.MockEnvironment)6 CompositePropertySource (org.springframework.core.env.CompositePropertySource)4 MapPropertySource (org.springframework.core.env.MapPropertySource)4 Environment (org.springframework.core.env.Environment)3 ProfileAnnotatedComponent (example.profilescan.ProfileAnnotatedComponent)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 CommandLinePropertySource (org.springframework.core.env.CommandLinePropertySource)2 PropertySource (org.springframework.core.env.PropertySource)2