From e3ea7a7d938faeebba7c88847ce51bb64c21733f Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 25 Apr 2017 13:05:08 -0700 Subject: [PATCH] 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 --- ...onPropertiesBindingPostProcessorTests.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java index 8d6ceaf514..67a649e5a0 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java @@ -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> map = this.context + .getBean(PropertiesWithComplexMap.class).getMap(); + Map 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> map; + + public Map> getMap() { + return this.map; + } + + public void setMap(Map> map) { + this.map = map; + } + + } + @Configuration @EnableConfigurationProperties public static class ConfigurationPropertiesWithFactoryBean {