Skip to content

Commit

Permalink
gh-1422 - fixed issue with properties end point
Browse files Browse the repository at this point in the history
  • Loading branch information
p013570 committed Nov 6, 2017
1 parent d555995 commit 2a78fe0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -25,9 +25,11 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;

import static uk.gov.gchq.gaffer.rest.SystemProperty.APP_CONTACT;
import static uk.gov.gchq.gaffer.rest.SystemProperty.APP_CONTACT_DEFAULT;
Expand Down Expand Up @@ -67,11 +69,14 @@ public Response getProperties() {
} else {
final String[] props = propertiesList.split(",");
properties = new LinkedHashMap<>(CORE_EXPOSED_PROPERTIES);
for (final String prop : props) {
if (StringUtils.isNotEmpty(prop)) {
properties.put(prop, System.getProperty(prop));
}
}
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);
}
});
}

return Response.ok(Collections.unmodifiableMap(properties))
Expand Down
Expand Up @@ -24,6 +24,7 @@
import javax.ws.rs.core.Response;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -87,17 +88,22 @@ public void shouldGetAllProperties() throws IOException {
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);
assertEquals(PropertiesServiceV2.CORE_EXPOSED_PROPERTIES.size() + 2, properties.size());
assertEquals("1", properties.get("gaffer.test1"));
assertEquals("1", properties.get("gaffer.test1"));

final LinkedHashMap<String, String> expectedProperties = new LinkedHashMap<>(PropertiesServiceV2.CORE_EXPOSED_PROPERTIES);
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
Expand All @@ -106,6 +112,7 @@ public void shouldGetKnownProperty() throws IOException {
System.setProperty("gaffer.properties", "gaffer.test1,gaffer.test2");
System.setProperty("gaffer.test1", "1");
System.setProperty("gaffer.test2", "2");

// When
final Response response = getClient().getProperty("gaffer.test1");

Expand All @@ -121,6 +128,7 @@ public void shouldGetKnownCoreProperty() throws IOException {
System.setProperty("gaffer.properties", "gaffer.test1,gaffer.test2");
System.setProperty("gaffer.test1", "1");
System.setProperty("gaffer.test2", "2");

// When
final Response response = getClient().getProperty(SystemProperty.APP_TITLE);

Expand All @@ -137,6 +145,7 @@ public void shouldGetOverriddenKnownCoreProperty() throws IOException {
System.setProperty("gaffer.test1", "1");
System.setProperty("gaffer.test2", "2");
System.setProperty(SystemProperty.APP_TITLE, "newTitle");

// When
final Response response = getClient().getProperty(SystemProperty.APP_TITLE);

Expand Down

0 comments on commit 2a78fe0

Please sign in to comment.