简体   繁体   中英

How to assert JSON 2D array using RestAssured?

Using RestAssured and I am truggling to assert on a 2D String array in the response body. I have response JSON as:

{
    "status": {
        "code": "00",
        "message": "SUCCESS",
        "timestamp": "2021-06-14T11:25:34Z"
    },
    "data": {
        "data": [
            [
                "elementZero",
                "elementOne",
                "elementTwo"
            ]
        ]
    }
}

And my code is as follows

    given()
            .auth().oauth2(token)
            .when()
            .pathParam("orderId", orderId)
            .get("/getScreeningsForOrder/{orderId}")
            .then()
            .statusCode(200)
            .contentType(ContentType.JSON)
            .assertThat()
            .body("data.data[0]", arrayContainingInAnyOrder("elementZero", "elementOne", "elementTwo"))
            .body("status.code", equalTo("00"))
            .body("status.message", equalTo("SUCCESS"))
            .body("status.timestamp", Matchers.startsWith(expectedTimestamp_yyyyMMdd))
            .extract()
            .response();

I get the following error:

Expected: ["elementZero", "elementOne", "elementTwo"] in any order
Actual: <[elementZero, elementOne, elementTwo]>

How can I assert on data.data to make sure it contains one element that matches my array?

Try these ones - "data.data[0][0]" or "data.data[0].[0]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM