Forum Discussion

vpachpute1's avatar
vpachpute1
Frequent Contributor
8 years ago

How to assert ascending/desciding order in response

Hi

 

I have one API which returns the transactions id's in descending order.

 

I have to assert the order.

 

Can you please suggest the way how to do it.

 

Please find the attached file for details.

 

Regards

Vishal

  • nmrao's avatar
    nmrao
    8 years ago

    Here you go:

     

    def xml = """<?xml version="1.0" encoding="UTF-8"?> <er-response>    <subscriptions-v2>          <subscription id="909" status="1" />          <subscription id="908" status="1" />          <subscription id="904" status="2" />          <subscription id="898" status="1" />          <subscription id="897" status="1" />          <subscription id="896" status="2" />          <subscription id="895" status="1" />          <subscription id="7" status="1" />          <subscription id="6" status="1" />          <subscription id="5" status="11" />       </subscriptions-v2>   </er-response>"""
    def parsedXml = new XmlSlurper().parseText(xml)
    //Get the ids from the response def idsFromResponse = parsedXml.'**'.findAll{ it.name() == 'subscription'}.collect{it.@id.text()} println "Original list from response : $idsFromResponse" //Sort the numbers in descending order def descIds = idsFromResponse.sort(false).reverse() assert idsFromResponse == descIds, "Response does not have the ids in descending order"
  • nmrao's avatar
    nmrao
    Champion Level 3
    The attachment has same values. Please provide data supporting your question.
    • vpachpute1's avatar
      vpachpute1
      Frequent Contributor

      Hi

       

      Sorry to say, but because of security policies, I cannot provide full response.

       

      But I need to check weather <id>16</id> is in descending order or not.

       

      Can you please provide the solution. So I will make necessary changes according to my actual response.

       

      Regards

      Vishal

      • nmrao's avatar
        nmrao
        Champion Level 3
        No one will ask you to provide your data. The request is about dummy data resembling the problem.