@Test public void readAll_shouldReturnResponseWithOkStatus() { when(bookDaoMock.readAll()).thenReturn(Collections.singletonList(book)); Response response = resource.readAll(); assertEquals(OK.getStatusCode(), response.getStatus()); List<Book> books = (List<Book>) response.getEntity(); assertEquals(1, books.size()); assertReflectionEquals(book, books.get(0)); }
@GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readAll() { List<Book> books = new ArrayList<>(bookDao.readAll()); GenericEntity<List<Book>> booksEntity = new GenericEntity<List<Book>>(books) { }; return Response.ok(booksEntity).build(); }
BookResource { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readAll() { List<Book> books = new ArrayList<>(bookDao.readAll()); GenericEntity<List<Book>> booksEntity = new GenericEntity<List<Book>>(books) { }; return Response.ok(booksEntity).build(); } }
BookResource { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readAll() { List<Book> books = new ArrayList<>(bookDao.readAll()); GenericEntity<List<Book>> booksEntity = new GenericEntity<List<Book>>(books) { }; return Response.ok(booksEntity).build(); } @Autowired  BookResource(BookDao bookDao); }
BookResource { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readAll() { List<Book> books = new ArrayList<>(bookDao.readAll()); GenericEntity<List<Book>> booksEntity = new GenericEntity<List<Book>>(books) { }; return Response.ok(booksEntity).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 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response readAll() { List<Book> books = new ArrayList<>(bookDao.readAll()); GenericEntity<List<Book>> booksEntity = new GenericEntity<List<Book>>(books) { }; return Response.ok(booksEntity).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; }