Include cookies in the HTTP response snippet
See gh-305 Closes gh-340
This commit is contained in:
committed by
Andy Wilkinson
parent
ece826166f
commit
46190535f7
@@ -269,6 +269,26 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
"response-headers.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCookie() {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("set-cookie",
|
||||
preprocessResponse(removeHeaders(HttpHeaders.DATE, HttpHeaders.CONTENT_TYPE))))
|
||||
.get("/set-cookie").then().statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/set-cookie"),
|
||||
"http-request.adoc", "http-response.adoc", "curl-request.adoc");
|
||||
|
||||
assertThat(
|
||||
new File("build/generated-snippets/set-cookie/http-response.adoc"),
|
||||
is(snippet(asciidoctor())
|
||||
.withContents(httpResponse(asciidoctor(), HttpStatus.OK)
|
||||
.header(HttpHeaders.SET_COOKIE, "name=value;domain=localhost;HttpOnly")
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedRequest() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -51,6 +52,8 @@ class TomcatServer extends ExternalResource {
|
||||
Context context = this.tomcat.addContext("/", null);
|
||||
this.tomcat.addServlet("/", "test", new TestServlet());
|
||||
context.addServletMappingDecoded("/", "test");
|
||||
this.tomcat.addServlet("/", "set-cookie", new CookiesServlet());
|
||||
context.addServletMappingDecoded("/set-cookie", "set-cookie");
|
||||
this.tomcat.start();
|
||||
this.port = this.tomcat.getConnector().getLocalPort();
|
||||
}
|
||||
@@ -104,4 +107,19 @@ class TomcatServer extends ExternalResource {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link HttpServlet} used to handle cookies-related requests in the tests.
|
||||
*/
|
||||
private static final class CookiesServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
Cookie cookie = new Cookie("name", "value");
|
||||
cookie.setDomain("localhost");
|
||||
cookie.setHttpOnly(true);
|
||||
|
||||
resp.addCookie(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user