Conditional Match Overview

Applies to ReadyAPI 3.54, last modified on September 13, 2024

About

The Conditional Match dispatch strategy of a virtual service provides greater control over the configuration of how virtual services respond to various requests, enabling more realistic and dynamic testing scenarios.

This feature allows you to pair specific requests with corresponding responses, configure multiple request/response pairs, and set a default response for unmatched requests.

Additionally, requests can be grouped and matched by signature, validating and matching requests based on data structure, with default responses provided for failed validations. You can configure requests with specific data configurations or arguments using operators like =, +, -, *, <, >, and regex.

This advanced functionality enables intricate request/response configurations, ensuring precise and accurate virtual service behavior.

The Conditional Match dispatch type is available for REST virtual services only.

Conditional Match is currently designed to work with body parameters only. It does not support matching based on query parameters.

Key Components

This section explains two essential components of Conditional Match:

  • Match: A set of conditions that must be satisfied for the chosen response to be sent to an incoming request.

  • Signature: A template that defines the body structure an incoming request needs to match to be paired with a specified response.

Getting Started

Start using Conditional Match by exploring its versatile applications to control how your system handles request-response interactions. This section guides you through scenarios and settings, demonstrating how to simulate user interactions, manage complex logic, and effectively test API behaviors. To get started, complete the following steps:

  1. Configure your virtual service.

  2. Set up your requests and responses by importing or recording.

  3. Configure the request - response pairing logic.

  4. Configure your signatures and assign requests to signatures to enable validation and match/no-match response expectations.

  5. Deploy and run the virtual service.

Matching Algorithm

This process outlines how the Matching Algorithm handles incoming requests by directing them to the appropriate Virtual Action, verifying signatures when required, and providing responses based on predefined matches or defaults.

  1. Receive the incoming request.

  2. Identify the endpoint and route it to the corresponding Virtual Action.

  3. Find a matching signature if signature verification is enabled.

  4. If a matching signature is found, proceed to find a corresponding match.

  5. Send the appropriate response based on the match.

  6. If no matching signature or match is found, send the Default response configured for the Virtual Action.

Settings for Conditional Match

The following settings allow you to configure how signatures are validated in Conditional Match, ensuring the appropriate handling of requests.

  • Validate Signatures: Validating signatures ensures that the requests and responses adhere to a predefined structure, enhancing reliability and consistency.

  • Don’t Validate Signatures: In some cases, it might be necessary to disable signature validation, allowing more flexibility in handling requests. In this case, the matching algorithm will use the first match from the top of the match list that works for the incoming request.

  • Validate Signature Headers: Validating headers ensures that the requests include the necessary metadata before they are processed.

  • Validate Signature Values: Validating the values of request parameters ensures that the data conforms to expected formats and ranges.

You can choose to enable or disable the signature validation options using checkboxes:

Checkbox Checked Unchecked
Verify Signature The system verifies if the incoming request’s parameter structure matches the parameter structure defined by the assigned signature (all parameters specified in the signature must be present in the incoming request and the incoming request must not contain any parameters that are not present in the signature). Matching occurs without validating parameter structure from the assigned signature.
Verify Signature Headers The system checks if the incoming request includes all headers specified in the assigned signature. Headers specified in the signature are not considered during the matching process.
Verify Header Values All conditions defined in the headers tab in the conditional match are evaluated during the matching process. Conditions defined in the headers tab in the conditional match are disregarded.

This feature lets you dynamically insert request values into responses, enhancing testing flexibility and accuracy.

Enabling Property Expansion in Conditional Match

Click the image to enlarge it.

When enabled, during the import of request/response pairs using Import from a file or Record from traffic the following behavior applies:

If both the request and response share a parameter with the same value, the response's value will be replaced with the Property Expansion syntax, using the default value recorded at the time. For further information on Property Expansion in Conditional Match, refer to the Property Expansion section.

Configure signature validation and header validation behaviors in Conditional Match with the JVM settings.

  • Signature Validation: Controls whether signature validation is enabled (true) or disabled (false).

    Note: Enabling this setting hides the UI option to toggle this functionality.
    readyapi.verify.signatures=true
  • Signature Header Validation: Controls whether signature header validation is enabled (true) or disabled (false).

    readyapi.verify.signatures.headers=true

Scenarios for Conditional Match

Conditional Match can be used in various scenarios where precise control over request-response interactions is required. For instance:

  • Simulating Different User Interactions: Adjust responses based on user-specific data sent in the request body.

  • Handling Complex Logic: Implement logic within mock services to respond differently based on intricate conditions.

  • Validate Signature Headers: Validating headers ensures that the requests include the necessary metadata before they are processed.

  • Testing Different API Behaviors: Test how your system reacts to a wide range of request conditions without changing the underlying code.

See Also

Conditional Match (Dispatch Strategy)
How to Use Conditional Match

Highlight search results