有什么方法我们只能验证字段名称而不是Pact json中的值

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

下面的示例是响应。在此,我只想验证字段而不是正文中的字段值。

当我签约时:

{
  "provider": {
    "name": "provider"
  },
  "consumer": {
    "name": "consumer"
  },
  "interactions": [
    {
      "description": "A valid data read request",
      "request": {
        "method": "GET",
        "path": "/v1/users",
        "query": {
          "user": [
            "1"
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "name": "xyz",
          "work": "gen",
          "age": "29",    
        }
      },
      "providerStates": [
        {
          "name": "user exists state"
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.4"
    }
  }
}

仅我需要验证姓名,年龄和工作等字段,而不是字段值。

pact
1个回答
0
投票
got solution we can achieve this using

 DslPart body = new PactDslJsonBody()
                    .eachKeyLike("name", PactDslJsonRootValue.stringType("xyz"))
                    .eachKeyLike("work", PactDslJsonRootValue.stringType("gen"))
                    .eachKeyLike("age", PactDslJsonRootValue.integerType(29))
                    .asBody()

and set this body to PactDslWithProvider body and we can have matching rule generated in the json so that when we verify only the field type and field name 
© www.soinside.com 2019 - 2024. All rights reserved.