aurelius
aurelius

Reputation: 4076

WebTestClient check jsonPath against another jsonPath

I have this "content" response from which I need to assert some values.

WebTestClient.BodyContentSpec content = response.expectStatus().isOk()
                .expectBody()
                .jsonPath("$.path1").isEqualTo(value1);

If I want to assert some JSON paths with predefined values all is good.

But the tricky part comes when I wanna check if a JSON path is equal to another JSON path.

JsonPathAssertions jsonPath2 = bodyContentSpec.jsonPath("$.path2");
JsonPathAssertions jsonPath3 = bodyContentSpec.jsonPath("$.path3");

So my question is how can I assert the content of jsonPath2 against jsonPath3 using org.hamcrest.Matchers.greaterThanOrEqualTo?

Upvotes: 1

Views: 1734

Answers (1)

Sascha
Sascha

Reputation: 1343

I think you could use the value(Consumer) method:

for simple operations:

jsonPath2.value(v->jsonPath3.isEqualTo(v));

for using special Matchers:

jsonPath2.value(v->jsonPath3.value(Matchers.greaterThanOrEqualTo(v)));

Upvotes: 3

Related Questions