0

I have Response json like below

{
  "orderId": "16057421778",
  "displayOrderId": "160574217786",
  "numberOfItems": 2,
  "items": [
    {
      "orderItemId": "3291379",
      "item": {
        "itemId": "10127763",
        "definingAttrs": null,
        "itemAttrs": {
          "ColorLevelURLIndicator": "true"
        },
        "descriptiveAttrs": null,
        "inventory": {
          "inventoryStatus": "Available",
          "lastUpdateDate": "2018-07-20T22:00:32"
        },
        "priceFlag": "2",
        "kicId": "KIC_131-7541-1347-476"
      },
      "quantity": 1,
      "bogoMessage": ""
    },
    {
      "orderItemId": "3292201",
      "shortSku": "628711393",
      "item": {
        "itemId": "10127763",
        "itemAttrs": {
          "ColorLevelURLIndicator": "true"
        },
        "descriptiveAttrs": null,
        "inventory": {
          "inventoryStatus": "Available",
          "lastUpdateDate": "2018-07-20T22:00:32"
        },
        "priceFlag": "2",
        "imageId": "anf_175595_02",
        "kicId": "KIC_131-7541-1347-476"
      },
      "quantity": 1,
      "bogoMessage": ""
    }
  ],
  "payment": null
}

and I have a JsonArray like ["orderId","displayOrderId"] now I want to validate that those two keys dont have null values or empty values in response.

I know I can just iterate over the response with the array values but that will waste a lot of time if the response is very big and I have n number of values to assert.

I am using RestAssured and JsonPath for validation

AswinRajaram
  • 1,519
  • 7
  • 18
coder
  • 1

1 Answers1

0

you have to implement hibernate validator annotation

@NotNull from Bean Validation (a validation provider such as Hibernate Validator is required to perform the validation).

For example, I sharing a model class. Shared all the of validation using like that

public class PartnerReq {

    private Integer id;
    @NotEmpty
    @Size(min=4, message="{NotEmpty.user.name}")
    private String name;
    @NotEmpty 
    @Email(message ="{NotEmpty.user.email}")
    private String email;
    @NotEmpty
    @Size(min=10, max= 10, message = "{NotEmpty.user.phone}")
    @Pattern(regexp = "[0-9]+")
    private String phone;
    @NotEmpty
    private String title;
    @NotEmpty
    private String instituteName;
    @NotEmpty
    private String description;
    @DateTimeFormat(pattern="dd/MM/yyyy")
    @NotNull
    @Past
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
    private Date activeTo;
    @DateTimeFormat(pattern="dd/MM/yyyy")
    @NotNull
    @Future
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
    private Date activeFrom;
    @NotNull
    private Boolean notify;
    @NotNull
    private Boolean loginStauts;
    private MultipartFile file;

//Setter and Getter
}
Faiz Akram
  • 559
  • 4
  • 10
  • I looked in to the documentation and it looks pretty neat but i will need to parse the response with my json array. As far as I understood this can be used once I have the values that I need to validated but the bigger problem is reading the values from response itself – coder Aug 13 '18 at 12:44