@Test public void readAll_shouldReturnResponseWithOkStatus() { Mockito.when(bookDaoMock.readAll()).thenReturn(Arrays.asList(book)); BookResource resource = new BookResource(bookDaoMock); ResponseEntity<BooksList> response = resource.readAll(); assertEquals(HttpStatus.OK, response.getStatusCode()); BooksList booksList = response.getBody(); assertEquals(1, booksList.getBooks().size()); assertReflectionEquals(book, booksList.getBooks().get(0)); }
@RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity<BooksList> readAll() { BooksList books = new BooksList(bookDao.readAll()); logger.info("found [{}] books", books.getBooks().size()); return new ResponseEntity<BooksList>(books, HttpStatus.OK); }
BookResource { @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity<BooksList> readAll() { BooksList books = new BooksList(bookDao.readAll()); logger.info("found [{}] books", books.getBooks().size()); return new ResponseEntity<BooksList>(books, HttpStatus.OK); } }
BookResource { @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity<BooksList> readAll() { BooksList books = new BooksList(bookDao.readAll()); logger.info("found [{}] books", books.getBooks().size()); return new ResponseEntity<BooksList>(books, HttpStatus.OK); } @Autowired  BookResource(BookDao bookDao); }
BookResource { @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity<BooksList> readAll() { BooksList books = new BooksList(bookDao.readAll()); logger.info("found [{}] books", books.getBooks().size()); return new ResponseEntity<BooksList>(books, HttpStatus.OK); } @Autowired  BookResource(BookDao bookDao); @RequestMapping(method = RequestMethod.POST, consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<String> create(@RequestBody Book book); @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<BooksList> readAll(); @RequestMapping(value = "/{isbn}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<Book> readByIsbn(@PathVariable String isbn); @RequestMapping(value = "/{isbn}", method = RequestMethod.PUT, consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<String> update(@RequestBody Book book); @RequestMapping(value = "{isbn}", method = RequestMethod.DELETE) ResponseEntity<String> delete(@PathVariable String isbn); @ExceptionHandler({EntityNotFoundException.class}) ResponseEntity<String> handleEntityNotFoundException(EntityNotFoundException e); @ExceptionHandler({EntityExistsException.class}) ResponseEntity<String> handleEntityExistsException(EntityExistsException e); }
BookResource { @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity<BooksList> readAll() { BooksList books = new BooksList(bookDao.readAll()); logger.info("found [{}] books", books.getBooks().size()); return new ResponseEntity<BooksList>(books, HttpStatus.OK); } @Autowired  BookResource(BookDao bookDao); @RequestMapping(method = RequestMethod.POST, consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<String> create(@RequestBody Book book); @RequestMapping(value = "/all", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<BooksList> readAll(); @RequestMapping(value = "/{isbn}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<Book> readByIsbn(@PathVariable String isbn); @RequestMapping(value = "/{isbn}", method = RequestMethod.PUT, consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) ResponseEntity<String> update(@RequestBody Book book); @RequestMapping(value = "{isbn}", method = RequestMethod.DELETE) ResponseEntity<String> delete(@PathVariable String isbn); @ExceptionHandler({EntityNotFoundException.class}) ResponseEntity<String> handleEntityNotFoundException(EntityNotFoundException e); @ExceptionHandler({EntityExistsException.class}) ResponseEntity<String> handleEntityExistsException(EntityExistsException e);  }