Record Requests to the Database
Now that the virtual service is connected to the database and is running, let's send some requests to it.
From ReadyAPI
Create a test suite and a test case. Then, add the JDBC Request test step. For more information on how you do this, see the Your First Functional Test tutorial.
In the test step editor, configure the database connection:
Make sure Connection is set to
<None>
.In the Driver field, enter
com.smartbear.servicev.jdbc.driver.JdbcVirtDriver
. This commands ReadyAPI to use the included JDBC driver to connect to the virtual service.Important
You do not need to install the
JdbcVirtDriver
driver when working with JDBC virtual services from ReadyAPI.To use a different JDBC client, download the driver from the SmartBear website and install it in the client application.
Specify the service’s Connection String. By default, virtual services that are run locally have the
jdbc:servicev://localhost:10080
address. If you use a different port or run the virtual service on a different computer, the address will be different.
To make sure your connection parameters are correct, click
.
ReadyAPI will test the connection to the virtual service without sending a request.
Enter an SQL Query for your request. For example:
Select city.* From city
Important
Do not use the Build Query button to create a query. ReadyAPI sends requests to the database to get table information and these requests will also be recorded. This may make it hard to find the real request.
Click
to run the test step or the entire test. The virtual service will route the sent request to the real database and then return the response from it.
From Java code
Add the JDBC driver to your project. You can do this in two ways:
If you use Maven, add the service-v-jdbc-driver dependency to your .pom file:
<dependencies> <dependency> <groupId>com.smartbear.readyapi</groupId> <artifactId>servicev-jdbc-virt-driver</artifactId> <version>1.0.0</version> </dependency> </dependencies>
Otherwise, download the driver manually and place it in the
<your-project>/lib
folder. Make sure your IDE loads the driver.
Then, connect to the virtual service from your code and send requests. Here is an example that sets up the connection and sends the simple Select query:
After the virtual service has recorded at least one transaction with the database it is ready to simulate responses. Next, we will modify the response returned by the virtual service.
Note
The virtual service will record the transaction and respond to the same request instead of the database.