use of cn.taketoday.core.env.StandardEnvironment 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.StandardEnvironment 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.StandardEnvironment in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertyCachingTests method setup.
@BeforeEach
void setup() {
this.environment = new StandardEnvironment();
this.propertySource = new MapPropertySource("test", Collections.singletonMap("spring", "boot"));
this.environment.getPropertySources().addLast(this.propertySource);
}
use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.
the class ResourceArrayPropertyEditorTests method strictSystemPropertyReplacementWithUnresolvablePlaceholder.
@Test
void strictSystemPropertyReplacementWithUnresolvablePlaceholder() {
PropertyEditor editor = new ResourceArrayPropertyEditor(new PathMatchingPatternResourceLoader(), new StandardEnvironment(), false);
System.setProperty("test.prop", "foo");
try {
assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("${test.prop}-${bar}"));
} finally {
System.getProperties().remove("test.prop");
}
}
use of cn.taketoday.core.env.StandardEnvironment in project today-infrastructure by TAKETODAY.
the class StandardEnvironmentTests method loadProperties.
@Test
void loadProperties() throws IOException {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources propertySources = environment.getPropertySources();
Properties properties = PropertiesUtils.loadProperties(ResourceUtils.getResource("classpath:info.properties"));
propertySources.addLast(new PropertiesPropertySource("info", properties));
assert "https://taketoday.cn".equals(environment.getProperty("site.host"));
}
Aggregations