1
我正在使用wireMock,即使存根响应为200 OK,我也得到500内部服务器错误的一致响应。Wiremock模拟返回HTTP 500
如果我调试,我看到连接总是关闭。任何想法可能会出错?或者我做错了什么。
这里的测试
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} &极限= {极限} &偏移= {偏移量}
上述呼叫是由在MyController中自动装配的客户端类中。这甚至有可能嘲笑,因为它不是一个直接的电话?