TL; DR;
Add supporting for custom http statuses in mocked responses
I copied logic from org.springframework.http.ResponseEntity
Foreword
In my company we use "custom not found status" in our REST API's to prevent mixing network error (404 "not found" for unknown routes) with rest responses (when entity with given id not found).
There are good example for rest controller tests.
Suppose we have a rest endpoint for car entity: GET /car/{id}
.
Let's try to write test for case when entity with given id not found. Something like that:
mockMvc.perform(get("/car/{id}/", nonExistsId.toString()))
.andExpect(status().is(404));
And if our code in rest controller have bug, then test will fail with something like "500 internal server error" But if we also make mistake in test in request's path, like that:
mockMvc.perform(get("/carS/{id}/", nonExistsId.toString()))
.andExpect(status().is(404));
then test will pass and we don't catch bugs in cases when entity with given id is non-exists. So, for this reason we used "454" as http status for "not found" case.
Problem
In our clients code we also write tests and want to cover this case with custom http status, but we cant because MockRestResponseCreators and MockClientHttpResponse not support custom http codes:
mockRestServiceServer.expect(requestTo(serverURI)
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(454)); // <-- will not work cause support only HttpStatus
Comment From: pivotal-cla
@AzZureman Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@AzZureman Thank you for signing the Contributor License Agreement!
Comment From: AzZureman
Can i do something to move PR forward?