Teltstra_Corpor
15 years agoOccasional Contributor
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
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