syed naveed
syed naveed

Reputation: 95

How to pass expected values stored in Map in rest assured assertion

I have a map where i have stored expected values

private static final Map<String, List<String>> time = new HashMap<>();

Now i want to validate my expected values against Json response so i found below function in rest assured but here i need to pass each value separately in Matchers.hasitems

 .then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems(time.get("in").get(0),time.get("in").get(1))

Is there a way I can pass the whole map in Matchers.hasitems and it validates all the expected values in map . something like below?

  .then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems("how can i pass map here") 

Upvotes: 0

Views: 975

Answers (1)

syed naveed
syed naveed

Reputation: 95

I converted the map to list and calling the function in matchers.hasItems have solved the issue.

private String[] expectedValues() {
        List<String> values = new ArrayList<>();
        for (Map.Entry<String, List<String>> time1 : time.entrySet()) {
            values.addAll(time1.getValue());
        }
        return values.toArray(new String[0]);
    }

calling here

.then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems(expectedValues());

Upvotes: 1

Related Questions