@Test public void testSecuredGreeting() throws Exception { log.info("Testing GreetingController.testSecuredGreeting..."); this.mockMvc.perform(get("/api/secured/greeting") .with(csrf()) .with(regularUser()) .accept(ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON)) .andDo(print()) .andExpect(status().isOk()) .andExpect(content().contentType(ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON)) .andExpect(jsonPath("$.id").value(1)) .andExpect(jsonPath("$.content").value("Hello, " + user.getUsername() + ". You have the role of ROLE_USER!")) .andExpect(authenticated().withRoles("USER")) ; log.info("Testing GreetingController.testSecuredGreeting SUCCESSFUL"); }
@RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Greeting securedGreeting() { return greetingService.securedGreeting(1.0f); }
GreetingController { @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Greeting securedGreeting() { return greetingService.securedGreeting(1.0f); } }
GreetingController { @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Greeting securedGreeting() { return greetingService.securedGreeting(1.0f); } @Autowired  GreetingController(GreetingService greetingService); }
GreetingController { @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Greeting securedGreeting() { return greetingService.securedGreeting(1.0f); } @Autowired  GreetingController(GreetingService greetingService); @RequestMapping(value = "/api/greeting") @ResponseStatus(HttpStatus.OK) Greeting greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name); @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting securedGreeting(); @RequestMapping(value = "/api/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting greetingV1Accept(@RequestParam(value = "name", required = false, defaultValue = "World") String name); @RequestMapping(value = "/api/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V2_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V2_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting greetingV2Accept(@RequestParam(value = "name", required = false, defaultValue = "World") String name); }
GreetingController { @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public Greeting securedGreeting() { return greetingService.securedGreeting(1.0f); } @Autowired  GreetingController(GreetingService greetingService); @RequestMapping(value = "/api/greeting") @ResponseStatus(HttpStatus.OK) Greeting greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name); @RequestMapping(value = "/api/secured/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting securedGreeting(); @RequestMapping(value = "/api/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting greetingV1Accept(@RequestParam(value = "name", required = false, defaultValue = "World") String name); @RequestMapping(value = "/api/greeting", headers = {"Accept="+ApplicationMediaType.APPLICATION_BEARCHOKE_V2_JSON_VALUE}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V2_JSON_VALUE) @ResponseStatus(HttpStatus.OK) Greeting greetingV2Accept(@RequestParam(value = "name", required = false, defaultValue = "World") String name);  }