简体   繁体   中英

How to check if list returned by Json path contains only 1 unique value

Json response:

{
  "result": [
    {
      "object": {
        "id": "myId"
      }
    },
    {
      "object": {
        "id": "myId"
      }
    }
  ]
}

Is there any way to assert that "id" does not have any other value except "myId" using rest assured assertion with hamcrest matcher?

Other sample assertion: response.then().assertThat().body("result", hasSize(greaterThan(0)));

Currently I am doing this by creating a set from the response and asserting that it has size 1 using testNG assertion but I want to achieve the same with restAssured assertion and hamcrest matcher

If you want to use method body , then solution is:

.body("result.object.id", everyItem(is("myId")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM