spring-framework / org.springframework.test.web.client

Package org.springframework.test.web.client

Types

DefaultRequestExpectation

open class DefaultRequestExpectation : RequestExpectation

Default implementation of RequestExpectation that simply delegates to the request matchers and the response creator it contains.

MockMvcClientHttpRequestFactory

open class MockMvcClientHttpRequestFactory : ClientHttpRequestFactory, AsyncClientHttpRequestFactory

A ClientHttpRequestFactory for requests executed via MockMvc.

As of 5.0 this class also implements org.springframework.http.client.AsyncClientHttpRequestFactory. However note that org.springframework.web.client.AsyncRestTemplate and related classes have been deprecated at the same time.

MockRestServiceServer

open class MockRestServiceServer

Main entry point for client-side REST testing. Used for tests that involve direct or indirect use of the RestTemplate. Provides a way to set up expected requests that will be performed through the RestTemplate as well as mock responses to send back thus removing the need for an actual server.

Below is an example that assumes static imports from MockRestRequestMatchers, MockRestResponseCreators, and ExpectedCount:

 RestTemplate restTemplate = new RestTemplate() MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build(); server.expect(manyTimes(), requestTo("/hotels/42")).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess("{ \"id\" : \"42\", \"name\" : \"Holiday Inn\"}", MediaType.APPLICATION_JSON)); Hotel hotel = restTemplate.getForObject("/hotels/{id}", Hotel.class, 42); // Use the hotel instance... // Verify all expectations met server.verify(); 

Note that as an alternative to the above you can also set the MockMvcClientHttpRequestFactory on a RestTemplate which allows executing requests against an instance of org.springframework.test.web.servlet.MockMvc.

RequestExpectation

interface RequestExpectation : ResponseActions, RequestMatcher, ResponseCreator

An extension of ResponseActions that also implements RequestMatcher and ResponseCreator

While ResponseActions is the API for defining expectations this sub-interface is the internal SPI for matching these expectations to actual requests and for creating responses.

ResponseCreator

interface ResponseCreator

A contract for creating a ClientHttpResponse. Implementations can be obtained via MockRestResponseCreators.

SimpleRequestExpectationManager

open class SimpleRequestExpectationManager : AbstractRequestExpectationManager

Simple RequestExpectationManager that matches requests to expectations sequentially, i.e. in the order of declaration of expectations.

When request expectations have an expected count greater than one, only the first execution is expected to match the order of declaration. Subsequent request executions may be inserted anywhere thereafter.

UnorderedRequestExpectationManager

open class UnorderedRequestExpectationManager : AbstractRequestExpectationManager

RequestExpectationManager that matches requests to expectations regardless of the order of declaration of expected requests.