I'm testing a simple medical rule: children of 2 years old should have MMR vaccine done
1) if a child is not 2 years old, he is not eligible
2) if a child is 2 years old, he is eligible for vaccine, and if he has done, then he is compliant, otherwise he's not compliant
I'm using data driven testing, the spreadsheet has patients' age and vaccine date (if he's done) like below
Header: Age VaccineDate isEligible isComplaint
2 01/01/2015 true true
1 null false null
2 null true false
If a patient is eligible, the xml response returns patientID
If a patient is NOT eligible, the xml response returns nothing
If a patient is eligible, the xml response also returns <compliance>true</compliance>, or <compliance>false</compliance>
For Eligibility I do xPath Assertion, in "xPath Expression" I have
declare namespace NDS='http://....;
exists( //NDS:QualityGuideline/NDSatientID)
for "Expected Result" I have ${DataSource#isEligible}
So if a patient is eligible, the node of patientID exists, "exists( //NDS:QualityGuideline/NDSatientID)" is true and it fits "isEligible" (true) in the datasource, if a patient is NOT eligible, the node of patientID doesn't exist, "exists( //NDS:QualityGuideline/NDS
atientID)" is false, it fits "isEligible" (false) in the datasource
For Compliance I do xPath Assertion, in "xPath Expression" I have
declare namespace NDS='http://....;
//NDS:QualityGuideline/NDS:compliance
for "Expected Result" I have ${DataSource#isCompliant}
So if a patient is compliant, I have the response <compliance>true</compliance>, it fits "isCompliant" (true) in the datasource, if a patient is NOT compliant, the response <compliance>false</compliance> fits "isCompliant" (false) in the datasource
The assertion on eligibility works perfectly, but the assertion on compliance only works when a patient is eligible, when a patient is not eligible, there's no response for compliance and it generates an error of "<compliance> doesn't exist"
In order to fix this, I'd like to add a condition for assertion on compliance so it only works when a patient is eligible (which means the node of <patientID> exists in the response), something like:
import com.eviware.soapui.support.XmlHolder
def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["NDS"] = "http://..."
def node = holder.getDomNode( "//NDS:QualityGuideline/patientID")
if node != null // if the node for <patientID> exists in the response, the patient is eligible, then assert compliance
{//NDS:QualityGuideline/NDS:compliance = ${DataSource#isCompliant} }
Of course the last line doesn't work, because it's xPath assertion not script assertion, so my question is, how do I write assertion on compliance with the condition that it only asserts when patient is eligible (if not eligible it won't assert)
I don't mind using script or xPath assertion or combination, as long as it works
Thanks a lot for help
Jerry