1
votes

I want to check if mandatory field not provided in Request Data JSON. Secondly want to check if supporting JSON object is not provided for CustomerType.

Here is my JSON that I want to validate.

{
      "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
        }
}

How can i achieve this by using JSR223 Assertion?

1
You can upvote answer if it helps .See meta.stackexchange.com/help/someone-answers - user7294900

1 Answers

0
votes

you need to assert only according to Individual or Company:

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
}