@Test public void testStoreException() throws Exception { doThrow(new NotificationStoreException()).when(store).store(anyString(), any(Rule.class)); final Rule rule = Rule.builder().withMaxSize(3).build(); final Response response = resources .client() .target("/v1/rules/follow") .request(MediaType.APPLICATION_JSON) .put(Entity.json(rule)); final ErrorMessage actual = response.readEntity(ErrorMessage.class); verify(store).store("follow", rule); assertThat(response.getStatus()).isEqualTo(500); assertThat(actual.getCode()).isEqualTo(500); }
@PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response store( @PathParam("category") final String category, @NotNull @Valid final Rule rule) { if (!rule.isValid()) { throw new NotificationException( Response.Status.BAD_REQUEST, "Rule must contain at least one of: max_size, max_duration, or match_on"); } try { store.store(category, rule); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to store rule", e); } return Response.noContent().build(); }
RuleResource { @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response store( @PathParam("category") final String category, @NotNull @Valid final Rule rule) { if (!rule.isValid()) { throw new NotificationException( Response.Status.BAD_REQUEST, "Rule must contain at least one of: max_size, max_duration, or match_on"); } try { store.store(category, rule); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to store rule", e); } return Response.noContent().build(); } }
RuleResource { @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response store( @PathParam("category") final String category, @NotNull @Valid final Rule rule) { if (!rule.isValid()) { throw new NotificationException( Response.Status.BAD_REQUEST, "Rule must contain at least one of: max_size, max_duration, or match_on"); } try { store.store(category, rule); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to store rule", e); } return Response.noContent().build(); } RuleResource(final RuleStore store); }
RuleResource { @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response store( @PathParam("category") final String category, @NotNull @Valid final Rule rule) { if (!rule.isValid()) { throw new NotificationException( Response.Status.BAD_REQUEST, "Rule must contain at least one of: max_size, max_duration, or match_on"); } try { store.store(category, rule); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to store rule", e); } return Response.noContent().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 { @PUT @Timed @Path("/{category}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response store( @PathParam("category") final String category, @NotNull @Valid final Rule rule) { if (!rule.isValid()) { throw new NotificationException( Response.Status.BAD_REQUEST, "Rule must contain at least one of: max_size, max_duration, or match_on"); } try { store.store(category, rule); } catch (NotificationStoreException e) { throw new NotificationException( Response.Status.INTERNAL_SERVER_ERROR, "Unable to store rule", e); } return Response.noContent().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();  }