Event Hooks provide a way to add custom functionality to the configuration sheet for generating synthetic test data. The following examples in the Sample Commerce domain demonstrate how to use Event Hooks in Synthetic Test Data Generation. Event Hooks allow the user to customise the functionality for calculations that may require business logic.
1. Total Amount Example
The Total Amount is based on the number of Order items multiplied by the Unit price.
What is the Event Hooks tab?
It's a way to specify doing a certain calculation before or after another calculation. So for example when you want to add up the Total Order Amount for a particular customer, it is necessary to first do a summation for each product bought based on the product price multiplied by the quantity. The productTotal for each product is then added together to form the Total Amount sold (The multiplication process (amount * quantity) must be done ahead of the summation process).
In our example, there are 2 tabs to consider:
If we look at the EventHooks tab,
We can see that there is a Process called UpdateTotalOrderValue which refers to a VIP flow called UpdateTotalOrderValue.vip. Further note that the scope of the flow is OrderItem. The 'When' column can either be set to 'After' or 'Before'. 'After' means the process should be executed after all OrderItems have been created/saved. 'Before' means the process should be executed before any of theOrderItems are created/saved. This allows the user to be able to manipulate the Order before generating any OrderItem which is sometimes useful if you want to manipulate and propagate a value to all the OrderItems of a current Order.
If we look at EventHooksParameters,
We see that there are 2 parameters for processing UpdateTotalOrderValue and they are 1) parOrder and 2) parOrderItems which contains the necessary information for calculating the TotalOrderValue. Variable lst_OrderItem is the way that the list of OrderItems is passed down to other flows. Variable values are passed down to other flows through the Variable field. In this case, the list of OrderItems is passed through lst_OrderItem_ . (The '' before and after the application object is a convention so if we had been working with products, the variable would be lst_Product.)
Note that the OrderItem Table contains both the UnitPrice and the Quantity.
2. Example for Referring Columns from the Same Table
In this section we will look at another example in the Sample Commerce domain for referring Columns from the same Table. In this example, we would like the phone & fax numbers to be the same. The way to do this is when the Supplier's Phone value is assigned in our tables, we can also assign the same value to our Supplier Fax value.
If you look at line 7 in the Supplier Table above, which contains the object Supplier..Phone., you can see that when Supplier.Phone is assigned a value, that value is also assigned to Supplier.Fax. This process results in the phone and fax variables being the same. Note that Columns can only be referred downwards i.e. the Column defined in Row 7 can be used in Row 8 column but Column defined in Row 9 cannot be used in Row 8 Column. If you would like, it is possible for you to manipulate the order of rows in which the column is defined.
3. Example for Referring Existing Data (varTargetRepo)
This example demonstrates how to use selected variable values across multiple tables.
This example focuses on the object Country.
If we look at line 5 of the Customer Table below:
We see that Country is being populated based on existing Countries that are already part of the System.
If we look at line 6 in the PreProcessVariables table above, we see that there is a database query to select the top 100 Countries from the Country repository. The value is assigned to varExisting_Country_. Once this is done, we have a list of countries that are available in the Database and can be referenced by any of our tables.
See line 5 in the Customer Table:
and line 6 in the Supplier Table below.
This example shows how to reference the same variable across multiple tables.
TEST DATA AUTOMATION SYNTHETIC TEST DATA GENERATION