I am trying to mock RestTemplate
with MockRestServiceServer
. When I am debugging my test, the response entity has the good status and content-type (tested with multiple status and content-type to check the differences), but the body is always null
.
final String uri = "/uri";
final String notNullJsonString = "{}";
// restTemplate is autowired
final MockRestServiceServer mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);
mockRestServiceServer.expect(
MockRestRequestMatchers.requestTo(new URI(uri))
).andRespond(
MockRestResponseCreators.withStatus(HttpStatus.ACCEPTED)
.contentType(MediaType.APPLICATION_JSON)
.body(notNullJsonString)
);
Best regards,
I had the exact same problem:
Try adding .bufferContent() to the MockRestServiceServer
final MockRestServiceServer mockRestServiceServer = MockRestServiceServer
.bindTo(requestTemplate)
.bufferContent()
.build()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With