wiremock

Wiremock not matching regex

浪子不回头ぞ 提交于 2019-12-24 17:53:07
问题 I'm using wiremock to mock certain requests and their respective response, but I'm trying to add a regex. Unfortunately, this just throws an exception stating that the request was not matched. { "request" : { "method": "GET", "urlPattern": "/my/service/url?^.*(specificParam.*(M[0-9]{9})).*$" }, "response": { ... } } I also tried it with "urlPattern": "/my/service/url\\?^.*(specificParam.*(M[0-9]{9})).*$" The request I'm sending is /my/service/url?saml2=disabled&filter=specificParam%20eq%20

Integration Testing with a fake server

天涯浪子 提交于 2019-12-24 17:26:02
问题 I have a service which connects to a set of api's which i want to test. I would like to make a Fake Service for my integration tests (to simulate failure situations) I cannot simply use @RestController as they are not loaded during a test, and I looked into mockserver but I am unsure if it is what I am looking for, as I do not want my test to trigger a mock call, but rather my code should trigger the api call normally, simply using the mock server rather than an actual server (the base url is

WireMock: Stubbing - How get object “testClient”?

大城市里の小女人 提交于 2019-12-23 16:24:31
问题 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")

How to get HTTPS endpoints to proxy successfully in WireMock?

眉间皱痕 提交于 2019-12-22 08:02:04
问题 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

HTTP Server Mock 从手工到平台的演变(二)

核能气质少年 提交于 2019-12-20 12:46:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 大家都知道,不管是 Web 系统、还是移动 APP,各自在与内部、外部系统之间进行数据交互时,大多数情况下都是依赖接口。在基于接口约定开发的模式下,依赖接口的产出时间如果延迟,将直接影响了整个研发调试的效率;如果不能对接口进行及早测试,那发现问题的时间就要被推迟了。既然双方约定了接口格式,为何不按照这个规范直接测试,何必在乎依赖接口什么时候产出,优先做到及早自测,后续只要替换接口联调通过即可。下面主要讲解基于 HTTP 协议的 API 接口模拟,从手工 Mock 到平台的演变过程。 遇到的问题 曾经遇到的困扰:在研发过程中接口调试对接难的问题: 场景一: 【需求阶段】Portal 前、后端约定基于接口开发 【开发阶段】前端开发完毕,后端接口尚未开发完毕,前端只能硬编码数据进行测试,造成接口对接调试延后,而且每次进行更多场景的数据调试,需要频繁重启服务、本地部署; 研发自测阶段无法及早开展,依赖接口约束大。 场景二: 【需求阶段】新功能开发,Portal 依赖计费的接口,双方约定基于接口开发(内部、外部依赖接口场景均通用) 【开发阶段】Portal 在开发进行中,计费尚未开发完毕,Portal 迟迟不能与计费对接调试(也有可能版本迭代步伐不一致的情况),测试阶段一直被推迟; 另外,即使计费接口开发完毕

NoSuchMethodError when using WireMock in an Android integration test

孤者浪人 提交于 2019-12-18 09:28:46
问题 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.<init> at com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSocketFactory(HttpClientFactory.java:110) at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClientConnectionManagerWithSSLSettings

URL Path Pattern Matching in WireMocks (pattern matching)

非 Y 不嫁゛ 提交于 2019-12-13 16:05:08
问题 I am using wiremock for REST API testing and I am facing the below problem. I have the following 2 json requests created. REQUEST 1: { "request": { "method": "GET", "urlPattern": "/api/v1/user/2158634832/ishop.*", "headers": { "Accept": { "contains": "application/json" }, "X-RequestId": { "matches": ".*" }, "X-SecurityToken": { "matches": "valid_secure_token" } } }, "response": { "status": 200, "jsonBody": { "user": { "ID": "5cc1b131-8858-4870-a7ce-fd37aa805ebf", "info": [ { "kid": "2f0ad36a

How to match a wiremock POST request with some optional JSON parameters & any values?

为君一笑 提交于 2019-12-12 18:09:33
问题 I need to use wiremock to test a POST request that's sending data like this: { "name": "known fixed value", "dateOfBirth": 5123456789000, "email": "known fixed value", "currentDate": any numeric value, "status": any text value with alphabets, numbers and symbols } The 1st 3 fields, name, dateOfBirth and email are fixed, known values, that don't change from one request to the next. The last 2 fields, currentDate and status change randomly from one request to the next, but are mandatory fields

Can WireMock play and record be used at the same time?

笑着哭i 提交于 2019-12-12 08:39:55
问题 I have an application that connect to an external third-party API, and of late the test instance of the API has not been particularly reliable. This stops development progress and turns our build pipelines to red, so I'd like to add an HTTP recording proxy to stop this happening. I've had WireMock recommended, and having tried its record and play features, it does seem to be very good - it pretty much worked out of the box. We simply change the configured URL for the external service, and

Is there a way to convert OpenAPI specifications to json mappings in maven?

一笑奈何 提交于 2019-12-11 10:03:14
问题 I need to convert OpenAPI specifications into json mappings so I could use them in my wiremock server, but I'm not sure if there is an available plugin to do this type of conversion. This is an example of an OpenAPI I'm using openapi: "3.0.0" paths: /fraudcheck: put: summary: Perform Fraud Check x-contracts: - contractId: 1 name: Should Mark Client as Fraud priority: 1 requestBody: content: application/json: schema: type: object properties: "client.id": type: integer loanAmount: type: integer