我正在尝试编写一个普通的合同来验证包含以下列表的json:
{
"id": "{id_val}",
"name": "{name_val}",
"age": "{age_val}",
"salary": "{salary_val}",
"designation": "{programmer_val}",
"addressList": [{
"street": "Park Avn",
"city": "West chester",
"zipCode": "{zip_val}"
},{
"street": "Park Avn",
"city": "West chester",
"zipCode": "{zip_val}"
}],
"phoneNumbers": [
"123456",
"987654"
],
"personalInformation": {
"gender": "Male",
"maritialstatus": "married"
}
}
相应的常规如下:
package contracts.beer.rest
import org.springframework.cloud.contract.spec.Contract
Contract.make{
description("""
Validating A CWP MO For New Customer
""")
request{
method 'POST'
url '/ValidateMO'
body(file("cwp_mo.json"))
bodyMatchers {
jsonPath('$.id',byRegex("[0-9]{2}"))
jsonPath('$.name',byRegex('[A-Za-z]+'))
jsonPath('$.age',byRegex('[2-9][0-9]'))
jsonPath('$.salary',byRegex('[1-9][0-9]{5}'))
jsonPath('$.designation',byRegex('[A-Za-z]+'))
jsonPath("\$.['addressList'][*].['zipCode']", byRegex('[0-9]{5}'))
}
headers {
contentType(applicationJson())
}
}
response{
status 200
body("""
{
"status":"OK"
}
""")
headers{
contentType(applicationJson())
}
}
}
运行测试用例后,即使我在'邮政编码中输入了错误的值,也无法正确验证地址列表。谁能告诉我我的问题在哪里?