Applies to ReadyAPI 2.8, last modified on August 16, 2019

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.

ReadyAPI cannot parse XML documents that contain the byte order mark (BOM) character.

Setting Up Properties

  1. In the virtual service editor, select the Query Match dispatch strategy.

  2. 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.

  3. Select a match on the list, and then set its properties:

    • The XPath expression to be used for extracting request data and the Expected Value. You can click to select a node and its data from the request body rather than type the expression. Click Extract to copy the expected value from the last request by using the specified XPath expression. See below.

    • In the Dispatch to drop-down list, set the response that the virtual service will return when the extracted data equals to the expected value.

    • Make sure the Disabled check box is clear. If it is selected, the service will exclude the selected match from the check.

    Service virtualization with ReadyAPI: Properties of the Query Match dispatch strategy

    Click the image to enlarge it.

    • Select the Query Type (XPath or JSONPath) you want to use in this match.

    • The Query (an XPath or JSONPath expression) to be used for extracting request data and the Expected Value. You can click to select a node and its data from the request body rather than type the expression. See below.

      Tip: To learn more about the JSONPath syntax, see JSONPath Reference.
    • In the Dispatch to drop-down list, set the response that the virtual service will return when the extracted data equals to the expected value.

    • Make sure the Disabled check box is clear. If it is selected, the service will exclude the selected match from the check.

    Service virtualization with ReadyAPI: Properties of the Query Match dispatch strategy

    Click the image to enlarge it.

  4. 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 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 SoapUI, from the Projects page, or from an external application like cURL.

How It Works

  1. Every time the virtual service receives a request, it iterates through the list of matches (from the top to the bottom).

  2. 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.

  3. If no matches were found, the virtual service returns the response that is set by Default Response.

See Also

Response Dispatching

Highlight search results