Need extended help on a earlier solution with groovy
My earlier problem and solution: (Solution was provided from Rao, and thanks to him)
I had to get mockresponse from an external file based on input request and below was the solution,
Below was the request:
<v2:BillAccountPackageReadRequest>
<v2:BillAccountNodeId></v2:BillAccountNodeId>
<v2:ContractSolutionNumber>SOL1</v2:ContractSolutionNumber>
<v2:HierarchyOnlySolutionNumber></v2:HierarchyOnlySolutionNumber>
</v2:BillAccountPackageReadRequest>
Mock response : ${content}
Mock response Script:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def soNumber = holder.getNodeValue("//*:BillAccountPackageReadRequest/*:ContractSolutionNumber")
def file = new File (groovyUtils.projectPath+"/MOCK/PATH1/${soNumber}.xml")
def fileToLoad = 'soapFault'
if (file.exists()) {
fileToLoad = soNumber
}
context.content = groovy.xml.XmlUtil.serialize(new XmlParser().parse(groovyUtils.projectPath+"/MOCK/PATH1/${fileToLoad}.xml"))
if SOL1.xml was present in projectpath/MOCK/PATH1 then content of SOL1.xml was given as mock response. Else soapFault.xml was loaded.
============================
NewProblem:
From above request, we can get any of the 3 fields now (Note: only one field can come in request at a time with value and not all )
So if <v2:ContractSolutionNumber>SOL1</v2:ContractSolutionNumber> then load SOL1.xml from PATH1
if <v2:BillAccountNodeId>SOL2</v2:BillAccountNodeId> then load SOL2.xml from PATH2
if <v2:HierarchyOnlySolutionNumber>SOL3</v2:HierarchyOnlySolutionNumber> then load SOL3.xml from PATH3
else SoapFault.xml