Forum Discussion

Gunarm_Dyne's avatar
Gunarm_Dyne
Occasional Contributor
16 years ago

groovyUtils.getXmlHolder Help Request

I'm currently writing a test suite for a service that takes a mailing address as input and standardizes it to a more recognizable form for a post office's reader. To do this I'm reading in a file of addresses and passing in each one to the service. So far I've been able to read in the file and convert the addresses to an array of strings for Tokenization, but inserting the tokens into the request is where I'm currently stuck.

Here's the XML of the SOAP request validateAddress:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://tempuri.org/XMLSchema.xsd">
<soapenv:Header/>
<soapenv:Body>
<xs:Official_Address_In_Stage>
<!--Zero or more repetitions:-->
<xs:Address id="?">
<xs:Street1>?</xs:Street1>
<xs:Street2>?</xs:Street2>
<xs:City>?</xs:City>
<xs:State>?</xs:State>
<xs:Zip>?</xs:Zip>
<!--Optional:-->
<xs:Country>?</xs:Country>
</xs:Address>
</xs:Official_Address_In_Stage>
</soapenv:Body>
</soapenv:Envelope>


And here's the snippet of Groovy code where I'm trying to use getXmlHolder to point to the Address block:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
holder = groovyUtils.getXmlHolder("validateAddress#Request") // !!!HOW DO I EXPAND THIS TO #//Official_Address_In_Stage#//Address without getting a NullPointerException?!!!
holder.namespaces["xs"] = //Address removed for security reasons, but it's there in my code

def size = context.getProperty("size") //size of the list of addresses read in from the file
def count = context.getProperty("count") //number of addresses already tokenized
def addresses = context.getProperty("addresses") //string array of the actual addresses


if (count < size)
{
def tokens = addresses[count].split("\t")

holder["//Street1"] = tokens[1]
//None of the addresses have a Street2 value
holder["//City"] = tokens[2]
holder["//State"] = tokens[3]
holder["//Zip"] = tokens[4]
holder["//Country"] = tokens[5]
holder.updateProperty()

context.setProperty("count", ++count);
testRunner.gotoStepByName("validateAddress")
return Math.random()
}
else
{
return context.result
}


Any help on how to configure that holder so I can populate those values would be greatly appreciated. I wrote something similar for this same service before, but the previous version had a more simple XML request where holder = groovyUtils.getXmlHolder("validateAddress#Request") was enough. Thanks for taking the time.

1 Reply

  • Gunarm_Dyne's avatar
    Gunarm_Dyne
    Occasional Contributor
    A co-worker and I figured it out. We simply had to change to holder["//xs:Street1"] = tokens[1]

    Thanks for taking the time to view the problem.