Commit e3ea7a7d authored by Madhura Bhave's avatar Madhura Bhave Committed by Phillip Webb

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
parent 2e83de58
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment