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 ConfigurationPropertiesMetaData metadata = new ConfigurationPropertiesMetaData();
private ConfigurationPropertiesMetaData metadata;
private String metadataLocations = "classpath:*/META-INF/*spring-configuration-metadata.json";
public ConfigurationPropertiesReportEndpoint() {
super("configprops");
@ -104,6 +106,15 @@ public class ConfigurationPropertiesReportEndpoint extends
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
public Map<String, Object> invoke() {
return extract(this.context);
@ -150,6 +161,9 @@ public class ConfigurationPropertiesReportEndpoint extends
*/
private Map<String, Object> safeSerialize(ObjectMapper mapper, Object bean,
String prefix) {
if (this.metadata == null) {
this.metadata = new ConfigurationPropertiesMetaData(this.metadataLocations);
}
try {
@SuppressWarnings("unchecked")
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 Set<String> keys = null;
private String metadataLocations;
public ConfigurationPropertiesMetaData(String metadataLocations) {
this.metadataLocations = metadataLocations;
}
public boolean matches(String prefix) {
if (this.matched.containsKey(prefix)) {
@ -348,7 +367,7 @@ public class ConfigurationPropertiesReportEndpoint extends
this.keys = new HashSet<String>();
ObjectMapper mapper = new ObjectMapper();
Resource[] resources = new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/*spring-configuration-metadata.json");
.getResources(this.metadataLocations);
for (Resource resource : resources) {
addKeys(mapper, resource);
}

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

Loading…
Cancel
Save