4

Here is my code which i wrote in onRequestscript

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
path = "D:\\Service\\something2.xml";
log.info("path = "+ path);
if (mockRequest.method == "POST" )
{
mockRunner.returnFile( mockRequest.httpResponse, new File(path))
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest)
}

But this script changes my XML entirely... I want to modify an existing XML(something.xml)..

i was actually Not able to modify the xml so i thought of changinf the xml instead.But according to my business logic its wrong... So can any one help me to modify the xml in onRequestscript....

XML like

<Something>
    <Data1>
      <value>100</value>
    <Data1>
    <Data2>
      <value>200</value>
    <Data2>
</Something>

to a modified like this

    <Something>
    <Data1>
      <value>101</value>
    <Data1>
    <Data2>
      <value>201</value>
    <Data2>
</Something>
coderslay
  • 13,960
  • 31
  • 73
  • 121
  • Can you provide example of XML and how it is being changed? Also I would assume web-service object doesn't change content of XML?!?! – MeIr Apr 22 '12 at 03:10
  • I am sorry, but I don't understand modification. You want to put space/tab on the root node? What is the purpose? Web-services typically doesn't care about spaces and stuff like that. – MeIr Apr 26 '12 at 02:11
  • Oh... I see you want to change values in the nodes.... Let me look at it tomorrow. – MeIr Apr 26 '12 at 02:12

1 Answers1

2

You can use XmlSlurper to parse and update values from XML file. Then generate a string from updated XML and set it to the response of your mock service.

I use free SoapUI 3.6.1 but it seems that its output object differs from your example. Revise the code for your needs.

// get and parse XML file content
path = "D:\\Service\\something2.xml";
def doc = new XmlSlurper().parse(path)

// update values
doc.Data1.value[0] = 101
doc.Data2.value[0] = 201

// generate and return XML string as service response
import groovy.xml.StreamingMarkupBuilder
def result = new StreamingMarkupBuilder().bind{ mkp.yield doc  }.toString()
mockResponse.setResponseContent(result)
Artem Zankovich
  • 2,319
  • 20
  • 36