Skip to content

Commit d38d797

Browse files
committed
Restore support for REST Assured
Closes gh-784
1 parent f5beaaa commit d38d797

File tree

53 files changed

+3403
-11
lines changed

Some content is hidden

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

53 files changed

+3403
-11
lines changed

build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ subprojects { subproject ->
117117
samples {
118118
dependOn "spring-restdocs-core:publishToMavenLocal"
119119
dependOn "spring-restdocs-mockmvc:publishToMavenLocal"
120+
dependOn "spring-restdocs-restassured:publishToMavenLocal"
120121
dependOn "spring-restdocs-webtestclient:publishToMavenLocal"
121122
dependOn "spring-restdocs-asciidoctor:publishToMavenLocal"
122123

@@ -132,6 +133,10 @@ samples {
132133
workingDir "$projectDir/samples/testng"
133134
}
134135

136+
restAssured {
137+
workingDir "$projectDir/samples/rest-assured"
138+
}
139+
135140
webTestClient {
136141
workingDir "$projectDir/samples/web-test-client"
137142
}

docs/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
internal(enforcedPlatform("org.springframework:spring-framework-bom:$springFrameworkVersion"))
2020

2121
testImplementation(project(":spring-restdocs-mockmvc"))
22+
testImplementation(project(":spring-restdocs-restassured"))
2223
testImplementation(project(":spring-restdocs-webtestclient"))
2324
testImplementation("jakarta.validation:jakarta.validation-api")
2425
testImplementation("junit:junit")

docs/src/docs/asciidoc/configuration.adoc

+37-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ TIP: To configure a request's context path, use the `contextPath` method on `Moc
4545

4646

4747

48+
[[configuration-uris-rest-assured]]
49+
==== REST Assured URI Customization
50+
51+
REST Assured tests a service by making actual HTTP requests. As a result, URIs must be
52+
customized once the operation on the service has been performed but before it is
53+
documented. A
54+
<<customizing-requests-and-responses-preprocessors-modify-uris, REST-Assured-specific
55+
preprocessor>> is provided for this purpose.
56+
57+
58+
4859
[[configuration-uris-webtestclient]]
4960
==== WebTestClient URI Customization
5061

@@ -79,6 +90,12 @@ include::{examples-dir}/com/example/mockmvc/CustomEncoding.java[tags=custom-enco
7990
include::{examples-dir}/com/example/webtestclient/CustomEncoding.java[tags=custom-encoding]
8091
----
8192

93+
[source,java,indent=0,role="secondary"]
94+
.REST Assured
95+
----
96+
include::{examples-dir}/com/example/restassured/CustomEncoding.java[tags=custom-encoding]
97+
----
98+
8299
TIP: When Spring REST Docs converts the content of a request or a response to a `String`, the `charset` specified in the `Content-Type` header is used if it is available.
83100
In its absence, the JVM's default `Charset` is used.
84101
You can configure the JVM's default `Charset` by using the `file.encoding` system property.
@@ -105,6 +122,13 @@ include::{examples-dir}/com/example/mockmvc/CustomFormat.java[tags=custom-format
105122
include::{examples-dir}/com/example/webtestclient/CustomFormat.java[tags=custom-format]
106123
----
107124

125+
[source,java,indent=0,role="secondary"]
126+
.REST Assured
127+
----
128+
include::{examples-dir}/com/example/restassured/CustomFormat.java[tags=custom-format]
129+
----
130+
====
131+
108132
109133
110134
[[configuration-default-snippets]]
@@ -134,6 +158,12 @@ include::{examples-dir}/com/example/mockmvc/CustomDefaultSnippets.java[tags=cust
134158
include::{examples-dir}/com/example/webtestclient/CustomDefaultSnippets.java[tags=custom-default-snippets]
135159
----
136160
161+
[source,java,indent=0,role="secondary"]
162+
.REST Assured
163+
----
164+
include::{examples-dir}/com/example/restassured/CustomDefaultSnippets.java[tags=custom-default-snippets]
165+
----
166+
137167
138168
139169
[[configuration-default-preprocessors]]
@@ -158,4 +188,10 @@ include::{examples-dir}/com/example/webtestclient/CustomDefaultOperationPreproce
158188
<1> Apply a request preprocessor that removes the header named `Foo`.
159189
<2> Apply a response preprocessor that pretty prints its content.
160190
161-
191+
[source,java,indent=0,role="secondary"]
192+
.REST Assured
193+
----
194+
include::{examples-dir}/com/example/restassured/CustomDefaultOperationPreprocessors.java[tags=custom-default-operation-preprocessors]
195+
----
196+
<1> Apply a request preprocessor that removes the header named `Foo`.
197+
<2> Apply a response preprocessor that pretty prints its content.

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ include::{examples-dir}/com/example/webtestclient/PerTestPreprocessing.java[tags
2424
<1> Apply a request preprocessor that removes the header named `Foo`.
2525
<2> Apply a response preprocessor that pretty prints its content.
2626

27+
.REST Assured
28+
----
29+
include::{examples-dir}/com/example/restassured/PerTestPreprocessing.java[tags=preprocessing]
30+
----
31+
<1> Apply a request preprocessor that removes the header named `Foo`.
32+
<2> Apply a response preprocessor that pretty prints its content.
33+
====
34+
2735
Alternatively, you may want to apply the same preprocessors to every test.
2836
You can do so by using the `RestDocumentationConfigurer` API in your `@Before` method to configure the preprocessors.
2937
For example, to remove the `Foo` header from all requests and pretty print all responses, you could do one of the following (depending on your testing environment):
@@ -44,6 +52,14 @@ include::{examples-dir}/com/example/webtestclient/EveryTestPreprocessing.java[ta
4452
<1> Apply a request preprocessor that removes the header named `Foo`.
4553
<2> Apply a response preprocessor that pretty prints its content.
4654
55+
[source,java,indent=0,role="secondary"]
56+
.REST Assured
57+
----
58+
include::{examples-dir}/com/example/restassured/EveryTestPreprocessing.java[tags=setup]
59+
----
60+
<1> Apply a request preprocessor that removes the header named `Foo`.
61+
<2> Apply a response preprocessor that pretty prints its content.
62+
4763
Then, in each test, you can perform any configuration specific to that test.
4864
The following examples show how to do so:
4965
@@ -59,6 +75,12 @@ include::{examples-dir}/com/example/mockmvc/EveryTestPreprocessing.java[tags=use
5975
include::{examples-dir}/com/example/webtestclient/EveryTestPreprocessing.java[tags=use]
6076
----
6177
78+
[source,java,indent=0,role="secondary"]
79+
.REST Assured
80+
----
81+
include::{examples-dir}/com/example/restassured/EveryTestPreprocessing.java[tags=use]
82+
----
83+
6284
Various built-in preprocessors, including those illustrated above, are available through the static methods on `Preprocessors`.
6385
See <<Preprocessors, below>> for further details.
6486
@@ -116,7 +138,7 @@ You can use `modifyParameters` on `Preprocessors` to add, set, and remove reques
116138
TIP: If you use MockMvc or a WebTestClient that is not bound to a server, you should customize URIs by <<configuration-uris, changing the configuration>>.
117139
118140
You can use `modifyUris` on `Preprocessors` to modify any URIs in a request or a response.
119-
When using WebTestClient bound to a server, this lets you customize the URIs that appear in the documentation while testing a local instance of the service.
141+
When using REST Assured or WebTestClient bound to a server, this lets you customize the URIs that appear in the documentation while testing a local instance of the service.
120142
121143
122144

0 commit comments

Comments
 (0)