0
点赞
收藏
分享

微信扫一扫

介绍个不错的RESTFUL MOCK的工具wiremock

凉夜lrs 2022-12-05 阅读 18


介绍个不错的RESTFUL MOCK的工具wiremock,地址在:
​​​http://wiremock.org/docs/running-standalone/ ​​​
简单使用:
java -jar wiremock-standalone-2.17.0.jar

public static void main(String[] args) throws IOException {
configureFor(8682);
removeAllMappings();

mock("/order/1", "01");
mock("/order/2", "02");
}

private static void mock(String url, String file) throws IOException {
ClassPathResource resource = new ClassPathResource("mock/response/" + file + ".txt");
String content = StringUtils.join(FileUtils.readLines(resource.getFile(), "UTF-8").toArray(), "\n");
stubFor(get(urlPathEqualTo(url)).willReturn(aResponse().withBody(content).withStatus(200)));
}

举报

相关推荐

0 条评论