Query Match (Dispatch Strategy)
About
The Query Match dispatch strategy of a virtual service extracts data from an incoming request, compares it with a baseline value and returns a response depending on the result of the comparison.
The strategy extracts data from the request body. To extract data, it uses XPath or JSONPath expressions. The body of the incoming request should contain data in the XML or JSON format correspondingly.
Important
ReadyAPI cannot parse XML documents that contain the byte order mark (BOM) character.
Setting Up Properties
In the virtual service editor, select the Query Match dispatch strategy.
Click
to create a match – a set of an XPath or JSONPath expression and expected value for the check. You can create multiple matches if needed. In this case, you will enable your virtual service to return different responses for different incoming request data.
Select a match on the list, and then set its properties:
In the Default Response box, select the response that the virtual service will return if no match is found.
In JMS virtual services, you can set the Default Response property to
<None>
to simulate the absence of responses.
There is no need to save the changes, ReadyAPI does this automatically. If the virtual service is running on your computer, ReadyAPI applies changes on-the-fly.
Tip
To specify the XPath or JSONPath expression, you can click
and select the desired XML node or JSON object in the subsequent dialog. The dialog will form the expression and insert it to the XPath or Query edit box. In SOAP and JMS virtual services, you can also click Extract to copy data to the Expected Value edit box.
To use this feature, you need to send a sample request to the virtual service before configuring dispatch properties. To do this, start the service and run the request, for which you define the dispatch strategy. You can run it in any way: from a test case in ReadyAPI Test, from the Projects page, or from an external application like cURL.
How It Works
Every time the virtual service receives a request, it iterates through the list of matches (from the top to the bottom).
For each match, it extracts data from the request body and compares this data against the expected value:
If the data is equal, the service returns the response specified for the match by the Dispatch to setting.
If the data differs, the service continues with the next match.
If no matches were found, the virtual service returns the response that is set by Default Response.