dimanche 28 février 2021

Validate nested response body rest assured

I know that there is a lot of information regarding validations in rest assure but unfortunately I am not able to find exactly the solution to my issue.

I am training to validate the response of the following JSON:

{
"A":[
  {
     "B":[
        {
           "C":"c",
           "D":"d"
        }
     ],
     "E":[
        {
           "F":[
              {
                 "G":"g1"   
              }
           ]
        },
        {
           "F":[
              {
                 "G":"g2"
              }
           ],
        },
        {
           "F":[]
        }
     ]
  }
],
"H": "h"
}

with the following code:

 response.body("A.E.F.G", hasItems(expectedValues.get(G).toArray(new String[0])))

expectedValues.get(G) return a list of g1 and g2.

the ERROR that I get is:

JSON path A.E.F.G doesn't match.
Expected: an array containing ["g1", "g2"]
Actual: [[[g1], [g2], []]]

How can I get that done?

Aucun commentaire:

Enregistrer un commentaire