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 an actual requests to remote services.
- Since:
- 3.2
- Author:
- Rossen Stoyanchev
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier 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
-
MockRestResponseCreators
public MockRestResponseCreators()
-
-
Method Details
-
withSuccess
ResponseCreatorfor a 200 response (OK). -
withSuccess
ResponseCreatorfor a 200 response (OK) with String body.- Parameters:
body- the response body, a "UTF-8" stringcontentType- the type of the content (may benull)
-
withSuccess
ResponseCreatorfor a 200 response (OK) with byte[] body.- Parameters:
body- the response bodycontentType- the type of the content (may benull)
-
withSuccess
ResponseCreatorfor a 200 response (OK) content withResource-based body.- Parameters:
body- the response bodycontentType- the type of the content (may benull)
-
withCreatedEntity
ResponseCreatorfor a 201 response (CREATED) with a 'Location' header.- Parameters:
location- the value for theLocationheader
-
withAccepted
ResponseCreatorfor a 202 response (ACCEPTED).- Since:
- 6.0
-
withNoContent
ResponseCreatorfor a 204 response (NO_CONTENT). -
withBadRequest
ResponseCreatorfor a 400 response (BAD_REQUEST). -
withUnauthorizedRequest
ResponseCreatorfor a 401 response (UNAUTHORIZED). -
withForbiddenRequest
ResponseCreatorfor a 403 response (FORBIDDEN).- Since:
- 6.0
-
withResourceNotFound
ResponseCreatorfor a 404 response (NOT_FOUND).- Since:
- 6.0
-
withRequestConflict
ResponseCreatorfor a 409 response (CONFLICT).- Since:
- 6.0
-
withTooManyRequests
ResponseCreatorfor a 429 ratelimited response (TOO_MANY_REQUESTS).- Since:
- 6.0
-
withTooManyRequests
ResponseCreatorfor a 429 rate-limited response (TOO_MANY_REQUESTS) with aRetry-Afterheader in seconds.- Since:
- 6.0
-
withServerError
ResponseCreatorfor a 500 response (SERVER_ERROR). -
withBadGateway
ResponseCreatorfor a 502 response (BAD_GATEWAY).- Since:
- 6.0
-
withGatewayTimeout
ResponseCreatorfor a 504 response (GATEWAY_TIMEOUT).- Since:
- 6.0
-
withStatus
ResponseCreatorwith a specific HTTP status.- Parameters:
status- the response status
-
withRawStatus
Variant ofwithStatus(HttpStatusCode)with an integer.- Parameters:
status- the response status- Since:
- 5.3.17
-
withException
ResponseCreatorwith an internal applicationIOException.For example, one could use this to simulate a
SocketTimeoutException.- Parameters:
ex- theExceptionto be thrown at HTTP call time- Since:
- 5.2.2
-