【发布时间】:2016-09-21 21:07:23
【问题描述】:
我正在尝试为一个使用 RestTemplate 的 REST Web 服务客户端编写 Junit。
下面是对REST模板的方法调用:
final ResponseEntity<LogDateVO[]> result = restTemplate.postForEntity(url, LogDateInputVO, LogDateVO[].class);
在我的测试课中,我正在尝试以下操作:
mockServer.expect(requestTo("http://abc.def.pvt:80/testOperations/api/traffic/logs/")).andExpect(method(HttpMethod.POST))
.andRespond(MockRestResponseCreators.withSuccess("{ \"id\" : \"42\", \"name\" : \"Holiday Inn\"}", MediaType.APPLICATION_JSON));
我无法取回结果,也无法继续使用此方法,我需要一些帮助才能获得此结果。
我的意图是当我的restTemplate 被调用时,它应该检查上述期望并返回成功并返回一些数据。
【问题讨论】:
标签: spring rest resttemplate