2 years ago
#43044
jacob1989
How to compare cucumber fields with pojo elements from json
I have a json:
{
"id": "12",
"title": "Records",
"contents": [
{
"id": "111",
"type": "medium"
},
{
"id": "222",
"type": "low"
}
],
"description": "lalala",
"category": {
"id": "000111",
"name": "Basic Name"
}
}
And I need to validate if there are certain values there. I use cucumber So in Cucumber I declare:
And Below fields matches
| category.name| Basic Name |
| category.id | 000111 |
How to compare them? I have json deserialized to pojo classes.
Now, I tried something like this:
ValidatableResponse json = response.then().statusCode(200);
for(Map.Entry<String, String> field: table.entrySet()) {
json.body(field.getKey(), containsInAnyOrder(field.getValue()));
}
...but it throws error:
> JSON path category.name doesn't match. Expected: iterable with items
> ["Basic Name"] in any order Actual: Basic Name
Also, tried:
public void mapsMatch(Map<String, String> table) {
Map<String, String> expectedFieldsValues = new HashMap<>(table);
Map<String, String> map1 = response.jsonPath().get();
Assert.assertTrue(map1.entrySet().containsAll((expectedFieldsValues.entrySet())));
}
but also throws AssertionError.
Any ideas what I am doing wrong, help?
java
json
cucumber
rest-assured
pojo
0 Answers
Your Answer