Forum Discussion

justkaissy's avatar
justkaissy
New Contributor
12 years ago

Urgently, Please! Compare sub-parameters to string

In my dataBase i have a string: 2014-07-07, 2014-07-08, 2014-06-11, 2014-06-18 and etc.
in response I get a list of parameters. Each parameter contains some sub-parameters (2014-07-07, 2014-07-08, 2014-06-11 and other). I need to compare these with my datas in data base.
Well, I need get sub-parameters and make a string with them. And I had to compare them together.
Can I do it? If yes, then HOW?

A piece of code for example:

<list>
<laboratoryTest>
<patientDateOfBirth>1983-05-14</patientDateOfBirth>
<patientFullName>Bla Bla Bla</patientFullName>
</laboratoryTest>
<laboratoryTest>
<patientDateOfBirth>1998-04-12</patientDateOfBirth>
<patientFullName>Tu Ru Tu</patientFullName>
</laboratoryTest>
<laboratoryTest>
<patientDateOfBirth>1943-03-19</patientDateOfBirth>
<patientFullName>La La La</patientFullName>
</laboratoryTest>
<laboratoryTest>
<patientDateOfBirth>1988-11-22</patientDateOfBirth>
<patientFullName>U Ru Ru</patientFullName>
</laboratoryTest>
</list>


Earlier Thanks for answer at my question.

3 Replies

  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    hi
    next time, do not create topic with "urgent", "help please", you won't have quick answer and your post may be removed by moderators

    about your issue, could you provide more details about what you really want to achieve? what is sub-parameters?
    regarding your example, explain which data you want to extract and compare with
  • justkaissy's avatar
    justkaissy
    New Contributor
    redfish4ktc2 wrote:
    hi
    next time, do not create topic with "urgent", "help please", you won't have quick answer and your post may be removed by moderators

    about your issue, could you provide more details about what you really want to achieve? what is sub-parameters?
    regarding your example, explain which data you want to extract and compare with


    Ok, I am sorry. Next time i will create correct posts.
    The sub-parameters are in tags <patientDateOfBirth>.
    I want to get the string all these sub-parameters as a string of '2014-07-07, 2014-07-08, 2014-06-11, 2014-06-18'
    Problem in the following. Each time we get misc quantity of parameters (<laboratoryTest>).
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    if I'm getting it right, you need to compare dates from response with some dates from database, is that correct?
    If yes, I'd say it would be better to compare them as collections, not just strings.

    This is just an example, but you should be able to take an idea from it:

    String xml = '''<list>
    <laboratoryTest>
    <patientDateOfBirth>1983-05-14</patientDateOfBirth>
    <patientFullName>Bla Bla Bla</patientFullName>
    </laboratoryTest>
    <laboratoryTest>
    <patientDateOfBirth>1998-04-12</patientDateOfBirth>
    <patientFullName>Tu Ru Tu</patientFullName>
    </laboratoryTest>
    <laboratoryTest>
    <patientDateOfBirth>1943-03-19</patientDateOfBirth>
    <patientFullName>La La La</patientFullName>
    </laboratoryTest>
    <laboratoryTest>
    <patientDateOfBirth>1988-11-22</patientDateOfBirth>
    <patientFullName>U Ru Ru</patientFullName>
    </laboratoryTest>
    </list>'''

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def holder = groovyUtils.getXmlHolder(xml)

    List<String> datesFromDatabase = ["2014-07-07", "2014-07-08", "2014-06-11", "2014-06-18"]
    List<String> datesFromResponse = holder.getNodeValues("//list/laboratoryTest/patientDateOfBirth")

    if (datesFromDatabase.size() != datesFromResponse.size()){
    testRunner.fail("Response didn't return correct count of dates!")
    } else{
    assert datesFromDatabase.sort() == datesFromResponse.sort()
    }


    Since it's in a collection, you can sort your dates (preventing situations when all dates are correctly returned, but just in wrong order) and check if the response returned expected count of them.
    Also, assert function will be ideal in this situation.
    In that example I used method fail(), but you can also throw new exception, it's all up to you.

    In case of any further questions, feel free to ask

    Regards,
    Marek