Forum Discussion

hicks's avatar
hicks
New Contributor
11 years ago

Need help with creating assertion (using response dateTime and comparing it against current time)

Hi,

I am working on REST apis and I have a problem. Records in my response are sorted randomly.

{
  "status": "success",
  "messages": [
    {
      "date_created": "Sat, 06 Jun 2015 18:29:15 +0000",
      "text": "Your booking is confirmed for 4 guests on Thursday, June 4 at Motel6",
      "status": "delivered",
      "dateCreated": "2015-06-06T18:29:15.000Z",
      "priceUnit": "USD"
    },
    {
      "date_created": "Sat, 06 Jun 2015 19:28:12 +0000",
      "text": "Your booking is confirmed for 2 guests on Thursday, June 4 at Motel6",
      "status": "delivered",
      "dateCreated": "2015-06-06T19:28:12.000Z",
      "priceUnit": "USD"
    },
    {
      "date_created": "Sat, 06 Jun 2015 18:29:01 +0000",
      "text": "Your booking is confirmed for 1 guest on Thursday, June 4 at Motel6",
      "status": "not delivered",
      "dateCreated": "2015-06-06T18:29:01.000Z",
      "priceUnit": "USD"
    }
  ],
  "page_size": 50
}

 

I need to verify the text of "text" node against predefined in test case parameters string.

Here's how I think this can be done:

 

1. Get current system time (For example "2015-06-06T19:28:05.000Z")
2. Compare it against all records (data value either from date_created or dateCreated) with absolute error of 15 seconds 
3. When first match found (second record in the above request), take first part of “text” node value ("Your booking is confirmed for") and compare it against test case parameter “success text”.

4. Fail if text doesn't match

 

Could any one please suggest how this can be written in Groovy?

No RepliesBe the first to reply