我正在尝试使用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)
);
致以最诚挚的问候,
答案 0 :(得分:2)
我遇到了同样的问题:
尝试将.bufferContent()添加到MockRestServiceServer
final MockRestServiceServer mockRestServiceServer = MockRestServiceServer
.bindTo(requestTemplate)
.bufferContent()
.build()