Forum Discussion
Cizo89
12 years agoFrequent 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:
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
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