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.RequestBodyUriSpec |
static interface |
WebTestClient.RequestHeadersSpec<S extends WebTestClient.RequestHeadersSpec<S>>
Specification for adding request headers and performing an exchange.
|
static interface |
WebTestClient.RequestHeadersUriSpec<S extends WebTestClient.RequestHeadersSpec<S>> |
static interface |
WebTestClient.ResponseSpec
Spec for declaring expectations on the response.
|
static interface |
WebTestClient.RouterFunctionSpec
Specification for customizing router function configuration.
|
static interface |
WebTestClient.UriSpec<S extends WebTestClient.RequestHeadersSpec<?>>
Specification for providing the URI of a request.
|
Modifier and Type | Field and Description |
---|---|
static String |
WEBTESTCLIENT_REQUEST_ID
The name of a request header used to assign a unique id to every request
performed through the
WebTestClient . |
Modifier and Type | Method and Description |
---|---|
static WebTestClient.MockServerSpec<?> |
bindToApplicationContext(ApplicationContext applicationContext)
Integration testing with a "mock" 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 with a "mock" server targeting specific annotated,
WebFlux controllers.
|
static WebTestClient.RouterFunctionSpec |
bindToRouterFunction(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.
|
static WebTestClient.MockServerSpec<?> |
bindToWebHandler(WebHandler webHandler)
Integration testing with a "mock" server targeting the given WebHandler.
|
WebTestClient.RequestHeadersUriSpec<?> |
delete()
Prepare an HTTP DELETE request.
|
WebTestClient.RequestHeadersUriSpec<?> |
get()
Prepare an HTTP GET request.
|
WebTestClient.RequestHeadersUriSpec<?> |
head()
Prepare an HTTP HEAD request.
|
WebTestClient.RequestBodyUriSpec |
method(HttpMethod method)
Prepare a request for the specified
HttpMethod . |
WebTestClient.Builder |
mutate()
Return a builder to mutate properties of this web test client.
|
WebTestClient |
mutateWith(WebTestClientConfigurer configurer)
Mutate the
WebTestClient , apply the given configurer, and build
a new instance. |
WebTestClient.RequestHeadersUriSpec<?> |
options()
Prepare an HTTP OPTIONS request.
|
WebTestClient.RequestBodyUriSpec |
patch()
Prepare an HTTP PATCH request.
|
WebTestClient.RequestBodyUriSpec |
post()
Prepare an HTTP POST request.
|
WebTestClient.RequestBodyUriSpec |
put()
Prepare an HTTP PUT request.
|
static final String WEBTESTCLIENT_REQUEST_ID
WebTestClient
. This can be useful for
storing contextual information at all phases of request processing (e.g.
from a server-side component) under that id and later to look up
that information once an ExchangeResult
is available.WebTestClient.RequestHeadersUriSpec<?> get()
WebTestClient.RequestHeadersUriSpec<?> head()
WebTestClient.RequestBodyUriSpec post()
WebTestClient.RequestBodyUriSpec put()
WebTestClient.RequestBodyUriSpec patch()
WebTestClient.RequestHeadersUriSpec<?> delete()
WebTestClient.RequestHeadersUriSpec<?> options()
WebTestClient.RequestBodyUriSpec method(HttpMethod method)
HttpMethod
.WebTestClient.Builder mutate()
WebTestClient mutateWith(WebTestClientConfigurer configurer)
WebTestClient
, apply the given configurer, and build
a new instance. Essentially a shortcut for:
mutate().apply(configurer).build();
configurer
- the configurer to applystatic WebTestClient.ControllerSpec bindToController(Object... controllers)
@EnableWebFlux
but can also be further customized through the returned spec.controllers
- the controllers to teststatic WebTestClient.MockServerSpec<?> bindToApplicationContext(ApplicationContext applicationContext)
ApplicationContext
such as
@EnableWebFlux
Java config and annotated controller Spring beans.applicationContext
- the contextWebTestClient
builderEnableWebFlux
static WebTestClient.RouterFunctionSpec bindToRouterFunction(RouterFunction<?> routerFunction)
routerFunction
- the RouterFunction to testWebTestClient
builderstatic WebTestClient.MockServerSpec<?> bindToWebHandler(WebHandler webHandler)
webHandler
- the handler to testWebTestClient
builderstatic WebTestClient.Builder bindToServer()
WebTestClient
builder