Class MockRestResponseCreators
java.lang.Object
org.springframework.test.web.client.response.MockRestResponseCreators
Static factory methods to obtain a 
ResponseCreator with a fixed
 response.
 In addition, see also the ExecutingResponseCreator implementation
 that performs actual requests to remote services.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic DefaultResponseCreatorResponseCreatorfor a 202 response (ACCEPTED).static DefaultResponseCreatorResponseCreatorfor a 502 response (BAD_GATEWAY).static DefaultResponseCreatorResponseCreatorfor a 400 response (BAD_REQUEST).static DefaultResponseCreatorwithCreatedEntity(URI location) ResponseCreatorfor a 201 response (CREATED) with a 'Location' header.static ResponseCreatorResponseCreatorwith an internal applicationIOException.static DefaultResponseCreatorResponseCreatorfor a 403 response (FORBIDDEN).static DefaultResponseCreatorResponseCreatorfor a 504 response (GATEWAY_TIMEOUT).static DefaultResponseCreatorResponseCreatorfor a 204 response (NO_CONTENT).static DefaultResponseCreatorwithRawStatus(int status) Variant ofwithStatus(HttpStatusCode)with an integer.static DefaultResponseCreatorResponseCreatorfor a 409 response (CONFLICT).static DefaultResponseCreatorResponseCreatorfor a 404 response (NOT_FOUND).static DefaultResponseCreatorResponseCreatorfor a 500 response (SERVER_ERROR).static DefaultResponseCreatorResponseCreatorfor a 503 response (SERVICE_UNAVAILABLE).static DefaultResponseCreatorwithStatus(HttpStatusCode status) ResponseCreatorwith a specific HTTP status.static DefaultResponseCreatorResponseCreatorfor a 200 response (OK).static DefaultResponseCreatorwithSuccess(byte[] body, MediaType contentType) ResponseCreatorfor a 200 response (OK) with byte[] body.static DefaultResponseCreatorwithSuccess(String body, MediaType contentType) ResponseCreatorfor a 200 response (OK) with String body.static DefaultResponseCreatorwithSuccess(Resource body, MediaType contentType) ResponseCreatorfor a 200 response (OK) content withResource-based body.static DefaultResponseCreatorResponseCreatorfor a 429 ratelimited response (TOO_MANY_REQUESTS).static DefaultResponseCreatorwithTooManyRequests(int retryAfter) ResponseCreatorfor a 429 rate-limited response (TOO_MANY_REQUESTS) with aRetry-Afterheader in seconds.static DefaultResponseCreatorResponseCreatorfor a 401 response (UNAUTHORIZED).
- 
Constructor Details- 
MockRestResponseCreatorspublic MockRestResponseCreators()
 
- 
- 
Method Details- 
withSuccessResponseCreatorfor a 200 response (OK).
- 
withSuccessResponseCreatorfor a 200 response (OK) with String body.- Parameters:
- body- the response body, a "UTF-8" string
- contentType- the type of the content (may be- null)
 
- 
withSuccessResponseCreatorfor a 200 response (OK) with byte[] body.- Parameters:
- body- the response body
- contentType- the type of the content (may be- null)
 
- 
withSuccessResponseCreatorfor a 200 response (OK) content withResource-based body.- Parameters:
- body- the response body
- contentType- the type of the content (may be- null)
 
- 
withCreatedEntityResponseCreatorfor a 201 response (CREATED) with a 'Location' header.- Parameters:
- location- the value for the- Locationheader
 
- 
withAcceptedResponseCreatorfor a 202 response (ACCEPTED).- Since:
- 6.0
 
- 
withNoContentResponseCreatorfor a 204 response (NO_CONTENT).
- 
withBadRequestResponseCreatorfor a 400 response (BAD_REQUEST).
- 
withUnauthorizedRequestResponseCreatorfor a 401 response (UNAUTHORIZED).
- 
withForbiddenRequestResponseCreatorfor a 403 response (FORBIDDEN).- Since:
- 6.0
 
- 
withResourceNotFoundResponseCreatorfor a 404 response (NOT_FOUND).- Since:
- 6.0
 
- 
withRequestConflictResponseCreatorfor a 409 response (CONFLICT).- Since:
- 6.0
 
- 
withTooManyRequestsResponseCreatorfor a 429 ratelimited response (TOO_MANY_REQUESTS).- Since:
- 6.0
 
- 
withTooManyRequestsResponseCreatorfor a 429 rate-limited response (TOO_MANY_REQUESTS) with aRetry-Afterheader in seconds.- Since:
- 6.0
 
- 
withServerErrorResponseCreatorfor a 500 response (SERVER_ERROR).
- 
withBadGatewayResponseCreatorfor a 502 response (BAD_GATEWAY).- Since:
- 6.0
 
- 
withGatewayTimeoutResponseCreatorfor a 504 response (GATEWAY_TIMEOUT).- Since:
- 6.0
 
- 
withStatusResponseCreatorwith a specific HTTP status.- Parameters:
- status- the response status
 
- 
withRawStatusVariant ofwithStatus(HttpStatusCode)with an integer.- Parameters:
- status- the response status
- Since:
- 5.3.17
 
- 
withExceptionResponseCreatorwith an internal applicationIOException.For example, one could use this to simulate a SocketTimeoutException.- Parameters:
- ex- the- Exceptionto be thrown at HTTP call time
- Since:
- 5.2.2
 
 
-