In this chapter, we’ll discuss how to get data into the testing infrastructure. We will use an instance of the Parabank example application shipped with Parasoft SOAtest and Virtualize and add a proxy to the application configuration so that we can capture the data to a data repository.
In this section:
Prerequisities
- An instance of the SOAtest/Virtualize server should be running. See Deploying the SOAtest and Virtualize Server WAR File.
- The example ParaBank project should be deployed. See Setting Up ParaBank.
- A data repository server should be deployed and configured to register with CTP. See Installing a Remote Data Repository Server.
Deploying the ParasoftJDBC Driver
We’ll start by deploying the ParasoftJDBC driver to Parabank and configuring a connection to the SOAtest/Virtualizer server. The Parasoft JDBC driver is a special JDBC driver that can act as a man-in-the-middle between the application and its regular JDBC driver. See About the Parasoft JDBC Driver to learn.
- Open the <SOATEST/VIRTUALIZE_INSTALL>/proxies directory
- Copy the ParasoftJDBCDriver.jar file to the <WORKSPACE>/ParaBank/WebContent/WEB-INF/lib directory.
Open the ParaBank/src/jdbc.properties file and specify the following settings:
jdbc.driverClassName=com.parasoft.xtest.jdbc.virt.driver.JDBCProxyDriver jdbc.url=jdbc:parasoft:proxydriver:org.hsqldb.jdbcDriver:@jdbc:hsqldb:hsql://localhost/parabank jdbc.username=sa jdbc.password=
- In the Virtualize desktop, open the Java perspective then choose Run> Run Configurations.
- Select Apache Tomcat> ParaBank Tomcat 8.5 Server.
Under the Arguments tab, add the following Parasoft JDBC Driver flags to what is already listed in the VM arguments section:
-Dparasoft.virtualize.server.url=http://localhost:9080 -Dparasoft.virtualize.group.id=parabank -Dparasoft.virtualize.driver.register.jdbcproxydriver.in.drivermanager=true -Dparasoft.virtualize.driver.proxy.direct=true
- Restart the ParaBank server with the updated run configuration. You can open the console view in Virtualize desktop and log in and out of the ParaBank to verify that the proxy is working.
If you are applying this tutorial to your own project, the documentation includes instructions on how to deploy the Parasoft JDBC Driver to several application. See Using the Parasoft JDBC Driver.
Recording Database Queries
In this step, we will record a database query and use it to create a virtual asset. Recording a database query will not add data to a data repository. An action, such as sending a message to virtual asset connected to the repository, must be taken in order to capture the data. You can perform this step in the Virtualize desktop or in CTP. We will use CTP in this tutorial, which requires some additional configuration.
Creating an Environment
We’ll create a new system, environment, and database component in CTP. A system is a representation of your development infrastructure. A system contains one or more representations of your environments, such as "regression testing", "integration testing", etc. Additionally, you can create several instances of an environment to meet your testing needs.
A system is a palette that is populated with several components, such as databases, servers, clients, etc. An instance of each component contains configurations used within specific environments. A realistic system would contain several components, but we will only use the database component to illustrate the workflow:
- Open CTP and choose Environment Manager from the application menu.
- Click Add System in the toolbar and choose the Create an empty system option.
- Click Create and click in the edit (pencil) button next to the New System label.
- Rename your system “Parabank” and click the apply (checkmark) button to save your change.
- Drag a Database component into the diagram area and click the save button.
- Choose New Environment from the actions drop-down menu on the system page.
- Click the edit button for the new environment and name it “Silo 1”.
- Save the environment.
You should now a have a system called Parabank that consists of a single database. The system contains the Silo 1 environment. We will next add multiple instances of the database component to configure different states.
Adding Database Component Instances to the Environment
A component is a type of object that can appear in your environments. You have to add instances of the component that perform specific functions for them to be useful.
- Hover your pointer over the top-right corner of the database component so that the options drop-down menu button appears.
- Click the drop-down menu and choose New Instance.
- Enter “Passthrough” in the Name field.
- Choose the HTTP option in the Real endpoints section and specify the host, port, and path to your application.
- Enable the JDBC Controller option and click Select a JDBC controller.
- Choose the “parabank” controller and specify Passthrough as the mode. You can leave the default for all other configurations in this section. Refer to Configuring JDBC Controllers for additional information about these settings.
- Click Finish and repeat steps 1-6 to configure a “Record” instance.
- Click Finish after configuring the Record instance.
You now have a passthrough mode and a record mode configured for the database component. The next step is to enable recording and capture a query.
Recording Database Queries from a CTP Environment
- Verify that the Record instance of the database component is enabled and click the Provision button.
- An overlay showing a successful provisioning should appear.
- Close the diagram editor and open the Parabank application.
- Log into Parabank (username/password: john/demo) and log back out. This action queries the database for the account information of the demo user.
- In CTP, change the database component instance to Passthrough and click Provision to stop recording.
- When recording is stopped, a new directory with database recording files will be added to the Virtualize server. You can switch to the Service Virtualization module to view the files in CTP.
The next step is to create a virtual asset connected to a data repository to capture the data associated with the query. We will use Virtualize desktop to complete this step.
Creating a Virtual Asset from the Database Recording
The data is not captured when you record a database query using the JDBC driver—only the query templates. We will create a virtual asset using the database query templates and attach a data repository and message responder to capture the data.
- In the Virtualize desktop, right-click the VirtualAssets folder in the Virtual Asset Explorer and choose Add New…> Virtual Asset (.pva) File.
- Enter
ParabankLogin
in the File name field and click Next. - Choose Recorded Database Queries and click Next.
- Choose the Virtualize server that recorded the database queries from the Server drop-down menu.
- Choose the location of the database from the Databases drop-down menu.
- Choose the Data Repository option in the Responder Data Source Type section and click Next.
- Specify your data repository server and credentials.
- Enter
ParabankDB
in the Repository name field. You can also specify an existing repository, but the data will be overwritten by the data captured when the virtual asset queries the database. The repository is a collection of related data sets. - In the Name field of the SQL Data Set section, enter
parabank-login
. A data set is a collection of related data fields. - Click Validate to ensure that the settings are configured correctly and click Finish when ready.
The virtual asset will populate the data repository with data from the database using the recorded SQL templates. Open the Test Data module in CTP and click on your repository to access the data.
Now that we have data captured in a database, we'll make a snapshot of the data repository so that we can always reset the data to its initial state if necessary.
Creating a Backup of the Repostory
- Select the ParabankDB repository in the Data tab and click Export.
- Specify a name for the export when prompted and click Export.
- Click on the server node to view the exported repository. All exports will be available from this screen.
- Click on the export to access management options and to view details.
The next step is to configure a virtual database instance that will pull data from the repository for testing purposes.
Creating a Virtual Database Instance
- Open the Environment Manager module to view your environment diagram.
- Choose Silo 1 in the Workspace tab and click Edit Diagram.
- Hover your pointer over the Database component and click the drop-down menu.
- Choose New Instance and enter “Virtual” in the name field.
- Enable the JDBC Controller option and click Select a JDBC Controller.
- Click the parabank controller and set the mode to Virtualize.
- Click Finish and click Provision to enable the environment instance.
You can verify that the virtual database is being used with data from the repository by using Test Data to make a change.
- Open Test Data module and navigate to the ParabankDB data repository.
- Click on the parabank-login data set to view the records.
- Click on the SQL template that includes balance information. This record should be in Row 4.
- Expand the row to access the record data and click the edit (pen) button.
- Change the value of the balance and click the save (checkmark) button.
- Return to ParaBank and login. The updated balance should be reflected.
At this point, you can clone and modify records and use the data in your API and manual UI tests. But we will use even more powerful Test Data features to scale and modify test data to meet any stage of the software testing lifecycle.