@Test public void addMessageWithInvalidLevel() throws JsonProcessingException { Message msg = new Message( "message with broken message level", Collections.singleton(MessagesContainer.MESSAGES_MAIN_PAGE_TAG), Message.MessageLevel.INFO, Duration.ofMinutes(10)); ObjectMapper objectMapper = new ObjectMapper(); final String invalidMessageLevel = "invalid"; String msgAsString = objectMapper.writeValueAsString(msg); msgAsString = msgAsString.replaceAll(Message.MessageLevel.INFO.toString(), invalidMessageLevel); assertTrue(msgAsString.contains(invalidMessageLevel)); Response r = target("messages") .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.json(msgAsString)); assertEquals(0, env.getMessages().stream().filter(m -> m.getMessageLevel().equals(invalidMessageLevel)).count()); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus()); }
@GET @Produces(MediaType.APPLICATION_JSON) public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { if (tag != null) { return env.getMessages(tag); } else { return env.getAllMessages(); } }
MessagesController { @GET @Produces(MediaType.APPLICATION_JSON) public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { if (tag != null) { return env.getMessages(tag); } else { return env.getAllMessages(); } } }
MessagesController { @GET @Produces(MediaType.APPLICATION_JSON) public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { if (tag != null) { return env.getMessages(tag); } else { return env.getAllMessages(); } }  }
MessagesController { @GET @Produces(MediaType.APPLICATION_JSON) public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { if (tag != null) { return env.getMessages(tag); } else { return env.getAllMessages(); } }  @POST @Consumes(MediaType.APPLICATION_JSON) Response addMessage(@Valid final Message message); @DELETE @Consumes(MediaType.TEXT_PLAIN) void removeMessagesWithTag(@QueryParam("tag") final String tag, final String text); @GET @Produces(MediaType.APPLICATION_JSON) Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag); }
MessagesController { @GET @Produces(MediaType.APPLICATION_JSON) public Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag) { if (tag != null) { return env.getMessages(tag); } else { return env.getAllMessages(); } }  @POST @Consumes(MediaType.APPLICATION_JSON) Response addMessage(@Valid final Message message); @DELETE @Consumes(MediaType.TEXT_PLAIN) void removeMessagesWithTag(@QueryParam("tag") final String tag, final String text); @GET @Produces(MediaType.APPLICATION_JSON) Set<AcceptedMessage> getMessages(@QueryParam("tag") final String tag);  }