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)));
}
}