0

I Post one Json with RestAssured and After I need to verify that all fields are stored in the database with the correct values.My Json is :

{
    "id": "1",
    "name": "name1",
    "description": "description1",
    "source": "source1",
    "target": "target1",
    "domain": "PM",
    "transformation_rules": [
        {
            "name": "name2",
            "filters": [
                {
                    "object": "object1",
                    "pattern": "pattern1"
                }
            ],
            "operations": [
                {
                    "pattern": "pattern2",
                    "replacement": "replacement1"
                }
            ]
        },
        {
            "name": "name3",
            "filters": [
                {
                    "object": "object2",
                    "pattern": "pattern2"
                }
            ],
            "operations": [
                {
                    "pattern": "pattern3",
                    "replacement": "replacement2"
                },
                {
                    "pattern": "pattern3",
                    "replacement": "replacement3"
                },
                {
                    "pattern": "pattern4",
                    "replacement": "replacement4"
                }
            ]
        }
    ],
    "conflict_policy": "ACCEPT_SOURCE"
}

So, I have :

responseGet = RestAssured.given().contentType(ContentType.JSON).when().get(urlApi + "/" + id);

My first verification is :

responseGet.then().body("$[0]['id']", equalTo("1"));

to verify that the field "id" equals to 1 it doesn't execute well and I change to :

responseGet.then().body("$.id", equalTo("1"));

and the same result ---> fails

Please, can you give me your suggestions for testing all the Json ? Just for information, I try to apply : https://github.com/json-path/JsonPath.

Thank you very much in Advance,

Best Regards,

ksouri
  • 21
  • 4

1 Answers1

0

You can directly use jsonPath() for checking this:

For example:

responseGet.body().jsonPath().getString("id").equals("1");

For reading JsonPath

Yogi
  • 1,805
  • 13
  • 24