Skip to content

Commit c83f6eb

Browse files
Berchris Requiaowilkinsona
authored andcommitted
Document how to parameterize REST Docs' output dir with WebTestClient
See gh-27755
1 parent f8ef908 commit c83f6eb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8063,6 +8063,16 @@ If you require more control over Spring REST Docs configuration than offered by
80638063
include::{code-examples}/test/autoconfigure/restdocs/webclient/AdvancedConfigurationExample.java[tag=configuration]
80648064
----
80658065

8066+
If you want to make use of Spring REST Docs support for a parameterized output directory, you can create a `WebTestClientBuilderCustomizer` bean.
8067+
The auto-configuration calls this `WebTestClientBuilderCustomizer` in order to create the `WebTestClient` bean for the current context
8068+
with the consumer provided in the parameter of the method `entityExchangeResultConsumer`.
8069+
The following example shows a `WebTestClientBuilderCustomizer` being defined:
8070+
8071+
[source,java,indent=0,subs="verbatim"]
8072+
----
8073+
include::{code-examples}/test/autoconfigure/restdocs/webclient/MyWebTestClientBuilderCustomizerConfiguration.java[]
8074+
----
8075+
80668076

80678077

80688078
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-docs-rest-assured]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2021 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+
* https://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.features.testing.springbootapplications.autoconfiguredspringrestdocs.withwebtestclient;
18+
19+
import org.springframework.boot.test.context.TestConfiguration;
20+
import org.springframework.boot.test.web.reactive.server.WebTestClientBuilderCustomizer;
21+
import org.springframework.context.annotation.Bean;
22+
23+
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
24+
25+
@TestConfiguration(proxyBeanMethods = false)
26+
public class MyWebTestClientBuilderCustomizerConfiguration {
27+
28+
@Bean
29+
public WebTestClientBuilderCustomizer restDocumentation() {
30+
return (builder) -> builder.entityExchangeResultConsumer(document("{method-name}"));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)