Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2018-08-08 14:48:16 +01:00
155 changed files with 465 additions and 1030 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 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.
@@ -57,12 +57,11 @@ final class IterableEnumeration<T> implements Iterable<T> {
/**
* Creates an {@code Iterable} that will iterate over the given {@code enumeration}.
*
* @param <T> the type of the enumeration's elements
* @param enumeration The enumeration to expose as an {@code Iterable}
* @param enumeration the enumeration to expose as an {@code Iterable}
* @return the iterable
*/
static <T> Iterable<T> iterable(Enumeration<T> enumeration) {
static <T> Iterable<T> of(Enumeration<T> enumeration) {
return new IterableEnumeration<>(enumeration);
}

View File

@@ -46,8 +46,6 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import static org.springframework.restdocs.mockmvc.IterableEnumeration.iterable;
/**
* A converter for creating an {@link OperationRequest} from a
* {@link MockHttpServletRequest}.
@@ -172,7 +170,7 @@ class MockMvcRequestConverter implements RequestConverter<MockHttpServletRequest
private Parameters extractParameters(MockHttpServletRequest servletRequest) {
Parameters parameters = new Parameters();
for (String name : iterable(servletRequest.getParameterNames())) {
for (String name : IterableEnumeration.of(servletRequest.getParameterNames())) {
for (String value : servletRequest.getParameterValues(name)) {
parameters.add(name, value);
}
@@ -182,8 +180,10 @@ class MockMvcRequestConverter implements RequestConverter<MockHttpServletRequest
private HttpHeaders extractHeaders(MockHttpServletRequest servletRequest) {
HttpHeaders headers = new HttpHeaders();
for (String headerName : iterable(servletRequest.getHeaderNames())) {
for (String value : iterable(servletRequest.getHeaders(headerName))) {
for (String headerName : IterableEnumeration
.of(servletRequest.getHeaderNames())) {
for (String value : IterableEnumeration
.of(servletRequest.getHeaders(headerName))) {
headers.add(headerName, value);
}
}

View File

@@ -44,7 +44,6 @@ public abstract class MockMvcRestDocumentation {
/**
* Provides access to a {@link MockMvcConfigurer} that can be used to configure a
* {@link MockMvc} instance using the given {@code contextProvider}.
*
* @param contextProvider the context provider
* @return the configurer
* @see ConfigurableMockMvcBuilder#apply(MockMvcConfigurer)
@@ -57,7 +56,6 @@ public abstract class MockMvcRestDocumentation {
/**
* Documents the API call with the given {@code identifier} using the given
* {@code snippets} in addition to any default snippets.
*
* @param identifier an identifier for the API call that is being documented
* @param snippets the snippets
* @return a Mock MVC {@code ResultHandler} that will produce the documentation
@@ -74,7 +72,6 @@ public abstract class MockMvcRestDocumentation {
* Documents the API call with the given {@code identifier} using the given
* {@code snippets} in addition to any default snippets. The given
* {@code requestPreprocessor} is applied to the request before it is documented.
*
* @param identifier an identifier for the API call that is being documented
* @param requestPreprocessor the request preprocessor
* @param snippets the snippets
@@ -93,7 +90,6 @@ public abstract class MockMvcRestDocumentation {
* Documents the API call with the given {@code identifier} using the given
* {@code snippets} in addition to any default snippets. The given
* {@code responsePreprocessor} is applied to the request before it is documented.
*
* @param identifier an identifier for the API call that is being documented
* @param responsePreprocessor the response preprocessor
* @param snippets the snippets
@@ -113,7 +109,6 @@ public abstract class MockMvcRestDocumentation {
* {@code snippets} in addition to any default snippets. The given
* {@code requestPreprocessor} and {@code responsePreprocessor} are applied to the
* request and response respectively before they are documented.
*
* @param identifier an identifier for the API call that is being documented
* @param requestPreprocessor the request preprocessor
* @param responsePreprocessor the response preprocessor

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.
@@ -57,7 +57,6 @@ public final class MockMvcRestDocumentationConfigurer extends
/**
* Returns a {@link UriConfigurer} that can be used to configure the request URIs that
* will be documented.
*
* @return the URI configurer
*/
public UriConfigurer uris() {

View File

@@ -46,7 +46,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a GET request. The url template
* will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the GET request
@@ -59,7 +58,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a GET request.
*
* @param uri the URL
* @return the builder for the GET request
*/
@@ -70,7 +68,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a POST request. The url template
* will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the POST request
@@ -83,7 +80,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
*
* @param uri the URL
* @return the builder for the POST request
*/
@@ -94,7 +90,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PUT request. The url template
* will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the PUT request
@@ -107,7 +102,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PUT request.
*
* @param uri the URL
* @return the builder for the PUT request
*/
@@ -118,7 +112,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request. The url
* template will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the PATCH request
@@ -131,7 +124,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a PATCH request.
*
* @param uri the URL
* @return the builder for the PATCH request
*/
@@ -142,7 +134,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request. The url
* template will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the DELETE request
@@ -155,7 +146,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a DELETE request.
*
* @param uri the URL
* @return the builder for the DELETE request
*/
@@ -166,7 +156,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request. The url
* template will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the OPTIONS request
@@ -179,7 +168,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request.
*
* @param uri the URL
* @return the builder for the OPTIONS request
*/
@@ -190,7 +178,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a HEAD request. The url template
* will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the HEAD request
@@ -203,7 +190,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a HEAD request.
*
* @param uri the URL
* @return the builder for the HEAD request
*/
@@ -214,7 +200,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a request with the given HTTP
* method. The url template will be captured and made available for documentation.
*
* @param httpMethod the HTTP method
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
@@ -241,7 +226,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a multipart request. The url
* template will be captured and made available for documentation.
*
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
* @return the builder for the file upload request
@@ -256,7 +240,6 @@ public abstract class RestDocumentationRequestBuilders {
/**
* Create a {@link MockHttpServletRequestBuilder} for a multipart request.
*
* @param uri the URL
* @return the builder for the file upload request
*/

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.
@@ -67,7 +67,6 @@ public class RestDocumentationResultHandler implements ResultHandler {
* fieldWithPath("page").description("The requested Page")
* ));
* </pre>
*
* @param snippets the snippets
* @return the new result handler
*/
@@ -91,7 +90,6 @@ public class RestDocumentationResultHandler implements ResultHandler {
/**
* Returns the {@link RestDocumentationGenerator} that is used as a delegate.
*
* @return the delegate
*/
protected final RestDocumentationGenerator<MockHttpServletRequest, MockHttpServletResponse> getDelegate() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 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.
@@ -69,8 +69,7 @@ public class UriConfigurer
/**
* Configures any documented URIs to use the given {@code scheme}. The default is
* {@code http}.
*
* @param scheme The URI scheme
* @param scheme the URI scheme
* @return {@code this}
*/
public UriConfigurer withScheme(String scheme) {
@@ -81,8 +80,7 @@ public class UriConfigurer
/**
* Configures any documented URIs to use the given {@code host}. The default is
* {@code localhost}.
*
* @param host The URI host
* @param host the URI host
* @return {@code this}
*/
public UriConfigurer withHost(String host) {
@@ -93,8 +91,7 @@ public class UriConfigurer
/**
* Configures any documented URIs to use the given {@code port}. The default is
* {@code 8080}.
*
* @param port The URI port
* @param port the URI port
* @return {@code this}
*/
public UriConfigurer withPort(int port) {

View File

@@ -48,7 +48,12 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationIntegrationTests.TestConfiguration;
import org.springframework.restdocs.templates.TemplateFormat;
import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.test.SnippetConditions;
import org.springframework.restdocs.test.SnippetConditions.CodeBlockCondition;
import org.springframework.restdocs.test.SnippetConditions.HttpRequestCondition;
import org.springframework.restdocs.test.SnippetConditions.HttpResponseCondition;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@@ -69,7 +74,6 @@ import static org.springframework.restdocs.headers.HeaderDocumentation.headerWit
import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
import static org.springframework.restdocs.mockmvc.IterableEnumeration.iterable;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
@@ -88,11 +92,6 @@ import static org.springframework.restdocs.request.RequestDocumentation.partWith
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.restdocs.request.RequestDocumentation.requestParts;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
import static org.springframework.restdocs.templates.TemplateFormats.markdown;
import static org.springframework.restdocs.test.SnippetConditions.codeBlock;
import static org.springframework.restdocs.test.SnippetConditions.httpRequest;
import static org.springframework.restdocs.test.SnippetConditions.httpResponse;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -142,7 +141,8 @@ public class MockMvcRestDocumentationIntegrationTests {
public void markdownSnippetGeneration() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(new MockMvcRestDocumentationConfigurer(this.restDocumentation)
.snippets().withEncoding("UTF-8").withTemplateFormat(markdown()))
.snippets().withEncoding("UTF-8")
.withTemplateFormat(TemplateFormats.markdown()))
.build();
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(document("basic-markdown"));
@@ -159,10 +159,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.andExpect(status().isOk()).andDo(document("curl-snippet-with-content"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-content/curl-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(String
.format("$ curl 'http://localhost:8080/' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -d 'content'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format(
"$ curl 'http://localhost:8080/' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -d 'content'"))));
}
@Test
@@ -174,10 +175,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("curl-snippet-with-cookies"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(String
.format("$ curl 'http://localhost:8080/' -i -X GET \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format(
"$ curl 'http://localhost:8080/' -i -X GET \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " --cookie 'cookieName=cookieVal'"))));
}
@Test
@@ -189,7 +191,7 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("curl-snippet-with-query-string"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash")
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format("$ curl "
+ "'http://localhost:8080/?foo=bar' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
@@ -205,10 +207,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("curl-snippet-with-content-and-parameters"));
assertThat(new File(
"build/generated-snippets/curl-snippet-with-content-and-parameters/curl-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(String
.format("$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -d 'some content'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format(
"$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n"
+ " -H 'Accept: application/json' \\%n"
+ " -d 'some content'"))));
}
@Test
@@ -220,7 +223,7 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("httpie-snippet-with-content"));
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-content/httpie-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash")
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format("$ echo 'content' | "
+ "http POST 'http://localhost:8080/' \\%n"
+ " 'Accept:application/json'"))));
@@ -235,10 +238,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("httpie-snippet-with-cookies"));
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(
String.format("$ http GET 'http://localhost:8080/' \\%n"
+ " 'Accept:application/json' \\%n"
+ " 'Cookie:cookieName=cookieVal'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String
.format("$ http GET 'http://localhost:8080/' \\%n"
+ " 'Accept:application/json' \\%n"
+ " 'Cookie:cookieName=cookieVal'"))));
}
@Test
@@ -250,7 +254,7 @@ public class MockMvcRestDocumentationIntegrationTests {
.andDo(document("httpie-snippet-with-query-string"));
assertThat(new File(
"build/generated-snippets/httpie-snippet-with-query-string/httpie-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash")
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format("$ http "
+ "--form POST 'http://localhost:8080/?foo=bar' \\%n"
+ " 'Accept:application/json' \\%n 'a=alpha'"))));
@@ -265,10 +269,11 @@ public class MockMvcRestDocumentationIntegrationTests {
.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"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(
String.format("$ echo " + "'some content' | http POST "
+ "'http://localhost:8080/?a=alpha' \\%n"
+ " 'Accept:application/json'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String
.format("$ echo " + "'some content' | http POST "
+ "'http://localhost:8080/?a=alpha' \\%n"
+ " 'Accept:application/json'"))));
}
@Test
@@ -357,9 +362,9 @@ public class MockMvcRestDocumentationIntegrationTests {
responseHeaders(headerWithName(HttpHeaders.SET_COOKIE)
.description("set-cookie"))));
assertThat(new File("build/generated-snippets/set-cookie/http-response.adoc"))
.has(content(httpResponse(asciidoctor(), HttpStatus.OK).header(
HttpHeaders.SET_COOKIE,
"name=value; Domain=localhost; HttpOnly")));
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
.header(HttpHeaders.SET_COOKIE,
"name=value; Domain=localhost; HttpOnly")));
}
@Test
@@ -428,9 +433,10 @@ public class MockMvcRestDocumentationIntegrationTests {
HttpHeaders.CONTENT_LENGTH),
replacePattern(pattern, "\"<<beta>>\""))))
.andReturn();
HttpRequestCondition originalRequest = httpRequest(asciidoctor(),
HttpRequestCondition originalRequest = httpRequest(TemplateFormats.asciidoctor(),
RequestMethod.GET, "/");
for (String headerName : iterable(result.getRequest().getHeaderNames())) {
for (String headerName : IterableEnumeration
.of(result.getRequest().getHeaderNames())) {
originalRequest.header(headerName, result.getRequest().getHeader(headerName));
}
assertThat(
@@ -438,11 +444,12 @@ public class MockMvcRestDocumentationIntegrationTests {
.has(content(originalRequest.header("Host", "localhost:8080")
.header("Content-Length", "13")
.content("{\"a\":\"alpha\"}")));
HttpRequestCondition preprocessedRequest = httpRequest(asciidoctor(),
RequestMethod.GET, "/");
HttpRequestCondition preprocessedRequest = httpRequest(
TemplateFormats.asciidoctor(), RequestMethod.GET, "/");
List<String> removedHeaders = Arrays.asList("a", HttpHeaders.HOST,
HttpHeaders.CONTENT_LENGTH);
for (String headerName : iterable(result.getRequest().getHeaderNames())) {
for (String headerName : IterableEnumeration
.of(result.getRequest().getHeaderNames())) {
if (!removedHeaders.contains(headerName)) {
preprocessedRequest.header(headerName,
result.getRequest().getHeader(headerName));
@@ -471,11 +478,12 @@ public class MockMvcRestDocumentationIntegrationTests {
.accept(MediaType.APPLICATION_JSON).content("{\"a\":\"alpha\"}"))
.andDo(document("default-preprocessed-request")).andReturn();
HttpRequestCondition preprocessedRequest = httpRequest(asciidoctor(),
RequestMethod.GET, "/");
HttpRequestCondition preprocessedRequest = httpRequest(
TemplateFormats.asciidoctor(), RequestMethod.GET, "/");
List<String> removedHeaders = Arrays.asList("a", HttpHeaders.HOST,
HttpHeaders.CONTENT_LENGTH);
for (String headerName : iterable(result.getRequest().getHeaderNames())) {
for (String headerName : IterableEnumeration
.of(result.getRequest().getHeaderNames())) {
if (!removedHeaders.contains(headerName)) {
preprocessedRequest.header(headerName,
result.getRequest().getHeader(headerName));
@@ -502,9 +510,9 @@ public class MockMvcRestDocumentationIntegrationTests {
String original = "{\"a\":\"alpha\",\"links\":[{\"rel\":\"rel\","
+ "\"href\":\"href\"}]}";
assertThat(
new File("build/generated-snippets/original-response/http-response.adoc"))
.has(content(httpResponse(asciidoctor(), HttpStatus.OK)
assertThat(new File(
"build/generated-snippets/original-response/http-response.adoc")).has(
content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
.header("a", "alpha")
.header("Content-Type", "application/json;charset=UTF-8")
.header(HttpHeaders.CONTENT_LENGTH,
@@ -513,8 +521,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/preprocessed-response/http-response.adoc"))
.has(content(httpResponse(asciidoctor(), HttpStatus.OK)
"build/generated-snippets/preprocessed-response/http-response.adoc")).has(
content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
.header("Content-Type", "application/json;charset=UTF-8")
.header(HttpHeaders.CONTENT_LENGTH,
prettyPrinted.getBytes().length)
@@ -539,11 +547,13 @@ public class MockMvcRestDocumentationIntegrationTests {
+ "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}");
assertThat(new File(
"build/generated-snippets/default-preprocessed-response/http-response.adoc"))
.has(content(httpResponse(asciidoctor(), HttpStatus.OK)
.header("Content-Type", "application/json;charset=UTF-8")
.header(HttpHeaders.CONTENT_LENGTH,
prettyPrinted.getBytes().length)
.content(prettyPrinted)));
.has(content(
httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
.header("Content-Type",
"application/json;charset=UTF-8")
.header(HttpHeaders.CONTENT_LENGTH,
prettyPrinted.getBytes().length)
.content(prettyPrinted)));
}
@Test
@@ -578,9 +588,10 @@ public class MockMvcRestDocumentationIntegrationTests {
.andExpect(status().isOk()).andDo(document("custom-context-path"));
assertThat(new File(
"build/generated-snippets/custom-context-path/curl-request.adoc"))
.has(content(codeBlock(asciidoctor(), "bash").withContent(String
.format("$ curl 'http://localhost:8080/custom/' -i -X GET \\%n"
+ " -H 'Accept: application/json'"))));
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
.withContent(String.format(
"$ curl 'http://localhost:8080/custom/' -i -X GET \\%n"
+ " -H 'Accept: application/json'"))));
}
@Test
@@ -617,6 +628,19 @@ public class MockMvcRestDocumentationIntegrationTests {
};
}
private CodeBlockCondition<?> codeBlock(TemplateFormat format, String language) {
return SnippetConditions.codeBlock(format, language);
}
private HttpRequestCondition httpRequest(TemplateFormat format,
RequestMethod requestMethod, String uri) {
return SnippetConditions.httpRequest(format, requestMethod, uri);
}
private HttpResponseCondition httpResponse(TemplateFormat format, HttpStatus status) {
return SnippetConditions.httpResponse(format, status);
}
/**
* Test configuration that enables Spring MVC.
*/