我想出了类似的东西:
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);
目标是测试会话结束后是否正确关闭资源,现在它可以正常工作。我想知道在使用不同的请求进行测试时是否有更好的方法可以使会话保持活动状态?