Polish "Fix configuration properties output for actuator"
Closes gh-9052
This commit is contained in:
@@ -35,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 {
|
||||
|
||||
@@ -199,36 +201,28 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testOutputAllOnlyGetterProperties() throws Exception {
|
||||
this.context.register(OnlyGetterPropertiesConfig.class);
|
||||
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).isNotNull();
|
||||
System.err.println(nestedProperties);
|
||||
assertThat(nestedProperties).containsOnlyKeys("prefix", "properties");
|
||||
assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
|
||||
Map<String, Object> propertiesMap = (Map<String, Object>) nestedProperties
|
||||
.get("properties");
|
||||
assertThat(propertiesMap).isNotNull();
|
||||
assertThat(propertiesMap).hasSize(4);
|
||||
String summary = (String) propertiesMap
|
||||
.get("summary");
|
||||
assertThat(summary).isNull();
|
||||
assertThat(propertiesMap).containsOnlyKeys("bar", "name", "map", "list");
|
||||
Map<String, Object> map = (Map<String, Object>) propertiesMap
|
||||
.get("map");
|
||||
assertThat(map).isNotNull();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("entryOne")).isEqualTo(true);
|
||||
assertThat(map).containsOnly(entry("entryOne", true));
|
||||
List<String> list = (List<String>) propertiesMap
|
||||
.get("list");
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0)).isEqualTo("abc");
|
||||
assertThat(list).containsExactly("abc");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -328,12 +322,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Configuration
|
||||
@Import(Base.class)
|
||||
public static class OnlyGetterPropertiesConfig {
|
||||
public static class InitializedMapAndListPropertiesConfig {
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "foo")
|
||||
public OnlyGetterProperties foo() {
|
||||
return new OnlyGetterProperties();
|
||||
public InitializedMapAndListProperties foo() {
|
||||
return new InitializedMapAndListProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
@@ -439,9 +435,11 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
}
|
||||
|
||||
public static class OnlyGetterProperties extends Foo {
|
||||
private Map<String, Boolean> map = new HashMap<>();
|
||||
private List<String> list = new ArrayList<>();
|
||||
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;
|
||||
@@ -450,6 +448,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
public List<String> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user