使用WireMock快速伪造RESTful服务
2023-09-11 14:18:14 时间
⒈下载WireMock独立运行程序
http://wiremock.org/docs/running-standalone/
⒉运行
java -jar wiremock-standalone-2.22.0.jar --port 7777
⒊项目中导入WireMock依赖
1 <dependency> 2 <groupId>com.github.tomakehurst</groupId> 3 <artifactId>wiremock</artifactId> 4 <version>2.22.0</version> 5 </dependency>
⒋添加模拟请求映射
1 package cn.coreqi.security.wiremock; 2 3 import com.github.tomakehurst.wiremock.client.WireMock; 4 import org.aspectj.util.FileUtil; 5 import org.springframework.core.io.ClassPathResource; 6 7 import java.io.IOException; 8 9 public class MockServer { 10 public static void main(String[] args) throws IOException { 11 WireMock.configureFor(7777); //告诉程序WireMock的服务端口 12 WireMock.removeAllMappings(); //把以前的所有配置清空 13 14 mock("/order/1","01"); 15 } 16 public static void mock(String url,String fileName) throws IOException { 17 ClassPathResource resource = new ClassPathResource("/mock/response/"+fileName+".txt"); 18 String content = FileUtil.readAsString(resource.getFile()); 19 WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(url)).willReturn(WireMock.aResponse().withBody(content).withStatus(200))); 20 } 21 }
相关文章
- falsk-restful代码通过swagger一键生成接口文档
- API/REST API /RESTFUL API
- PHP RESTful
- Laravel 内置 Route::resource 可以直接创建 restful 风格的接口
- flask_restful中reqparse解析器继承
- Flask-RESTful的简单使用
- Java RESTful Web Service实战(第2版) 1.6 快速了解Java REST服务
- Java RESTful Web Service实战(第2版) 2.2 资源定位
- Spring整合CXF实现基于Restful风格的webservice
- 拦截RESTful API并做相应处理的方式
- 分布式框架简介SSM组合+ springmvc+mybatis+shiro+restful+bootstrap
- JEESZ RestFul服务介绍
- WCF 改成 restful api
- 说说自己对RESTful API的理解s
- spring boot 2 全局统一返回RESTful风格数据、统一异常处理
- flask-利用Blueprint、flask_restful编写一个后端测试项目
- RESTful Web Services: A Tutorial--reference
- Http与Restful之间的关系
- springmvc+mybatis+restful+webservice Jeesz分布式架构