我有这个“内容”响应,我需要从中断言一些值。
WebTestClient.BodyContentSpec content = response.expectStatus().isOk()
.expectBody()
.jsonPath("$.path1").isEqualTo(value1);
如果我想断言一些具有预定义值的 JSON 路径,一切都很好。
但是当我想检查一个 JSON 路径是否等于另一个 JSON 路径时,棘手的部分就来了。
JsonPathAssertions jsonPath2 = bodyContentSpec.jsonPath("$.path2");
JsonPathAssertions jsonPath3 = bodyContentSpec.jsonPath("$.path3");
所以我的问题是如何使用 org.hamcrest.Matchers.greaterThanOrEqualTo
断言 jsonPath2
的内容针对 jsonPath3
?
最佳答案
我想你可以使用 value(Consumer)
方法:
对于简单的操作:
jsonPath2.value(v->jsonPath3.isEqualTo(v));
使用特殊匹配器:
jsonPath2.value(v->jsonPath3.value(Matchers.greaterThanOrEqualTo(v)));
关于java - WebTestClient 根据另一个 jsonPath 检查 jsonPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55702745/