use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method createEnvironment.
private ConfigurableEnvironment createEnvironment(String propName, String propValue) {
MockPropertySource propertySource = mockPropertySource(propName, propValue);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addLast(propertySource);
return environment;
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class ResourceBannerTests method printBanner.
private String printBanner(Resource resource, String bootVersion, String applicationVersion, String applicationTitle) {
ResourceBanner banner = new MockResourceBanner(resource, bootVersion, applicationVersion, applicationTitle);
ConfigurableEnvironment environment = new MockEnvironment();
Map<String, Object> source = Collections.<String, Object>singletonMap("a", "1");
environment.getPropertySources().addLast(new MapPropertySource("map", source));
ByteArrayOutputStream out = new ByteArrayOutputStream();
banner.printBanner(environment, getClass(), new PrintStream(out));
return out.toString();
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method customEnvironment.
@Test
public void customEnvironment() throws Exception {
TestSpringApplication application = new TestSpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
verify(application.getLoader()).setEnvironment(environment);
}
use of org.springframework.core.env.ConfigurableEnvironment 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.ConfigurableEnvironment 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");
}
Aggregations