Skip to content

Conversation

@zaynetro
Copy link
Contributor

@zaynetro zaynetro commented Nov 9, 2017

Closes #10967

This is my work in progress to autoconfigure WebTestClient.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 9, 2017

@Configuration
@ConditionalOnClass(WebTestClientRestDocumentation.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
Copy link
Contributor

@eddumelendez eddumelendez Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be REACTIVE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zaynetro
Copy link
Contributor Author

zaynetro commented Nov 9, 2017

How do I execute one test only?

Specifically org.springframework.boot.test.autoconfigure.restdocs.WebTestClientRestDocsAutoConfigurationIntegrationTests

@wilkinsona
Copy link
Member

@zaynetro You can either run that test in your IDE, or use -Dtestcase on the command line

@zaynetro
Copy link
Contributor Author

I figured that with this change test succeeds:

diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java
index 8997ebb4bd..68264a8e3d 100644
--- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfiguration.java
@@ -30,6 +30,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.http.codec.ClientCodecConfigurer;
+import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
 import org.springframework.test.web.reactive.server.WebTestClient;
 import org.springframework.test.web.reactive.server.WebTestClient.Builder;
 import org.springframework.util.CollectionUtils;
@@ -49,11 +50,13 @@ public class WebTestClientAutoConfiguration {

        @Bean
        @ConditionalOnMissingBean
-       public WebTestClient webTestClient(ApplicationContext applicationContext) {
+       public WebTestClient webTestClient(ApplicationContext applicationContext, WebTestClientRestDocumentationConfigurer configurer) {
                WebTestClient.Builder builder = WebTestClient
                                .bindToApplicationContext(applicationContext).configureClient();
                customizeWebTestClient(builder, applicationContext);
                customizeWebTestClientCodecs(builder, applicationContext);
+               builder.baseUrl("https://api.example.com/");
+               builder.filter(configurer);
                return builder.build();
        }

I know it isn't not the proper way to set up the WebTestClient. Due to the lack of knowledge I don't know how to add Configurer only if RestDocs are setup.

Could someone point me at how I can overcome this and whether I am doing it at the right place?

<module name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck">
<property name="excludes"
value="io.restassured.RestAssured.*, org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.ArgumentMatchers.*, org.mockito.Matchers.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.ExpectedCount.*, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*" />
value="io.restassured.RestAssured.*, org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.ArgumentMatchers.*, org.mockito.Matchers.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.ExpectedCount.*, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*

@zaynetro zaynetro changed the title WIP Add web test client restdocs autoconfiguration Add web test client restdocs autoconfiguration Nov 12, 2017
@zaynetro
Copy link
Contributor Author

Figured it out.

@zaynetro
Copy link
Contributor Author

Yay! Let me know if something else needs to be changed.

@zaynetro
Copy link
Contributor Author

Any chance this can get merged some time soon?

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Nov 16, 2017
@wilkinsona
Copy link
Member

@zaynetro Thanks for the PR. I'll try to review and merge this in RC1.

@wilkinsona wilkinsona added priority: normal type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Nov 17, 2017
@wilkinsona wilkinsona added this to the 2.0.0.RC1 milestone Nov 17, 2017
@wilkinsona wilkinsona self-assigned this Nov 17, 2017
wilkinsona added a commit that referenced this pull request Jan 9, 2018
* gh-10969:
  Polish "Add auto-configuration for using REST Docs with WebTestClient"
  Add auto-configuration for using REST Docs with WebTestClient
@wilkinsona
Copy link
Member

Thanks for the PR, @zaynetro. I've merged the changes into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support WebTestClient in AutoConfigureRestDocs

5 participants