Fix tests some more

Eclipse (by default) does not create the JSON metadata when
it compiles the @ConfigurationProperties beans. So running on
the command lilne gets scarily different than in an IDE. Fixed
by externalizing the metadata location and setting it to something
empty in the tests.
pull/1958/head
Dave Syer 10 years ago
parent 90af8bf54a
commit 1254508357

@ -84,7 +84,9 @@ public class ConfigurationPropertiesReportEndpoint extends
private ConfigurationBeanFactoryMetaData beanFactoryMetaData; private ConfigurationBeanFactoryMetaData beanFactoryMetaData;
private ConfigurationPropertiesMetaData metadata = new ConfigurationPropertiesMetaData(); private ConfigurationPropertiesMetaData metadata;
private String metadataLocations = "classpath:*/META-INF/*spring-configuration-metadata.json";
public ConfigurationPropertiesReportEndpoint() { public ConfigurationPropertiesReportEndpoint() {
super("configprops"); super("configprops");
@ -104,6 +106,15 @@ public class ConfigurationPropertiesReportEndpoint extends
this.sanitizer.setKeysToSanitize(keysToSanitize); this.sanitizer.setKeysToSanitize(keysToSanitize);
} }
/**
* Location path for JSON metadata about config properties.
*
* @param metadataLocations the metadataLocations to set
*/
public void setMetadataLocations(String metadataLocations) {
this.metadataLocations = metadataLocations;
}
@Override @Override
public Map<String, Object> invoke() { public Map<String, Object> invoke() {
return extract(this.context); return extract(this.context);
@ -150,6 +161,9 @@ public class ConfigurationPropertiesReportEndpoint extends
*/ */
private Map<String, Object> safeSerialize(ObjectMapper mapper, Object bean, private Map<String, Object> safeSerialize(ObjectMapper mapper, Object bean,
String prefix) { String prefix) {
if (this.metadata == null) {
this.metadata = new ConfigurationPropertiesMetaData(this.metadataLocations);
}
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> result = new HashMap<String, Object>(mapper.convertValue( Map<String, Object> result = new HashMap<String, Object>(mapper.convertValue(
@ -315,6 +329,11 @@ public class ConfigurationPropertiesReportEndpoint extends
private Map<String, Set<String>> matched = new HashMap<String, Set<String>>(); private Map<String, Set<String>> matched = new HashMap<String, Set<String>>();
private Set<String> keys = null; private Set<String> keys = null;
private String metadataLocations;
public ConfigurationPropertiesMetaData(String metadataLocations) {
this.metadataLocations = metadataLocations;
}
public boolean matches(String prefix) { public boolean matches(String prefix) {
if (this.matched.containsKey(prefix)) { if (this.matched.containsKey(prefix)) {
@ -348,7 +367,7 @@ public class ConfigurationPropertiesReportEndpoint extends
this.keys = new HashSet<String>(); this.keys = new HashSet<String>();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
Resource[] resources = new PathMatchingResourcePatternResolver() Resource[] resources = new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/*spring-configuration-metadata.json"); .getResources(this.metadataLocations);
for (Resource resource : resources) { for (Resource resource : resources) {
addKeys(mapper, resource); addKeys(mapper, resource);
} }

@ -206,6 +206,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertNotNull(map);
System.err.println(nestedProperties);
// Only one property is mapped in metadata so the others are ignored // Only one property is mapped in metadata so the others are ignored
assertEquals(1, map.size()); assertEquals(1, map.size());
assertEquals("foo", ((Map<String, Object>) map.get("map")).get("name")); assertEquals("foo", ((Map<String, Object>) map.get("map")).get("name"));
@ -241,6 +242,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
ConfigurationBeanFactoryMetaData beanFactoryMetaData) { ConfigurationBeanFactoryMetaData beanFactoryMetaData) {
ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint(); ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint();
endpoint.setConfigurationBeanFactoryMetaData(beanFactoryMetaData); endpoint.setConfigurationBeanFactoryMetaData(beanFactoryMetaData);
endpoint.setMetadataLocations("classpath*:/test-metadata.json");
return endpoint; return endpoint;
} }

Loading…
Cancel
Save