Skip to content

Commit c8e46f6

Browse files
committed
Merge branch '2.1.x'
2 parents 554bff6 + 059337f commit c8e46f6

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7772,6 +7772,28 @@ generate the default snippets. The following example shows a
77727772

77737773

77747774

7775+
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs-web-test-client]]
7776+
===== Auto-configured Spring REST Docs Tests with WebTestClient
7777+
`@AutoConfigureRestDocs` can also be used with `WebTestClient`. You can inject it by using
7778+
`@Autowired` and use it in your tests as you normally would when using `@WebFluxTest` and
7779+
Spring REST Docs, as shown in the following example:
7780+
7781+
[source,java,indent=0]
7782+
----
7783+
include::{code-examples}/test/autoconfigure/restdocs/webclient/UsersDocumentationTests.java[tag=source]
7784+
----
7785+
7786+
If you require more control over Spring REST Docs configuration than offered by the
7787+
attributes of `@AutoConfigureRestDocs`, you can use a
7788+
`RestDocsWebTestClientConfigurationCustomizer` bean, as shown in the following example:
7789+
7790+
[source,java,indent=0]
7791+
----
7792+
include::{code-examples}/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java[tag=configuration]
7793+
----
7794+
7795+
7796+
77757797
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs-rest-assured]]
77767798
===== Auto-configured Spring REST Docs Tests with REST Assured
77777799
`@AutoConfigureRestDocs` makes a `RequestSpecification` bean, preconfigured to use Spring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient;
18+
19+
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer;
20+
import org.springframework.boot.test.context.TestConfiguration;
21+
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
22+
23+
public class AdvancedConfigurationExample {
24+
25+
// tag::configuration[]
26+
@TestConfiguration
27+
public static class CustomizationConfiguration
28+
implements RestDocsWebTestClientConfigurationCustomizer {
29+
30+
@Override
31+
public void customize(WebTestClientRestDocumentationConfigurer configurer) {
32+
configurer.snippets().withEncoding("UTF-8");
33+
}
34+
35+
}
36+
// end::configuration[]
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.test.autoconfigure.restdocs.webclient;
18+
19+
// tag::source[]
20+
import org.junit.jupiter.api.Test;
21+
import org.junit.runner.RunWith;
22+
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
25+
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
26+
import org.springframework.test.context.junit4.SpringRunner;
27+
import org.springframework.test.web.reactive.server.WebTestClient;
28+
29+
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
30+
31+
@RunWith(SpringRunner.class)
32+
@WebFluxTest
33+
@AutoConfigureRestDocs
34+
public class UsersDocumentationTests {
35+
36+
@Autowired
37+
private WebTestClient webTestClient;
38+
39+
@Test
40+
void listUsers() {
41+
this.webTestClient.get().uri("/").exchange().expectStatus().isOk().expectBody()
42+
.consumeWith(document("list-users"));
43+
}
44+
45+
}
46+
// end::source[]

0 commit comments

Comments
 (0)