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
-
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultResponseCreator
ResponseCreator
for a 400 response (BAD_REQUEST).static DefaultResponseCreator
withCreatedEntity
(URI location) ResponseCreator
for a 201 response (CREATED) with a 'Location' header.static ResponseCreator
ResponseCreator
with an internal applicationIOException
.static DefaultResponseCreator
ResponseCreator
for a 204 response (NO_CONTENT).static DefaultResponseCreator
withRawStatus
(int status) Variant ofwithStatus(HttpStatusCode)
with an integer.static DefaultResponseCreator
ResponseCreator
for a 500 response (SERVER_ERROR).static DefaultResponseCreator
withStatus
(HttpStatusCode status) ResponseCreator
with a specific HTTP status.static DefaultResponseCreator
ResponseCreator
for a 200 response (OK).static DefaultResponseCreator
withSuccess
(byte[] body, MediaType contentType) ResponseCreator
for a 200 response (OK) with byte[] body.static DefaultResponseCreator
withSuccess
(String body, MediaType contentType) ResponseCreator
for a 200 response (OK) with String body.static DefaultResponseCreator
withSuccess
(Resource body, MediaType contentType) ResponseCreator
for a 200 response (OK) content withResource
-based body.static DefaultResponseCreator
ResponseCreator
for a 401 response (UNAUTHORIZED).
-
Constructor Details
-
MockRestResponseCreators
public MockRestResponseCreators()
-
-
Method Details
-
withSuccess
ResponseCreator
for a 200 response (OK). -
withSuccess
ResponseCreator
for a 200 response (OK) with String body.- Parameters:
body
- the response body, a "UTF-8" stringcontentType
- the type of the content (may benull
)
-
withSuccess
ResponseCreator
for a 200 response (OK) with byte[] body.- Parameters:
body
- the response bodycontentType
- the type of the content (may benull
)
-
withSuccess
ResponseCreator
for a 200 response (OK) content withResource
-based body.- Parameters:
body
- the response bodycontentType
- the type of the content (may benull
)
-
withCreatedEntity
ResponseCreator
for a 201 response (CREATED) with a 'Location' header.- Parameters:
location
- the value for theLocation
header
-
withNoContent
ResponseCreator
for a 204 response (NO_CONTENT). -
withBadRequest
ResponseCreator
for a 400 response (BAD_REQUEST). -
withUnauthorizedRequest
ResponseCreator
for a 401 response (UNAUTHORIZED). -
withServerError
ResponseCreator
for a 500 response (SERVER_ERROR). -
withStatus
ResponseCreator
with 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
ResponseCreator
with an internal applicationIOException
.For example, one could use this to simulate a
SocketTimeoutException
.- Parameters:
ex
- theException
to be thrown at HTTP call time- Since:
- 5.2.2
-