AuthenticationController { @RequestMapping(value = "/validate", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = TEXT_PLAIN_VALUE) @ResponseBody public String validate(@RequestBody Token token) { logger.info("Received validation request of token {}", token); return authenticationService.validate(token.getToken()); } @Autowired  AuthenticationController(
      AuthenticationService authenticationService,
      AuthorizationHeaderGenerator authorizationHeaderGenerator); @RequestMapping(value = "/login", method = POST, produces = TEXT_PLAIN_VALUE) ResponseEntity<String> login(
      @RequestParam(USERNAME) String username,
      @RequestParam(PASSWORD) String password); @RequestMapping(value = "/validate", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = TEXT_PLAIN_VALUE) @ResponseBody String validate(@RequestBody Token token);  }
@Test public void validatesTokenAgainstStoredUserSessions() throws Exception { when(authenticationService.validate(token)).thenReturn(username); mockMvc.perform( post("/rest/validate") .contentType(APPLICATION_JSON_UTF8_VALUE) .content(objectMapper.writeValueAsBytes(new Token(token)))) .andExpect(status().isOk()) .andExpect(content().string(username)); }