use of cn.taketoday.core.env.StandardEnvironment 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.StandardEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method descendantOfPropertyAccessWhenMutableWithCacheShouldBePerformant.
@Test
// gh-21416
void descendantOfPropertyAccessWhenMutableWithCacheShouldBePerformant() {
Function<StandardEnvironment, Long> descendantOfPerformance = (environment) -> {
Iterable<ConfigurationPropertySource> sources = ConfigurationPropertySources.get(environment);
ConfigurationPropertyName missing = ConfigurationPropertyName.of("missing");
long start = System.nanoTime();
for (int i = 0; i < 1000; i++) {
for (ConfigurationPropertySource source : sources) {
assertThat(source.containsDescendantOf(missing)).isEqualTo(ConfigurationPropertyState.ABSENT);
}
}
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
};
StandardEnvironment environment = createPerformanceTestEnvironment(false);
long baseline = descendantOfPerformance.apply(environment);
ConfigurationPropertyCaching.get(environment).enable();
long cached = descendantOfPerformance.apply(environment);
assertThat(cached).isLessThan(baseline / 2);
}
use of cn.taketoday.core.env.StandardEnvironment 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.StandardEnvironment 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.StandardEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method createPerformanceTestEnvironment.
private StandardEnvironment createPerformanceTestEnvironment(boolean immutable) {
StandardEnvironment environment = new StandardEnvironment();
PropertySources propertySources = environment.getPropertySources();
for (int i = 0; i < 100; i++) {
propertySources.addLast(new TestPropertySource(i, immutable));
}
ConfigurationPropertySources.attach(environment);
return environment;
}
Aggregations