cancel
Showing results for 
Search instead for 
Did you mean: 

Set dynamic XML element value to a mockResponse present in external file.

SOLVED
Apoorva6
Frequent Contributor

Re: Set dynamic XML element value to a mockResponse present in external file.

Hi Rao,

Below was the sample script you provided earlier. To implement my current scenario in below script, if file exists, then I need to set the $banum and $custid in file.
Can you please help me to achieve that ?

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/GCP/GetBill/${soNumber}.xml")
def fileToLoad = 'soapFault'
if (file.exists()) {

//I need to write the $banum and $custid to file having mock response here

    fileToLoad = soNumber    
}
context.content = groovy.xml.XmlUtil.serialize(new XmlParser().parse(groovyUtils.projectPath+"/MOCK/GCP/GetBill/${fileToLoad}.xml"))

nmrao
Community Hero

Re: Set dynamic XML element value to a mockResponse present in external file.

But the request here is different in this case compare to previous answer's request, right? 



Regards,
Rao.
Apoorva6
Frequent Contributor

Re: Set dynamic XML element value to a mockResponse present in external file.

Hi Rao, yes, request is different. All I need is the comment section in above script to set those Dynamic values in mockresponse.
nmrao
Community Hero

Re: Set dynamic XML element value to a mockResponse present in external file.

It will have impact to get the file name itself as it is using xpath from different request. Did you already send the new request that is used in this case? If so, point which data to be extracted from that request?



Regards,
Rao.
Apoorva6
Frequent Contributor

Re: Set dynamic XML element value to a mockResponse present in external file.

Hi Rao, Yes, I have attached new request again here which I will be using, to get the mock response. but before getting response, I need to set the $banum and $custid in mock response.I have also attached mockResponse here with expected response. I have commented in response which value is $custid and which is $banum in mockResponse attachemnt.

nmrao
Community Hero

Re: Set dynamic XML element value to a mockResponse present in external file.

Ok, what values to be replaced in the response is clear. However, it is not clear from the request what value are to be mapped.
Can you just add the comment in request as well?
I can see there only two, but names are confusing.
for example=>

request element vs response element

ContractSolutionNumber <=>custid
Mode<=>banum


Regards,
Rao.
Apoorva6
Frequent Contributor

Re: Set dynamic XML element value to a mockResponse present in external file.

Hi Roa,

 

First step is to get $custid and $banum from JDBC which I am already able to get.

Next I need to set above 2 values in Mock response which I mentioned in earlier comment.

The request to mockResponse has ContractSolutionNumber value which is globally set parameter (S12345) . I need to check if the file exists with name S12345 (which has mockResponse) and then set $banum and $custid in it.

nmrao
Community Hero

Re: Set dynamic XML element value to a mockResponse present in external file.

You mean to say:
User sends the request which contains 'ContractSolutionNumber'. Use this in the jdbc query to retrieve custId, and banum. Then pass it them in mock response. Right?


Regards,
Rao.
Apoorva6
Frequent Contributor

Re: Set dynamic XML element value to a mockResponse present in external file.

Hi Rao, no. First test step is jdbc to get $custid and $banum from db. I am able to do that. Next I need these to be set in mockresponse for which request is 'ContractSolutionNumber' from input global property .
nmrao
Community Hero

Re: Set dynamic XML element value to a mockResponse present in external file.

When you say you got the values from jdbc result, how these values are available in Mock response?

 

Other way, then why the request mentioned in file "sol12345.xml.Request.txt" is really required? So, its a bit confusing. 

Even if I assume the file is used to just get the response, which makes sense. 

Still the initial question stands there. Hope you get my point.

That is the reason I was saying just run the jdbc in side mock response step itself. 

Just another thougt, since it is mocking only, what are you particular about the data base values; kind of serving actual response which be not be really needed, IMO.



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors