Forum Discussion

bmcim123's avatar
bmcim123
Occasional Contributor
8 years ago

Assertions to verify items are being returned in alphabetical order/ascending/descending order etc

 
 

How can I perform assertions on the RESPONSE of a REST API request in order to verify the items (such as DocumentID are being returned in alphabetical order/ascending/descending order etc)

 

Thanks :-)

  • nmrao's avatar
    nmrao
    8 years ago
    Based on the script given, you should be able adopt the script for all these properties.

    Just pass required value to "getPropertyValues".
    • bmcim123's avatar
      bmcim123
      Occasional Contributor

      Hi

       

      After calling a API used for sorting, please see further below the typical JSON Response I need to perform assertions on.

       

       

      Please note the results for transactionId are being returned in ascending order so I need to perform an assertion on this.  I will need to carry out other assertions on new API calls for results being returned in descending order etc.

       

      JSON Response

       

      "results": [
      {
      "transactionId": 001
      "documentNumber": "1234",
      "purchaseDate": "2012-05-01T00:00:00",
      "uploadedBy": "Kane, Lucy"
      },
      {
      "transactionId": 002,
      "userId": "f4b012345678",
      "documentNumber": "105343998358653377",
      "customerReference": "32145",
      "purchaseDate": "2004-12-01T00:00:00",
      "uploadedBy": "Mac, Mike"
      },
      {
      "transactionId": 003,
      "userId": "f4b0d0c3",
      "documentNumber": "1085593563205677",
      "purchaseDate": "2006-09-21T00:00:00",
      "uploadedBy": "Kelly, Anne"
      },

      • nmrao's avatar
        nmrao
        Champion Level 3
        Was it a number or string? Just because, they are padded with zeros.
  • Hi, I am completely new to soap/groovy and need to use this function. My question is how do I get the information provided from my API into the script? ie my api returns:  

     

    "name": Micky Mouse

    "address1": 1234 Sesame St

    "city": New York

     

    How do i pass that information into the groovy script replacing

     

    "transactionId": 001
    "documentNumber": "1234",
    "purchaseDate": "2012-05-01T00:00:00",
    "uploadedBy": "Kane, Lucy" 

     

    Thanks for any help you can provide!

    -j