mercredi 16 novembre 2016

Way to keep session alive while testing spring application

I've came up with something like this:

ResponseEntity<String> responseEntity1 = restTemplate.postForEntity("/app/start", path, String.class);
(...)

HttpHeaders requestHeadersSession = new HttpHeaders();
requestHeadersSession.set("Cookie", responseEntity1.getHeaders().get("Set-Cookie").get(0));
HttpEntity<String> requestEntityToKeepSession = new HttpEntity<>(path, requestHeadersSession);
restTemplate.postForEntity("/app/endSession", requestEntityToKeepSession, String.class);

restTemplate.postForEntity("/app/start", path, String.class);

Goal is to test if it correctly close resources after session ends, and right now it works. I'm wondering if there is better way to keep session alive while testing with different requests?

Aucun commentaire:

Enregistrer un commentaire