Polish "Include cookies in request snippets"

See gh-336

Closes gh-302
Closes gh-303
Closes gh-304
This commit is contained in:
Andy Wilkinson
2017-02-02 14:42:43 +00:00
parent 25bc6c37da
commit a9c1e04081
16 changed files with 107 additions and 117 deletions

View File

@@ -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.

View File

@@ -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.
@@ -32,6 +32,7 @@ import org.springframework.restdocs.operation.OperationRequestPart;
import org.springframework.restdocs.operation.Parameters;
import org.springframework.restdocs.snippet.Snippet;
import org.springframework.restdocs.snippet.TemplatedSnippet;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@@ -102,17 +103,16 @@ public class CurlRequestSnippet extends TemplatedSnippet {
}
private void writeCookies(CliOperationRequest request, PrintWriter printer) {
if (request.getCookies() != null && request.getCookies().size() > 0) {
printer.print(" --cookie ");
if (!CollectionUtils.isEmpty(request.getCookies())) {
StringBuilder cookiesBuilder = new StringBuilder();
for (Cookie cookie : request.getCookies()) {
cookiesBuilder.append(String.format("%s=%s;", cookie.getName(), cookie.getValue()));
if (cookiesBuilder.length() > 0) {
cookiesBuilder.append(";");
}
cookiesBuilder.append(
String.format("%s=%s", cookie.getName(), cookie.getValue()));
}
String cookiesHeader = cookiesBuilder.substring(0, cookiesBuilder.length() - 1); // remove trailing semicolon
printer.print(String.format("'%s'", cookiesHeader)); // add single quotes
printer.print(String.format(" --cookie '%s'", cookiesBuilder.toString()));
}
}

View File

@@ -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.
@@ -108,6 +108,7 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
PrintWriter printer = new PrintWriter(requestItems);
writeFormDataIfNecessary(request, printer);
writeHeaders(request, printer);
writeCookies(request, printer);
writeParametersIfNecessary(request, printer);
return requestItems.toString();
}
@@ -162,9 +163,12 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
writer.print(String.format(" '%s:%s'", entry.getKey(), header));
}
}
}
private void writeCookies(OperationRequest request, PrintWriter writer) {
for (Cookie cookie : request.getCookies()) {
writer.print(String.format(" 'Cookie:%s=%s'", cookie.getName(), cookie.getValue()));
writer.print(String.format(" 'Cookie:%s=%s'", cookie.getName(),
cookie.getValue()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 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.
@@ -89,9 +89,11 @@ public interface OperationRequest {
URI getUri();
/**
* Returns cookies sent with the request.
* Returns {@link Cookie Cookies} sent with the request. If no cookies were sent an
* empty collection is returned.
*
* @return the cookies
* @return the cookies, never {@code null}
* @since 1.2.0
*/
Collection<Cookie> getCookies();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 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.
@@ -45,7 +45,8 @@ class StandardOperationRequest extends AbstractOperationMessage
/**
* Creates a new request with the given {@code uri} and {@code method}. The request
* will have the given {@code headers}, {@code parameters}, and {@code parts}.
* will have the given {@code headers}, {@code parameters}, {@code parts}, and
* {@code cookies}.
*
* @param uri the uri
* @param method the method
@@ -53,11 +54,11 @@ class StandardOperationRequest extends AbstractOperationMessage
* @param headers the headers
* @param parameters the parameters
* @param parts the parts
* @param cookies the cookies
*/
StandardOperationRequest(URI uri, HttpMethod method, byte[] content,
HttpHeaders headers, Parameters parameters,
Collection<OperationRequestPart> parts,
Collection<Cookie> cookies) {
Collection<OperationRequestPart> parts, Collection<Cookie> cookies) {
super(content, headers);
this.uri = uri;
this.method = method;

View File

@@ -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.
@@ -254,12 +254,11 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithCookies() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i" +
" --cookie 'name1=value1;name2=value2'"));
.withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i"
+ " --cookie 'name1=value1;name2=value2'"));
new CurlRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1")
.cookie("name2", "value2").build());
.cookie("name1", "value1").cookie("name2", "value2").build());
}
@Test
@@ -269,9 +268,10 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
+ "'metadata={\"description\": \"foo\"}'";
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
new CurlRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@@ -286,9 +286,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -302,8 +302,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -318,9 +318,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
}
@Test
@@ -332,7 +332,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test

View File

@@ -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.
@@ -255,12 +255,11 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithCookies() throws IOException {
this.snippets.expectHttpieRequest().withContents(
codeBlock("bash").content("$ http GET 'http://localhost/foo'" +
" 'Cookie:name1=value1' 'Cookie:name2=value2'"));
codeBlock("bash").content("$ http GET 'http://localhost/foo'"
+ " 'Cookie:name1=value1' 'Cookie:name2=value2'"));
new HttpieRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1")
.cookie("name2", "value2").build());
.cookie("name1", "value1").cookie("name2", "value2").build());
}
@Test
@@ -270,9 +269,10 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
+ " 'metadata'@<(echo '{\"description\": \"foo\"}')");
this.snippets.expectHttpieRequest()
.withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
new HttpieRequestSnippet().document(
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@@ -288,9 +288,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -304,8 +304,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -320,9 +320,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
}
@Test
@@ -334,7 +334,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test

View File

