Package org.springframework.test.web.client

# Class AbstractRequestExpectationManager

java.lang.Object
org.springframework.test.web.client.AbstractRequestExpectationManager

All Implemented Interfaces:
  `RequestExpectationManager`

Direct Known Subclasses:
  `SimpleRequestExpectationManager`, `UnorderedRequestExpectationManager`

public abstract class AbstractRequestExpectationManager extends Object implements RequestExpectationManager
Base class for `RequestExpectationManager` implementations responsible for storing expectations and actual requests, and checking for unsatisfied expectations at the end.

Subclasses are responsible for validating each request by matching it to expectations following the order of declaration or not.

Since:
  4.3
Author:
  Rossen Stoyanchev, Juergen Hoeller

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected static class`
`AbstractRequestExpectationManager.RequestExpectationGroup`
Helper class to manage a group of remaining expectations.

## Constructor Summary

Constructors
Constructor
Description
`AbstractRequestExpectationManager()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`afterExpectationsDeclared()`
Invoked at the time of the first actual request, which effectively means the expectations declaration phase is over.
`protected AssertionError`
`createUnexpectedRequestError(org.springframework.http.client.ClientHttpRequest request)`
Return an `AssertionError` that a subclass can raise for an unexpected request.
`ResponseActions`
`expectRequest(ExpectedCount count, RequestMatcher matcher)`
Set up a new request expectation.
`protected List<RequestExpectation>`
`getExpectations()`
Return a read-only list of the expectations.
`protected String`
`getRequestDetails()`
Return details of executed requests.
`protected List<org.springframework.http.client.ClientHttpRequest>`
`getRequests()`
Return a read-only list of requests executed so far.
`protected RequestExpectation`
`matchRequest(org.springframework.http.client.ClientHttpRequest request)`
As of 5.0.3 subclasses should implement this method instead of `#validateRequestInternal(ClientHttpRequest)` in order to match the request to an expectation, leaving the call to create the response as a separate step (to be invoked by this class).
`void`
`reset()`
Reset the internal state removing all expectations and recorded requests.
`org.springframework.http.client.ClientHttpResponse`
`validateRequest(org.springframework.http.client.ClientHttpRequest request)`
Validate the given actual request against the declared expectations.
`void`
`verify()`
Verify that all expectations have been met.
`void`
`verify(Duration timeout)`
Variant of `RequestExpectationManager.verify()` that waits for up to the specified time for all expectations to be fulfilled.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AbstractRequestExpectationManager

public AbstractRequestExpectationManager()

## Method Details

### getExpectations

protected List<RequestExpectation> getExpectations()
Return a read-only list of the expectations.

### getRequests

protected List<org.springframework.http.client.ClientHttpRequest> getRequests()
Return a read-only list of requests executed so far.

### expectRequest

public ResponseActions expectRequest(ExpectedCount count, RequestMatcher matcher)
Description copied from interface: `RequestExpectationManager`
Set up a new request expectation. The returned `ResponseActions` is used to add more expectations and define a response.

This is a delegate for `MockRestServiceServer.expect(ExpectedCount, RequestMatcher)`.

Specified by:
  `expectRequest` in interface `RequestExpectationManager`
  `matcher` - a request expectation
Returns:
  for setting up further expectations and define a response
See Also:
  - `MockRestServiceServer.expect(RequestMatcher)`
  - `MockRestServiceServer.expect(ExpectedCount, RequestMatcher)`

### validateRequest

public org.springframework.http.client.ClientHttpResponse validateRequest(org.springframework.http.client.ClientHttpRequest request) throws IOException
Description copied from interface: `RequestExpectationManager`
Validate the given actual request against the declared expectations. Is successful return the mock response to use or raise an error.

This is used in `MockRestServiceServer` against actual requests.

Specified by:
  `validateRequest` in interface `RequestExpectationManager`
Parameters:
  `request` - the request
Returns:
  the response to return if the request was validated.
Throws:
  `IOException` - in case of any validation errors

### afterExpectationsDeclared

protected void afterExpectationsDeclared()
Invoked at the time of the first actual request, which effectively means the expectations declaration phase is over.

### matchRequest

protected RequestExpectation matchRequest(org.springframework.http.client.ClientHttpRequest request) throws IOException
As of 5.0.3 subclasses should implement this method instead of `#validateRequestInternal(ClientHttpRequest)` in order to match the request to an expectation, leaving the call to create the response as a separate step (to be invoked by this class).

Parameters:
  `request` - the current request
Returns:
  the matched expectation with its request count updated via `RequestExpectation.incrementAndValidate()`.
Throws:
  `IOException`
Since:
  5.0.3

### verify

public void verify()
Description copied from interface: `RequestExpectationManager`
Verify that all expectations have been met.

This is a delegate for `MockRestServiceServer.verify()`.

Specified by:
  `verify` in interface `RequestExpectationManager`
See Also:
  - `MockRestServiceServer.verify()`

### verify

public void verify(Duration timeout)
Description copied from interface: `RequestExpectationManager`
Variant of `RequestExpectationManager.verify()` that waits for up to the specified time for all expectations to be fulfilled. This can be useful for tests that involve asynchronous requests.

Specified by:
  `verify` in interface `RequestExpectationManager`
Parameters:
  `timeout` - how long to wait for all expectations to be met

### getRequestDetails

protected String getRequestDetails()
Return details of executed requests.

### createUnexpectedRequestError

protected AssertionError createUnexpectedRequestError(org.springframework.http.client.ClientHttpRequest request)
Return an `AssertionError` that a subclass can raise for an unexpected request.

### reset

public void reset()
Description copied from interface: `RequestExpectationManager`
Reset the internal state removing all expectations and recorded requests.

This is a delegate for `MockRestServiceServer.reset()`.

Specified by:
  `reset` in interface `RequestExpectationManager`
See Also:
  - `MockRestServiceServer.reset()`