Wiremock 的新版本 2.1.7 改变了很多。通过在运行时以编程方式添加存根,以前的一些方法似乎不再适用于直接方法。
例如,我可以像这样在 1.57 版中添加一个存根:
private void setStub(WireMockServer server, String url, RequestMethod requestMethod, Object body)
throws JsonProcessingException {
UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy();
urlStrategy.setUrl(url);
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(body);
StubMapping mapping = new MappingBuilder(requestMethod, urlStrategy).willReturn(
new ResponseDefinitionBuilder().withHeader("Access-Control-Allow-Origin", "*").withBody(jsonInString)).build();
server.addStubMapping(mapping);
}
我怎样才能在 2.1.7 中实现这一点?(是的,我阅读了文档,但我发现只有 JUnit 注释,在我的情况下没有用)。