use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method commandLinePropertySourceEnhancesEnvironment.
@Test
public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.<String, Object>singletonMap("foo", "original")));
application.setEnvironment(environment);
this.context = application.run("--foo=bar", "--bar=foo");
assertThat(environment).has(matchingPropertySource(CompositePropertySource.class, "commandLineArgs"));
assertThat(environment.getProperty("bar")).isEqualTo("foo");
// New command line properties take precedence
assertThat(environment.getProperty("foo")).isEqualTo("bar");
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method emptyCommandLinePropertySourceNotAdded.
@Test
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method commandLinePropertySource.
@Test
public void commandLinePropertySource() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run("--foo=bar");
assertThat(environment).has(matchingPropertySource(CommandLinePropertySource.class, "commandLineArgs"));
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method propertiesFileEnhancesEnvironment.
@Test
public void propertiesFileEnhancesEnvironment() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.
the class NestedBeansElementTests method getBean_withActiveProfile.
@Test
public void getBean_withActiveProfile() {
ConfigurableEnvironment env = new StandardEnvironment();
env.setActiveProfiles("dev");
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
reader.setEnvironment(env);
reader.loadBeanDefinitions(XML);
// should not throw NSBDE
bf.getBean("devOnlyBean");
Object foo = bf.getBean("foo");
assertThat(foo, instanceOf(Integer.class));
bf.getBean("devOnlyBean");
}
Aggregations