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 forRequestExpectationManagerimplementations 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 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 classAbstractRequestExpectationManager.RequestExpectationGroupHelper class to manage a group of remaining expectations.
Constructor Summary
Constructors Constructor Description AbstractRequestExpectationManager()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterExpectationsDeclared()Invoked at the time of the first actual request, which effectively means the expectations declaration phase is over.protected AssertionErrorcreateUnexpectedRequestError(ClientHttpRequest request)Return anAssertionErrorthat a sub-class can raise for an unexpected request.ResponseActionsexpectRequest(ExpectedCount count, RequestMatcher matcher)Set up a new request expectation.protected List<RequestExpectation>getExpectations()protected StringgetRequestDetails()Return details of executed requests.protected List<ClientHttpRequest>getRequests()voidreset()Reset the internal state removing all expectations and recorded requests.ClientHttpResponsevalidateRequest(ClientHttpRequest request)Validate the given actual request against the declared expectations.protected abstract ClientHttpResponsevalidateRequestInternal(ClientHttpRequest request)Subclasses must implement the actual validation of the request matching to declared expectations.voidverify()Verify that all expectations have been met.
Constructor Detail
AbstractRequestExpectationManager
public AbstractRequestExpectationManager()
Method Detail
getExpectations
protected List<RequestExpectation> getExpectations()
getRequests
protected List<ClientHttpRequest> getRequests()
expectRequest
public ResponseActions expectRequest(ExpectedCount count, RequestMatcher matcher)
Description copied from interface:RequestExpectationManagerSet up a new request expectation. The returnedResponseActionsis used to add more expectations and define a response.This is a delegate for
MockRestServiceServer.expect(ExpectedCount, RequestMatcher).- Specified by:
 expectRequestin interfaceRequestExpectationManagermatcher- a request expectation- Returns:
 - for setting up further expectations and define a response
 - See Also:
 MockRestServiceServer.expect(RequestMatcher),MockRestServiceServer.expect(ExpectedCount, RequestMatcher)
validateRequest
public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOException
Description copied from interface:RequestExpectationManagerValidate the given actual request against the declared expectations. Is successful return the mock response to use or raise an error.This is used in
MockRestServiceServeragainst actual requests.- Specified by:
 validateRequestin interfaceRequestExpectationManager- 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.
validateRequestInternal
protected abstract ClientHttpResponse validateRequestInternal(ClientHttpRequest request) throws IOException
Subclasses must implement the actual validation of the request matching to declared expectations.- Throws:
 IOException
verify
public void verify()
Description copied from interface:RequestExpectationManagerVerify that all expectations have been met.This is a delegate for
MockRestServiceServer.verify().- Specified by:
 verifyin interfaceRequestExpectationManager- See Also:
 MockRestServiceServer.verify()
getRequestDetails
protected String getRequestDetails()
Return details of executed requests.
createUnexpectedRequestError
protected AssertionError createUnexpectedRequestError(ClientHttpRequest request)
Return anAssertionErrorthat a sub-class can raise for an unexpected request.
reset
public void reset()
Description copied from interface:RequestExpectationManagerReset the internal state removing all expectations and recorded requests.This is a delegate for
MockRestServiceServer.reset().- Specified by:
 resetin interfaceRequestExpectationManager- See Also:
 MockRestServiceServer.reset()