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

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. 

  1. Open the <SOATEST/VIRTUALIZE_INSTALL>/proxies directory
  2. Copy the ParasoftJDBCDriver.jar file to the <WORKSPACE>/ParaBank/WebContent/WEB-INF/lib directory.
     
  3. 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= 

     

  4. In the Virtualize desktop, open the Java perspective then choose  Run> Run Configurations
  5. Select  Apache Tomcat> ParaBank Tomcat 8.5 Server
  6. 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 

     

  7. 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:

  1. Open CTP and choose Environment Manager from the application menu.
  2. Click Add System in the toolbar and choose the Create an empty system option.
  3. Click Create and click in the edit (pencil) button next to the New System label.
  4. Rename your system “Parabank” and click the apply (checkmark) button to save your change.
  5. Drag a Database component into the diagram area and click the save button.
  6. Choose New Environment from the actions drop-down menu on the system page.
     
  7. Click the edit button for the new environment and name it “Silo 1”.
  8. 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. 

  1. Hover your pointer over the top-right corner of the database component so that the options drop-down menu button appears.
  2. Click the drop-down menu and choose New Instance.
  3. Enter “Passthrough” in the Name field.
  4. Choose the HTTP option in the Real endpoints section and specify the host, port, and path to your application.
  5. Enable the JDBC Controller option and click Select a JDBC controller. 
  6. 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. 
  7. Click Finish and repeat steps 1-6 to configure a “Record” instance.
  8. 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 

  1. Verify that the Record instance of the database component is enabled and click the Provision button.
  2. An overlay showing a successful provisioning should appear.
  3. Close the diagram editor and open the Parabank application.
  4. Log into Parabank (username/password: john/demo) and log back out. This action queries the database for the account information of the demo user.
     
  5. In CTP, change the database component instance to Passthrough and click Provision to stop recording.
  6. 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. 

  1. In the Virtualize desktop, right-click the VirtualAssets folder in the Virtual Asset Explorer and choose Add New…> Virtual Asset (.pva) File.
  2. Enter ParabankLogin in the File name field and click Next.
  3. Choose Recorded Database Queries and click Next.
  4. Choose the Virtualize server that recorded the database queries from the Server drop-down menu.
  5. Choose the location of the database from the Databases drop-down menu.
  6. Choose the Data Repository option in the Responder Data Source Type section and click Next.
  7. Specify your data repository server and credentials.
  8. 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.
  9. In the Name field of the SQL Data Set section, enter parabank-login. A data set is a collection of related data fields.
  10. 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 TDA 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

  1. Select the ParabankDB repository in the Data tab and click Export.
  2. Specify a name for the export when prompted and click Export.
  3. Click on the server node to view the exported repository. All exports will be available from this screen.
  4. 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 

  1. Open the Environment Manager module to view your environment diagram.
  2. Choose Silo 1 in the Workspace tab and click Edit Diagram.
  3. Hover your pointer over the Database component and click the drop-down menu.
  4. Choose New Instance and enter “Virtual” in the name field.
  5. Enable the JDBC Controller option and click Select a JDBC Controller.
  6. Click the parabank controller and set the mode to Virtualize.
  7. 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 TDA to make a change. 

  1. Open the TDA module and navigate to the ParabankDB data repository.
  2. Click on the parabank-login data set to view the records.
  3. Click on the SQL template that includes balance information. This record should be in Row 4.
  4. Expand the row to access the record data and click the edit (pen) button.
  5. Change the value of the balance and click the save (checkmark) button. 
  6. 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 TDA features to scale and modify test data to meet any stage of the software testing lifecycle. 

  • No labels