Add an example showing how to use AutoConfigureRestDocs with WebTestClient
See original GitHub issue@AutoConfigureRestDocs
used with WebTestClient causes the following NullPointerException:
java.lang.NullPointerException
at java.util.HashMap.putMapEntries(HashMap.java:501)
at java.util.HashMap.<init>(HashMap.java:490)
at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.retrieveConfiguration(WebTestClientRestDocumentation.java:143)
at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:80)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:540)
at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:197)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:540)
at com.example.demo.web.UserControllerWithAutoconfigureDocTest.shouldGetUser(UserControllerWithAutoconfigureDocTest.java:31)
Here’s a complete minimal test case reproducing the problem: https://github.com/jnizet/webtestclientrestdocsissue
See the failing test, with the complete stack trace, in https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithAutoconfigureDocTest.java
The same test not using REST Docs passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerTest.java
And the same test using REST docs but configuring it manually also passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithApplicationContextDocTest.java
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Thanks for the offer. The problem isn’t specific to
WebTestClient
and REST Docs’ MockMvc and REST Assured integration can fail in a similar way. I think it’s right that it fails and I don’t think that just adding a null check would be an improvement. It may, however, be an improvement to check for the configuration being null and, if it is, throwing something like anIllegalStateException
that guides the user towards the integration with whatever testing client is in use being incorrectly configured.Closing in favour of PR #15978