Home > Blockchain >  How to assert that a property in body has only a few predefined values
How to assert that a property in body has only a few predefined values

Time:12-28

Json body:

{
  "result": [
    {
      "object": {
        "type": "mattress"
      }
    },
    {
      "object": {
        "type": "pillow"
      }
    }
  ]
}

How do I assert that type is only either pillow or a mattress (there can be more so I am looking for a generic solution) using rest-assured body and hamcrest assertions?

Example assertion:

response.then().assertThat().body("result", hasSize(greaterThan(0)));

CodePudding user response:

This code would solve your problem:

.body("result.object.type",  everyItem(isOneOf("mattress", "pillow")));
  • Related