0

I need to compare all the countries present in Response1 should be present in Response2 also. So How Can I take all the countries from both the responses and validate? I tried on storing country in ArrayList but not able to validate it.

Json Response 1:

{
  "plan": {
    "program": "gtr",
    "syter": "yes"
  },
  "Map": {
    "List": [
      {
        "id": "tyt6577",
        "proxy": "ENABLED",
        "type": "BENEFIT",
        "country": "us",
        "triag": null
      },
      {
        "id": "yyaqtf6327",
        "proxy": "ENABLED",
        "type": "BENEFIT",
        "country": "aus",
        "triag": null
      },
      {
        "id": "676hwjsgvhgv",
        "proxy": "ENABLED",
        "type": "BENEFIT",
        "country": "rus",
        "triag": null
      },
      {
        "id": "676hsdhgv",
        "proxy": "ENABLED",
        "type": "BENEFIT",
        "country": "spa",
        "triag": null
      },
      {
        "id": "623ujhhgv",
        "proxy": "ENABLED",
        "type": "BENEFIT",
        "country": "cha",
        "triag": null
      }
    ]
  }
}

Json Response 2:

[
  {
    "id": "tyt6577",
    "proxy": "ENABLED",
    "type": "BENEFIT",
    "country": "rus",
    "triag": null
  },
  {
    "id": "yyaqtf6327",
    "proxy": "ENABLED",
    "type": "BENEFIT",
    "country": "spa",
    "triag": null
  },
  {
    "id": "676hwjsgvhgv",
    "proxy": "ENABLED",
    "type": "BENEFIT",
    "country": "us",
    "triag": null
  },
  {
    "id": "676hsdhgv",
    "proxy": "ENABLED",
    "type": "BENEFIT",
    "country": "aus",
    "triag": null
  },
  {
    "id": "623ujhhgv",
    "proxy": "ENABLED",
    "type": "BENEFIT",
    "country": "cha",
    "triag": null
  }
]
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
Halycon
  • 1
  • 1

1 Answers1

0

This would work for you

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
...
List<String> country = res.jsonPath().get("Map.List.country");
List<String> country2 = res2.jsonPath().get("country");
assertThat(country2, containsInAnyOrder(country.toArray()));
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • If I use that then error is coming --->Cannot resolve method 'from(io.restassured.response.Response)' – Halycon Jul 04 '22 at 05:28
  • Then I tried to cast it to input stream, then the below error came after running the script Step failed java.lang.ClassCastException: io.restassured.internal.RestAssuredResponseImpl cannot be cast to java.io.InputStream – Halycon Jul 04 '22 at 05:32
  • @Halycon where exactly did you get this error, in which line? Can you paste the whole error here? – cheparsky Jul 25 '22 at 19:23