Merge pull request #9052 from strattonw:issue-3269

* pr/9052:
  Polish "Fix configuration properties output for actuator"
  Fix configuration properties output for actuator
pull/8428/merge
Stephane Nicoll 8 years ago
commit fea178a13c

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.endpoint; package org.springframework.boot.actuate.endpoint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -57,6 +58,7 @@ import org.springframework.util.StringUtils;
* *
* @author Christian Dupuis * @author Christian Dupuis
* @author Dave Syer * @author Dave Syer
* @author Stephane Nicoll
*/ */
@ConfigurationProperties(prefix = "endpoints.configprops") @ConfigurationProperties(prefix = "endpoints.configprops")
public class ConfigurationPropertiesReportEndpoint public class ConfigurationPropertiesReportEndpoint
@ -334,10 +336,13 @@ public class ConfigurationPropertiesReportEndpoint
// If there's a setter, we assume it's OK to report on the value, // If there's a setter, we assume it's OK to report on the value,
// similarly, if there's no setter but the package names match, we assume // similarly, if there's no setter but the package names match, we assume
// that its a nested class used solely for binding to config props, so it // that its a nested class used solely for binding to config props, so it
// should be kosher. This filter is not used if there is JSON metadata for // should be kosher. Lists and Maps are also auto-detected by default since
// the property, so it's mainly for user-defined beans. // that's what the metadata generator does. This filter is not used if there
return (setter != null) || ClassUtils.getPackageName(parentType) // is JSON metadata for the property, so it's mainly for user-defined beans.
.equals(ClassUtils.getPackageName(type)); return (setter != null)
|| ClassUtils.getPackageName(parentType).equals(ClassUtils.getPackageName(type))
|| Map.class.isAssignableFrom(type)
|| Collection.class.isAssignableFrom(type);
} }
private AnnotatedMethod findSetter(BeanDescription beanDesc, private AnnotatedMethod findSetter(BeanDescription beanDesc,
@ -354,5 +359,4 @@ public class ConfigurationPropertiesReportEndpoint
} }
} }
} }

@ -17,6 +17,8 @@
package org.springframework.boot.actuate.endpoint; package org.springframework.boot.actuate.endpoint;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -33,11 +35,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint} serialization. * Tests for {@link ConfigurationPropertiesReportEndpoint} serialization.
* *
* @author Dave Syer * @author Dave Syer
* @author Stephane Nicoll
*/ */
public class ConfigurationPropertiesReportEndpointSerializationTests { public class ConfigurationPropertiesReportEndpointSerializationTests {
@ -195,6 +199,32 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
assertThat(map.get("address")).isEqualTo("192.168.1.10"); 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 @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
public static class Base { public static class Base {
@ -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 { public static class Foo {
private String name = "654321"; private String name = "654321";
@ -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;
}
}
} }

Loading…
Cancel
Save