I receive the following response on a bad request against my API. I am using RestAssured for my rest response assertions.
{
"message": "An entity of type topic was passed in an invalid format",
"meta": {
"display": {
"topic": [
{
"name": [
"must not be blank"
]
},
{
"contentType": [
"must not be blank"
]
},
{
"content": [
"must not be blank"
]
},
{
"version": [
"must not be blank"
]
}
]
}
}
}
I need to verify value of all the properties of the response. I am struggling to verify this path: meta.display.topic.contentType
. I cannot come up with the GPath for it.
Here is the assertion that I am making:
given().body("{}").when()
.post(BASE_URL)
.prettyPeek()
.then()
.statusCode(400)
.contentType(ContentType.JSON)
.body("message", is("An entity of type topic was passed in an invalid format"),
"meta.display.topic.contentType", is("must not be blank"));
Since the path is not correct, assertion always fails.
To avoid hardcoded array positions for topic object following will work:
meta.display.topic.find { it.contentType != null }.contentType[0]