@Test public void readByIsbn_shouldReturnResponseWithOkStatus() { Mockito.when(bookDaoMock.readByIsbn(ISBN)).thenReturn(Optional.of(book)); BookResource resource = new BookResource(bookDaoMock); 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}) @Nonnull public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } throw new NotFoundException("Book with ISBN[" + isbn + "] does not exist."); }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } throw new NotFoundException("Book with ISBN[" + isbn + "] does not exist."); } }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } throw new NotFoundException("Book with ISBN[" + isbn + "] does not exist."); } @Autowired  BookResource(BookDao bookDao); }
BookResource { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } throw new NotFoundException("Book with ISBN[" + isbn + "] does not exist."); } @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 { @GET @Path("{isbn}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Nonnull public Response readByIsbn(@PathParam("isbn") String isbn) throws NotFoundException { Optional<Book> optional = bookDao.readByIsbn(isbn); if (optional.isPresent()) { return Response.ok(optional.get()).build(); } throw new NotFoundException("Book with ISBN[" + isbn + "] does not exist."); } @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);  }