Dynamic stub response

257 views
Skip to first unread message

nishar1...@gmail.com

unread,
Dec 23, 2016, 2:44:52 AM12/23/16
to mountebank-discuss
My response is as follows:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns:Response TID="f1645e6f-3836-4005-a1cd-994c5a914f30" xmlns:ns="http://wsg.avis.com/wsbang">
<OTA_VehResRS xsi:schemaLocation="http://www.opentravel.org/OTA/2008/05 OTA_VehResRS" Target="Production" Version="1.0" SequenceNmbr="2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opentravel.org/OTA/2003/05">
<Success/>
<VehResRSCore>
......
<ConfID Type="14" ID="06983280GB3"/>
<Vendor>Avis</Vendor>
<VehRentalCore PickUpDateTime="2016-12-23T10:00:00".......
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I want to create a imposter in such a way that I can dynamically change the ID attribute value in the ConfID tag.

Brandon Byars

unread,
Dec 23, 2016, 12:17:55 PM12/23/16
to nishar1...@gmail.com, mountebank-discuss
Hi there,
The best way for now is to use the decorate behavior, which allows you to tokenize the response and fill in the dynamic value with a JavaScript function. Some folks from the community are currently working on the ability to copy the dynamic value from something in the request or to fill it in with a CSV file without JavaScript. I expect those features to be released in the next couple months.

Have a look at the example on the linked page around adding the current time to the response. It's quite similar to your situation.
-Brandon


--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nishar1...@gmail.com

unread,
Dec 26, 2016, 5:14:46 AM12/26/16
to mountebank-discuss, nishar1...@gmail.com

----------------------------
The response is in XML format. What would be the code to parse the XML response in order to replace the ID attribute value in the ConfID tag.


Brandon Byars

unread,
Dec 29, 2016, 10:03:14 AM12/29/16
to nishar1...@gmail.com, mountebank-discuss
In that case, parsing the XML sounds like overkill. You can simply set up the response with tokens where you want to replace dynamic values and use a string replace. So, in a simplified example:

{
  "responses": [{
    "is": {
      "body": "<ConfID Type=\"14\" ID=\"${ID-TO-REPLACE}\"/>"
    },
    "_behaviors": {
      "decorate": "function (request, response) { response.body = response.body.replace('${ID-TO-REPLACE}', 132); }"
    }
  }]
}

Reply all
Reply to author
Forward
0 new messages