@ -17,6 +17,8 @@
@@ -17,6 +17,8 @@
package org.springframework.boot.actuate.endpoint ;
import java.net.InetAddress ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
@ -33,11 +35,13 @@ import org.springframework.context.annotation.Configuration;
@@ -33,11 +35,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.entry ;
/ * *
* Tests for { @link ConfigurationPropertiesReportEndpoint } serialization .
*
* @author Dave Syer
* @author Stephane Nicoll
* /
public class ConfigurationPropertiesReportEndpointSerializationTests {
@ -195,6 +199,32 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@@ -195,6 +199,32 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
assertThat ( map . get ( "address" ) ) . isEqualTo ( "192.168.1.10" ) ;
}
@Test
@SuppressWarnings ( "unchecked" )
public void testInitializedMapAndList ( ) throws Exception {
this . context . register ( InitializedMapAndListPropertiesConfig . class ) ;
EnvironmentTestUtils . addEnvironment ( this . context , "foo.map.entryOne:true" ,
"foo.list[0]:abc" ) ;
this . context . refresh ( ) ;
ConfigurationPropertiesReportEndpoint report = this . context
. getBean ( ConfigurationPropertiesReportEndpoint . class ) ;
Map < String , Object > properties = report . invoke ( ) ;
assertThat ( properties ) . containsKeys ( "foo" ) ;
Map < String , Object > nestedProperties = ( Map < String , Object > ) properties
. get ( "foo" ) ;
assertThat ( nestedProperties ) . containsOnlyKeys ( "prefix" , "properties" ) ;
assertThat ( nestedProperties . get ( "prefix" ) ) . isEqualTo ( "foo" ) ;
Map < String , Object > propertiesMap = ( Map < String , Object > ) nestedProperties
. get ( "properties" ) ;
assertThat ( propertiesMap ) . containsOnlyKeys ( "bar" , "name" , "map" , "list" ) ;
Map < String , Object > map = ( Map < String , Object > ) propertiesMap
. get ( "map" ) ;
assertThat ( map ) . containsOnly ( entry ( "entryOne" , true ) ) ;
List < String > list = ( List < String > ) propertiesMap
. get ( "list" ) ;
assertThat ( list ) . containsExactly ( "abc" ) ;
}
@Configuration
@EnableConfigurationProperties
public static class Base {
@ -290,6 +320,18 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@@ -290,6 +320,18 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
}
@Configuration
@Import ( Base . class )
public static class InitializedMapAndListPropertiesConfig {
@Bean
@ConfigurationProperties ( prefix = "foo" )
public InitializedMapAndListProperties foo ( ) {
return new InitializedMapAndListProperties ( ) ;
}
}
public static class Foo {
private String name = "654321" ;
@ -393,4 +435,20 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@@ -393,4 +435,20 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
}
public static class InitializedMapAndListProperties extends Foo {
private Map < String , Boolean > map = new HashMap < String , Boolean > ( ) ;
private List < String > list = new ArrayList < String > ( ) ;
public Map < String , Boolean > getMap ( ) {
return this . map ;
}
public List < String > getList ( ) {
return this . list ;
}
}
}