views:

208

answers:

2

My question is about putting data elements (from groovy script) in the response in SoapUI. I've an array of data that I would like to put in my response (in different tags/elements)


I'm aware of putting a simple element like this:

The element "MyName" in the Xml response:

<ns:MyName>${MyName}</ns:MyName>

Is mapped from the Groovy script by

context.setProperty("MyName" , "My name" )


Now the problem:

my Xml response looks like this:

   <soapenv:Body>
  <ns:GetDataSummaryResponse>
     <!--Optional:-->
     <ns:GetDataSummaryResult>
        <ns:DataSummary>
           <!--Zero or more repetitions:-->
           <ns:DataSummaryResponseDetail>
              <ns:Name>?</ns:Name>
              <!--Optional:-->
              <ns:DataProgress>
                 <!--Optional:-->
                 <From>?</From>
                 <!--Optional:-->
                 <Procent>?</Procent>
                 <!--Optional:-->
                 <To>?</To>
                 <!--Optional:-->

In Groovy I've built data array which is filled with data for example like this:

context:[DataSummary:[DataSummaryResponseDetail:[Name:My name, DataProgress:[From:some text, Procent:some value, To:some text]]]

In the response I'm able to see the whole value of ${DataSummary} but how do I get the element "Procent"

I maybe am wrong about how to build my context data, but feel free to adjust!

BR/SeeU

A: 

I haven't work with SoapUI, but have you tried this:

${DataSummary.DataSummaryResponseDetail.DataProgress.Procent}

If DataSummary is an array, you could access the first entry using

${DataSummary[0].DataSummaryResponseDetail.DataProgress.Procent}

You can iterate over the array using the method each(), so

${DataSummary.each { it.DataSummaryResponseDetail.DataProgress.Procent }}

would get you all entries.

Christoph Metzendorf
Nope!Since DataSummary like many other stuff here are "arrays", I need a way to declare which index I'm interested in.
SeeU
Thanks for our reply. As I wrote earlier I build an array in Groovy But the data is included in the xml response like this"[DataSummary:[DataSummaryResponseDetail:[Name:My name, DataProgress:[From:some text, Procent:some value, To:some text]]]" also as string.I've tried the simpler variants as follow but I'get no value back.${DataSummary[0].DataSummaryResponseDetail[0].Name}${DataSummaryResponseDetail[0].Name}If I use "${DataSummary}" I get back the whole string. Does it have anything with XPATH to do to reach the data I need?Do I have to build my Context(DataSummary) another way?
SeeU
A: 

I managed to do this with a lot of searching. First of all, I needed to use "=" in front of the element to be able to get a handle like ${=DataSummary[0]} This works on the top level of my data shown before.

But to really solve the problem I created a Class in Groovy like this:

Code: Select all Class DataSummaryResponseDetail { public String name public DataProgress DataProgress = new DataProgress() public Value[] value = new Value[2] } class DataProgress { public Date From public Date To public float Procent } class Value { public String Currency public int Amount }

def hsrd = new DataSummaryResponseDetail()
hsrd.name = 'Some name'
hsrd.value[0]=new Value()
hsrd.value[0].Amount = 1000
hsrd.value[0].Currency = 'SEK'
hsrd.totalValue.Amount = 2000
hsrd.totalValue.Currency = 'USD' 

and then in the response xml. I refer to elements like this ${hsrd.value[0].Amount} ${=hsrd.totalValue.Amount}

def hsrd = new DataSummaryResponseDetail() hsrd.name = 'Some name' hsrd.value[0]=new Value() hsrd.value[0].Amount = 1000 hsrd.value[0].Currency = 'SEK' hsrd.totalValue.Amount = 2000 hsrd.totalValue.Currency = 'USD'

Problem solved. If you know of a better way, please let me know.

SeeU