use of cn.taketoday.core.env.ConfigurableEnvironment in project today-infrastructure by TAKETODAY.
the class ApplicationTests method addProfiles.
@Test
void addProfiles() {
Application application = new Application(ExampleConfig.class);
application.setApplicationType(ApplicationType.NONE_WEB);
application.setAdditionalProfiles("foo");
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
assertThat(environment.acceptsProfiles(Profiles.of("foo"))).isTrue();
}
use of cn.taketoday.core.env.ConfigurableEnvironment in project today-infrastructure by TAKETODAY.
the class ApplicationTests method disableCommandLinePropertySource.
@Test
void disableCommandLinePropertySource() {
Application application = new Application(ExampleConfig.class);
application.setApplicationType(ApplicationType.NONE_WEB);
application.setAddCommandLineProperties(false);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run("--foo=bar");
assertThat(environment).doesNotHave(matchingPropertySource(PropertySource.class, "commandLineArgs"));
}
use of cn.taketoday.core.env.ConfigurableEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method getWhenAttachedShouldReturnAttached.
@Test
void getWhenAttachedShouldReturnAttached() {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources sources = environment.getPropertySources();
sources.addFirst(new MapPropertySource("test", Collections.singletonMap("a", "b")));
int expectedSize = sources.size();
ConfigurationPropertySources.attach(environment);
assertThat(ConfigurationPropertySources.get(environment)).hasSize(expectedSize);
}
use of cn.taketoday.core.env.ConfigurableEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method attachShouldAddAdapterAtBeginning.
@Test
void attachShouldAddAdapterAtBeginning() {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources sources = environment.getPropertySources();
sources.addLast(new SystemEnvironmentPropertySource("system", Collections.singletonMap("SERVER_PORT", "1234")));
sources.addLast(new MapPropertySource("config", Collections.singletonMap("server.port", "4568")));
int size = sources.size();
ConfigurationPropertySources.attach(environment);
assertThat(sources.size()).isEqualTo(size + 1);
PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
assertThat(resolver.getProperty("server.port")).isEqualTo("1234");
}
use of cn.taketoday.core.env.ConfigurableEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method attachShouldReattachInMergedSetup.
@Test
void attachShouldReattachInMergedSetup() {
ConfigurableEnvironment parent = new StandardEnvironment();
ConfigurationPropertySources.attach(parent);
ConfigurableEnvironment child = new StandardEnvironment();
child.merge(parent);
child.getPropertySources().addLast(new MapPropertySource("config", Collections.singletonMap("my.example_property", "1234")));
ConfigurationPropertySources.attach(child);
assertThat(child.getProperty("my.example-property")).isEqualTo("1234");
}
Aggregations