@Test public void getProperty() { final Map<String, String> expected = new HashMap<>(); expected.put("test.prop", "test_value"); new Expectations() { { priamServer.getConfiguration(); result = fakeConfiguration; times = 3; } }; String expectedJsonString = GsonJsonSerializer.getGson().toJson(expected); Response response = resource.getProperty("test.prop", null); assertEquals(200, response.getStatus()); assertEquals(expectedJsonString, response.getEntity()); Map<String, Object> result = GsonJsonSerializer.getGson().fromJson(response.getEntity().toString(), Map.class); assertNotNull(result); assertTrue(!result.isEmpty()); Response defaultResponse = resource.getProperty("not.a.property", "NOVALUE"); expected.clear(); expected.put("not.a.property", "NOVALUE"); expectedJsonString = GsonJsonSerializer.getGson().toJson(expected); assertEquals(200, defaultResponse.getStatus()); assertEquals(expectedJsonString, defaultResponse.getEntity()); result = GsonJsonSerializer.getGson() .fromJson(defaultResponse.getEntity().toString(), Map.class); assertEquals(result, expected); Response badResponse = resource.getProperty("not.a.property", null); assertEquals(404, badResponse.getStatus()); }
@GET @Path("/unstructured/{name}") public Response getProperty( @PathParam("name") String name, @QueryParam("default") String defaultValue) { Map<String, Object> result = new HashMap<>(); try { String value = priamServer.getConfiguration().getProperty(name, defaultValue); if (value != null) { result.put(name, value); return Response.ok(GsonJsonSerializer.getGson().toJson(result)).build(); } else { result.put("message", String.format("No such property: [%s]", name)); logger.error(String.format("No such property: [%s]", name)); return Response.status(404) .entity(GsonJsonSerializer.getGson().toJson(result)) .type(MediaType.APPLICATION_JSON) .build(); } } catch (Exception e) { logger.error("Error while executing getPriamConfig", e); return Response.serverError().build(); } }
PriamConfig { @GET @Path("/unstructured/{name}") public Response getProperty( @PathParam("name") String name, @QueryParam("default") String defaultValue) { Map<String, Object> result = new HashMap<>(); try { String value = priamServer.getConfiguration().getProperty(name, defaultValue); if (value != null) { result.put(name, value); return Response.ok(GsonJsonSerializer.getGson().toJson(result)).build(); } else { result.put("message", String.format("No such property: [%s]", name)); logger.error(String.format("No such property: [%s]", name)); return Response.status(404) .entity(GsonJsonSerializer.getGson().toJson(result)) .type(MediaType.APPLICATION_JSON) .build(); } } catch (Exception e) { logger.error("Error while executing getPriamConfig", e); return Response.serverError().build(); } } }
PriamConfig { @GET @Path("/unstructured/{name}") public Response getProperty( @PathParam("name") String name, @QueryParam("default") String defaultValue) { Map<String, Object> result = new HashMap<>(); try { String value = priamServer.getConfiguration().getProperty(name, defaultValue); if (value != null) { result.put(name, value); return Response.ok(GsonJsonSerializer.getGson().toJson(result)).build(); } else { result.put("message", String.format("No such property: [%s]", name)); logger.error(String.format("No such property: [%s]", name)); return Response.status(404) .entity(GsonJsonSerializer.getGson().toJson(result)) .type(MediaType.APPLICATION_JSON) .build(); } } catch (Exception e) { logger.error("Error while executing getPriamConfig", e); return Response.serverError().build(); } } @Inject  PriamConfig(PriamServer server); }
PriamConfig { @GET @Path("/unstructured/{name}") public Response getProperty( @PathParam("name") String name, @QueryParam("default") String defaultValue) { Map<String, Object> result = new HashMap<>(); try { String value = priamServer.getConfiguration().getProperty(name, defaultValue); if (value != null) { result.put(name, value); return Response.ok(GsonJsonSerializer.getGson().toJson(result)).build(); } else { result.put("message", String.format("No such property: [%s]", name)); logger.error(String.format("No such property: [%s]", name)); return Response.status(404) .entity(GsonJsonSerializer.getGson().toJson(result)) .type(MediaType.APPLICATION_JSON) .build(); } } catch (Exception e) { logger.error("Error while executing getPriamConfig", e); return Response.serverError().build(); } } @Inject  PriamConfig(PriamServer server); @GET @Path("/structured/{group}") Response getPriamConfig(@PathParam("group") String group); @GET @Path("/structured/{group}/{name}") Response getPriamConfigByName(
            @PathParam("group") String group, @PathParam("name") String name); @GET @Path("/unstructured/{name}") Response getProperty(
            @PathParam("name") String name, @QueryParam("default") String defaultValue); }
PriamConfig { @GET @Path("/unstructured/{name}") public Response getProperty( @PathParam("name") String name, @QueryParam("default") String defaultValue) { Map<String, Object> result = new HashMap<>(); try { String value = priamServer.getConfiguration().getProperty(name, defaultValue); if (value != null) { result.put(name, value); return Response.ok(GsonJsonSerializer.getGson().toJson(result)).build(); } else { result.put("message", String.format("No such property: [%s]", name)); logger.error(String.format("No such property: [%s]", name)); return Response.status(404) .entity(GsonJsonSerializer.getGson().toJson(result)) .type(MediaType.APPLICATION_JSON) .build(); } } catch (Exception e) { logger.error("Error while executing getPriamConfig", e); return Response.serverError().build(); } } @Inject  PriamConfig(PriamServer server); @GET @Path("/structured/{group}") Response getPriamConfig(@PathParam("group") String group); @GET @Path("/structured/{group}/{name}") Response getPriamConfigByName(
            @PathParam("group") String group, @PathParam("name") String name); @GET @Path("/unstructured/{name}") Response getProperty(
            @PathParam("name") String name, @QueryParam("default") String defaultValue);  }