首页 > 其他 > 详细

wiremock

时间:2020-01-06 16:39:13      阅读:77      评论:0      收藏:0      [点我收藏+]

1.部署服务器

(1)打开wiremock官网
技术分享图片

(2)下载
技术分享图片

(3)启动服务 设置端口号
技术分享图片

2.代码

(1)创建
技术分享图片

(2)main 方法 启动

public class MockServer {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        configureFor(8062); // 配置端口    
        removeAllMappings();  // 清除配置

        mock("/order/1", "01"); // url
        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");
                // get 访问,返回body ,和100状态
        stubFor(get(urlPathEqualTo(url)).willReturn(aResponse().withBody(content).withStatus(200)));
    }

}

3 访问 http://localhost:8062/order/1

wiremock

原文:https://www.cnblogs.com/tekken-wang/p/12156481.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!