wiremock

前后端分离中,使用swagger2和WireMock提高开发速度

两盒软妹~` 提交于 2019-12-04 17:59:33
一、使用swagger2生成接口文档 依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <!-- swagger的bootstrap的美化界面 --> <dependency>   <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> 在springboot的启动类上加@EnableSwagger2注解 在controller的接口上加@ApiOperation(value = "用户查询服务")注解表明接口的作用。 swagger2中常用注解: @Api():用在请求的类上,表示对类的说明,也代表了这个类是swagger2的资源    参数:tags:说明该类的作用,参数是个数组,可以填多个。       value="该参数没什么意义,在UI界面上不显示,所以不用配置"       description = "用户基本信息操作" @ApiOperation():用于方法

How to write integration tests with spring-cloud-netflix and feign

微笑、不失礼 提交于 2019-12-04 15:47:12
问题 I use Spring-Cloud-Netflix for communication between micro services. Let's say I have two services, Foo and Bar, and Foo consumes one of Bar's REST endpoints. I use an interface annotated with @FeignClient : @FeignClient public interface BarClient { @RequestMapping(value = "/some/url", method = "POST") void bazzle(@RequestBody BazzleRequest); } Then I have a service class SomeService in Foo, which calls the BarClient . @Component public class SomeService { @Autowired BarClient barClient;

基于Wiremock创建Mock Service平台(转)

江枫思渺然 提交于 2019-12-04 14:16:33
本文链接:https://blog.csdn.net/liuchunming033/article/details/52399397 1、Wiremock工具介绍 一般开发项目都会分模块进行,比如都会把前端和后端分开,在前端和后端里面也通常是分模块开发的。当开发进度不一致时,可以对依赖接口构建Mock Service,模拟不同输入/数据/场景,这样不至于影响本模块的开发进度。构建Mock Service方法很多,今天介绍Wiremock,Wiremock非常轻便易用,甚至不用编程,一个jar包基本够用了,当然,也可以把它引用写进测试代码里。 官网地址:http://wiremock.org/ Jar包下载:http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.1.10/wiremock-standalone-2.1.10.jar 2、Wiremock工作原理 启动wiremock java -jar wiremock-2.1.10-standalone.jar –port 9999 —verbose1 (–port设定端口为9999; –verbose开启日志。更多参数需要参考: http://wiremock.org/docs/running-standalone/

WireMock-强大的模拟测试工具

ぃ、小莉子 提交于 2019-12-04 03:58:01
简介 官方是这样介绍的:WireMock是一个基于HTTP的API模拟器,可以模拟你的API,以进行快速,强大和全面测试,它的核心是Web服务器,它可以启动以提供对特定请求的罐装响应(存根),并捕获传入的请求,以便以后进行检查(验证),WireMock的所有功能都可以通过其REST(JSON)接口和Java API进行访问。此外,可以通过JSON文件配置存根。 Maven <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8</artifactId> <version>2.25.1</version> <scope>test</scope> </dependency> 独立的服务器 WireMock服务器可以在其自己的进程中运行,并可以通过Java API,HTTP上的JSON或JSON文件进行配置。一旦你已经 下载独立的JAR ,并通过命令运行起来即可: java -jar wiremock-standalone-2.25.1.jar 命令行选项 可以在命令行上添加指定的内容,eg: --port:设置HTTP端口号,eg:--port 8888 --https-port:如果指定,则在提供的端口上启用HTTPS。注意:当您指定此参数时

How to get HTTPS endpoints to proxy successfully in WireMock?

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am writing an HTTP record-playback proxy which internally uses WireMock, and am having a problem with recording HTTPS targets. HTTP sites work fine. Here is how I set up the WireMock proxy for an unencrypted site: java \ - jar / var / proximate / wiremock - standalone - 2.4 . 1.jar \ -- port 9000 \ -- proxy - all http : //ilovephp.jondh.me.uk \ -- record - mappings \ -- root - dir / remote / experiment / record / http I then can record anything on that site using this command: wget - e use_proxy = yes - e http_proxy = proximate -

NoSuchMethodError when using WireMock in an Android integration test

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Got the following stack trace when trying to start a WireMockServer in my robotium android test. Might be a conflict between 2 versions of Apache Http client, but I did not manage to solve it yet. Any idea? java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLSocketFactory. at com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSocketFactory(HttpClientFactory.java:110) at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClientConnectionManagerWithSSLSettings(HttpClientFactory.java:88) at com.github.tomakehurst

Wiremock : how to upload file to folder __files with API

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: the documentation of wiremock says that we can mock a a request that retrieve a file thanks to this code : { "request": { "method": "GET", "url": "/body-file" }, "response": { "status": 200, "bodyFileName": "path/to/myfile.xml" } } But now I have to find a way to reaaly upload the file other wise I have 500 error on the request. <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/> <title>Error 500 </title> </head> <body> <h2>HTTP ERROR: 500</h2> <p>Problem accessing /body-file. Reason: <pre> java.lang

WireMock: Stubbing - How get object “testClient”?

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to test http request/response. So I use WireMock. I want to stub response for specific request: Here code: public class WireMockPersons { @Rule public WireMockRule wireMockRule = new WireMockRule(8089); @Test public void exactUrlOnly() { stubFor(get(urlEqualTo("/some/thing")) .willReturn(aResponse() .withHeader("Content-Type", "text/plain") .withBody("Hello world!"))); assertThat(testClient.get("/some/thing").statusCode(), is(200)); assertThat(testClient.get("/some/thing/else").statusCode(), is(404)); } Code is not compile because no

WireMock和Spring MVC模拟器

☆樱花仙子☆ 提交于 2019-12-02 21:28:20
WireMock和Spring MVC模拟器 Spring Cloud Contract提供了一个方便的类,可以将JSON WireMock存根加载到Spring MockRestServiceServer 中。 以下是一个例子: @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockForDocsMockServerApplicationTests { @Autowired private RestTemplate restTemplate; @Autowired private Service service; @Test public void contextLoads() throws Exception { // will read stubs classpath MockRestServiceServer server = WireMockRestServiceServer.with(this.restTemplate) .baseUrl("http://example.org").stubs("classpath:/stubs/resource.json") .build(); // We're asserting

配置Zuul代理下游的认证

天涯浪子 提交于 2019-12-02 21:28:13
配置Zuul代理下游的认证 您可以通过 proxy.auth.* 设置控制 @EnableZuulProxy 下游的授权行为。 例: application.yml proxy: auth: routes: customers: oauth2 stores: passthru recommendations: none 在此示例中,“客户”服务获取OAuth2令牌中继,“存储”服务获取传递(授权头只是通过下游),“建议”服务已删除其授权头。 如果有令牌可用,则默认行为是执行令牌中继,否则为passthru。 有关 详细信息, 请参阅 ProxyAuthenticationProperties 。 Spring Cloud为Cloud Foundry Cloudfoundry的Spring Cloud可以轻松地 在 Cloud Foundry (平台即服务) 中运行 Spring Cloud 应用程序 。 Cloud Foundry有一个“服务”的概念,它是“绑定”到应用程序的中间件,本质上为其提供包含凭据的环境变量(例如,用于服务的位置和用户名)。 spring-cloud-cloudfoundry-web 项目为Cloud Foundry中的webapps的一些增强功能提供基本支持:自动绑定到单点登录服务,并可选择启用粘性路由进行发现。 spring-cloud