@ -49,7 +49,16 @@ public class EnableConfigurationPropertiesTests {
TestUtils . addEnviroment ( this . context , "name:foo" ) ;
TestUtils . addEnviroment ( this . context , "name:foo" ) ;
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 , this . context . getBeanNamesForType ( TestProperties . class ) . length ) ;
assertEquals ( 1 , this . context . getBeanNamesForType ( TestProperties . class ) . length ) ;
assertEquals ( "foo" , this . context . getBean ( TestProperties . class ) . getName ( ) ) ;
assertEquals ( "foo" , this . context . getBean ( TestProperties . class ) . name ) ;
}
@Test
public void testBasicPropertiesBindingWithAnnotationOnBaseClass ( ) {
this . context . register ( DerivedConfiguration . class ) ;
TestUtils . addEnviroment ( this . context , "name:foo" ) ;
this . context . refresh ( ) ;
assertEquals ( 1 , this . context . getBeanNamesForType ( DerivedProperties . class ) . length ) ;
assertEquals ( "foo" , this . context . getBean ( BaseProperties . class ) . name ) ;
}
}
@Test
@Test
@ -75,7 +84,7 @@ public class EnableConfigurationPropertiesTests {
TestUtils . addEnviroment ( this . context , "name:foo" ) ;
TestUtils . addEnviroment ( this . context , "name:foo" ) ;
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 , this . context . getBeanNamesForType ( MoreProperties . class ) . length ) ;
assertEquals ( 1 , this . context . getBeanNamesForType ( MoreProperties . class ) . length ) ;
assertEquals ( "foo" , this . context . getBean ( MoreProperties . class ) . getName( ) ) ;
assertEquals ( "foo" , this . context . getBean ( MoreProperties . class ) . name ) ;
}
}
@Test
@Test
@ -84,7 +93,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
String [ ] beanNames = this . context . getBeanNamesForType ( TestProperties . class ) ;
String [ ] beanNames = this . context . getBeanNamesForType ( TestProperties . class ) ;
assertEquals ( "Wrong beans: " + Arrays . asList ( beanNames ) , 1 , beanNames . length ) ;
assertEquals ( "Wrong beans: " + Arrays . asList ( beanNames ) , 1 , beanNames . length ) ;
assertEquals ( "bar" , this . context . getBean ( TestProperties . class ) . getName( ) ) ;
assertEquals ( "bar" , this . context . getBean ( TestProperties . class ) . name ) ;
}
}
@Test
@Test
@ -93,7 +102,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
String [ ] beanNames = this . context . getBeanNamesForType ( TestProperties . class ) ;
String [ ] beanNames = this . context . getBeanNamesForType ( TestProperties . class ) ;
assertEquals ( "Wrong beans: " + Arrays . asList ( beanNames ) , 1 , beanNames . length ) ;
assertEquals ( "Wrong beans: " + Arrays . asList ( beanNames ) , 1 , beanNames . length ) ;
assertEquals ( "bar" , this . context . getBean ( TestProperties . class ) . getName( ) ) ;
assertEquals ( "bar" , this . context . getBean ( TestProperties . class ) . name ) ;
}
}
@Test
@Test
@ -102,8 +111,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 ,
assertEquals ( 1 ,
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
assertEquals ( "foo" , this . context . getBean ( ResourceBindingProperties . class )
assertEquals ( "foo" , this . context . getBean ( ResourceBindingProperties . class ) . name ) ;
. getName ( ) ) ;
}
}
@Test
@Test
@ -113,8 +121,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 ,
assertEquals ( 1 ,
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
assertEquals ( "other" , this . context . getBean ( ResourceBindingProperties . class )
assertEquals ( "other" , this . context . getBean ( ResourceBindingProperties . class ) . name ) ;
. getName ( ) ) ;
}
}
@Test
@Test
@ -124,8 +131,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 ,
assertEquals ( 1 ,
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
assertEquals ( "foo" , this . context . getBean ( ResourceBindingProperties . class )
assertEquals ( "foo" , this . context . getBean ( ResourceBindingProperties . class ) . name ) ;
. getName ( ) ) ;
}
}
@Test
@Test
@ -135,8 +141,7 @@ public class EnableConfigurationPropertiesTests {
this . context . refresh ( ) ;
this . context . refresh ( ) ;
assertEquals ( 1 ,
assertEquals ( 1 ,
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
this . context . getBeanNamesForType ( ResourceBindingProperties . class ) . length ) ;
assertEquals ( "bar" , this . context . getBean ( ResourceBindingProperties . class )
assertEquals ( "bar" , this . context . getBean ( ResourceBindingProperties . class ) . name ) ;
. getName ( ) ) ;
}
}
@Test
@Test
@ -180,6 +185,11 @@ public class EnableConfigurationPropertiesTests {
protected static class TestConfiguration {
protected static class TestConfiguration {
}
}
@Configuration
@EnableConfigurationProperties ( DerivedProperties . class )
protected static class DerivedConfiguration {
}
@Configuration
@Configuration
protected static class DefaultConfiguration {
protected static class DefaultConfiguration {
@Bean
@Bean
@ -206,7 +216,7 @@ public class EnableConfigurationPropertiesTests {
}
}
public String getName ( ) {
public String getName ( ) {
return this . properties . getName( ) ;
return this . properties . name ;
}
}
}
}
@ -215,15 +225,25 @@ public class EnableConfigurationPropertiesTests {
protected static class MoreConfiguration {
protected static class MoreConfiguration {
}
}
@ConfigurationProperties
protected static class BaseProperties {
private String name ;
public void setName ( String name ) {
this . name = name ;
}
}
protected static class DerivedProperties extends BaseProperties {
}
@ConfigurationProperties
@ConfigurationProperties
protected static class TestProperties {
protected static class TestProperties {
private String name ;
private String name ;
private int [ ] array ;
private int [ ] array ;
private List < Integer > list = new ArrayList < Integer > ( ) ;
private List < Integer > list = new ArrayList < Integer > ( ) ;
public String getName ( ) {
// No getter - you should be able to bind to a write-only bean
return this . name ;
}
public void setName ( String name ) {
public void setName ( String name ) {
this . name = name ;
this . name = name ;
@ -245,25 +265,21 @@ public class EnableConfigurationPropertiesTests {
protected static class MoreProperties {
protected static class MoreProperties {
private String name ;
private String name ;
public String getName ( ) {
return this . name ;
}
public void setName ( String name ) {
public void setName ( String name ) {
this . name = name ;
this . name = name ;
}
}
// No getter - you should be able to bind to a write-only bean
}
}
@ConfigurationProperties ( path = "${binding.location:classpath:name.yml}" )
@ConfigurationProperties ( path = "${binding.location:classpath:name.yml}" )
protected static class ResourceBindingProperties {
protected static class ResourceBindingProperties {
private String name ;
private String name ;
public String getName ( ) {
return this . name ;
}
public void setName ( String name ) {
public void setName ( String name ) {
this . name = name ;
this . name = name ;
}
}
// No getter - you should be able to bind to a write-only bean
}
}
}
}