Skip to content

Commit

Permalink
gh-1422 - fixed bug with properties service
Browse files Browse the repository at this point in the history
  • Loading branch information
p013570 committed Nov 6, 2017
1 parent 2a78fe0 commit 2615f14
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
Expand Up @@ -61,23 +61,18 @@ private static Map<String, String> createCoreExposedProperties() {

@Override
public Response getProperties() {
final Map<String, String> properties;

final String propertiesList = System.getProperty(EXPOSED_PROPERTIES);
if (null == propertiesList) {
properties = Collections.emptyMap();
} else {
final String[] props = propertiesList.split(",");
properties = new LinkedHashMap<>(CORE_EXPOSED_PROPERTIES);
Stream.concat(CORE_EXPOSED_PROPERTIES.keySet().stream(), Arrays.stream(props))
.filter(StringUtils::isNotEmpty)
.forEach(prop -> {
final String value = System.getProperty(prop);
if (null != value) {
properties.put(prop, value);
}
});
}
final Map<String, String> properties = new LinkedHashMap<>();
final String customPropNamesCsv = System.getProperty(EXPOSED_PROPERTIES);
final Stream<String> customPropNames = null != customPropNamesCsv ? Arrays.stream(customPropNamesCsv.split(",")) : Stream.empty();
Stream.concat(CORE_EXPOSED_PROPERTIES.keySet().stream(), customPropNames)
.filter(StringUtils::isNotEmpty)
.forEach(prop -> {
String value = System.getProperty(prop);
if (null == value) {
value = CORE_EXPOSED_PROPERTIES.get(prop);
}
properties.put(prop, value);
});

return Response.ok(Collections.unmodifiableMap(properties))
.header(ServiceConstants.GAFFER_MEDIA_TYPE_HEADER, ServiceConstants.GAFFER_MEDIA_TYPE)
Expand Down
Expand Up @@ -101,8 +101,26 @@ public void shouldGetAllProperties() throws IOException {
expectedProperties.put("gaffer.test1", "1");
expectedProperties.put("gaffer.test2", "2");
expectedProperties.put(SystemProperty.APP_TITLE, "newTitle");
assertEquals("1", properties.get("gaffer.test1"));
assertEquals("2", properties.get("gaffer.test2"));
assertEquals(expectedProperties, properties);
}

@Test
public void shouldGetAllPropertiesWhenNoCustomPropertiesCsvDefined() throws IOException {
//Given
System.setProperty("gaffer.test1", "1");
System.setProperty("gaffer.test2", "2");
System.setProperty("gaffer.test3", "3");
System.setProperty(SystemProperty.APP_TITLE, "newTitle");

// When
final Response response = getClient().getProperties();

//Then
assertEquals(200, response.getStatus());
Map<String, Object> properties = response.readEntity(Map.class);

final LinkedHashMap<String, String> expectedProperties = new LinkedHashMap<>(PropertiesServiceV2.CORE_EXPOSED_PROPERTIES);
expectedProperties.put(SystemProperty.APP_TITLE, "newTitle");
assertEquals(expectedProperties, properties);
}

Expand Down

0 comments on commit 2615f14

Please sign in to comment.