public interface WebTestClient
WebClient, and actually delegating to a WebClient
instance, but with a focus on testing.
The WebTestClient has 3 setup options without a running server:
bindToController(java.lang.Object...)
bindToApplicationContext(org.springframework.context.ApplicationContext)
bindToRouterFunction(org.springframework.web.reactive.function.server.RouterFunction<?>)
and 1 option for actual requests on a socket:
| Modifier and Type | Interface and Description |
|---|---|
static interface |
WebTestClient.BodyContentSpec
Spec for expectations on the response body content.
|
static interface |
WebTestClient.BodySpec<B,S extends WebTestClient.BodySpec<B,S>>
Spec for expectations on the response body decoded to a single Object.
|
static interface |
WebTestClient.Builder
Steps for customizing the
WebClient used to test with
internally delegating to a WebClient.Builder. |
static interface |
WebTestClient.ControllerSpec
Specification for customizing controller configuration equivalent to, and
internally delegating to, a
WebFluxConfigurer. |
static interface |
WebTestClient.ListBodySpec<E>
Spec for expectations on the response body decoded to a List.
|
static interface |
WebTestClient.MockServerSpec<B extends WebTestClient.MockServerSpec<B>>
Base specification for setting up tests without a server.
|
static interface |
WebTestClient.RequestBodySpec |
static interface |
WebTestClient.RequestHeadersSpec<S extends WebTestClient.RequestHeadersSpec<S>>
Specification for adding request headers and performing an exchange.
|
static interface |
WebTestClient.ResponseSpec
Spec for declaring expectations on the response.
|
static interface |
WebTestClient.UriSpec<S extends WebTestClient.RequestHeadersSpec<?>>
Specification for providing the URI of a request.
|
| Modifier and Type | Method and Description |
|---|---|
static WebTestClient.MockServerSpec<?> |
bindToApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Integration testing without a server with WebFlux infrastructure detected
from an
ApplicationContext such as @EnableWebFlux
Java config and annotated controller Spring beans. |
static WebTestClient.ControllerSpec |
bindToController(Object... controllers)
Integration testing without a server targeting specific annotated,
WebFlux controllers.
|
static WebTestClient.Builder |
bindToHttpHandler(org.springframework.http.server.reactive.HttpHandler httpHandler)
Integration testing without a server targeting the given HttpHandler.
|
static WebTestClient.MockServerSpec<?> |
bindToRouterFunction(org.springframework.web.reactive.function.server.RouterFunction<?> routerFunction)
Integration testing without a server targeting WebFlux functional endpoints.
|
static WebTestClient.Builder |
bindToServer()
Complete end-to-end integration tests with actual requests to a running server.
|
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> |
delete()
Prepare an HTTP DELETE request.
|
WebTestClient |
exchangeMutator(UnaryOperator<org.springframework.web.server.ServerWebExchange> mutator)
Filter the client applying the given transformation function on the
ServerWebExchange to every request. |
WebTestClient |
filter(org.springframework.web.reactive.function.client.ExchangeFilterFunction filterFunction)
Filter the client with the given
ExchangeFilterFunction. |
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> |
get()
Prepare an HTTP GET request.
|
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> |
head()
Prepare an HTTP HEAD request.
|
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> |
options()
Prepare an HTTP OPTIONS request.
|
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> |
patch()
Prepare an HTTP PATCH request.
|
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> |
post()
Prepare an HTTP POST request.
|
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> |
put()
Prepare an HTTP PUT request.
|
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> get()
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> head()
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> post()
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> put()
WebTestClient.UriSpec<WebTestClient.RequestBodySpec> patch()
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> delete()
WebTestClient.UriSpec<WebTestClient.RequestHeadersSpec<?>> options()
WebTestClient filter(org.springframework.web.reactive.function.client.ExchangeFilterFunction filterFunction)
ExchangeFilterFunction.filterFunction - the filter to apply to this clientExchangeFilterFunction.apply(ExchangeFunction)WebTestClient exchangeMutator(UnaryOperator<org.springframework.web.server.ServerWebExchange> mutator)
ServerWebExchange to every request.
Note: this option is applicable only when testing without an actual running server.
mutator - the transformation functionstatic WebTestClient.ControllerSpec bindToController(Object... controllers)
@EnableWebFlux
but can also be further customized through the returned spec.controllers - the controllers to teststatic WebTestClient.MockServerSpec<?> bindToApplicationContext(org.springframework.context.ApplicationContext applicationContext)
ApplicationContext such as @EnableWebFlux
Java config and annotated controller Spring beans.applicationContext - the contextWebTestClient builderEnableWebFluxstatic WebTestClient.MockServerSpec<?> bindToRouterFunction(org.springframework.web.reactive.function.server.RouterFunction<?> routerFunction)
routerFunction - the RouterFunction to testWebTestClient builderstatic WebTestClient.Builder bindToHttpHandler(org.springframework.http.server.reactive.HttpHandler httpHandler)
httpHandler - the handler to testWebTestClient builderstatic WebTestClient.Builder bindToServer()
WebTestClient builder