Remove admonitions surrounding code snippets
This commit is contained in:
@@ -27,13 +27,11 @@ a URL to connect to a running server.
|
||||
|
||||
The following example shows how to create a server setup to test one `@Controller` at a time:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
client = WebTestClient.bindToController(new TestController()).build();
|
||||
----
|
||||
====
|
||||
|
||||
The preceding example loads the <<web-reactive.adoc#webflux-config,WebFlux Java configuration>> and
|
||||
registers the given controller. The resulting WebFlux application is tested
|
||||
@@ -48,14 +46,12 @@ on the builder to customize the default WebFlux Java configuration.
|
||||
The following example shows how to set up a server from a
|
||||
<<web-reactive.adoc#webflux-fn,RouterFunction>>:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
RouterFunction<?> route = ...
|
||||
client = WebTestClient.bindToRouterFunction(route).build();
|
||||
----
|
||||
====
|
||||
|
||||
Internally, the configuration is passed to `RouterFunctions.toWebHandler`.
|
||||
The resulting WebFlux application is tested without an HTTP server by using mock
|
||||
@@ -69,7 +65,6 @@ request and response objects.
|
||||
The following example shows how to setup a server from the Spring configuration of your application or
|
||||
some subset of it:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -92,7 +87,6 @@ some subset of it:
|
||||
<1> Specify the configuration to load
|
||||
<2> Inject the configuration
|
||||
<3> Create the `WebTestClient`
|
||||
====
|
||||
|
||||
Internally, the configuration is passed to `WebHttpHandlerBuilder` to set up
|
||||
the request processing chain. See
|
||||
@@ -107,13 +101,11 @@ and response objects.
|
||||
|
||||
The following server setup option lets you connect to a running server:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
client = WebTestClient.bindToServer().baseUrl("http://localhost:8080").build();
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +117,6 @@ options, including base URL, default headers, client filters, and others. These
|
||||
are readily available following `bindToServer`. For all others, you need to use
|
||||
`configureClient()` to transition from server to client configuration, as follows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -134,7 +125,6 @@ are readily available following `bindToServer`. For all others, you need to use
|
||||
.baseUrl("/test")
|
||||
.build();
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
@@ -148,7 +138,6 @@ up to the point of performing a request by using `exchange()`. What follows afte
|
||||
|
||||
Typically, you start by asserting the response status and headers, as follows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -159,7 +148,6 @@ Typically, you start by asserting the response status and headers, as follows:
|
||||
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
// ...
|
||||
----
|
||||
====
|
||||
|
||||
Then you specify how to decode and consume the response body:
|
||||
|
||||
@@ -169,7 +157,6 @@ Then you specify how to decode and consume the response body:
|
||||
|
||||
Then you can use built-in assertions for the body. The following example shows one way to do so:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -178,11 +165,9 @@ Then you can use built-in assertions for the body. The following example shows o
|
||||
.expectStatus().isOk()
|
||||
.expectBodyList(Person.class).hasSize(3).contains(person);
|
||||
----
|
||||
====
|
||||
|
||||
You can also go beyond the built-in assertions and create your own, as the following example shows:
|
||||
|
||||
====
|
||||
----
|
||||
client.get().uri("/persons/1")
|
||||
.exchange()
|
||||
@@ -192,11 +177,9 @@ You can also go beyond the built-in assertions and create your own, as the follo
|
||||
// custom assertions (e.g. AssertJ)...
|
||||
});
|
||||
----
|
||||
====
|
||||
|
||||
You can also exit the workflow and get a result, as follows:
|
||||
|
||||
====
|
||||
----
|
||||
EntityExchangeResult<Person> result = client.get().uri("/persons/1")
|
||||
.exchange()
|
||||
@@ -204,7 +187,6 @@ You can also exit the workflow and get a result, as follows:
|
||||
.expectBody(Person.class)
|
||||
.returnResult();
|
||||
----
|
||||
====
|
||||
|
||||
TIP: When you need to decode to a target type with generics, look for the overloaded methods
|
||||
that accept
|
||||
@@ -219,7 +201,6 @@ instead of `Class<T>`.
|
||||
If the response has no content (or you do not care if it does) use `Void.class`, which ensures
|
||||
that resources are released. The following example shows how to do so:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -228,11 +209,9 @@ that resources are released. The following example shows how to do so:
|
||||
.expectStatus().isNotFound()
|
||||
.expectBody(Void.class);
|
||||
----
|
||||
====
|
||||
|
||||
Alternatively, if you want to assert there is no response content, you can use code similar to the following:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -242,7 +221,6 @@ Alternatively, if you want to assert there is no response content, you can use c
|
||||
.expectStatus().isCreated()
|
||||
.expectBody().isEmpty();
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
@@ -253,7 +231,6 @@ When you use `expectBody()`, the response is consumed as a `byte[]`. This is use
|
||||
raw content assertions. For example, you can use
|
||||
http://jsonassert.skyscreamer.org[JSONAssert] to verify JSON content, as follows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -263,11 +240,9 @@ http://jsonassert.skyscreamer.org[JSONAssert] to verify JSON content, as follows
|
||||
.expectBody()
|
||||
.json("{\"name\":\"Jane\"}")
|
||||
----
|
||||
====
|
||||
|
||||
You can also use https://github.com/jayway/JsonPath[JSONPath] expressions, as follows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -278,7 +253,6 @@ You can also use https://github.com/jayway/JsonPath[JSONPath] expressions, as fo
|
||||
.jsonPath("$[0].name").isEqualTo("Jane")
|
||||
.jsonPath("$[1].name").isEqualTo("Jason");
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
@@ -289,7 +263,6 @@ To test infinite streams (for example, `"text/event-stream"` or `"application/st
|
||||
you need to exit the chained API (by using `returnResult`), immediately after the response status
|
||||
and header assertions, as the following example shows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -300,13 +273,11 @@ and header assertions, as the following example shows:
|
||||
.returnResult(MyEvent.class);
|
||||
|
||||
----
|
||||
====
|
||||
|
||||
Now you can consume the `Flux<T>`, assert decoded objects as they come, and then
|
||||
cancel at some point when test objectives are met. We recommend using the `StepVerifier`
|
||||
from the `reactor-test` module to do that, as the following example shows:
|
||||
|
||||
====
|
||||
[source,java,intent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -319,7 +290,6 @@ from the `reactor-test` module to do that, as the following example shows:
|
||||
.thenCancel()
|
||||
.verify();
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user