Major improvement here. When I created the teststep, I used REST instead of HTTP. Now my Groovy is working (below) but I have challenge to produce a proper log.
For this particular API, it does not return any XML response is it is successful. If error, it would response with something like this:
<error>
<type>EntityNotFound</type>
<message>Subscriber data could not be found for IMS user identity "sip:+13313140098@ims.mnc330.mcc302.3gppnetwork.org" and selection key "Meswitch::::"</message>
</error>
With my Groovy below,
if the API is successful, my Groovy would throw an error "Null PointerException" because there is no XML response.
If the API fail, the Groovy would not output the 'type' and 'message'.
In summary, the Groovy can now execute the teststep but would not give me proper log.
----------------------------------------------------------------------------------------------------------------------------------------------
// TAS-PUT Input file: 13313140097
import java.text.SimpleDateFormat
def date = new Date()
def file_date = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss")
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def csvFilePath = "C:\\Gemalto-Groovy\\msisdn-list.csv"
def reportFile = "C:\\Gemalto-Groovy\\Reports\\TAS-PUT-"+file_date.format(date)+".log"
testRunner.testCase.setPropertyValue( "TARGET-1", "" )
context.fileReader = new BufferedReader(new FileReader(csvFilePath))
File report = new File(reportFile)
rowsData = context.fileReader.readLines()
int rowsize = rowsData.size()
report.text = "TAS-PUT "+file_date.format(date)
report << "\n"
for(int i =0; i < rowsize; i++)
{
def log_date = new Date()
def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
rowdata = rowsData[i]
String[] data = rowdata.split(",")
testRunner.testCase.setPropertyValue( "TARGET-1", data[0] )
testRunner.runTestStepByName( "PT-Groovy-TAS-PUT")
tStep = testRunner.testCase.getTestStepByName("PT-Groovy-TAS-PUT")
def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def xml = new XmlSlurper().parseText(xmlResponse)
def MESSAGE1 = xml.error.@type.text()
def MESSAGE2 = xml.error.@message.text()
log.info " Seq="+i+" "+data[0] + " " + MESSAGE1 + " " + MESSAGE2
report << "\n"+"Seq="+i+" "+sdf.format(log_date)+" "+data[0] + " " + MESSAGE1 + " " + MESSAGE2
}