Interface RestTestClient
public interface RestTestClient
Client for testing web servers that uses 
RestClient 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 MockMvc
server with a mock request and response.
Use one of the bindToXxx() methods to create an instance. For example:
- Since:
- 7.0
- Author:
- Rob Worsnop, Rossen Stoyanchev
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSpec for expectations on the response body content.static interfaceRestTestClient.BodySpec<B, S extends RestTestClient.BodySpec<B,S>> Spec for expectations on the response body decoded to a single Object.static interfaceRestTestClient.Builder<B extends RestTestClient.Builder<B>>Steps to customize the underlyingRestClientviaRestClient.Builder.static interfaceRestTestClient.MockMvcSetupBuilder<S extends RestTestClient.Builder<S>, M extends MockMvcBuilder>Extension ofRestTestClient.Builderfor tests against a MockMvc server.static interfaceSpecification for providing the 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 interfaceExtension ofRestTestClient.Builderfor tests against а RouterFunction MockMvc setup.static interfaceExtension ofRestTestClient.Builderfor tests against а standalone MockMvc setup.static interfaceRestTestClient.UriSpec<S extends RestTestClient.RequestHeadersSpec<?>>Specification for providing the URI of a request.static interfaceExtension ofRestTestClient.Builderfor tests against а WebAppContext MockMvc setup.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe name of a request header used to assign a unique ID to every request performed through theRestTestClient.
- 
Method SummaryModifier and TypeMethodDescriptionstatic RestTestClient.Builder<?> Begin creating aRestTestClientby providing an already initializedMockMvcinstance to use as the server.Begin creating aRestTestClientwith a WebApplicationContext MockMvc setup.bindToController(Object... controllers) Begin creating aRestTestClientwith a Standalone MockMvc setup.bindToRouterFunction(RouterFunction<?>... routerFunctions) Begin creating aRestTestClientwith a RouterFunction MockMvc setup.static RestTestClient.Builder<?> This server setup option allows you to connect to a live server.static RestTestClient.Builder<?> bindToServer(ClientHttpRequestFactory requestFactory) A variant ofbindToServer()with a pre-configured request factory.delete()Prepare an HTTP DELETE request.get()Prepare an HTTP GET request.head()Prepare an HTTP HEAD request.method(HttpMethod method) Prepare a request for the specifiedHttpMethod.<B extends RestTestClient.Builder<B>>
 RestTestClient.Builder<B> mutate()Return a builder to mutate properties of this test client.options()Prepare an HTTP OPTIONS request.patch()Prepare an HTTP PATCH request.post()Prepare an HTTP POST request.put()Prepare an HTTP PUT request.
- 
Field Details- 
RESTTESTCLIENT_REQUEST_IDThe name of a request header used to assign a unique ID to every request performed through theRestTestClient. This can be useful to store contextual information under that ID at all phases of request processing (for example, from a server-side component) and later look up that information once anExchangeResultis available.- See Also:
 
 
- 
- 
Method Details- 
getRestTestClient.RequestHeadersUriSpec<?> get()Prepare an HTTP GET request.- Returns:
- a spec for specifying the target URL
 
- 
headRestTestClient.RequestHeadersUriSpec<?> head()Prepare an HTTP HEAD request.- Returns:
- a spec for specifying the target URL
 
- 
postPrepare an HTTP POST request.- Returns:
- a spec for specifying the target URL
 
- 
putPrepare an HTTP PUT request.- Returns:
- a spec for specifying the target URL
 
- 
patchPrepare an HTTP PATCH request.- Returns:
- a spec for specifying the target URL
 
- 
deleteRestTestClient.RequestHeadersUriSpec<?> delete()Prepare an HTTP DELETE request.- Returns:
- a spec for specifying the target URL
 
- 
optionsRestTestClient.RequestHeadersUriSpec<?> options()Prepare an HTTP OPTIONS request.- Returns:
- a spec for specifying the target URL
 
- 
methodPrepare a request for the specifiedHttpMethod.- Returns:
- a spec for specifying the target URL
 
- 
mutateReturn a builder to mutate properties of this test client.
- 
bindToControllerBegin creating aRestTestClientwith a Standalone MockMvc setup.
- 
bindToRouterFunctionstatic RestTestClient.RouterFunctionSetupBuilder bindToRouterFunction(RouterFunction<?>... routerFunctions) Begin creating aRestTestClientwith a RouterFunction MockMvc setup.
- 
bindToApplicationContextstatic RestTestClient.WebAppContextSetupBuilder bindToApplicationContext(WebApplicationContext context) Begin creating aRestTestClientwith a WebApplicationContext MockMvc setup.
- 
bindToBegin creating aRestTestClientby providing an already initializedMockMvcinstance to use as the server.
- 
bindToServerThis server setup option allows you to connect to a live server.RestTestClient client = RestTestClient.bindToServer() .baseUrl("http://localhost:8080") .build();- Returns:
- chained API to customize client config
 
- 
bindToServerA variant ofbindToServer()with a pre-configured request factory.- Returns:
- chained API to customize client config
 
 
-