I have a Spring Controller that contains a logout endpoint
@PostMapping("/logout")
public ResponseEntity<Void> logout() {
var request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
try {
request.logout();
return new ResponseEntity<>(HttpStatus.OK);
} catch (ServletException e) {
log.error("Unable to logout");
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
How can I test this using mockmvc ?
What I have so far is this piece of code, but I don't know how to test that the request.logout() was called (what are its effects?).
mvc.perform(MockMvcRequestBuilders.post("/logout").principal(principal)).expect(??)