Ask a Question

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

SOLVED
bmcim123
Occasional Contributor

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 🙂

16 REPLIES 16
bmcim123
Occasional Contributor

You are the best. THANK-YOU SO VERY MUCH FOR YOUR TIME AND EFFORT HELPING ME TODAY 🙂

@bmcim123

Here is the better version of the script which handle multiple properties without hassle.

All you need to do is just add the property name to below (example given, look for below statements in the script)

//ATTENTION: add the list of property names
def userList = ['transactionId', 'uploadedBy', 'purchaseDate']

https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/json/CheckOrderOfMultiProperties.gro...



Regards,
Rao.
bmcim123
Occasional Contributor

Hi

 

I can only sort on one property at a time, so one API call per sort, example API calls, sort by TransactionId Ascending/sort by DocumentId Descending etc etc.  I am assuming I change the userList (as per your script) accordingly?

 

Can I ask you to add a few brief comments to the script so that I understand it better, if you have the time.  Thank-you so very much.

bmcim123
Occasional Contributor

Hi

 

I am having difficulties trying to get the script to work

 

Here is the JSON RESPONSE for my API.  I need to verify the fileName property is in ascending order and in a separate test/assertion descending order

 

 

ASCENDING ORDER:-

 

"results": [
{
"trackingEntryId": 752,
"documentId": 741,
"fileId": 731,
"fileName": "1000rows.xlsx",
"status": "Success",
"uploadedBy": "Smith, Will",
"uploadedDate": "2017-06-28T15:58:33.3463573",
"transactions": 1000
},
{
"trackingEntryId": 753,
"documentId": 742,
"fileId": 732,
"fileName": "700rows.xlsx",
"status": "Success",
"uploadedBy": "Smith, Will",
"uploadedDate": "2017-06-28T16:02:00.7279932",
"transactions": 700
},
{
"trackingEntryId": 643,
"documentId": 632,
"fileId": 623,
"fileName": "a73afef9-6af3-46f6-8084-059614bd523e.xlsx",
"status": "Success",
"uploadedBy": "Sinatra, Frank",
"uploadedDate": "2017-06-27T09:26:32.0337874",
"transactions": 1
},

 

 

*Can you add comments to your script as i am unsure of where you are getting the values from/cannot get the script to work.

 

THANKS 

bmcim123
Occasional Contributor

 
bmcim123
Occasional Contributor

In particular, what is the following statement doing?

 

def getPropertyValues = { prop ->
 json.results."$prop"
jwashkuhn
Senior Member

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

cancel
Showing results for 
Search instead for 
Did you mean: