Forum Discussion

CXin's avatar
CXin
Frequent Contributor
13 years ago

How to verify if the value in response is sort by descending

Hello,

Here is the case we want to see if a node value in response is order by descending. I was trying to figure that out but failed.
Anyone here can help me out? Thanks.
The sample output like below and we want to add an assertion to verify if "create_date" is order by descending
<ads>
<ad>
<create_date>value1</create_date>
</ad>
...
<ad>
<create_date>value1</create_date>
</ad>
...
</ads>

Thanks in advance!
Sophie

6 Replies

  • RJanecek's avatar
    RJanecek
    Regular Contributor
    you can add value in the list:

    def date = []
    int datecount = Integer.parseInt (holderResponse.getNodeValue( "count(//*[local-name()='create_date' and namespace-uri()='yournamespace])") )
    for(int i = 1; i <= datecount; i++){
    date.add( holderResponse.getNodeValue( "//*[local-name()='create_date' and namespace-uri()='yournamespace']") )
    }

    and then compare in this list if i > i+1 or you can clone this list sort it and compare if these lists are equals
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Sophie,

    can you give us a complete example response message to work on for providing a solution?

    regards!

    /Ole
    SmartBear Software
  • CXin's avatar
    CXin
    Frequent Contributor
    Hi,

    Thanks much for those replies. For now we have search ad cases via some criterias and have to verify if the search result matches to those criterias.
    e.g
    1, sort by price/date/distance descending/ascending.
    2, filter out the ads which create date is < the input criteria
    3, filter out the ads which the price is in a range(minPrice, maxPrice)

    Attach is a output sample. I hope you there could provide a solution on how I can add an assertion for the output to verify those cases.
    PS:I am just a very beginner in soapUI field and still learning, so please explain more detailed on how to. Thanks much.

    Best,
    Sophie
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Sophie,

    I don't think this can be done without groovy unfortunately - I think the suggestion given by RJanecek above is a good start

    regards!

    /Ole
    SmartBear Software
  • CXin's avatar
    CXin
    Frequent Contributor
    Hi RJanecek,

    I tried to add the script below in Script Assertion, but seems like i cant get each date value via the loop. And can get the could of date-time.
    I have 3 ads so with 3 different creation-date-time.

    -
    import com.eviware.soapui.support.XmlHolder
    def date = []
    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    holder.namespaces["ad"] = myNameSpace
    int datecount = Integer.parseInt (holder.getNodeValue( "count(//ad:ads/ad:ad/ad:creation-date-time)") )

    for(int i = 0; i < datecount; i++){
    date.add( holder.getNodeValue( "//ad:ads/ad:ad/ad:creation-date-time") )
    }
    -

    And below is the assertion I added for date-time content
    //ad:ads[1]/ad:ad[3]/ad:creation-date-time[1]/text()
    So am wondering if I need to add an index in that loop, like this date.add( holder.getNodeValue( "//ad:ads[1]/ad:ad/ad:creation-date-time[1]/text()") )
    ??

    Thanks,
    Sophie
  • RJanecek's avatar
    RJanecek
    Regular Contributor
    firstly you should have some root element secondly you should define namespace prefixes