我想检查Request Data JSON中是否提供了必填字段。其次要检查是否没有为CustomerType提供支持JSON对象。
这是我要验证的JSON。
{
"Transaction": {
"TrType": "Vehicle", -- This is mandatory field
"CustomerType": "Individual", -- This is mandatory field and depend upon Customer type user must have to pass IndividualClient or CompanyClient
},
"IndividualClient": {
"FirstName": "Test First Name", -- Optional field
"LName": "Test Last Name", -- Mandatory field
},
"CompanyClient": {
"CompanyName": "Company Name", -- mandatory field
}
}
如何通过使用JSR223 Assertion来实现这一目标?
答案 0 :(得分:0)
您需要根据个人或公司声明 :
if (jsonRequest.Transaction.CustomerType.contains("Individual")) {
assert jsonRequest.IndividualClient
assert jsonRequest.IndividualClient.size() >=0
assert jsonRequest.IndividualClient.LName
} else {
assert jsonRequest.CompanyClient
assert jsonRequest.CompanyClient.size() >=0
assert jsonRequest.CompanyClient.CompanyName
}