@Test public void testFetchException() throws Exception { when(store.fetch()).thenThrow(new NotificationStoreException()); final Response response = resources.client().target("/v1/rules").request(MediaType.APPLICATION_JSON).get(); final ErrorMessage actual = response.readEntity(ErrorMessage.class); verify(store).fetch(); assertThat(response.getStatus()).isEqualTo(500); assertThat(actual.getCode()).isEqualTo(500); }
@GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Response fetch() { final Optional<Map<String, Rule>> rules; try { rules = store.fetch(); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e); } if (!rules.isPresent()) { throw new NotificationException(Response.Status.NOT_FOUND, "No rules found"); } return Response.ok(rules.get()).build(); }
RuleResource { @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Response fetch() { final Optional<Map<String, Rule>> rules; try { rules = store.fetch(); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e); } if (!rules.isPresent()) { throw new NotificationException(Response.Status.NOT_FOUND, "No rules found"); } return Response.ok(rules.get()).build(); } }
RuleResource { @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Response fetch() { final Optional<Map<String, Rule>> rules; try { rules = store.fetch(); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e); } if (!rules.isPresent()) { throw new NotificationException(Response.Status.NOT_FOUND, "No rules found"); } return Response.ok(rules.get()).build(); } RuleResource(final RuleStore store); }
RuleResource { @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Response fetch() { final Optional<Map<String, Rule>> rules; try { rules = store.fetch(); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e); } if (!rules.isPresent()) { throw new NotificationException(Response.Status.NOT_FOUND, "No rules found"); } return Response.ok(rules.get()).build(); } RuleResource(final RuleStore store); @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) Response fetch(); @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response store(
      @PathParam("category") final String category, @NotNull @Valid final Rule rule); @DELETE @Timed @Path("/{category}") Response delete(@PathParam("category") final String category); @DELETE @Timed Response delete(); }
RuleResource { @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) public Response fetch() { final Optional<Map<String, Rule>> rules; try { rules = store.fetch(); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e); } if (!rules.isPresent()) { throw new NotificationException(Response.Status.NOT_FOUND, "No rules found"); } return Response.ok(rules.get()).build(); } RuleResource(final RuleStore store); @GET @JSONP @Timed @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) Response fetch(); @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response store(
      @PathParam("category") final String category, @NotNull @Valid final Rule rule); @DELETE @Timed @Path("/{category}") Response delete(@PathParam("category") final String category); @DELETE @Timed Response delete();  }