Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2018-03-27 14:13:45 +01:00
5 changed files with 38 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -105,7 +105,7 @@ public class CurlRequestSnippet extends TemplatedSnippet {
CliOperationRequest request = new CliOperationRequest(operation.getRequest());
writeUserOptionIfNecessary(request, builder);
writeHttpMethodIfNecessary(request, builder);
writeHttpMethod(request, builder);
List<String> additionalLines = new ArrayList<>();
writeHeaders(request, additionalLines);
@@ -144,11 +144,8 @@ public class CurlRequestSnippet extends TemplatedSnippet {
}
}
private void writeHttpMethodIfNecessary(OperationRequest request,
StringBuilder builder) {
if (!HttpMethod.GET.equals(request.getMethod())) {
builder.append(String.format(" -X %s", request.getMethod()));
}
private void writeHttpMethod(OperationRequest request, StringBuilder builder) {
builder.append(String.format(" -X %s", request.getMethod()));
}
private void writeHeaders(CliOperationRequest request, List<String> lines) {

View File

@@ -59,15 +59,15 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequest() throws IOException {
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo' -i"));
codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo").build());
}
@Test
public void getRequestWithParameter() throws IOException {
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo?a=alpha' -i"));
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?a=alpha' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").param("a", "alpha").build());
}
@@ -83,7 +83,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithContent() throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo' -i -d 'content'"));
.content("$ curl 'http://localhost/foo' -i -X GET -d 'content'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").content("content").build());
}
@@ -91,7 +91,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequestWithQueryString() throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?param=value' -i"));
.content("$ curl 'http://localhost/foo?param=value' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").build());
}
@@ -100,7 +100,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
public void getRequestWithTotallyOverlappingQueryStringAndParameters()
throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?param=value' -i"));
.content("$ curl 'http://localhost/foo?param=value' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param=value")
.param("param", "value").build());
@@ -110,7 +110,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
public void getRequestWithPartiallyOverlappingQueryStringAndParameters()
throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i"));
.content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.param("a", "alpha").param("b", "bravo").build());
@@ -119,15 +119,15 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequestWithDisjointQueryStringAndParameters() throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i"));
.content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
}
@Test
public void getRequestWithQueryStringWithNoValue() throws IOException {
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo?param' -i"));
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo?param' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param").build());
}
@@ -242,8 +242,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithHeaders() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i"
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
@@ -254,8 +254,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithHeadersMultiline() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash")
.content(String.format("$ curl 'http://localhost/foo' -i \\%n"
.withContents(codeBlock("bash").content(
String.format("$ curl 'http://localhost/foo' -i -X GET \\%n"
+ " -H 'Content-Type: application/json' \\%n"
+ " -H 'a: alpha'")));
new CurlRequestSnippet(CliDocumentation.multiLineFormat())
@@ -267,8 +267,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithCookies() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i"
this.snippets.expectCurlRequest().withContents(
codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"
+ " --cookie 'name1=value1;name2=value2'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
@@ -336,7 +336,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException {
this.snippets.expectCurlRequest().withContents(codeBlock("bash")
.content("$ curl 'http://localhost/foo' -i -u 'user:secret'"));
.content("$ curl 'http://localhost/foo' -i -u 'user:secret' -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
@@ -363,10 +363,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void customHostHeaderIsIncluded() throws IOException {
this.snippets.expectCurlRequest()
.withContents(codeBlock("bash").content(
"$ curl 'http://localhost/foo' -i" + " -H 'Host: api.example.com'"
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
this.snippets.expectCurlRequest().withContents(codeBlock("bash").content(
"$ curl 'http://localhost/foo' -i -X GET -H 'Host: api.example.com'"
+ " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")

View File

@@ -179,10 +179,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("curl-snippet-with-cookies"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ curl 'http://localhost:8080/' -i \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'")))));
is(snippet(asciidoctor())
.withContents(codeBlock(asciidoctor(), "bash").content(String
.format("$ curl 'http://localhost:8080/' -i -X GET \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'")))));
}
@Test
@@ -617,9 +618,9 @@ public class MockMvcRestDocumentationIntegrationTests {
assertThat(
new File(
"build/generated-snippets/custom-context-path/curl-request.adoc"),
is(snippet(asciidoctor())
.withContents(codeBlock(asciidoctor(), "bash").content(String
.format("$ curl 'http://localhost:8080/custom/' -i \\%n"
is(snippet(asciidoctor()).withContents(
codeBlock(asciidoctor(), "bash").content(String.format(
"$ curl 'http://localhost:8080/custom/' -i -X GET \\%n"
+ " -H 'Accept: application/json'")))));
}

View File

@@ -121,7 +121,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ curl 'http://localhost:"
+ tomcat.getPort() + "/' -i \\%n"
+ tomcat.getPort() + "/' -i -X GET \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -H 'Content-Type: " + contentType + "' \\%n"
+ " --cookie 'cookieName=cookieVal'")))));

View File

@@ -177,10 +177,11 @@ public class WebTestClientRestDocumentationIntegrationTests {
.expectBody().consumeWith(document("curl-snippet-with-cookies"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ curl 'https://api.example.com/' -i \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'")))));
is(snippet(asciidoctor())
.withContents(codeBlock(asciidoctor(), "bash").content(String
.format("$ curl 'https://api.example.com/' -i -X GET \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'")))));
}
@Test