@Test public void search_ShouldReturnTodoList() { TodoDocument document = TodoTestUtil.createDocument(TodoTestUtil.ID, TodoTestUtil.DESCRIPTION, TodoTestUtil.TITLE); List<TodoDocument> documents = createDocuments(document); when(serviceMock.search(eq(SEARCH_TERM), any(Pageable.class))).thenReturn(documents); PageRequest page = new PageRequest(1, 1); List<TodoDTO> results = controller.search(SEARCH_TERM, page); verify(serviceMock, times(1)).search(SEARCH_TERM, page); verifyNoMoreInteractions(serviceMock); assertEquals(documents.size(), results.size()); for (int index = 0; index < documents.size(); index++) { TodoDocument expected = documents.get(index); TodoDTO actual = results.get(index); assertEquals(Long.valueOf(expected.getId()), actual.getId()); assertEquals(expected.getTitle(), actual.getTitle()); assertNull(actual.getDescription()); } }
@RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody public List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page) { LOGGER.debug("Search todo entries with search term: {} and page: {}", searchTerm, page); List<TodoDocument> todoEntries = service.search(searchTerm, page); LOGGER.debug("Found {} todo entries", todoEntries.size()); return createSearchResultDTOs(todoEntries); }
TodoController { @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody public List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page) { LOGGER.debug("Search todo entries with search term: {} and page: {}", searchTerm, page); List<TodoDocument> todoEntries = service.search(searchTerm, page); LOGGER.debug("Found {} todo entries", todoEntries.size()); return createSearchResultDTOs(todoEntries); } }
TodoController { @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody public List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page) { LOGGER.debug("Search todo entries with search term: {} and page: {}", searchTerm, page); List<TodoDocument> todoEntries = service.search(searchTerm, page); LOGGER.debug("Found {} todo entries", todoEntries.size()); return createSearchResultDTOs(todoEntries); }  }
TodoController { @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody public List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page) { LOGGER.debug("Search todo entries with search term: {} and page: {}", searchTerm, page); List<TodoDocument> todoEntries = service.search(searchTerm, page); LOGGER.debug("Found {} todo entries", todoEntries.size()); return createSearchResultDTOs(todoEntries); }  @RequestMapping(value = "/api/todo", method = RequestMethod.POST) @ResponseBody TodoDTO add(@RequestBody TodoDTO dto); @RequestMapping(value = "/api/todo/search/count/{searchTerm}", method = RequestMethod.GET) @ResponseBody long countSearchResults(@PathVariable("searchTerm") String searchTerm); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.DELETE) @ResponseBody TodoDTO deleteById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo", method = RequestMethod.GET) @ResponseBody List<TodoDTO> findAll(); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.PUT) @ResponseBody TodoDTO update(@RequestBody TodoDTO dto, @PathVariable("id") Long todoId); @ExceptionHandler(FormValidationError.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) FormValidationErrorDTO handleFormValidationError(FormValidationError validationError); @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page); @ExceptionHandler(TodoNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) void handleTodoNotFoundException(TodoNotFoundException ex); }
TodoController { @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody public List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page) { LOGGER.debug("Search todo entries with search term: {} and page: {}", searchTerm, page); List<TodoDocument> todoEntries = service.search(searchTerm, page); LOGGER.debug("Found {} todo entries", todoEntries.size()); return createSearchResultDTOs(todoEntries); }  @RequestMapping(value = "/api/todo", method = RequestMethod.POST) @ResponseBody TodoDTO add(@RequestBody TodoDTO dto); @RequestMapping(value = "/api/todo/search/count/{searchTerm}", method = RequestMethod.GET) @ResponseBody long countSearchResults(@PathVariable("searchTerm") String searchTerm); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.DELETE) @ResponseBody TodoDTO deleteById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo", method = RequestMethod.GET) @ResponseBody List<TodoDTO> findAll(); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.GET) @ResponseBody TodoDTO findById(@PathVariable("id") Long id); @RequestMapping(value = "/api/todo/{id}", method = RequestMethod.PUT) @ResponseBody TodoDTO update(@RequestBody TodoDTO dto, @PathVariable("id") Long todoId); @ExceptionHandler(FormValidationError.class) @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) FormValidationErrorDTO handleFormValidationError(FormValidationError validationError); @RequestMapping(value = "/api/todo/search/{searchTerm}", method = RequestMethod.GET) @ResponseBody List<TodoDTO> search(@PathVariable("searchTerm") String searchTerm, Pageable page); @ExceptionHandler(TodoNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) void handleTodoNotFoundException(TodoNotFoundException ex);  }