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