Class DefaultRequestExpectation
- java.lang.Object
 - org.springframework.test.web.client.DefaultRequestExpectation
 
- All Implemented Interfaces:
 RequestExpectation,RequestMatcher,ResponseActions,ResponseCreator
public class DefaultRequestExpectation extends Object implements RequestExpectation
Default implementation ofRequestExpectationthat simply delegates to the request matchers and the response creator it contains.- Since:
 - 4.3
 - Author:
 - Rossen Stoyanchev
 
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultRequestExpectation.RequestCountHelper class that keeps track of actual vs expected request count.
Constructor Summary
Constructors Constructor Description DefaultRequestExpectation(ExpectedCount expectedCount, RequestMatcher requestMatcher)Create a new request expectation that should be called a number of times as indicated byRequestCount.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResponseActionsandExpect(RequestMatcher requestMatcher)Add a request expectation.voidandRespond(ResponseCreator responseCreator)Define the response.ClientHttpResponsecreateResponse(ClientHttpRequest request)Create a response for the given request.protected DefaultRequestExpectation.RequestCountgetRequestCount()protected List<RequestMatcher>getRequestMatchers()protected ResponseCreatorgetResponseCreator()booleanhasRemainingCount()Whether there is a remaining count of invocations for this expectation.booleanisSatisfied()Whether the requirements for this request expectation have been met.voidmatch(ClientHttpRequest request)Match the given request against specific expectations.
Constructor Detail
DefaultRequestExpectation
public DefaultRequestExpectation(ExpectedCount expectedCount, RequestMatcher requestMatcher)
Create a new request expectation that should be called a number of times as indicated byRequestCount.- Parameters:
 expectedCount- the expected request expectedCount
Method Detail
getRequestCount
protected DefaultRequestExpectation.RequestCount getRequestCount()
getRequestMatchers
protected List<RequestMatcher> getRequestMatchers()
getResponseCreator
protected ResponseCreator getResponseCreator()
andExpect
public ResponseActions andExpect(RequestMatcher requestMatcher)
Description copied from interface:ResponseActionsAdd a request expectation.- Specified by:
 andExpectin interfaceResponseActions- Returns:
 - the expectation
 
andRespond
public void andRespond(ResponseCreator responseCreator)
Description copied from interface:ResponseActionsDefine the response.- Specified by:
 andRespondin interfaceResponseActions- Parameters:
 responseCreator- the creator of the response
match
public void match(ClientHttpRequest request) throws IOException
Description copied from interface:RequestMatcherMatch the given request against specific expectations.- Specified by:
 matchin interfaceRequestMatcher- Parameters:
 request- the request to make assertions on- Throws:
 IOException- in case of I/O errors
createResponse
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException
Description copied from interface:ResponseCreatorCreate a response for the given request.- Specified by:
 createResponsein interfaceResponseCreator- Parameters:
 request- the request- Throws:
 IOException
hasRemainingCount
public boolean hasRemainingCount()
Description copied from interface:RequestExpectationWhether there is a remaining count of invocations for this expectation.- Specified by:
 hasRemainingCountin interfaceRequestExpectation
isSatisfied
public boolean isSatisfied()
Description copied from interface:RequestExpectationWhether the requirements for this request expectation have been met.- Specified by:
 isSatisfiedin interfaceRequestExpectation