带有AND/OR条件的wiremock java matchingJsonPath不起作用


{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}

这是我的json,我想将这个请求json与以下条件匹配:

  1. 电池->面糊->id为1001以及
  2. 浇头->id为5001

我尝试过的:

多个,每个都有RequestBody类似:

.withRequestBody(matchigJsonPath("$.batters.batter[?(@.id == '1001')]")
.withRequestBody(matchigJsonPath("$.topping[?(@.id == '5001')]")

这很有效

然而,我想要的是只有一个带有AND/OR运算符的matchingJsonPath,这样我就不需要重复withRequestBody

我知道我可以使用&&,但只有当它们在同一个元素下时,这才会起作用,请参阅http://jsonpath.herokuapp.com/其中$..book[?(@.price==8.99 && @.category=='fiction')]将工作,因为pricecategory都在book

我使用的是wiremock 2.33

我不确定wiremock是否支持Filter Operators。

使用Jayway JSONPath,您可以在中尝试以下查询https://jsonpath.herokuapp.com/那就行了。

包含

$[?(@.batters.batter[*].id contains "1001" && @.topping[*].id contains "5001")] 

IN

$[?("1001" in @.batters.batter[*].id && "5001" in @.topping[*].id)]

$[?(@.batters.batter[?(@.id == '1001')] empty false  && @.topping[?(@.id == '5001')] empty false)] 

相关内容

  • 没有找到相关文章

最新更新