@Test public void create_shouldReturnResponseWithNoContentStatus() { Mockito.when(bookDaoMock.create(book)).thenReturn(Optional.of(book)); BookResource resource = new BookResource(bookDaoMock); Response response = resource.create(book); assertEquals(NO_CONTENT.getStatusCode(), response.getStatus()); }
@POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response create(Book book) { if (bookDao.create(book).isPresent()) { return Response.status(NO_CONTENT).build(); } return Response.status(BAD_REQUEST) .entity("Book with ISBN[" + book.getIsbn() + "] already exists.") .type(MediaType.TEXT_PLAIN).build(); }
BookResource { @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response create(Book book) { if (bookDao.create(book).isPresent()) { return Response.status(NO_CONTENT).build(); } return Response.status(BAD_REQUEST) .entity("Book with ISBN[" + book.getIsbn() + "] already exists.") .type(MediaType.TEXT_PLAIN).build(); } }
BookResource { @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response create(Book book) { if (bookDao.create(book).isPresent()) { return Response.status(NO_CONTENT).build(); } return Response.status(BAD_REQUEST) .entity("Book with ISBN[" + book.getIsbn() + "] already exists.") .type(MediaType.TEXT_PLAIN).build(); } @Autowired  BookResource(BookDao bookDao); }
BookResource { @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response create(Book book) { if (bookDao.create(book).isPresent()) { return Response.status(NO_CONTENT).build(); } return Response.status(BAD_REQUEST) .entity("Book with ISBN[" + book.getIsbn() + "] already exists.") .type(MediaType.TEXT_PLAIN).build(); } @Autowired  BookResource(BookDao bookDao); @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response create(Book book); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response readAll(); @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response readByIsbn(@PathParam("isbn") String isbn); @PUT @Path("{isbn}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response update(Book book); @DELETE @Path("{isbn}") @Nonnull Response delete(@PathParam("isbn") String isbn); }
BookResource { @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response create(Book book) { if (bookDao.create(book).isPresent()) { return Response.status(NO_CONTENT).build(); } return Response.status(BAD_REQUEST) .entity("Book with ISBN[" + book.getIsbn() + "] already exists.") .type(MediaType.TEXT_PLAIN).build(); } @Autowired  BookResource(BookDao bookDao); @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response create(Book book); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response readAll(); @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response readByIsbn(@PathParam("isbn") String isbn); @PUT @Path("{isbn}") @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull Response update(Book book); @DELETE @Path("{isbn}") @Nonnull Response delete(@PathParam("isbn") String isbn);  }