Reputation: 4914
I have a test case where I connect to database and query some data, save the result to properties then make a request to an API and compare the saved property with JSON response.
This works unless the results are null.
This is the XML result from the database.
I save the result in a script in assertion
import com.eviware.soapui.support.XmlHolder
def holder = new XmlHolder(messageExchange.responseContent)
context.testCase.setPropertyValue('SECONDARYPHONE', holder.getNodeValue('//*:SECONDARYPHONE'))
context.testCase.setPropertyValue('FAX', holder.getNodeValue('//*:FAX'))
then in JSON request to API I get
{
"portalId": 87776,
"name": "iOS Robotics",
"address1": "Update your company address",
"address2": "under Settings > My Company",
"city": "Reston",
"state": "VA",
"zip": "20191",
"primaryPhone": "unknown",
"secondaryPhone": null,
"fax": null
}
an in assertion step
import net.sf.json.groovy.JsonSlurper
def jsonResponse = new JsonSlurper().parseText(messageExchange.responseContent)
log.info('Second')
log.info(context.testCase.getPropertyValue('SECONDARYPHONE'))
log.info('json')
log.info(jsonResponse.secondaryPhone)
assert jsonResponse.secondaryPhone == context.testCase.getPropertyValue('SECONDARYPHONE')
I get
assert jsonResponse.secondaryPhone == context.testCase.getPropertyValue('SECONDARYPHONE') | | | | | | | | | | | null | | | | com.eviware.soapui.impl.wsdl.WsdlTestCasePro@12ff4536 | | | [ThreadIndex:0, RunCount:0, ExecutionID:5cf927e7-817f-4785-9152-f35e634cfe58] | | false | net.sf.json.JSONObject@162d059c (toString() threw net.sf.json.JSONException) net.sf.json.JSONObject@2419444e (toString() threw net.sf.json.JSONException)
how can I check and compare the null values in this case?
Upvotes: 1
Views: 879
Reputation: 21359
That is because, the jdbc result has empty
value and json has null
for the secondPhone.
So, check if jdbc result is empty for any property / attribute, then check for non equality; otherwise check for equality.
Another alternative is - in the first script, if the jdbc response value for an element is empty, then save it as null
.
Upvotes: 1