Jatin Shashoo Jatin Shashoo - 1 year ago 103
Groovy Question

messageExchange object not available on JDBC Teststep assertion but available on SOAP Request assertions

My motive is to assert the response from a JDBC call with an XML document which I have stored in 'Properties' test step. I need to validate some values.

I am trying to use Script type assertions for the JDBC Test step in SoapUI 5.2.1. I have previously created script type assertions for 'SOAP Request' Test steps too and they work fine. In case of JDBC, when I use :

def testCase = messageExchange.modelItem.testCase;

I get the error

"Cannot get property 'modelItem' on null object".

The same thing was used on a script assertion at a SOAP Request and it worked fine. Somehow, the implicit object 'messageExchange' is not available only for a JDBC Test step and it throws an NPE.
enter image description here

Rao Rao
Answer Source

It is not true that messageExchange object is not available. Because, if you see top right corner of Script Assertion editor, it is evident that messageExchange object is available(as shown below).

Script is invoked with log, context, and messageExchange variables

Is it the case that you running the script assertion without actually running the jdbc test step?

In the script assertion, the test case properties can be access using below groovy statement:

def propValue = context.testCase.getPropertyValue('PROPERTY_NAME')
log.info "Property value is : ${propValue}"

The same above statement should work both in Groovy Script test step and in Script Assertion as well.

In case if you need test case object, then

Change from:

def testCase = messageExchange.modelItem.testCase;


def testCase = context.testCase


From the comments, author of the question, requested to get the JDBC response from the Script Assertion.

In spite of the variables messageExchange is available in Script Assertion, looks it is only applicable to Soap or Rest type steps.

However, user should still be able to access the response in the Script Assertion using below statement:

import groovy.xml.*    
log.info context.responseAsXml
def responseSlurper = new XmlSlurper().parseText(context.responseAsXml)
log.info responseSlurper.ResultSet.Row.size()

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download