Refer to Data in Responses

Applies to ReadyAPI 3.52, last modified on April 18, 2024

To use values from data sources in virtual service responses, you need to insert property expansions that refer to the needed data source properties. To do this:

  1. Switch to the Setup page of the virtual service editor.

  2. Select the desired response.

  3. In the property editor on the right, select your data source from the Data Source drop-down list:

    Service virtualization and API testing: Selecting data source

    Click the image to enlarge it.

  4. Use the property expansion syntax to refer to a property:

    ${property-name}

    – or –

    ${#MockResponse#property-name}

    You can insert these expressions into the response body or into a header. The property names are case-insensitive:

    Service virtualization and API testing: Referring to data source properties

    Click the image to enlarge it.

    If needed, you can use multiple property expansions, for instance:

    Service virtualization and API testing: Using multiple properties

    Click the image to enlarge it.

    For REST service users: The described functionality is available only when the Response Property Expansion property is true. By default, the property value is true. You may need to check it if the property expansion stopped working for some reason.

    Referring in Scripts

    To refer to a data source property in script code, you use the mockResponse.getPropertyValue(...) function. The property names are case-insensitive:

    Groovy

    def propertyValue = mockResponse.getPropertyValue('my-property-name')
    mockResponse.responseContent = "<data>" + propertyValue + "</data>"

    The getPropertyValue(...) function returns the property value in the “property expansion” format. For example, mockResponse.getPropertyValue('City') will return ${City}, not the actual value of the property like a string or a number. ReadyAPI will handle this expression and insert the actual value before sending the response. This means that you cannot check or compare actual property values in scripts.

See Also

Data Sources in Virtual Services

Highlight search results