Search in sources :

Example 11 with ConfigurableEnvironment

use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method addProfilesOrder.

@Test
public void addProfilesOrder() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.setAdditionalProfiles("foo");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run("--spring.profiles.active=bar,spam");
    // Command line should always come last
    assertThat(environment.getActiveProfiles()).containsExactly("foo", "bar", "spam");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 12 with ConfigurableEnvironment

use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method createReadyEvent.

private SpringApplicationEvent createReadyEvent(String propName, String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationReadyEvent(new SpringApplication(), new String[] {}, context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent)

Example 13 with ConfigurableEnvironment

use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method createPreparedEvent.

private SpringApplicationEvent createPreparedEvent(String propName, String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationPreparedEvent(new SpringApplication(), new String[] {}, context);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent)

Example 14 with ConfigurableEnvironment

use of org.springframework.core.env.ConfigurableEnvironment in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProviderTests method testWithActiveProfile.

@Test
public void testWithActiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ProfileAnnotatedComponent(example.profilescan.ProfileAnnotatedComponent) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 15 with ConfigurableEnvironment

use of org.springframework.core.env.ConfigurableEnvironment in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProviderTests method testWithInactiveProfile.

@Test
public void testWithInactiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles("other");
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ProfileAnnotatedComponent(example.profilescan.ProfileAnnotatedComponent) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) StandardEnvironment(org.springframework.core.env.StandardEnvironment) 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