Forum Discussion

geoffcamp's avatar
geoffcamp
Contributor
16 years ago

Using assertions to validate responses that needs ordering

Hi,

I've got a response that is (correctly) returning the same set of tags multiple times.  For example:


    5261260886931759
    PERSON


    2211260886918334
    PERSON


    4131260886927904
    ORG


What I want to do is use an assertion to check that the response I'm receiving against a previously stored "correct" response.
I had used an XPath Match for this initially.  However I now know that for a specific database the order in which the records are returned is not fixed, therefore when they are returned in a differing order to the stored response then the assertion (correctly) fails, even though the reponse is valid

I've tried using XQUery

declare namespace soapenc='http://schemas.xmlsoap.org/soap/encoding/';
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace v02='http://www.Test.com/party/facade/interfaces/PersonIsV02';

{for $x in //getPartyCandidateListResponse/candidateParty/party/partyIdentifier/string()
order by $x return {data($x)}}


Which correctly returns the partyIdentifiers in ascending numeric order


    2211260886918334
    4131260886927904
    5261260886931759


This would allow me to check that the correct records have been returned, which is useful, however what I really want returned is the full XML response, but where the sets of tags have been re-ordered.
I've tried a number of things which I don't bore you with (but can expand on if you're interested), however each of them has met with a varying degree of failure.

Is there a way to do this within SOAP UI?  Is it something that can be accomplished within XQuery, or is there a way this can be done within the Grovvy scripting?

Any help would be appreciated.

Cheers,
Geoff
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I don't know what the full response looks like but I think the following will sort the fragment you've shown (assuming it is valid xml:)

    [tt:2qpappg4]
    {
    for $x in //party
    order by $x/partyIdentifier/string()
    return $x
    }
    [/tt:2qpappg4]
    gets you

    [tt:2qpappg4]

    2211260886918334
    PERSON


    4131260886927904
    ORG


    5261260886931759
    PERSON

    [/tt:2qpappg4]

    Does that help?
  • Wonderful!  Thank you for the very quick response, that appears to be exactly what I need.

    Cheers,
    Geoff
  • Could ypu please explain how to use Xpath and Xquery assertion the given WSDL.

    declare xml expression and expected result.pls explain by step by step(using soapui 3.5.1)

    Hi this is ilango ,
    I am learning soapUI,Please explain the Xpath Match assertion and XQury assertion with right example.(i mean free WSDL available from the net).

    I tried the following example.
    WSDL:http://www.webservicex.net/globalweather.asmx?wsdl

    Request
    --------------
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET">
    <soap:Header/>
    <soap:Body>
    <web:GetCitiesByCountry>
    <!--Optional:-->
    <web:CountryName>India</web:CountryName>
    </web:GetCitiesByCountry>
    </soap:Body>
    </soap:Envelope>


    Response
    ----------------
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
    <GetCitiesByCountryResult><![CDATA[<NewDataSet>
    <Table>
    <Country>British Indian Ocean Territory</Country>
    <City>Diego Garcia</City>
    </Table>
    <Table>