use of cn.taketoday.core.env.MapPropertySource 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.MapPropertySource 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.MapPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method fromPropertySourceShouldFlattenPropertySources.
@Test
void fromPropertySourceShouldFlattenPropertySources() {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("foo", Collections.singletonMap("foo", "bar")));
environment.getPropertySources().addFirst(new MapPropertySource("far", Collections.singletonMap("far", "far")));
PropertySources sources = new PropertySources();
sources.addFirst(new PropertySource<Environment>("env", environment) {
@Override
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
sources.addLast(new MapPropertySource("baz", Collections.singletonMap("baz", "barf")));
Iterable<ConfigurationPropertySource> configurationSources = ConfigurationPropertySources.from(sources);
assertThat(configurationSources.iterator()).toIterable().hasSize(5);
}
use of cn.taketoday.core.env.MapPropertySource 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");
}
use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.
the class DefaultConfigurationPropertySourceTests method getValueWhenOriginCapableShouldIncludeSourceOrigin.
@Test
void getValueWhenOriginCapableShouldIncludeSourceOrigin() {
Map<String, Object> source = new LinkedHashMap<>();
source.put("key", "value");
PropertySource<?> propertySource = new OriginCapablePropertySource<>(new MapPropertySource("test", source));
TestPropertyMapper mapper = new TestPropertyMapper();
ConfigurationPropertyName name = ConfigurationPropertyName.of("my.key");
mapper.addFromConfigurationProperty(name, "key");
DefaultConfigurationPropertySource adapter = new DefaultConfigurationPropertySource(propertySource, mapper);
assertThat(adapter.getConfigurationProperty(name).getOrigin().toString()).isEqualTo("TestOrigin key");
}
Aggregations