Polish "Include cookies in the HTTP response snippet"
See gh-340 Closes gh-305
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,8 @@ class MockMvcResponseConverter implements ResponseConverter<MockHttpServletRespo
|
||||
}
|
||||
}
|
||||
|
||||
if (response.getCookies() != null && !headers.containsKey(HttpHeaders.SET_COOKIE)) {
|
||||
if (response.getCookies() != null
|
||||
&& !headers.containsKey(HttpHeaders.SET_COOKIE)) {
|
||||
for (Cookie cookie : response.getCookies()) {
|
||||
headers.add(HttpHeaders.SET_COOKIE, generateSetCookieHeader(cookie));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public class MockMvcResponseConverterTests {
|
||||
private final MockMvcResponseConverter factory = new MockMvcResponseConverter();
|
||||
|
||||
@Test
|
||||
public void httpResponse() {
|
||||
public void basicResponse() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
@@ -67,6 +67,7 @@ public class MockMvcResponseConverterTests {
|
||||
|
||||
assertThat(operationResponse.getHeaders().size(), is(1));
|
||||
assertTrue(operationResponse.getHeaders().containsKey(HttpHeaders.SET_COOKIE));
|
||||
assertThat(operationResponse.getHeaders().get(HttpHeaders.SET_COOKIE), equalTo(Collections.singletonList("name=value;domain=localhost;HttpOnly")));
|
||||
assertThat(operationResponse.getHeaders().get(HttpHeaders.SET_COOKIE), equalTo(
|
||||
Collections.singletonList("name=value;domain=localhost;HttpOnly")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,17 +371,16 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)).build();
|
||||
|
||||
mockMvc.perform(get("/set-cookie"))
|
||||
.andExpect(status().isOk())
|
||||
mockMvc.perform(get("/set-cookie")).andExpect(status().isOk())
|
||||
.andDo(document("set-cookie",
|
||||
responseHeaders(headerWithName(HttpHeaders.SET_COOKIE).description("set-cookie"))));
|
||||
responseHeaders(headerWithName(HttpHeaders.SET_COOKIE)
|
||||
.description("set-cookie"))));
|
||||
|
||||
assertThat(
|
||||
new File("build/generated-snippets/set-cookie/http-response.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"))));
|
||||
.withContents(httpResponse(asciidoctor(), HttpStatus.OK).header(
|
||||
HttpHeaders.SET_COOKIE,
|
||||
"name=value;domain=localhost;HttpOnly"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -274,19 +274,17 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("set-cookie",
|
||||
preprocessResponse(removeHeaders(HttpHeaders.DATE, HttpHeaders.CONTENT_TYPE))))
|
||||
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"),
|
||||
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")
|
||||
)
|
||||
)
|
||||
);
|
||||
.withContents(httpResponse(asciidoctor(), HttpStatus.OK).header(
|
||||
HttpHeaders.SET_COOKIE,
|
||||
"name=value;domain=localhost;HttpOnly"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -113,7 +113,8 @@ class TomcatServer extends ExternalResource {
|
||||
private static final class CookiesServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
Cookie cookie = new Cookie("name", "value");
|
||||
cookie.setDomain("localhost");
|
||||
cookie.setHttpOnly(true);
|
||||
|
||||
Reference in New Issue
Block a user