Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/509#discussion_r24665148
--- Diff:
usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
---
@@ -97,5 +103,38 @@ public void testShutdown() throws Exception {
assertFalse(getManagementContext().isRunning());
}});
}
-
+
+ @Test
+ void testGetConfig() throws Exception {
+
((ManagementContextInternal)getManagementContext()).getBrooklynProperties().put("foo.bar.baz",
"quux");
+ try {
+
assertEquals(client().resource("/v1/server/config/foo.bar.baz").get(String.class),
"quux");
+ } finally {
+
((ManagementContextInternal)getManagementContext()).getBrooklynProperties().remove("foo.bar.baz");
+ }
+ }
+
+ @Test
+ void testGetMissingConfigThrowsException() throws Exception {
+ final String key = "foo.bar.baz";
+ BrooklynProperties properties =
((ManagementContextInternal)getManagementContext()).getBrooklynProperties();
+ Object existingValue = null;
+ boolean keyAlreadyPresent = false;
+ String response = null;
+ if (properties.containsKey(key)) {
+ existingValue = properties.remove(key);
+ keyAlreadyPresent = true;
+ }
+ try {
+ response = client().resource("/v1/server/config/" +
key).get(String.class);
+ } catch (UniformInterfaceException e) {
+ assertEquals(e.getResponse().getStatus(), 204);
--- End diff --
Does this test pass?! It's asserting a 204 rather than a 404 (i.e. "No
Content').
My personal preference is to put the `Asserts.fail` inside the try block,
and not to do a `return` inside the catch block. I find that clearer, but no
strong feelings.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---