如何使用Wiremock通过Json响应获取属性变量

问题描述 投票:0回答:1

我需要使用流量鹦鹉和Wiremock进行具有不同值的动态响应。

我在json文件中进行了模式集成测试,以便在调用API时得到响应。

我需要致电产品服务来检索特定产品,我的请求json:

request.json
{
  "request" {
    "urlPathPattern": "/urlResponse/product/1000",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "response.json",
    "transformers": [
      "response-template"
    ]
  }
}

而且我需要这样的东西:

response.json
{
  "id": {{request.path.[2]}},
  "type": VARIABLE or DYNAMIC CONTENT,
  "other attr"....
}

我想根据请求传递可变内容,例如,我有一个对象

public CustomObject {
  private int id = 1000;
  private String type = "product";
}

[当我调用ID为1000的产品的API时,我需要一个类型设置为“ product”的response.json。我看到了交通鹦鹉example的文档,但我不知道如何申请。

编辑1:是否可以在request.json中定义一个映射来定义响应的变量类型?像这样的东西:

If I have an ID with 1000
objMap = 1000; type = "product",
objMap = 2000; type = "Balloon",
etc...
java testing integration-testing wiremock traffic-simulation
1个回答
0
投票

尝试https://www.smocker.org/

Smocker是用于Java应用程序的网络虚拟化工具。这是一个开放源代码软件,可以观看您的Java应用程序通过Rich Web应用程序进行的所有网络交互的模拟。您可以轻松地发现Java应用程序如何处理外部网络依赖性。

© www.soinside.com 2019 - 2024. All rights reserved.