Tekken

  博客园  ::  :: 新随笔  ::  ::  :: 管理

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

posted on 2020-01-06 15:19  Tekken250  阅读(129)  评论(0)    收藏  举报