Class MockRestResponseCreators
java.lang.Object
org.springframework.test.web.client.response.MockRestResponseCreators
Static factory methods for obtaining a
ResponseCreator instance.
Eclipse users: consider adding this class as a Java editor favorite. To navigate, open the Preferences and type "favorites".
- Since:
- 3.2
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 204 response (NO_CONTENT).static DefaultResponseCreatorResponseCreatorfor a 500 response (SERVER_ERROR).static DefaultResponseCreatorwithStatus(HttpStatus 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 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
-
withNoContent
ResponseCreatorfor a 204 response (NO_CONTENT). -
withBadRequest
ResponseCreatorfor a 400 response (BAD_REQUEST). -
withUnauthorizedRequest
ResponseCreatorfor a 401 response (UNAUTHORIZED). -
withServerError
ResponseCreatorfor a 500 response (SERVER_ERROR). -
withStatus
ResponseCreatorwith a specific HTTP status.- Parameters:
status- the response status
-
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
-