Forum Discussion

sayome's avatar
sayome
New Contributor
13 years ago

Using count to assert a range

Hello,

I am fairly new to SOAPUI and I have been trying to perform an assertion and it is giving me some issues. I am testing a webservice that return the amount of appointments available for a date range as follows;

<a:Appointment>
<a:AppointmentType>
<a:Caption>AM</a:Caption>
<a:Description>Morning</a:Description>
<a:Duration>300</a:Duration>
<a:ID>1</a:ID>
<a:StartTime>0001-01-01T08:00:00</a:StartTime>
</a:AppointmentType>
<a:Date>2012-10-16T08:00:00+01:00</a:Date>
<a:Preferred>true</a:Preferred>
</a:Appointment>
<a:Appointment>
<a:AppointmentType>
<a:Caption>PM</a:Caption>
<a:Description>Afternoon</a:Description>
<a:Duration>240</a:Duration>
<a:ID>2</a:ID>
<a:StartTime>0001-01-01T13:00:00</a:StartTime>
</a:AppointmentType>
<a:Date>2012-10-16T13:00:00+01:00</a:Date>
<a:Preferred>true</a:Preferred>
</a:Appointment>
<a:Appointment>
<a:AppointmentType>
<a:Caption>AM</a:Caption>
<a:Description>Morning</a:Description>
<a:Duration>300</a:Duration>
<a:ID>1</a:ID>
<a:StartTime>0001-01-01T08:00:00</a:StartTime>
</a:AppointmentType>
<a:Date>2012-10-17T08:00:00+01:00</a:Date>
<a:Preferred>true</a:Preferred>
</a:Appointment>
<a:Appointment>
<a:AppointmentType>
<a:Caption>PM</a:Caption>
<a:Description>Afternoon</a:Description>
<a:Duration>240</a:Duration>
<a:ID>2</a:ID>
<a:StartTime>0001-01-01T13:00:00</a:StartTime>
</a:AppointmentType>
<a:Date>2012-10-17T13:00:00+01:00</a:Date>
<a:Preferred>true</a:Preferred>
</a:Appointment>


As you will see, two properties called ID (in bold) define the total appointment for a day. My test is to count the total number of ID returned so if the date range is 1 day then two IDs will be returned. So my test is written as thus at the moment;

count(//a:ID)<=2

This will be true for any number of occurrence between 0 and 2, however, 0 is not valid response. Please can anyone tell me how to eliminate 0 as count cannot accept range like 0>count(//a:ID)<=2?
Cheers
  • sayome's avatar
    sayome
    New Contributor
    I believe I have a hack for this. What I did was to create two assertions for the same property. One assertion test that the property count is greater than zero and I created another assertion that test that the property is greater than or equal to the value I expect. Therefore, if the property is empty or zero then the first assertion that test if the property is greater than zero fails and that gives an indication that something is not right.

    This may be a hack but until there is a better way of asserting a range of counts, the test is robust enough.