Forum Discussion

Teltstra_Corpor's avatar
Teltstra_Corpor
Occasional Contributor
15 years ago

mockResponse groovy script - modifying context with map/list

Hi,

I have a mockService running with few mockResponses.
I am using groovy inside mockResponse to update the context and retun the response with data updated from a flat file/csv file.
Doing so I have hit few blockers.

1. I don't know how to update an array type in the response context.

2. I am also not sure how to update the context variables in an iteration with different values.

For example, consider the following as the mockResponse,

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
......
<tag1>${value1}</tag1>
<tag2>${value2}</tag2>
....
....

now there cane be more than 1 rows/values for each of tag1 and tag2. For instance if I have say 2 rows/values then my response to any request should be something like:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
.......
<tag1>${value1}</tag1>
<tag2>${value2}</tag2>
<tag1>${value3}</tag1>
<tag2>${value4}</tag2>

Just wondering how can I modify my response based on the number of rows/tuples in my csv/flat file.

'would be wonderful if I can get some help from the forum.

cheers
devy

4 Replies

  • Hi Devy,

    I think easiest is to create the entire array xml inside the script.. ie your mockResponse just contains

    ${values}

    and the script builds the entire XML string

    Does that make sense?

    regards,

    /Ole
    SmartBear Software
  • Teltstra_Corpor's avatar
    Teltstra_Corpor
    Occasional Contributor
    Thanks Ole!
    And sorry for the delayed response.

    Actually this is what I was looking for but not sure how to do it.
    Is it possible to build entire mockResponse xml using groovy.

    We are trying to migrate from SOATest and with SOAtest we were using python scripts to build the response.
    trying to do the same with groovy and SoapUI.

    cheers,
    devy.
  • Teltstra_Corpor's avatar
    Teltstra_Corpor
    Occasional Contributor
    I tried preparing the xml using groovy.

    now I send a string as response which I modify using groovy.
    But now i get "java.lang.ClassFormatError: Invalid method Code length" ... code length being 76222.

    guess my xml response is way over JVM limit.

    Is there a way to get around it?
  • Telstra wrote:
    I tried preparing the xml using groovy.

    now I send a string as response which I modify using groovy.
    But now i get "java.lang.ClassFormatError: Invalid method Code length" ... code length being 76222.

    guess my xml response is way over JVM limit.

    Is there a way to get around it?

    Hi!

    I think that it's not the XML response, but the actual script that is too long. May we have a look at it (e-mail to support with a reference to this topic if confidential) or can you somehow shorten it yourself?

    Regards!

    Henrik
    SmartBear Software