From 7a935d371bffe2a6925d77258a67c8f08e2d08a4 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 13 Aug 2013 16:13:52 +0100 Subject: [PATCH] Add test for nested properties --- .../EnableConfigurationPropertiesTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index e3feed56e12..b4dd4a71018 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -52,6 +52,16 @@ public class EnableConfigurationPropertiesTests { assertEquals("foo", this.context.getBean(TestProperties.class).name); } + @Test + public void testNestedPropertiesBinding() { + this.context.register(NestedConfiguration.class); + TestUtils.addEnviroment(this.context, "name:foo", "nested.name:bar"); + this.context.refresh(); + assertEquals(1, this.context.getBeanNamesForType(NestedProperties.class).length); + assertEquals("foo", this.context.getBean(NestedProperties.class).name); + assertEquals("bar", this.context.getBean(NestedProperties.class).nested.name); + } + @Test public void testBasicPropertiesBindingWithAnnotationOnBaseClass() { this.context.register(DerivedConfiguration.class); @@ -190,6 +200,11 @@ public class EnableConfigurationPropertiesTests { protected static class DerivedConfiguration { } + @Configuration + @EnableConfigurationProperties(NestedProperties.class) + protected static class NestedConfiguration { + } + @Configuration protected static class DefaultConfiguration { @Bean @@ -225,6 +240,29 @@ public class EnableConfigurationPropertiesTests { protected static class MoreConfiguration { } + @ConfigurationProperties + protected static class NestedProperties { + private String name; + private Nested nested = new Nested(); + + public void setName(String name) { + this.name = name; + } + + public Nested getNested() { + return this.nested; + } + + protected static class Nested { + private String name; + + public void setName(String name) { + this.name = name; + } + + } + } + @ConfigurationProperties protected static class BaseProperties { private String name;