Wiremock:如何匹配不具有特定属性的JSON请求?

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

我正在尝试模拟在POST中接受JSON正文的API调用,它有两个可能的响应:

  1. 如果正文包含SearchCenter属性,则答案为A
  2. 如果正文不包含SearchCenter,则回答B。>
  3. 在Wiremock文档的Request Matching章中,它仅显示如何肯定地

匹配JSON,而没有显示如何匹配缺少的属性。

带有SearchCenter的样品请求:

{
    "GeoCoordinatesResponseFormat": "DecimalDegree",
    "ProviderID": "bla bla",
    "SearchCenter": {
        "GeoCoordinates": {
            "DecimalDegree": {
                "Latitude": "{{search_lat}}",
                "Longitude": "{{search_lon}}"
            }
        },
        "Radius": {{search_radius}}
    }
}

没有SearchCenter的样品请求:

{
    "GeoCoordinatesResponseFormat": "DecimalDegree",
    "ProviderID": "bla bla"
}

我正在尝试模拟一个在POST中接受JSON正文的API调用,它具有两个可能的响应:如果正文包含SearchCenter属性,如果正文不包含...,则回答A。

json rest testing wiremock
1个回答
0
投票

有两种方法可以完成此操作。第一个将使用正则表达式匹配器/不使用匹配器。假设您正在使用存根...

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