Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2018-03-27 13:01:20 +01:00
31 changed files with 329 additions and 424 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.
@@ -93,9 +93,8 @@ public class MockMvcRequestConverterTests {
@Test
public void requestWithCookies() throws Exception {
OperationRequest request = createOperationRequest(
MockMvcRequestBuilders.get("/foo")
.cookie(new javax.servlet.http.Cookie("cookieName1",
"cookieVal1"),
MockMvcRequestBuilders.get("/foo").cookie(
new javax.servlet.http.Cookie("cookieName1", "cookieVal1"),
new javax.servlet.http.Cookie("cookieName2", "cookieVal2")));
assertThat(request.getUri(), is(URI.create("http://localhost/foo")));
assertThat(request.getMethod(), is(HttpMethod.GET));

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.
@@ -160,9 +160,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/").accept(MediaType.APPLICATION_JSON).content("content"))
.andExpect(status().isOk()).andDo(document("curl-snippet-with-content"));
assertThat(
new File(
"build/generated-snippets/curl-snippet-with-content/curl-request.adoc"),
assertThat(new File(
"build/generated-snippets/curl-snippet-with-content/curl-request.adoc"),
is(snippet(asciidoctor())
.withContents(codeBlock(asciidoctor(), "bash").content(String
.format("$ curl 'http://localhost:8080/' -i -X POST \\%n"
@@ -178,9 +177,8 @@ public class MockMvcRestDocumentationIntegrationTests {
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"),
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"
@@ -194,9 +192,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/?foo=bar").param("foo", "bar").param("a", "alpha")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andDo(document("curl-snippet-with-query-string"));
assertThat(
new File(
"build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"),
assertThat(new File(
"build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(
codeBlock(asciidoctor(), "bash").content(String.format("$ curl "
+ "'http://localhost:8080/?foo=bar' -i -X POST \\%n"
@@ -211,12 +208,11 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/").param("a", "alpha").accept(MediaType.APPLICATION_JSON)
.content("some content")).andExpect(status().isOk())
.andDo(document("curl-snippet-with-content-and-parameters"));
assertThat(
new File(
"build/generated-snippets/curl-snippet-with-content-and-parameters/curl-request.adoc"),
is(snippet(asciidoctor())
.withContents(codeBlock(asciidoctor(), "bash").content(String
.format("$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n"
assertThat(new File(
"build/generated-snippets/curl-snippet-with-content-and-parameters/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(
codeBlock(asciidoctor(), "bash").content(String.format(
"$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -d 'some content'")))));
}
@@ -229,9 +225,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/").accept(MediaType.APPLICATION_JSON).content("content"))
.andExpect(status().isOk())
.andDo(document("httpie-snippet-with-content"));
assertThat(
new File(
"build/generated-snippets/httpie-snippet-with-content/httpie-request.adoc"),
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-content/httpie-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ echo 'content' | "
+ "http POST 'http://localhost:8080/' \\%n"
@@ -246,9 +241,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)
.cookie(new Cookie("cookieName", "cookieVal"))).andExpect(status().isOk())
.andDo(document("httpie-snippet-with-cookies"));
assertThat(
new File(
"build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"),
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ http GET 'http://localhost:8080/' \\%n"
+ " 'Accept:application/json' \\%n"
@@ -262,11 +256,10 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/?foo=bar").param("foo", "bar").param("a", "alpha")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andDo(document("httpie-snippet-with-query-string"));
assertThat(
new File(
"build/generated-snippets/httpie-snippet-with-query-string/httpie-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(),
"bash").content(String.format("$ http "
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-query-string/httpie-request.adoc"),
is(snippet(asciidoctor()).withContents(
codeBlock(asciidoctor(), "bash").content(String.format("$ http "
+ "--form POST 'http://localhost:8080/?foo=bar' \\%n"
+ " 'Accept:application/json' \\%n 'a=alpha'")))));
}
@@ -278,9 +271,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(post("/").param("a", "alpha").content("some content")
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andDo(document("httpie-snippet-post-with-content-and-parameters"));
assertThat(
new File(
"build/generated-snippets/httpie-snippet-post-with-content-and-parameters/httpie-request.adoc"),
assertThat(new File(
"build/generated-snippets/httpie-snippet-post-with-content-and-parameters/httpie-request.adoc"),
is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash")
.content(String.format("$ echo " + "'some content' | http POST "
+ "'http://localhost:8080/?a=alpha' \\%n"
@@ -487,9 +479,8 @@ public class MockMvcRestDocumentationIntegrationTests {
}
}
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\"%n}");
assertThat(
new File(
"build/generated-snippets/preprocessed-request/http-request.adoc"),
assertThat(new File(
"build/generated-snippets/preprocessed-request/http-request.adoc"),
is(snippet(asciidoctor())
.withContents(preprocessedRequest.content(prettyPrinted))));
}
@@ -499,8 +490,7 @@ public class MockMvcRestDocumentationIntegrationTests {
Pattern pattern = Pattern.compile("(\"alpha\")");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)
.operationPreprocessors()
.withRequestDefaults(prettyPrint(),
.operationPreprocessors().withRequestDefaults(prettyPrint(),
removeHeaders("a", HttpHeaders.HOST,
HttpHeaders.CONTENT_LENGTH),
replacePattern(pattern, "\"<<beta>>\"")))
@@ -523,9 +513,8 @@ public class MockMvcRestDocumentationIntegrationTests {
}
}
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\"%n}");
assertThat(
new File(
"build/generated-snippets/default-preprocessed-request/http-request.adoc"),
assertThat(new File(
"build/generated-snippets/default-preprocessed-request/http-request.adoc"),
is(snippet(asciidoctor())
.withContents(preprocessedRequest.content(prettyPrinted))));
}
@@ -555,9 +544,8 @@ public class MockMvcRestDocumentationIntegrationTests {
.content(original))));
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\",%n \"links\" : "
+ "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}");
assertThat(
new File(
"build/generated-snippets/preprocessed-response/http-response.adoc"),
assertThat(new File(
"build/generated-snippets/preprocessed-response/http-response.adoc"),
is(snippet(asciidoctor())
.withContents(httpResponse(asciidoctor(), HttpStatus.OK)
.header("Content-Type", "application/json;charset=UTF-8")
@@ -571,8 +559,8 @@ public class MockMvcRestDocumentationIntegrationTests {
Pattern pattern = Pattern.compile("(\"alpha\")");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation)
.operationPreprocessors().withResponseDefaults(
prettyPrint(), maskLinks(), removeHeaders("a"),
.operationPreprocessors().withResponseDefaults(prettyPrint(),
maskLinks(), removeHeaders("a"),
replacePattern(pattern, "\"<<beta>>\"")))
.build();
@@ -582,9 +570,8 @@ public class MockMvcRestDocumentationIntegrationTests {
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\",%n \"links\" : "
+ "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}");
assertThat(
new File(
"build/generated-snippets/default-preprocessed-response/http-response.adoc"),
assertThat(new File(
"build/generated-snippets/default-preprocessed-response/http-response.adoc"),
is(snippet(asciidoctor())
.withContents(httpResponse(asciidoctor(), HttpStatus.OK)
.header("Content-Type", "application/json;charset=UTF-8")
@@ -611,9 +598,8 @@ public class MockMvcRestDocumentationIntegrationTests {
finally {
Thread.currentThread().setContextClassLoader(previous);
}
assertThat(
new File(
"build/generated-snippets/custom-snippet-template/curl-request.adoc"),
assertThat(new File(
"build/generated-snippets/custom-snippet-template/curl-request.adoc"),
is(snippet(asciidoctor()).withContents(equalTo("Custom curl request"))));
mockMvc.perform(get("/")).andDo(document("index", curlRequest(