use of cn.taketoday.core.env.CompositePropertySource in project today-framework by TAKETODAY.
the class ApplicationTests method commandLinePropertySourceEnhancesEnvironment.
@Test
void commandLinePropertySourceEnhancesEnvironment() {
Application application = new Application(ExampleConfig.class);
application.setApplicationType(ApplicationType.NONE_WEB);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.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");
CompositePropertySource composite = (CompositePropertySource) environment.getPropertySources().get("commandLineArgs");
assertThat(composite.getPropertySources()).hasSize(2);
assertThat(composite.getPropertySources()).first().matches((source) -> source.getName().equals("applicationCommandLineArgs"), "is named applicationCommandLineArgs");
assertThat(composite.getPropertySources()).element(1).matches((source) -> source.getName().equals("commandLineArgs"), "is named commandLineArgs");
}
use of cn.taketoday.core.env.CompositePropertySource in project today-infrastructure by TAKETODAY.
the class ApplicationTests method commandLinePropertySourceEnhancesEnvironment.
@Test
void commandLinePropertySourceEnhancesEnvironment() {
Application application = new Application(ExampleConfig.class);
application.setApplicationType(ApplicationType.NONE_WEB);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.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");
CompositePropertySource composite = (CompositePropertySource) environment.getPropertySources().get("commandLineArgs");
assertThat(composite.getPropertySources()).hasSize(2);
assertThat(composite.getPropertySources()).first().matches((source) -> source.getName().equals("applicationCommandLineArgs"), "is named applicationCommandLineArgs");
assertThat(composite.getPropertySources()).element(1).matches((source) -> source.getName().equals("commandLineArgs"), "is named commandLineArgs");
}
Aggregations