Skip to content

Commit cfb1fbc

Browse files
committed
Add support for using WebFlux's WebTestClient to document an API
Closes gh-384
1 parent 1cd74a5 commit cfb1fbc

File tree

52 files changed

+2948
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2948
-58
lines changed

build.gradle

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ allprojects {
1616
group = 'org.springframework.restdocs'
1717
repositories {
1818
mavenCentral()
19-
maven { url 'https://repo.spring.io/milestone' }
2019
}
2120
}
2221

@@ -35,7 +34,7 @@ sonarqube {
3534
}
3635

3736
ext {
38-
springVersion = '5.0.0.RC4'
37+
springVersion = '5.0.0.RELEASE'
3938
javadocLinks = [
4039
'http://docs.oracle.com/javase/8/docs/api/',
4140
"http://docs.spring.io/spring-framework/docs/$springVersion/javadoc-api/",
@@ -74,11 +73,12 @@ subprojects {
7473
dependency 'org.hamcrest:hamcrest-core:1.3'
7574
dependency 'org.hamcrest:hamcrest-library:1.3'
7675
dependency 'org.hibernate:hibernate-validator:5.4.1.Final'
76+
dependency 'org.jacoco:org.jacoco.agent:0.7.9'
7777
dependency 'org.jruby:jruby-complete:9.1.13.0'
7878
dependency 'org.junit.jupiter:junit-jupiter-api:5.0.0-M4'
7979
dependency 'org.mockito:mockito-core:1.10.19'
8080
dependency 'org.springframework.hateoas:spring-hateoas:0.23.0.RELEASE'
81-
dependency 'org.jacoco:org.jacoco.agent:0.7.9'
81+
dependency 'org.synchronoss.cloud:nio-multipart-parser:1.1.0'
8282
}
8383
}
8484

@@ -168,6 +168,7 @@ samples {
168168
dependOn 'spring-restdocs-core:install'
169169
dependOn 'spring-restdocs-mockmvc:install'
170170
dependOn 'spring-restdocs-restassured:install'
171+
dependOn 'spring-restdocs-webtestclient:install'
171172
dependOn 'spring-restdocs-asciidoctor:install'
172173

173174
restNotesGrails {
@@ -190,6 +191,10 @@ samples {
190191
workingDir "$projectDir/samples/rest-assured"
191192
}
192193

194+
webTestClient {
195+
workingDir "$projectDir/samples/web-test-client"
196+
}
197+
193198
slate {
194199
workingDir "$projectDir/samples/rest-notes-slate"
195200
build false

config/checkstyle/checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<module name="AvoidStarImport" />
7474
<module name="AvoidStaticImport">
7575
<property name="excludes"
76-
value="com.jayway.restassured.RestAssured.*, io.restassured.RestAssured.*, org.junit.Assert.*, org.junit.Assume.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.cli.CliDocumentation.*, org.springframework.restdocs.headers.HeaderDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.IterableEnumeration.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*, org.springframework.restdocs.payload.PayloadDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.request.RequestDocumentation.*, org.springframework.restdocs.restassured.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.snippet.Attributes.*, org.springframework.restdocs.templates.TemplateFormats.*, org.springframework.restdocs.test.SnippetMatchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*" />
76+
value="com.jayway.restassured.RestAssured.*, io.restassured.RestAssured.*, org.junit.Assert.*, org.junit.Assume.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.cli.CliDocumentation.*, org.springframework.restdocs.headers.HeaderDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.IterableEnumeration.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*, org.springframework.restdocs.payload.PayloadDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.request.RequestDocumentation.*, org.springframework.restdocs.restassured.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.snippet.Attributes.*, org.springframework.restdocs.templates.TemplateFormats.*, org.springframework.restdocs.test.SnippetMatchers.*, org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.web.reactive.function.BodyInserters.*, org.springframework.web.reactive.function.server.RequestPredicates.GET, org.springframework.web.reactive.function.server.RequestPredicates.POST" />
7777
</module>
7878
<module name="IllegalImport" />
7979
<module name="RedundantImport" />

docs/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ plugins {
33
}
44

55
repositories {
6-
maven {
7-
url 'https://repo.spring.io/release'
8-
}
6+
maven { url 'https://repo.spring.io/release' }
7+
maven { url 'https://repo.spring.io/snapshot' }
98
}
109

1110
dependencies {
12-
asciidoctor 'io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.1.RELEASE'
11+
asciidoctor 'io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.2.BUILD-SNAPSHOT'
1312
testCompile project(':spring-restdocs-mockmvc')
1413
testCompile project(':spring-restdocs-restassured')
14+
testCompile project(':spring-restdocs-webtestclient')
1515
testCompile 'io.rest-assured:rest-assured'
1616
testCompile 'javax.validation:validation-api'
1717
testCompile 'junit:junit'

docs/src/docs/asciidoc/configuration.adoc

+26
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ using the `RestDocumentationConfigurer` API. For example, to use `ISO-8859-1`:
5454
include::{examples-dir}/com/example/mockmvc/CustomEncoding.java[tags=custom-encoding]
5555
----
5656

57+
[source,java,indent=0,role="secondary"]
58+
.WebTestClient
59+
----
60+
include::{examples-dir}/com/example/webtestclient/CustomEncoding.java[tags=custom-encoding]
61+
----
62+
5763
[source,java,indent=0,role="secondary"]
5864
.REST Assured
5965
----
@@ -79,6 +85,12 @@ box. You can change the default format using the `RestDocumentationConfigurer` A
7985
include::{examples-dir}/com/example/mockmvc/CustomFormat.java[tags=custom-format]
8086
----
8187

88+
[source,java,indent=0,role="secondary"]
89+
.WebTestClient
90+
----
91+
include::{examples-dir}/com/example/webtestclient/CustomFormat.java[tags=custom-format]
92+
----
93+
8294
[source,java,indent=0,role="secondary"]
8395
.REST Assured
8496
----
@@ -109,6 +121,12 @@ snippet by default:
109121
include::{examples-dir}/com/example/mockmvc/CustomDefaultSnippets.java[tags=custom-default-snippets]
110122
----
111123

124+
[source,java,indent=0,role="secondary"]
125+
.WebTestClient
126+
----
127+
include::{examples-dir}/com/example/webtestclient/CustomDefaultSnippets.java[tags=custom-default-snippets]
128+
----
129+
112130
[source,java,indent=0,role="secondary"]
113131
.REST Assured
114132
----
@@ -130,6 +148,14 @@ include::{examples-dir}/com/example/mockmvc/CustomDefaultOperationPreprocessors.
130148
<1> Apply a request preprocessor that will remove the header named `Foo`.
131149
<2> Apply a response preprocessor that will pretty print its content.
132150

151+
[source,java,indent=0,role="secondary"]
152+
.WebTestClient
153+
----
154+
include::{examples-dir}/com/example/webtestclient/CustomDefaultOperationPreprocessors.java[tags=custom-default-operation-preprocessors]
155+
----
156+
<1> Apply a request preprocessor that will remove the header named `Foo`.
157+
<2> Apply a response preprocessor that will pretty print its content.
158+
133159
[source,java,indent=0,role="secondary"]
134160
.REST Assured
135161
----

docs/src/docs/asciidoc/customizing-requests-and-responses.adoc

+22
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ include::{examples-dir}/com/example/mockmvc/PerTestPreprocessing.java[tags=prepr
1818
<1> Apply a request preprocessor that will remove the header named `Foo`.
1919
<2> Apply a response preprocessor that will pretty print its content.
2020

21+
[source,java,indent=0,role="secondary"]
22+
.WebTestClient
23+
----
24+
include::{examples-dir}/com/example/webtestclient/PerTestPreprocessing.java[tags=preprocessing]
25+
----
26+
<1> Apply a request preprocessor that will remove the header named `Foo`.
27+
<2> Apply a response preprocessor that will pretty print its content.
28+
2129
[source,java,indent=0,role="secondary"]
2230
.REST Assured
2331
----
@@ -39,6 +47,14 @@ include::{examples-dir}/com/example/mockmvc/EveryTestPreprocessing.java[tags=set
3947
<1> Apply a request preprocessor that will remove the header named `Foo`.
4048
<2> Apply a response preprocessor that will pretty print its content.
4149

50+
[source,java,indent=0,role="secondary"]
51+
.WebTestClient
52+
----
53+
include::{examples-dir}/com/example/webtestclient/EveryTestPreprocessing.java[tags=setup]
54+
----
55+
<1> Apply a request preprocessor that will remove the header named `Foo`.
56+
<2> Apply a response preprocessor that will pretty print its content.
57+
4258
[source,java,indent=0,role="secondary"]
4359
.REST Assured
4460
----
@@ -55,6 +71,12 @@ Then, in each test, any configuration specific to that test can be performed. Fo
5571
include::{examples-dir}/com/example/mockmvc/EveryTestPreprocessing.java[tags=use]
5672
----
5773

74+
[source,java,indent=0,role="secondary"]
75+
.WebTestClient
76+
----
77+
include::{examples-dir}/com/example/webtestclient/EveryTestPreprocessing.java[tags=use]
78+
----
79+
5880
[source,java,indent=0,role="secondary"]
5981
.REST Assured
6082
----

0 commit comments

Comments
 (0)