Test binding of environment variables to maps
Add a test case to show that the updated configuration properties binder correctly binds environment variables to complex maps. Closes gh-8902
This commit is contained in:
committed by
Phillip Webb
parent
2e83de58ec
commit
e3ea7a7d93
@@ -368,6 +368,22 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
|
||||
.containsEntry("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void systemPropertiesShouldBindToMap() throws Exception {
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
MutablePropertySources propertySources = env.getPropertySources();
|
||||
propertySources.addLast(new SystemEnvironmentPropertySource("system",
|
||||
Collections.singletonMap("TEST_MAP_FOO_BAR", "baz")));
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setEnvironment(env);
|
||||
this.context.register(PropertiesWithComplexMap.class);
|
||||
this.context.refresh();
|
||||
Map<String, Map<String, String>> map = this.context
|
||||
.getBean(PropertiesWithComplexMap.class).getMap();
|
||||
Map<String, String> foo = map.get("foo");
|
||||
assertThat(foo).containsEntry("bar", "baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overridingPropertiesInEnvShouldOverride() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
@@ -765,6 +781,23 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@ConfigurationProperties(prefix = "test")
|
||||
public static class PropertiesWithComplexMap {
|
||||
|
||||
private Map<String, Map<String, String>> map;
|
||||
|
||||
public Map<String, Map<String, String>> getMap() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, Map<String, String>> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public static class ConfigurationPropertiesWithFactoryBean {
|
||||
|
||||
Reference in New Issue
Block a user