测试jsonpath该数组包含任何顺序的specfic对象

Mar*_*ijk 5 spring spring-mvc spring-test jsonpath

我正在测试一个Spring控制器,它可以回馈400字段错误.这些字段错误是包含"路径"和"消息"字段的对象数组.

现在我想测试一些特定的调用返回具有特定路径和消息的多个错误.

我无法接近下面的任何东西:

.andExpect(jsonPath("$.fieldErrors[*].path", containsInAnyOrder("title", "description")))
.andExpect(jsonPath("$.fieldErrors[*].message", containsInAnyOrder(
    "The maximum length of the description is 500 characters.",
    "The maximum length of the title is 100 characters.")));
Run Code Online (Sandbox Code Playgroud)

但这使得选项保持开放,即"路径"和"消息"的错误组合被接受.

有任何想法如何改进jsonpath来测试这个?

Mar*_*ijk 13

这似乎是更好的方法:

.andExpect(jsonPath('$.fieldErrors[?(@.path == \'title\' && @.message == \'The maximum length of the title is 100 characters.\')]').exists())
Run Code Online (Sandbox Code Playgroud)