@@ -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.
@@ -54,7 +54,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.row("`X-Test`", "one").row("`Accept`", "two")
.row("`Accept-Encoding`", "three")
.row("`Accept-Language`", "four").row("`Cache-Control`", "five")
.row("`Connection`", "six").row("`Cookie`", "seven"));
.row("`Connection`", "six"));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one"),
headerWithName("Accept").description("two"),
@@ -63,8 +63,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Cache-Control").description("five"),
headerWithName(
"Connection")
.description("six"),
headerWithName("Cookie").description("seven")))
.description("six")))
.document(
this.operationBuilder
.request(
@@ -73,15 +72,9 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("Accept", "*/*")
.header("Accept-Encoding",
"gzip, deflate")
.header("Accept-Language",
"en-US,en;q=0.5")
.header("Cache-Control",
"max-age=0")
.header("Connection",
"keep-alive")
.header("Cookie",
"cookie1=cookieVal1; cookie2=cookieVal2")
.build());
.header("Accept-Language", "en-US,en;q=0.5")
.header("Cache-Control", "max-age=0")
.header("Connection", "keep-alive").build());
}
@Test
@@ -150,7 +143,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test")
.header("Accept-Encoding",
"gzip, deflate")
.header("Accept", "*/*").build());
.header("Accept", "*/*").build());
}
@Test

View File

@@ -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.
@@ -90,9 +90,7 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1")
.cookie("name2", "value2")
.build());
.cookie("name1", "value1").cookie("name2", "value2").build());
}
@Test
@@ -142,8 +140,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.POST, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").method("POST").content(content).build());
@@ -154,8 +152,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.POST, "/foo?a=alpha")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
@@ -168,8 +166,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo?b=bravo")
@@ -182,8 +180,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo?b=bravo").method("POST")
@@ -196,8 +194,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo?b=bravo&a=alpha").method("POST")
@@ -251,8 +249,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world";
this.snippets.expectHttpRequest()
.withContents(httpRequest(RequestMethod.PUT, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content).header(
HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
.header(HttpHeaders.HOST, "localhost").content(content)
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").method("PUT").content(content).build());
@@ -284,7 +282,7 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).build());
.part("image", "<< data >>".getBytes()).build());
}
@Test
@@ -310,8 +308,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.param("a", "apple", "avocado").param("b", "banana")
.part("image", "<< data >>".getBytes()).build());
.param("a", "apple", "avocado").param("b", "banana")
.part("image", "<< data >>".getBytes()).build());
}
@Test
@@ -347,9 +345,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes())
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.build());
.part("image", "<< data >>".getBytes())
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE).build());
}
@Test

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.
@@ -93,8 +93,7 @@ public class MockMvcRequestConverterTests {
@Test
public void requestWithCookies() throws Exception {
OperationRequest request = createOperationRequest(MockMvcRequestBuilders
.get("/foo")
.cookie(new Cookie("cookieName1", "cookieVal1"),
.get("/foo").cookie(new Cookie("cookieName1", "cookieVal1"),
new Cookie("cookieName2", "cookieVal2")));
assertThat(request.getUri(), is(URI.create("http://localhost/foo")));
assertThat(request.getMethod(), is(HttpMethod.GET));

View File

@@ -166,10 +166,9 @@ public class MockMvcRestDocumentationIntegrationTests {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)).build();
mockMvc.perform(get("/")
.accept(MediaType.APPLICATION_JSON)
.cookie(new Cookie("cookieName", "cookieVal")))
.andExpect(status().isOk()).andDo(document("curl-snippet-with-cookies"));
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)
.cookie(new Cookie("cookieName", "cookieVal"))).andExpect(status().isOk())
.andDo(document("curl-snippet-with-cookies"));
assertThat(
new File(
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"),
@@ -231,10 +230,8 @@ public class MockMvcRestDocumentationIntegrationTests {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)).build();
mockMvc.perform(get("/")
.accept(MediaType.APPLICATION_JSON)
.cookie(new Cookie("cookieName", "cookieVal")))
.andExpect(status().isOk())
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)
.cookie(new Cookie("cookieName", "cookieVal"))).andExpect(status().isOk())
.andDo(document("httpie-snippet-with-cookies"));
assertThat(
new File(

View File

@@ -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.
@@ -60,13 +60,13 @@ class RestAssuredRequestConverter
extractCookies(requestSpec));
}
private Collection<javax.servlet.http.Cookie> extractCookies(FilterableRequestSpecification requestSpec) {
private Collection<javax.servlet.http.Cookie> extractCookies(
FilterableRequestSpecification requestSpec) {
Collection<javax.servlet.http.Cookie> cookies = new ArrayList<>();
for (Cookie cookie : requestSpec.getCookies()) {
cookies.add(new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue()));
cookies.add(
new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue()));
}
return cookies;
}

View File

@@ -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.
@@ -148,8 +148,7 @@ public class RestAssuredRequestConverterTests {
@Test
public void cookies() {
RequestSpecification requestSpec = RestAssured.given().port(this.port)
.cookie("cookie1", "cookieVal1")
.cookie("cookie2", "cookieVal2");
.cookie("cookie1", "cookieVal1").cookie("cookie2", "cookieVal2");
requestSpec.get("/");
OperationRequest request = this.factory
.convert((FilterableRequestSpecification) requestSpec);

View File

@@ -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.
@@ -124,17 +124,15 @@ public class RestAssuredRestDocumentationIntegrationTests {
String contentType = "text/plain; charset=UTF-8";
given().port(this.port).filter(documentationConfiguration(this.restDocumentation))
.filter(document("curl-snippet-with-cookies")).accept("application/json")
.contentType(contentType)
.cookie("cookieName", "cookieVal").get("/")
.then()
.statusCode(200);
.contentType(contentType).cookie("cookieName", "cookieVal").get("/")
.then().statusCode(200);
assertThat(
new File(
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content("$ curl 'http://localhost:" + this.port + "/' -i "
+ "-H 'Accept: application/json' "
+ "-H 'Content-Type: " + contentType + "' "
+ "-H 'Accept: application/json' " + "-H 'Content-Type: "
+ contentType + "' "
+ "--cookie 'cookieName=cookieVal'"))));
}