我正在尝试使用RestTemplate
模拟MockRestServiceServer
。在调试测试时,响应实体具有良好的状态和内容类型(使用多种状态和内容类型进行测试以检查差异),但主体始终为,始终为 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)
);
此致,
最佳答案
我有同样的问题:
尝试将.bufferContent()添加到MockRestServiceServer
final MockRestServiceServer mockRestServiceServer = MockRestServiceServer
.bindTo(requestTemplate)
.bufferContent()
.build()