Data Source Tutorial

This tutorial shows how to configure a virtual service to use the Excel data source.

Overview

We will create a virtual service that will return details about pets. For this purpose, we have created a table:

tutorial-data-source-overview.png

The first row of the table contains the names of data source properties, while the rest contain data for the response.

1. Import project

Before you start, download the project and the Excel file that we use as a data source:

go.gifReadyAPI project

go.gifExcel data sheet

Now, import the project into ReadyAPI:

  • In ReadyAPI, select File > Import Packed Project and in the dialog that occurs, select the downloaded package with the project:

    Data Source virtual services in ReadyAPI: Import project

2. Add data source virtual service

  1. Open the virtual service and switch to the Data Sources page:

    Opening Data Source page in ReadyAPI Virtualization
  2. Click add.png to add a new data source:

    Creating a new data source in ReadyAPI Virtualization
  3. Select the Excel data source type and click Browse and look for the Excel data sheet you downloaded earlier:

    Selecting an Excel file as a data source
  4. ReadyAPI offers you to import the properties. Click Yes, and in the resulting dialog, specify the following properties:

    Worksheet:

    Sheet1

    Start at cell:

    A1

    Click OK. ReadyAPI creates properties using column names in the data sheet:

    Importing properties from a data source
  5. Specify the following properties for the data source:

    Worksheet:

    Sheet1

    Start at cell:

    A2

    The Worksheet property specifies the sheet that contains the needed data.

    The Start at cell property commands ReadyAPI to start gathering data from the specified cell. It helps skip rows if they do not contain data. In our example, the first column contains property names, so we set the property to A2 to ignore it:

    Excel data source configuration

3. Insert data into response

  1. Switch to the Setup page and open the response. Expand the Data Source page and select the created data source from the drop-down list:

    Selecting data source in virtual service response
  2. To insert the value from the data source, you need to insert the property expansion. The simplest way to insert it is to use the context menu. Expand the Edit panel. Right-click within the Editor panel and select the needed property:

    Inserting data source property into the response

    Repeat this step for all properties of the Pet object. At the end, you should get the response body like this:

4. Run test

  1. Click run.png to run the virtual service:

    Running virtual service

    Important

    Make sure that another application does not occupy the virtual service port. If needed, change the port in the virtual service properties:

  2. Open the functional test.

    Important

    If you changed the virtual service port, change the request endpoint:

    ReadyAPI: Change virtual API port
    1. Select the API in the Navigator.

    2. Click Edit next to the endpoint you want to change.

    3. Change the endpoint and click Save.

    Click run.png to run the test:

    tutorial-run-test-case.png

    ReadyAPI sends several requests to the virtual service. For each response, the virtual service gathers data from a new data source row. To see it, switch to the Transaction Log and open any transaction:

    Viewing virtual service responses

    When the data source ends, ReadyAPI starts from the first row:

    Viewing virtual service response that exceeds data source capacity

Next steps

go.gifData Sources and Data-Driven Tests

go.gifData Source Types

go.gifProperty Expansion

go.gifVirtual Service Scripting

See Also

Publication date: