【发布时间】:2017-04-26 23:11:46
【问题描述】:
我正在使用wireMock,即使存根响应为200 OK,我也得到500 Internal Server Error 的一致响应。
如果我调试,我看到连接总是关闭的。知道可能出了什么问题吗?或者我做错了什么。
这是测试
public class MyControllerTest {
@Autowired
MyController myController;
String id1 = "id1";
String id2 = "id2";
Integer offset = 0;
Integer limit = 1;
int port = 8080;
protected WireMockServer wireMockServer;
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(port);
@Test
public void hosDriversHoursOfServiceGet() throws Exception {
stubFor(WireMock.get(urlEqualTo("/path/endPoint"))
.withQueryParam("id1", equalTo(id1))
.withQueryParam("id2", equalTo(id2))
.withQueryParam("limit", equalTo(limit.toString()))
.withQueryParam("offset", equalTo(offset.toString()))
.willReturn(aResponse().withStatus(200).withBody((getJsonString()))));
Response response = myController.hosDriversHoursOfServiceGet(driverId, 1, 1);
assertEquals(Integer.valueOf(1), response.getCount());
}
private String getJsonString() {
return "{\"count\":1}";
}
}
试图模拟: http://localhost:8080/path/endPoint?id1={id1}&id2={id2}&limit={limit}&offset={offset}
上述调用是在 MyController 中自动装配的客户端类中进行的。因为它不是直接调用,所以甚至可以模拟吗?
【问题讨论】: