Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 28ae521

Browse files
Josef-Reichardtjmisur
authored andcommitted
Support for WebTestClient (#239)
* WebTestClient sample application * Support WebTestClient * Added unit tests * Rafactoring & more tests * Fixed path issue with WebTestClient * Fixed type in WebTestClient sample application * Added WebTestClient in docs * Fixed indentation * Built docs * Fixed indentation * Add test scope * Added Mono and Flux return type support * Fixed NoClassDefFound issue in non webflux projects * Added webtestclient sample app to travis ci * Added unit tests for Mono and Flux return type * Refactored type checks * Cleanup * Improved docs * Fixed missing URL issue when using UriBuilder
1 parent 0fa013f commit 28ae521

File tree

36 files changed

+4791
-18
lines changed

36 files changed

+4791
-18
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ script:
2626
- mvn verify -B
2727
- ./gradlew check
2828
- cd ..
29+
- cd java-webtestclient
30+
- mvn verify -B
31+
- cd ..
2932
- cd ..
3033
after_success:
3134
- test "$TRAVIS_BRANCH" = "master"

docs/index.html

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@
432432
<h1>Spring Auto REST Docs</h1>
433433
<div class="details">
434434
<span id="author" class="author">Scalable Capital</span><br>
435-
<span id="revnumber">version 2.0.1</span>
435+
<span id="revnumber">version 2.0.2-SNAPSHOT</span>
436436
</div>
437437
<div id="toc" class="toc2">
438438
<div id="toctitle">Table of Contents</div>
@@ -539,6 +539,10 @@ <h2 id="faq"><a class="link" href="#faq">FAQ</a></h2>
539539
<p>Yes, it is easy to use in existing or new Spring MVC tests. Take a look at the example.</p>
540540
</li>
541541
<li>
542+
<p><em>Does it work with Spring WebTestClient?</em></p>
543+
<p>Yes, but only basic support yet. Take a look at the example.</p>
544+
</li>
545+
<li>
542546
<p><em>Does it work with REST Assured tests?</em></p>
543547
<p>Not yet. We may add support for REST Assured in the future, but your PR is also welcome.</p>
544548
</li>
@@ -579,7 +583,7 @@ <h3 id="gettingstarted-requirements"><a class="link" href="#gettingstarted-requi
579583
<p>Java 7</p>
580584
</li>
581585
<li>
582-
<p>Spring REST Docs 2.0.0.RELEASE (see <a href="http://docs.spring.io/spring-restdocs/docs/2.0.0.RELEASE/reference/html5/">documentation</a>)</p>
586+
<p>Spring REST Docs 2.0.1.RELEASE (see <a href="http://docs.spring.io/spring-restdocs/docs/2.0.1.RELEASE/reference/html5/">documentation</a>)</p>
583587
</li>
584588
<li>
585589
<p>Jackson has to be used for creating and parsing JSON</p>
@@ -592,7 +596,7 @@ <h3 id="gettingstarted-usage"><a class="link" href="#gettingstarted-usage">Usage
592596
<div class="olist arabic">
593597
<ol class="arabic">
594598
<li>
595-
<p>Setup project for <a href="http://docs.spring.io/spring-restdocs/docs/2.0.0.RELEASE/reference/html5/#getting-started">Spring REST Docs</a></p>
599+
<p>Setup project for <a href="http://docs.spring.io/spring-restdocs/docs/2.0.1.RELEASE/reference/html5/#getting-started">Spring REST Docs</a></p>
596600
</li>
597601
<li>
598602
<p>Additional configuration for this extension:</p>
@@ -730,9 +734,9 @@ <h3 id="gettingstarted-usage"><a class="link" href="#gettingstarted-usage">Usage
730734
</div>
731735
</li>
732736
<li>
733-
<p>Configure MockMvc</p>
737+
<p>Configure MockMvc or WebTestClient</p>
734738
<div class="listingblock">
735-
<div class="title">Test class</div>
739+
<div class="title">MockMvc Test class</div>
736740
<div class="content">
737741
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Autowired
738742
private WebApplicationContext context;
@@ -777,6 +781,41 @@ <h3 id="gettingstarted-usage"><a class="link" href="#gettingstarted-usage">Usage
777781
}</code></pre>
778782
</div>
779783
</div>
784+
<div class="listingblock">
785+
<div class="title">WebTestClient Test class</div>
786+
<div class="content">
787+
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Autowired
788+
private ApplicationContext context;
789+
790+
protected WebTestClient webTestClient;
791+
792+
@Rule
793+
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
794+
795+
@Before
796+
public void setUp() throws Exception {
797+
this.webTestClient = WebTestClient
798+
.bindToApplicationContext(context)
799+
.apply(springSecurity())
800+
.configureClient()
801+
.baseUrl("http://localhost:8080/")
802+
.filter(documentationConfiguration(restDocumentation)
803+
.snippets()
804+
.withDefaults(WebTestClientInitializer.prepareSnippets(context),
805+
CliDocumentation.curlRequest(),
806+
HttpDocumentation.httpRequest(),
807+
HttpDocumentation.httpResponse(),
808+
AutoDocumentation.requestFields(),
809+
AutoDocumentation.responseFields(),
810+
AutoDocumentation.pathParameters(),
811+
AutoDocumentation.requestParameters(),
812+
AutoDocumentation.description(),
813+
AutoDocumentation.methodAndPath(),
814+
AutoDocumentation.section()))
815+
.build();
816+
}</code></pre>
817+
</div>
818+
</div>
780819
</li>
781820
</ol>
782821
</div>
@@ -1483,10 +1522,10 @@ <h3 id="snippets-custom"><a class="link" href="#snippets-custom">Custom snippet<
14831522
<h3 id="snippets-customization"><a class="link" href="#snippets-customization">Snippet customization</a></h3>
14841523
<div class="paragraph">
14851524
<p>Provide your own template in <code>org/springframework/restdocs/templates/asciidoctor</code> (or <code>markdown</code>) package of your resources.
1486-
You can override <a href="https://github.com/spring-projects/spring-restdocs/tree/v2.0.0.RELEASE/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates">REST Docs templates</a>
1525+
You can override <a href="https://github.com/spring-projects/spring-restdocs/tree/v2.0.1.RELEASE/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates">REST Docs templates</a>
14871526
and <a href="https://github.com/ScaCap/spring-auto-restdocs/tree/master/spring-auto-restdocs-core/src/main/resources/org/springframework/restdocs/templates">Auto REST Docs templates</a>.
14881527
Important is to omit <code>default-</code> part from the template name so that the resolution algorithm will prefer this custom template.
1489-
See also <a href="http://docs.spring.io/spring-restdocs/docs/2.0.0.RELEASE/reference/html5/#documenting-your-api-customizing-snippets">original documentation</a> for additional details.</p>
1528+
See also <a href="http://docs.spring.io/spring-restdocs/docs/2.0.1.RELEASE/reference/html5/#documenting-your-api-customizing-snippets">original documentation</a> for additional details.</p>
14901529
</div>
14911530
</div>
14921531
</div>
@@ -1566,7 +1605,7 @@ <h3 id="constraints-custom"><a class="link" href="#constraints-custom">Custom co
15661605
Each description is a property where the key is the full class name of the annotation suffixed with <code>.description</code>.
15671606
The value is the description and can contain placeholders for annotation methods,
15681607
e.g. <code>${value}</code> to get the content of <code>value()</code>.
1569-
For more details, see original documentation of <a href="http://docs.spring.io/spring-restdocs/docs/2.0.0.RELEASE/reference/html5/#documenting-your-api-constraints-describing">here</a>.</p>
1608+
For more details, see original documentation of <a href="http://docs.spring.io/spring-restdocs/docs/2.0.1.RELEASE/reference/html5/#documenting-your-api-constraints-describing">here</a>.</p>
15701609
</div>
15711610
<div class="paragraph">
15721611
<p>Example for the constraint annotation <code>myproject.constraints.OneOf</code>:</p>
@@ -1796,9 +1835,9 @@ <h4 id="contributing-installing-testjar"><a class="link" href="#contributing-ins
17961835
<div class="listingblock">
17971836
<div class="title">Bash</div>
17981837
<div class="content">
1799-
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">mvn install:install-file -Dfile=lib/spring-restdocs-core-2.0.0.RELEASE-test.jar \
1838+
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">mvn install:install-file -Dfile=lib/spring-restdocs-core-2.0.1.RELEASE-test.jar \
18001839
-DgroupId=org.springframework.restdocs -DartifactId=spring-restdocs-core \
1801-
-Dversion=2.0.0.RELEASE -Dpackaging=test-jar -Dclassifier=test</code></pre>
1840+
-Dversion=2.0.1.RELEASE -Dpackaging=test-jar -Dclassifier=test</code></pre>
18021841
</div>
18031842
</div>
18041843
</div>
@@ -1809,7 +1848,7 @@ <h4 id="contributing-building-testjar"><a class="link" href="#contributing-build
18091848
but if you ever want to upgrade the version of Spring REST Docs in this project this step has to be done.</p>
18101849
</div>
18111850
<div class="paragraph">
1812-
<p>We use version 2.0.0.RELEASE of Spring REST Docs in this example.</p>
1851+
<p>We use version 2.0.1.RELEASE of Spring REST Docs in this example.</p>
18131852
</div>
18141853
<div class="paragraph">
18151854
<p>You find the currently required version in <code>pom.xml</code>:</p>
@@ -1820,7 +1859,7 @@ <h4 id="contributing-building-testjar"><a class="link" href="#contributing-build
18201859
<pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml">&lt;dependency&gt;
18211860
&lt;groupId&gt;org.springframework.restdocs&lt;/groupId&gt;
18221861
&lt;artifactId&gt;spring-restdocs-core&lt;/artifactId&gt;
1823-
&lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
1862+
&lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
18241863
&lt;classifier&gt;test&lt;/classifier&gt;
18251864
&lt;scope&gt;test&lt;/scope&gt;
18261865
&lt;/dependency&gt;</code></pre>
@@ -1835,13 +1874,13 @@ <h4 id="contributing-building-testjar"><a class="link" href="#contributing-build
18351874
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">git clone git@github.com:spring-projects/spring-restdocs.git
18361875
cd spring-restdocs
18371876
git fetch --tags
1838-
git checkout tags/v2.0.0.RELEASE
1877+
git checkout tags/v2.0.1.RELEASE
18391878
./gradlew build</code></pre>
18401879
</div>
18411880
</div>
18421881
<div class="paragraph">
18431882
<p>Afterwards the test JAR is located at
1844-
<code>spring-restdocs/spring-restdocs-core/build/libs/spring-restdocs-core-2.0.0.RELEASE-test.jar</code>
1883+
<code>spring-restdocs/spring-restdocs-core/build/libs/spring-restdocs-core-2.0.1.RELEASE-test.jar</code>
18451884
and has to be installed with the Maven command shown in the section above.</p>
18461885
</div>
18471886
</div>
@@ -1860,8 +1899,8 @@ <h4 id="contributing-building-build"><a class="link" href="#contributing-buildin
18601899
</div>
18611900
<div id="footer">
18621901
<div id="footer-text">
1863-
Version 2.0.1<br>
1864-
Last updated 2018-03-29 11:56:38 CEST
1902+
Version 2.0.2-SNAPSHOT<br>
1903+
Last updated 2018-07-19 08:37:35 MESZ
18651904
</div>
18661905
</div>
18671906
<link rel="stylesheet" href="highlight/styles/github.min.css">

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@
254254
<artifactId>jackson-databind</artifactId>
255255
<version>2.9.3</version>
256256
</dependency>
257+
<dependency>
258+
<groupId>org.springframework</groupId>
259+
<artifactId>spring-webflux</artifactId>
260+
<version>5.0.2.RELEASE</version>
261+
<scope>provided</scope>
262+
</dependency>
257263
<dependency>
258264
<groupId>org.springframework</groupId>
259265
<artifactId>spring-test</artifactId>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Java WebTestClient Example
2+
3+
This project shows the use of Spring Auto REST Docs with WebTestClient in a Java 8 project.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This folder contains `ìndex.html` from the `target\generated-docs` so that everyone
2+
can see the generated documentation without having to generate it.

0 commit comments

Comments
 (0)