@Test public void readByIsbn_shouldReturnResponseWithOkStatus() { when(bookDaoMock.readByIsbn(ISBN)).thenReturn(Optional.of(book)); Response response = resource.readByIsbn(ISBN); assertEquals(OK.getStatusCode(), response.getStatus()); assertNotNull(response.getEntity()); assertEquals(book, response.getEntity()); }
@GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } return Response.status(NOT_FOUND).entity(format(BOOK_NOT_FOUND_MSG, isbn)).build(); }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } return Response.status(NOT_FOUND).entity(format(BOOK_NOT_FOUND_MSG, isbn)).build(); } }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } return Response.status(NOT_FOUND).entity(format(BOOK_NOT_FOUND_MSG, isbn)).build(); } @Autowired  BookResource(BookDao bookDao); }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } return Response.status(NOT_FOUND).entity(format(BOOK_NOT_FOUND_MSG, isbn)).build(); } @Autowired  BookResource(BookDao bookDao); @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response create(Book book); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response readAll(); @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response readByIsbn(@PathParam("isbn") String isbn); @PUT @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response update(Book book); @DELETE @Path("{isbn}") Response delete(@PathParam("isbn") String isbn); }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } return Response.status(NOT_FOUND).entity(format(BOOK_NOT_FOUND_MSG, isbn)).build(); } @Autowired  BookResource(BookDao bookDao); @POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response create(Book book); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response readAll(); @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response readByIsbn(@PathParam("isbn") String isbn); @PUT @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) Response update(Book book); @DELETE @Path("{isbn}") Response delete(@PathParam("isbn") String isbn); static final String BOOK_NOT_FOUND_MSG; static final String BOOK_EXISTS_MSG; }