Description

The QueryEachLoopV2Gen allows querying a column within a database table, using an SQL select statement, on EACH iteration of test Generation. 


Select statements, at this level, should only retrieve one row in the result set. Even if the result set retrieves more than one row, the Generator will only return the first row.


In This Article


Restrictions

  • The Generator will not run if any of the following keywords are found in the query (update, delete, set, or truncate).


Generator Parameters

The following parameters may be configured for the QueryEachLoopV2Gen Generator. Items with an asterisk* are required. 

  • resourcePath* - Defines the path on a user's local machine, where the resource file for the JDBC configuration properties file exists.
  • resourceSubDir - Defines an optional subdirectory under the resourcePath where the resource file for the JDBC configuration properties file exists.
  • resourceName* - Defines the name of the configuration properties file that contains the database connection information.
  • grVar1 - Defines the first of five possible variables to use in the SQL select statement.
  • grVar2 - Defines a second of five possible variables to use in the SQL select statement.
  • grVar3 - Defines a third of five possible variables to use in the SQL select statement.
  • grVar4 - Defines a fourth of five possible variables to use in the SQL select statement.
  • grVar5 - Defines a fifth of five possible variables to use in the SQL select statement.
  • query* - Defines the SQL select statement to run.
  • list - Defines a list of values that will be used for preview purposes only. Three values are all that is necessary for preview data.
  • defaultValue - Defines the default value to use if the query does not return any value.


JDBC Configuration File

This Generator utilizes a configuration file stored locally on the user's computer or a shared test server to obtain the necessary information to connect to a specific database via JDBC. For detailed information, refer to 'What is a JDBC Config File?'

Example Story

Actors

  • Tester -  The QA Tester that wants to generate the test data.
  • User - The object of data needed to be synthetically generated.

Key Components

  • employee table - A database table that contains user information.
  • externalId - A value, safe for public access, that uniquely identifies a User in the Employee Table.

Plot

  • A Tester wants to retrieve a User's actual age from the employee production database table while merging the age value with other synthetically generated values like the user's first name, last name, address, city, state, and zip code.

  • In order for the Tester to attain a User's age from the employee table, the Tester must first retrieve the first 1000 User externalIds from the Employee Table using the QueryBeforeLoopV2Gen Generator.

  • Then, on each iteration, as data is synthetically generated for each user, the Tester will use the QueryEachLoopV2Gen Generator to retrieve the User's age from the employee table for the given externalId.

  • The Tester must also define a configuration properties file on their local computer. This file will contain the JDBC connection information to an SQL database.
    • The Tester will define their base directory, which stores configuration files on their local computer, in the global resource named #{resource.jdbc.directory}.

    • The Tester will create a subdirectory called employee under the base directory.

    • With the employee subdirectory, the Tester will create a file called config.properties that will contain the JDBC connection information to the database.


Employee Domain

This is a preview of the User Domain data on the GenRocket web platform.


  • Within the GenRocket Web Platform, the Tester will create a new Project.

  • Within this project, the Tester will also need to create a Domain called employee.

  • The Domain will contain the following Attributes, with each associated to the following Generators:
    • id  - RangeGen
    • externalId - QueryBeforeLoopV2Gen
    • age - QueryEachLoopV2Gen
    • lastName - NameGen
    • firstName - NameGen
    • address - AddressGen
    • city - USStateCapitalGen
    • state - USStateAbbrevGen
    • zipCode - USStateCapitalZipCodeGen


Attribute externalId - QueryBeforeLoopV2Gen

The following provides a visual example of how the Generator configuration will appear for the externalId Attribute and is based on the given usage example. 


The externalId Attribute uses the QueryBeforLoopV2Gen Generator, and the image below shows the parameter configuration necessary for this example. For more information about this Generator, please see How Do I Use the QueryBeforeLoopV2Gen Generator.


Note: Please remember that the above image is based on the given example, and specific parameters may need to be different depending on your needs.


Attribute age - QueryEachLoopV2Gen

The following provides a visual example of how the Generator configuration will appear when the necessary parameters have been configured for the given example.  


Note: Please remember that the above image is based on the given example, and specific parameters may need to be different depending on your needs.