我正在使用 wireMock,即使 stub 响应是 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}";
}
}
最佳答案
问题解决了,这都与wiremock和我的应用程序中的Javax-servlet-api依赖有关。将wiremock 从wiremock 2.6.0 更改为wiremock-standalone,它使用了应用程序的servlet-api 依赖项,基本上它起作用了。
不确定这是否是正确的答案,但它有效。
https://stackoverflow.com/questions/43646030/