接口 WebTestClient
- 所有已知实现类:
DefaultWebTestClient
public interface WebTestClient
Client for testing web servers that uses
WebClient internally to
perform requests while also providing a fluent API to verify responses.
This client can connect to any server over HTTP, or to a WebFlux application
via mock request and response objects.
Use one of the bindToXxx methods to create an instance. For example:
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Brian Clozel, Sam Brannen, Michał Rowicki, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型接口说明static interfaceSpec for expectations on the response body content.static interfaceWebTestClient.BodySpec<B,S extends WebTestClient.BodySpec<B, S>> Spec for expectations on the response body decoded to a single Object.static interfaceSteps for customizing theWebClientused to test with, internally delegating to aWebClient.Builder.static interfaceSpec for expectations on the response body decoded to a List.static interfaceBase specification for setting up tests without a server.static interfaceSpecification for providing body of a request.static interfaceSpecification for providing the body and the URI of a request.static interfaceSpecification for adding request headers and performing an exchange.static interfaceSpecification for providing request headers and the URI of a request.static interfaceChained API for applying assertions to a response.static interfaceSpecification for customizing router function configuration.static interfaceWebTestClient.UriSpec<S extends WebTestClient.RequestHeadersSpec<?>>Specification for providing the URI of a request. -
字段概要
字段修饰符和类型字段说明static final StringThe name of a request header used to assign a unique id to every request performed through theWebTestClient. -
方法概要
修饰符和类型方法说明bindToRouterFunction(cn.taketoday.web.handler.function.RouterFunction<?> routerFunction) Use this option to set up a server from aRouterFunction.static WebTestClient.BuilderThis server setup option allows you to connect to a live server through a Reactor Netty client connector.static WebTestClient.BuilderbindToServer(cn.taketoday.http.client.reactive.ClientHttpConnector connector) A variant ofbindToServer()with a pre-configured connector.delete()Prepare an HTTP DELETE request.get()Prepare an HTTP GET request.head()Prepare an HTTP HEAD request.method(cn.taketoday.http.HttpMethod method) Prepare a request for the specifiedHttpMethod.mutate()Return a builder to mutate properties of this web test client.mutateWith(WebTestClientConfigurer configurer) Mutate theWebTestClient, apply the given configurer, and build a new instance.options()Prepare an HTTP OPTIONS request.patch()Prepare an HTTP PATCH request.post()Prepare an HTTP POST request.put()Prepare an HTTP PUT request.
-
字段详细资料
-
WEBTESTCLIENT_REQUEST_ID
The name of a request header used to assign a unique id to every request performed through theWebTestClient. 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 anExchangeResultis available.- 另请参阅:
-
-
方法详细资料
-
get
WebTestClient.RequestHeadersUriSpec<?> get()Prepare an HTTP GET request.- 返回:
- a spec for specifying the target URL
-
head
WebTestClient.RequestHeadersUriSpec<?> head()Prepare an HTTP HEAD request.- 返回:
- a spec for specifying the target URL
-
post
Prepare an HTTP POST request.- 返回:
- a spec for specifying the target URL
-
put
Prepare an HTTP PUT request.- 返回:
- a spec for specifying the target URL
-
patch
WebTestClient.RequestBodyUriSpec patch()Prepare an HTTP PATCH request.- 返回:
- a spec for specifying the target URL
-
delete
WebTestClient.RequestHeadersUriSpec<?> delete()Prepare an HTTP DELETE request.- 返回:
- a spec for specifying the target URL
-
options
WebTestClient.RequestHeadersUriSpec<?> options()Prepare an HTTP OPTIONS request.- 返回:
- a spec for specifying the target URL
-
method
Prepare a request for the specifiedHttpMethod.- 返回:
- a spec for specifying the target URL
-
mutate
WebTestClient.Builder mutate()Return a builder to mutate properties of this web test client. -
mutateWith
Mutate theWebTestClient, apply the given configurer, and build a new instance. Essentially a shortcut for:mutate().apply(configurer).build();
- 参数:
configurer- the configurer to apply- 返回:
- the mutated test client
-
bindToRouterFunction
static WebTestClient.RouterFunctionSpec bindToRouterFunction(cn.taketoday.web.handler.function.RouterFunction<?> routerFunction) Use this option to set up a server from aRouterFunction. Internally the provided configuration is passed toRouterFunctions#toWebHandler. The resulting WebFlux application will be tested without an HTTP server using a mock request and response.- 参数:
routerFunction- the RouterFunction to test- 返回:
- chained API to customize server and client config; use
WebTestClient.MockServerSpec.configureClient()to transition to client config
-
bindToServer
This server setup option allows you to connect to a live server through a Reactor Netty client connector.WebTestClient client = WebTestClient.bindToServer() .baseUrl("http://localhost:8080") .build();- 返回:
- chained API to customize client config
-
bindToServer
static WebTestClient.Builder bindToServer(cn.taketoday.http.client.reactive.ClientHttpConnector connector) A variant ofbindToServer()with a pre-configured connector.- 返回:
- chained API to customize client config
-