Solved
Forum Discussion
Apoorva6
10 years agoFrequent Contributor
Hi Rup,
Rest does not work for me. Please provide Soap groovy script. I have attached sample WSDL here. in that salesOrderNumber is the dynamic value which corresponding mock response need to be loaded. sample request is also attached.
nmrao
10 years agoCommunity Hero
Sorry to interrupt Rup.
The details helped Apoorva.
And this is my first try on mocking, followed the video from the same link that I provided earlier.
Here are the steps:
1. Generate a SOAP Mock Service by right click on to the service that you intended ( I believe, you know it already, added this for those who not aware, and this is first time for me too)
2. Selete the intended mock operation.
- Choose SCRIPT for Dispatch, Response 1 for Default Response
- Open Response 1 and remove the existing reponse and just have ${content} as value for response
- In the script editor have the following script:
/*This script reads the salesOrderNumber from request using xpath
* and checks corresponding response xml file from
* mockResponses directory of your soapui project location.
* Also expects a soapFault.xml file in the same location
* in order to send soap fault if no sales order number maches the
* existing files.
* For example, soapui project located under C:\soapuiProjects
* create a subdirectory called mockResponses under above directory
* Make sure all your mock response files for sales orders under
* C:\soapuiProjects\mockResponses directory including soapFault.xml
* Assuming that the soap response file extension is xml, not txt
*/
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def holder = groovyUtils.getXmlHolder(mockRequest.requestContent) def soNumber = holder.getNodeValue("//*:BillingOrderLoadRequest/*:salesOrderNumber") def file = new File (groovyUtils.projectPath+"/mockResponses/${soNumber}.xml") def fileToLoad = 'soapFault' if (file.exists()) { fileToLoad = soNumber } context.content = groovy.xml.XmlUtil.serialize(new XmlParser().parse(groovyUtils.projectPath+"/mockResponses/${fileToLoad}.xml"))
Sample soapFault.xml
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <Body> <Fault> <faultcode xsi:type="xsd:string">Client</faultcode> <faultstring xsi:type="xsd:string">Could not find the mock response file for the given sales order number</faultstring> </Fault> </Body> </Envelope>