Description
A Test Data Query performs a MongoDB query on the defined database resource. This MongoDB query can be performed in one of two ways for a database: Mongo Before and Mongo Each.
When should you use a MongoDB Test Data Query?
- When you want to query real data from a MongoDB database and blend it with synthetically generated data.
How does MongoDB Test Data Queries Work?
- Create a MongoDB Test Data Query (Mongo Before or Mongo Each)
- Configure the Query Parameters
- Configure the Mongo Parameters
- Add Domains and Attributes for the real data to populate
2 Types of MongoDB Queries
Mongo Before - Query columns from one or more database collections as a set of data that is buffered into memory.
Mongo Each - Query one row of columns, from one or more database collections, on each row iteration of test data generation.
MongoDB Query Configuration Components
A Test Data Query configuration has the following primary components:
- Parameters - Define the resource path, sub-directory, name, and variables for the Test Data Query.
- MongoDB Query Parameters - Defines the collection name, method name, query, sort and projection, which constitute the MongoDB query to be performed on the database.
- Domain Attributes - Defines the Attributes that will be populated by the real data obtained from the MongoDB query.
In This Article
- Prerequisite: MongoDB Properties File
- Step 1: Configure Test Data Query Parameters
- Step 2: Enter the MongoDB Query Parameters
- Step 3: Add Domain Attributes to the Test Data Query
Prerequisite: MongoDB Properties File
A config.properties file must be available on your local computer to connect to the MondoDB database and perform the query. The properties file contains the database connection information and should be stored in the Resource Path location that is defined in the Query Parameters.
Here are the parameters required in the properties file:
host=localhost port=27017 database=anyDB user=root password=root
Tip: You can create a separate properties file for each database to avoid the additional steps of changing the database information each time the database changes. When doing so, you will need to place these files in their own sub-directory and include the sub-directory within the configuration.
Step 1: Configure Test Data Query Parameters
Test Data Query Parameters define any resources variables to be used during the MongoDB Query. Available parameters vary based on the type of query.
Mongo Before
Items with an asterisk (*) are required to perform this type of Test Data Query.
resourcePath* - Defines the path where the resource file for MongoDB connection properties exists.
resourceSubDir - Defines an optional sub-directory under the resourcePath where the resource file for MongoDB connection properties exists.
resourceName* - Defines the name of the resource that contains the database connection information on a user's local machine.
bufferSize* - Defines how many rows to keep in memory at a time. Note: Setting the number of rows to a very high number may cause an OutOfMemoryException to occur if the computer does not have enough available memory. The default buffer size is 1000 rows.
setLoop* - setLoop provides the ability to OVERRIDE the loopCount, at the Scenario level, and to the number of rows that are queried. The default is set to False.
queryOnce* - When the Domain that defines the query has a Parent Domain, it becomes a Child Domain of the Parent Domain. This flag determines if the Child Domain's query should be executed each time the Child Domain is called from the Parent Domain or if the query should only be executed once, the first time the Parent Domain calls the Child Domain. The default is set True to query once.
grVar1 - The first of five possible variables that may be used within the MongoDB Query.
grVar2 - The second of five possible variables that may be used within the MongoDB Query.
grVar3 - The third of five possible variables that may be used within the MongoDB Query.
grVar4 - The fourth of five possible variables that may be used within the MongoDB Query.
grVar5 - The fifth of five possible variables that may be used within the MongoDB Query.
Mongo Each
Items with an asterisk (*) are required to perform this type of Test Data Query.
resourcePath* - Defines the path where the resource file for MongoDB connection properties exists.
resourceSubDir -Defines an optional sub-directory under the resourcePath where the resource file for MongoDB connection properties exists.
resourceName* - Defines the name of the resource that contains the database connection information on a user's local machine.
grVar1 - The first of five possible variables that may be used within the MongoDB Query.
grVar2 - The second of five possible variables that may be used within the MongoDB Query.
grVar3 - The third of five possible variables that may be used within the MongoDB Query.
grVar4 - The fourth of five possible variables that may be used within the MongoDB Query.
grVar5 - The fifth of five possible variables that may be used within the MongoDB Query.
Note: Remember to click Save after making changes to the parameter configuration.
Step 2: Enter the MongoDB Query Parameters
Items with an asterisk (*) are required.
collectionName* - Defines the collection name for MongoDB Query.
methodName* - Defines the method name name for MongoDB Query. Method Name can be either find or aggregate.
query - Defines the MongoDB Query. This parameter is mandatory if methodName is aggregate.
sort - Defines the sort parameter for MongoDB Query.
projection - Defines the projection parameter for MongoDB Query. This parameter is mandatory if methodName is find.
The MongoDB Parameter form if methodName is find:
Step 3: Add Domain Attributes to the Test Data Query
To finish the configuration, you will need to add the Domain Attributes. Data read from columns will be populated into the Domain Attributes for the Test Data Query. This will need to be done for each queried column of data in the database collection.
Click on Add below the Domain/Attribute/Column table.
Select the Domain and Attribute from the drop-down menus.
Enter the name of the Column being read by the MongoDB Query.
Click Save to finish.
The new Domain Attribute will appear in the table as shown below:
Note: Options in the Action Column can be used to edit or delete a Domain Attribute from the Test Data Query configuration.