mibrahim.iti
mibrahim.iti

Reputation: 2060

REST Assured getting map values only from response body

Imagine i called a RESTful service and it returns this in response body

[
  {
    "key": "Reason1 key",
    "values": {
      "en": "Reason1 English translation",
      "es": "Reason1 Spanish translation"
    }
  },
  {
    "key": "Reason2 key",
    "values": {
      "en": "Reason2 English translation",
      "es": "Reason2 Spanish translation"
    }
  }
]

I need to get only values which map key is 'en'

So i am expecting the result to be like that after filtering it

["Reason1 English translation", "Reason2 English translation"]

OR

{"Reason1 English translation", "Reason2 English translation"}

I had try this next code but still not completed

response.then().body("findAll { it }.collect { it.values }", hasItems("Reason1 English translation", "Reason2 English translation"))

and it return

[{en=Reason1 English translation, es=Reason1 Spanish translation}, {en=Reason2 English translation, es=Reason2 Spanish translation}]

So how can i get only map values which matching map key condition of equality of 'en'?

Upvotes: 0

Views: 2117

Answers (1)

aristotll
aristotll

Reputation: 9177

Changes to ....body("findAll { it }.collect { it.values.en }"

Add en to get the en nodes rather than the entire values node.

Upvotes: 1

Related Questions