@Test public void event() throws Exception { mockMvc.perform(get("/event")) .andExpect(status().isOk()) .andExpect( content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[0].name", is("Chess Tournament"))) .andExpect(jsonPath("$[0].location", is("Bursa"))) .andExpect(jsonPath("$[0].privacy", is(false))) .andExpect(jsonPath("$[1].name", is("Tennis Tournament"))) .andExpect(jsonPath("$[1].location", is("Ankara"))) .andExpect(jsonPath("$[1].privacy", is(true))); verify(repo, times(1)).findAll(); verifyNoMoreInteractions(repo); }
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody List<Event> event() { return repository.findAll(); }
EventController { @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody List<Event> event() { return repository.findAll(); } }
EventController { @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody List<Event> event() { return repository.findAll(); } @Autowired  EventController(EventRepository repository); }
EventController { @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody List<Event> event() { return repository.findAll(); } @Autowired  EventController(EventRepository repository); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<Event> event(); @RequestMapping(method = RequestMethod.GET, value = "", params = "name", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody Event eventByName(@RequestParam("name") String name); @RequestMapping(method = RequestMethod.GET, value = "", params = "privacy", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<Event> eventByPrivacy(@RequestParam("privacy") Boolean privacy); @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody Event insertData(ModelMap model,
                     @ModelAttribute("insertEvent") @Valid Event event,
                     BindingResult result); @RequestMapping(method = RequestMethod.DELETE, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteEvent(@PathVariable("id") long id); @ExceptionHandler(CustomException.class) ResponseEntity<ErrorResponse> exceptionHandler(Exception ex); }
EventController { @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody List<Event> event() { return repository.findAll(); } @Autowired  EventController(EventRepository repository); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<Event> event(); @RequestMapping(method = RequestMethod.GET, value = "", params = "name", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody Event eventByName(@RequestParam("name") String name); @RequestMapping(method = RequestMethod.GET, value = "", params = "privacy", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody List<Event> eventByPrivacy(@RequestParam("privacy") Boolean privacy); @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody Event insertData(ModelMap model,
                     @ModelAttribute("insertEvent") @Valid Event event,
                     BindingResult result); @RequestMapping(method = RequestMethod.DELETE, value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody ResponseEntity<Void> deleteEvent(@PathVariable("id") long id); @ExceptionHandler(CustomException.class) ResponseEntity<ErrorResponse> exceptionHandler(Exception ex);  }