【问题标题】:Wiremock mock returning HTTP 500Wiremock 模拟返回 HTTP 500
【发布时间】: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 中自动装配的客户端类中进行的。因为它不是直接调用,所以甚至可以模拟吗?

【问题讨论】:

    标签: junit4 wiremock


    【解决方案1】:

    问题已解决,这都与wiremock 和我的应用程序中的Javax-servlet-api 依赖关系有关。将wiremock从wiremock 2.6.0更改为wiremock-standalone,它使用了应用程序的servlet-api依赖,基本上它工作了。

    不确定这是否是正确的答案,但它确实有效。

    【讨论】:

    • 我可以确认这个解决方案值得尝试,它帮助了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多