Add test for nested properties
This commit is contained in:
parent
4e83826b41
commit
c25736d84f
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue