Есть ли способ, которым мы можем проверить только имя поля, а не значение в Pact json - PullRequest
0 голосов
/ 13 февраля 2020

Пример ниже - ответ. В этом я просто хочу проверить поле, а не значение поля из тела.

Когда я заключаю договор, проверьте:

{
  "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"
    }
  }
}

Только мне нужно проверить поле, такое как имя, возраст и работа не значение поля.

1 Ответ

0 голосов
/ 14 февраля 2020
    got solution we can achieve this using

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

or for only optional

     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 
...