问题标签 [wiremock-standalone]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
131 浏览

json - 如何验证 json 键是否包含 Wiremock 中的特定值

我有以下请求网址:

http://localhost:9082/v1/action/query

我在wiremock请求文件中有以下请求:

  1. {"queryString":"从 mydetails 中选择 firstname、lastname、workphone、id、accountId}

    {“请求”:{“方法”:“POST”,“url”:“/v1/action/query”,“bodyPatterns”:[{“包含”:“queryString=from mydetails”}]},“响应” : { "status": 200, "bodyFileName": "mydetails.json", "headers": { "Content-Type": "application/json" } } }

  2. {"queryString":"从 myinfo 中选择 firstname, lastname, workphone, id, accountId}

    {“请求”:{“方法”:“POST”,“url”:“/v1/action/query”,“bodyPatterns”:[{“包含”:“queryString = from myinfo”}]},“响应” :{“状态”:200,“bodyFileName”:“myinfo.json”,“标题”:{“内容类型”:“应用程序/json”}}}

现在我对这两个请求都有相同的 URL。如果我们在 queryString Json key 中获取“来自 myinfo”的表,我必须验证是否在请求正文中。然后返回 myinfo 文件。如果我们有“来自 Mydetails”,那么我的详细信息就会被调用。

我们有什么建议吗?

0 投票
1 回答
833 浏览

mocking - 动态wiremock捕获路径参数并返回响应

我正在尝试使用 WireMock 创建动态模拟。我有一种情况,如果我指定 URL

http://localhost:8989/api/account/121

那么我应该收到这样的回复:

简而言之,路径参数在响应正文中返回,但我不确定我应该如何捕获 121 并使用wiremock 在响应中返回它。

对于这种要求

或者

我可以使用什么所以响应将过滤掉 id 和角色并放入响应中。

我正在使用独立的wiremock jar 2.27.2 来创建wiremock-server。

0 投票
1 回答
143 浏览

mocking - 动态wiremock捕获过滤器参数并返回响应

我正在尝试使用 WireMock 创建动态模拟。我有一种情况,如果我指定 URL

对于这种要求

我可以使用什么所以响应将过滤掉 id 和角色并放入响应中。

我正在使用独立的wiremock jar 2.27.2 来创建wiremock-server。

0 投票
0 回答
762 浏览

wiremock - 使用wiremock时异步测试的ConditionTimeout

我有一个跨多个测试类使用的wiremock实例,直到最近它一直运行良好,当用于测试异步方法时,当测试类单独运行时,测试通过但当整个测试运行时(mvn测试),一些异步类测试因 ConditionTimeOut错误而失败。验证失败是因为,我认为,当调用验证并且等待库正在等待它时,wiremock 服务器没有完成。只是我基于此链接的理解-> https://github.com/tomakehurst/wiremock/issues/565

https://github.com/tomakehurst/wiremock/issues/574

这是我的wiremock类def:

这是一个示例测试异步类:

堆:

  1. 爪哇 14
  2. 线模 2.26.2
  3. 春季启动 2.3.2.RELEASE
0 投票
1 回答
176 浏览

testing - wiremock to mock public backend response

I am testing on an app that is making calls to a public backend.

I want to use wiremock to mock reponses from the public backends.

I was looking at something like

  1. the app makes a request to api.example.com which is forced through the wiremock proxy on localhost:<port>
  2. wiremock matches the URL based on the rules I provide and returns a mock response

The only examples I could find map localhost requests to real backends or mock responses to localhost.

0 投票
1 回答
1299 浏览

wiremock - 如何使用 Wiremock 在字段中返回请求正文作为响应

我有一个 JSON 请求如下:

我需要在字段中发送完整的请求 JSON 对象作为响应。我的 Wiremock 存根 JSON 是,

如何在字段中发送请求正文作为响应?

我现在得到错误:

编辑:-

2.19.0我正在使用导致此问题的wiremock版本。我将版本升级到2.21.0现在问题已解决

但是在响应中,我仍然遇到以下问题,请求正文在双引号内,这是一个无效的 JSON。回复:-

0 投票
1 回答
205 浏览

wiremock - Validate/Match JSON field for number and not string in the input request in Wiremock

I am trying to validate a particular json field amount in the request to have number and not string

Now request1 and request2 are working fine and request3 fails. But I expect request2 to fail as well because it is a string and not number as it is in double quotes.

Request 1,

Request 2,

Request 3,

Is this possible?. I see in wiremock docs

0 投票
1 回答
185 浏览

spring-boot - 独立的wiremock服务器作为spring boot应用程序

我正在尝试将模拟服务作为弹簧启动应用程序。我可以在 Spring Boot 应用程序中使用独立的模拟服务器吗?当我尝试在 Spring Boot 应用程序内的任何端口上运行模拟服务器时,它会引发“地址已绑定异常”有没有办法解决这个问题,以便我可以将模拟服务作为 Spring Boot Docker 容器运行并配置我想模拟的网址。

0 投票
1 回答
48 浏览

wiremock - 需要进行哪些修改才能使 Wiremock 运行?

我有一个名为 ReportService 的 .Net Core Web API 解决方案,它调用另一个 API 端点(我们可以称之为 PayrollService)来获取工资报告。所以我的要求是使用 Wiremock.Net 模拟 PayrollService。

目前我还编写了一个自动化测试用例,它将直接调用 ReportService 控制器并执行所有服务逻辑,以及调用 PayrollService 和 DB 层逻辑的类,并将从 ReportService 中获取 HTTP 结果。

请注意,自动化测试用例是一个单独的解决方案。所以我的要求是像以前一样在 ReportService 上运行自动化测试用例,工资单服务将被 Wiremock 模拟。

那么,代码库中需要进行哪些更改?我们是否必须将 ReportService 的 url 更改为 ReportService 解决方案中的 Wiremock 服务器基本 url?请让我们知道,并请使用我在关于项目名称的问题中使用的术语,以便我清楚。

0 投票
1 回答
356 浏览

java - 在wiremock记录映射期间忽略请求中的某些元素

我正在使用wiremock 来记录映射。我正在使用 proxyBaseUrl,因此当映射不存在时,它会被路由到代理并记录请求和响应。在我的请求中,我希望映射忽略一些与时间戳相关的请求对象项。这样,当创建映射时,我已经有了timestamp通配符 like \"timestamp\": \"${json-unit.any-string}\"。我的测试创建了不同的时间戳,我希望wiremock在创建映射时忽略那些请求对象

当我运行测试时,会创建 100 个映射并逐个遍历它们,更新它们会很痛苦。所以我想提前训练记录映射以忽略某些请求对象。我该怎么做?