Definition

The Surrogate-Parent-Primary Pattern is a derivative of the Parent-Primary Pattern and the Permutation-Primary Pattern.  The Primary Domain has a Parent Domain; however, the Primary Domain needs to directly inherit test data generated from a Domain that is neither the Parent Domain nor a Sibling Domain yet still has its Parent Domain in its ancestry.  This unrelated Domain must generate its test data after the Parent Domain but before the Primary Domain, thus becoming the Primary Domain's Surrogate Parent Domain.

This Surrogate Parent Domain further enforces the Permutation-Primary Pattern in that the number of records generated by the Primary Domain is the sum of the number or Parent iterations multiplied by the number of Surrogate iterations.

Object Diagram

DhfPJRJiEwuQrF8O1GmCeHZILGLyiYE8xQ.png

Surrogate-Parent-Primary Pattern

  • See Parent-Primary Test Data Generation Design Pattern
  • See Permutation-Primary Test Data Generation Design Pattern

Surrogate-Parent-Primary Pattern Iteration Example

Pseudo Code Example

The Pseudo code below shows a sequence in which test data is generated for the Surrogate-Parent-Primary.

     

for (parentLoop 1..N) do 
  parent.generateNext()
  surrogateSet = Surrogate.findAllBySomeId(parent.someValue)
  for (surrogateLoop in 1..surrogateSet.size) do
    surrogate.generateNext()
    for (primaryLoop in 1..N) do
      primary.generateNext()

     

Concrete Example

This concrete example explains how an Order Header must generate at least 1 Order Item with each Order Item generating 5 Order Item Options, without being directly to Order Options.


Scenario

  •     An Order Header Domain is the parent to the Order Item Domain
  •     The Order Item Domain is the parent to the Order Item Option Domain
  •     For each Order Header record generated, there must be 1 Order Item record generated
  •     Each Order Item record will randomly generate a productId between 1 and 25
  •     However, for each Order Item, there must be N Order Options
  •     The Order Item Options are not related to the Order Item as a Parent Domain or a Sibling Domain
  •     The set of Order Item Options must be selected from a Surrogate Domain where the productId = orderItem.productId
  •     The surrogate returns the set of N Order Item Options associated to the productId
  •     For each Surrogate Domain, an Order Item Option will be generated
  •     Thus, each Order Item will have N Order Item Options