Description

This article tells a story using snap-shots from a GenRocket project to show how G-Map components are used to solve a database test data insertion challenge. In this challenge, the child data being generated and inserted into a database table, by a GenRocket Scenario, does not know the value of the parent key-value, because it was not Generated by the GenRocket parent Scenario during insertion. Thus, the Mapping Design Pattern must be used to solve the test data challenge.  


Image of the GMapInsertPattenDemo Project - Project Dashboard


Story Summary

During the testing of a workflow process, test data needs to be inserted into two database tables, a customer table, and an address table, where each address has a foreignKey relationship with a customer.  


The workflow process will utilize two GenRocket Scenarios to populate the two tables, a CustomerScenario and AddressScenario, respectively.


ER Diagram

The Entity Relationship Diagram below shows a visual definition of the customer and address tables, their columns, primary keys, and the address table's foreign key relationship to the customer table.



However, when the data is inserted into the customer table, the primary ID value must be generated by the database, not GenRocket. Since the database will make the primary key for each customer, the AddressScenario will not know the values of the customer IDs created, it only knows the IDs that GenRocket has created.


Thus, the mapping design pattern will be used to map the Customer.id value that GenRocket generates, to the primary ID value created by the database. Then, when the Address Scenario generates its data, for each Address.Customer.id value it generates, it will be able to retrieve the mapped primary ID value that was originally created by the database.


Data Diagram

The Data Diagram below shows a graphical representation of the mapping design pattern where a Genrocket generated value is mapped to a database-generated value.



G-Map Concrete Implementation of the Mapping Design Pattern

 Several G-Map components can be used to concretely implement the mapping design pattern. 


GMapServer

The GMapServer will be launched on a local computer (preferably Linux), within a terminal, on port 8500. Thus, a configuration file, named Config8500.xml, will need to be created and located on the local computer, to configure both the GMapGenericSQLInsertReceiver and the GMapBatchGen to access the GMapServer on port 8500. 


Config8500.xml

<config>   
  <requestURL>http://localhost:8500/rest/</requestURL>
</config> 


GMapGenericSQLInsertReceiver

The GMapGenericSQLInsertReceiver is assigned to the Customer Domain. When the CustomerScenario generates data, the GMapGenericSQLInsertReceiver will insert data into the customer database table and send batches of Key-Value/Data value data to a GMapServer.  The Key-Value is the GenRocket generated Customer.id value, while the Data-Value is the database generated primary ID.


Image of the Customer Domain using the GMapGenericSQLInsertReceiver


Image of the GMapGenericSQLInsertReceiver with configure parameters 


GMapBatchGen Generator

The GMapBatchGen can be utilized in one of two ways to retrieve Value-Data via Key-Data, from a GMapServer, for a given Domain Attribute.

  1. Scenario Attribute - A Scenario Domain Attribute can reference Ancestor Domain Attributes.
  2. Test Data Case Attribute - A Test Data Case Domain Attribute can reference Ancestor Domain Attributes.


In the example below, option 1, using the GMapBatchGen within a Scenario Attribute, was used. The Diagram below shows the Address.customerId using the GMapBatchGen to reference the Customer.id as its Key-Data value.



Note: The Address Domain will use the ubiquitous GenericSQLInsertReceiver to insert data into the AddressTable.


Image of the Address Domain using the GenericSQLInsertReceiver


Image of the GenericSQLInsertReceiver with configure parameters


Video Example Test Data Generation & Population

The video below provides a walkthrough of the above example and generates data using a G-Map Server.