An imitated web service runs on a server, responds to client queries, and receives requests from users. You must include virtual operations (or actions) in your virtual service in order to achieve this capability. They outline the requests that will be made for this service. You can specify one or more potential replies for each request. Depending on the test conditions, the virtual service will return either this or that response. In this article, the reader will learn about virtual services. We will also discuss how to create a JDBC Virtual Service and how to Connect the JDBC Virtual Service to Existing Data.
Create a JDBC Virtual Service
Follow these steps to begin interacting with a JDBC virtual service:
1. Create an empty project
Make a new project first:
Choose File > New Empty Project from the ReadyAPI menu.
2. Add a JDBC virtual service to the project
Click + while pointing at the APIs (Virtual) node in the Navigator panel.
This will open the dialogue box for the New Virtual Service (see below).
To create a blank JDBC virtual service, choose Empty JDBC in the New Virtual Service dialogue box:
Give the virtual service a name, then click OK.
A new empty service will be created by ReadyAPI, and then it will be made editable. The virtual service will then be configured and made ready for recording requests.
Connect the JDBC Virtual Service to an Existing Data
There is no data in the JDBC virtual service that you built. Using JDBC virtual services as a proxy to send JDBC requests to the database and store transactions, you can record JDBC virtual services in ReadyAPI. In this section, we'll link the virtual service to a database:
Route and Record Non-Virtualized Request from the Route Options drop-down menu:
When you use the virtual service in this mode, it will direct your requests to the designated database and log the transaction. The service will return the previously saved response if a request has already been recorded.
2. In the Route to the text box, type the database connection string.
JDBC drivers are used by ReadyAPI to connect to the database. The drivers for the most often used databases are included in the installation package. Install the database driver to ReadyAPI>/bin/ext. If it is not already there, then restart ReadyAPI.
Depending on the database provider you use, your connection string might look something like this for a MySQL database:
jdbc:mysql://localhost:3306/world
3. Give the user's login information. The database will be accessed using ReadyAPI. There are two ways to do this:
In the text fields for the user name and password. When you enter information into these text boxes, ReadyAPI automatically adds user credentials to the connection string. In order to increase security, it additionally disguises the text you type in the password field:
Throughout the connection string. The driver and database provider determine where you should insert user credentials.
4. Start the virtual service once you have the proper user credentials and connection string.
The database connection attempt is made by ReadyAPI. It will indicate an error if the connection is unsuccessful.
Sending JDBC requests to a virtual service once it has been set up and started will allow you to log the requests. The tutorial's following section explains how to use ReadyAPI to do this.
Modify the Response
A request to the database and a response from it were previously logged. You can add to the transactions you've previously recorded or stop recording altogether. This step outlines how to edit the recorded answers.
Modify the virtual response
Terminate the virtual service:
2. While routing is enabled, the virtual service cannot be modified. Before altering the recorded response, disable routing:
3. Choose the answer. The data you downloaded from the database will be displayed in the editor on the right. Change the value in a cell by double-clicking on it. Enter to accept your changes.
Tip: Use the Clone Row or Add Empty Row options when you right-click within the table to add more rows. By choosing Remove Rows, you can also eliminate all of the selected rows.
4. Launch the virtual service again.
Get the modified response
Reopen the JDBC Request test step and issue the same query in a new request to the virtual service. The service will deliver updated information:
An error message titled "Statement not virtualized" will appear if you send a request that wasn't recorded.
Frequently Asked Questions
What is the virtual service called in ready API?
It simulates replies to client requests and defines the processes that real API users will call.
What is a virtual service?
An indirect or direct provision of a real service by a virtual node through the use of a virtual router is referred to as a virtual service.
What is stub service?
Service stubs are simulations of real services that can be used in testing environments to replace them functionally.
What is mock REST API?
A mock API server or mock server API mimics a real API server by responding to requests with plausible mock API answers.