How to change xml to onRequestscript () in SOAP interface

Here is my code that 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 completely changes my XML ... I want to change the existing XML (something.xml) ..

i actually could not change xml, so I thought about changing xml instead. But according to my business logic, this is wrong ... So can anyone help me change the xml in onRequestscript ....

Xml like

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

for modified type

  <Something> <Data1> <value>101</value> <Data1> <Data2> <value>201</value> <Data2> </Something> 
+4
source share
1 answer

You can use XmlSlurper to parse and update values ​​from an XML file. Then generate the string from the updated XML and set it in response to your service layout.

I use the free SoapUI 3.6.1, but it seems that its output object is different from your example. Change 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) 
+2
source

Source: https://habr.com/ru/post/1403594/


All Articles