1

I am trying to validate a REST response. Is it possible to use an array as parameter to containsonly?

Ex:

        String values[] = line.split(",");
        given().
            when().
            then().
                statusCode(200).
                body("value", containsOnly(values));

Also, can we use variables as parameters to other methods like HasItems, equalTo etc? Ex: body(HasItems(values))

HaC
  • 902
  • 12
  • 24
Nix
  • 41
  • 3

2 Answers2

0

Yes, You could use any appropriate matcher to check whole body or just part of it. Just take attention on a object type returned by pecified path - first argument of body().

RocketRaccoon
  • 2,559
  • 1
  • 21
  • 30
0

Try this :

Response resp = RestAssured.given()
                .header("Content-Type", "application/vnd.dpd.public.v1+json")
                .body(FixtureHelpers.fixture("request/request.json"))
                .post("/");
            resp
                .then()
                .statusCode(200)
                .body("random.object", CoreMatchers.equalTo("value"));

This would work for request.json object like :

{"random":{"object": "value"}}
Prus
  • 23
  • 6