Table of contents
1.
Introduction
2.
Property Expansion in Responses
2.1.
Project and Service Properties
2.2.
Data Source Properties
3.
Configure Data Sources in Virtual Services
3.1.
Configure Data Sources
3.2.
Configure Data Source Options
4.
Refer to Data in Responses
4.1.
Referring in Scripts
5.
Frequently Asked Questions
5.1.
What are the uses of property expansion?
5.2.
What is the use of configuring Data Sources in Virtual Services?
5.3.
What is the use of the trim function in Data Source?
6.
Conclusion
Last Updated: Mar 27, 2024

Data Sources in Virtual Services in Ready API

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

ReadyAPI helps Agile and DevOps development teams improve API quality by allowing them to manage and run automated functional, security, and performance tests through a single centralized interface. ReadyAPI empowers software teams to share testing projects and artifacts, report and fix errors straight from the testing IDE, and distribute licenses among team members.

This blog explains the details of Data Sources in Virtual Services in Ready API along with the details of Property Expansion, Configure Data Sources in Virtual Services, and References to Data in Responses.

Without further ado, let's get started.

API Image

Property Expansion in Responses

You can add property values from your Project, virtual service, or data source to the response contents in ReadyAPI:

  • Your Project's or virtual service's custom properties (those that are displayed on the Custom Properties tab at the bottom of the Navigator panel) can be included.
     
  • Any characteristic of a data source you connected to a response.
     

The virtual service increases the properties and swaps out their references with actual property values before responding to a client.

Let's look into the details of Project and Service properties.

Project and Service Properties

The following syntax should be used to refer to a property:

Syntax:

${#MockService#property-name}

 

Use this syntax to refer to a project property:

Syntax:

${#Project#property-name}

 

Simply provide the reference expression in the response properties' Edit box.
Using the Get Data command from the context menu is a simple approach to adding a property reference: set the insertion point in the Edit box's desired location, then use the context menu to right-click and choose Get Data > property-name.

Use code similar to this to refer to service and project properties in scripts:

Code:

def propertyValue = requestContext.mockService.getPropertyValue('your-property-name')
//Project custom property
def propertyValue2 = requestContext.mockService.project.getProperty('your-property-name').getValue();

 

Let's look into the details of Data Source properties.

Data Source Properties

Use the following syntax to make a reference to a data source property:

Syntax:

${#MockResponse#datasource-property-name}


Use the following code to refer to these properties from the script:

Code:

def propertyValue = mockResponse.getPropertyValue('datasource-property-name')


The Get Data command does not allow the insertion of data source properties.
To expand these characteristics, you must specify the data source in the response's Data Source field for a virtual service.

Lets dive into the details of Configuring Data Sources in Virtual Services.

Configure Data Sources in Virtual Services

Data Image

On the Data Sources page, you can configure Data Sources. All data sources have different characteristics. They allow access to the data in the data source and correlate to the columns in the data source.

Configure Data Sources

The steps to configure Data Sources are as follows:

  • Go to the Virtual Service Editor's Data Sources page. The data source name must be entered in the dialogue box that appears after clicking Add on the page toolbar.
     
  • Choose the type of data source and provide the connection details.
     
  • For the data source, create some properties. The properties give users access to the data in the data source. The property names you give must match the column names of the data source, whether it is an Excel sheet, a database, or a comma-separated value (CSV) file.
     

After configuring data source settings and creating them, you can utilize properties in answers.

Configure Data Source Options

The steps to configure Data Sources options are as follows:

  • Choose the data source that has to be configured. Open the configuration dialogue.
     
  • Configure the options:
    • Trim - Requests the data source and trim the obtained text values of any leading and trailing spaces.
       
    • Entitize - Orders that the appropriate entities be used in place of specific HTML symbols (such as & or >). (like & or >).
       

Let's look into the details of References to Data in Responses.

Refer to Data in Responses

You must introduce property expansions that reference the required data source properties to use values from data sources in virtual service responses. The steps are as follows:

  • Go to the virtual service editor's Setup page.
     
  • Choose the appropriate answer.
     
  • Choose your data source from the Data Source drop-down list in the property editor on the right.
     
  • Refer to a property by using the property expansion syntax:

Syntax:

${property-name}

or  

${#MockResponse#property-name}

 

These phrases can be included in a header or the response body. The names of the properties are case-insensitive.

Referring in Scripts

The mockResponse.getPropertyValue(...) function is used to refer to a data source property in script code. The names of the properties are case-insensitive:

Code: 

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

Frequently Asked Questions

What are the uses of property expansion?

Using property expansion, you can include variable components in a property value, a request body, scripts, and other places.

What is the use of configuring Data Sources in Virtual Services?

The Data Sources in Virtual Services allow access to the data in the data source and correlate to the columns in the data source.

What is the use of the trim function in Data Source?

The trim function in the Data source is used to identify the data source and remove any leading and trailing spaces from the text values you acquire.

Conclusion

In this article, we have extensively discussed the details of Data Sources in Virtual Services in Ready API and Property Expansion, Configure Data Sources in Virtual Services, and References to Data in Responses.

We hope that this blog has helped you enhance your knowledge regarding Data Sources in Virtual Services in Ready API, and if you would like to learn more, check out our articles on ReadyAPI. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. Happy Coding!!

Thank You Image
Live masterclass