按请求的身体映射使用两个匹配

问题描述 投票:1回答:1

我有身体的http请求:

 endpoint = http://127.0.0.1:54400/json
reqBody:
{                                                                                                                                                                                                                                            
    "action": "Handler:GET_DICTIONARY",
    "locale": "ro",
    "data": {"dictionary_type":"MTS"}
}

我需要获得简短的回复。这里是我的Wiremock映射:

{
  "request": {
    "method": "POST",
    "bodyPatterns": [
      {
        "contains": "Handler:GET_DICTIONARY"
      }
    ]
  },
  "response": {
    "headers": {
      "Content-Type": "application/json"
    },
    "status": 200,
    "fixedDelayMilliseconds": 3000,
    "bodyFileName": "t2a/micb/webclient/_mts_response.json"
  }
}

但我还有许多其他请求,内容请求的正文与文本:

"Handler:GET_DICTIONARY"

所以结果我也需要映射

"dictionary_type":"MTS"

因为文字

"dictionary_type":"MTS""Handler:GET_DICTIONARY"创建UNIQUE请求。

那么我如何通过请求的身体使用这两个匹配?

wiremock
1个回答
0
投票

除了你的“包含”之外,我建议添加“matchesJsonPath”

"bodyPatterns": [
        {
            "matchesJsonPath": "$.data[?(@.dictionary_type == 'MTS')]"
        }
]

这将保证使用dictionary_type = MTS的所有请求都将映射到该响应。

© www.soinside.com 2019 - 2024. All rights reserved.