Description

There are 2 ways you can add Business Rules to existing Scenarios:


1. Using G-Rules Self-Service platform

2. Using APIs 


Both G-Rules and APIs can be used when working with multiple Attributes where conditions on one Attribute are dependent on values of one or more Attributes. They can be set up with the G-Rules Dashboard or as an API Call. 


This article provides a brief example of how an example set of conditions can be set up within the G-Rule Dashboard and how the Domains, Attributes, and G-Rules can be used to generate test data through an API Call.


In This Article


Rule-Based Conditions for Investment Domain Attributes

Based on the Customer's age, the industry and transaction amount range needs to be set. 

The following conditions will be part of this API Example: 


Business Rules for industry Attribute:

  • For age 18-25, the investment industries should be banking, pharma, retail.
  • For age 26-40, the investment industries should be banking, pharma, retail, mining, manufacturing, oil, motor insurance.
  • For age 41-65, the investment industries should be 50% banking, 28% oil, 22% healthcare 


Business Rules for transaction Attribute:


  • For banking and oil:
    • If age is 18-25, transactions should be between 50-500 
    • If age is 26-40 it should be 150-5000
    • If age is 41+ it should be 2000-8000
  • For other industries:
    • If age is 18-25, transactions should be between 150-1000
    • If age is 26-40 it should be 1001-2500
    • If age is 41-65 transaction value should be between 2501-5000
    • If  age 65+ it should be 5001-10000


Create Investment Domain and Attributes

The first step is to create a Domain with no Business rules. Once you have your GenRocket Scenario ready, either you can use G-Rules or APIs or both to apply rules to the existing Scenario.



Test Data Rules Example

This section explains how you can use the G-Rules platform to add Business rules to the existing Scenario. The G-Rules Dashboard can be accessed by expanding the Self Serve drop-down menu for a Project Version of a given Domain:
 


These Rules can be set up as a G-Rules Suite within the web platform. Screenshots of these rules created within the G-Rules Dashboard are shown below. 


Rule #1

  • For age 18-25, the investment industries should be banking, pharma, retail.


The GEN_VALUE is generated value from ListGen Generator in the Then Actions Section.

API Request Parameters for Rule #1

{
  "api": [
    {
      "methodName": "generatorParametersSet",
      "parameters": {
        "attributeName": "Investment.age",
        "generatorPosition": "0",
        "parameterMap": {
          "startRange": "18",
          "endRange": "25"
        }
      }
    },
    {
      "methodName": "generatorParametersSet",
      "parameters": {
        "attributeName": "Investment.industry",
        "generatorPosition": "0",
        "parameterMap": {
          "list": [
            "banking",
            "pharma",
            "retail"
          ]
        }
      }
    }
  ]
}


Rule #2

  • For age 26-40, the investment industries should be banking, pharma, retail, mining, manufacturing, oil, motor insurance.


The GEN_VALUE is generated value from ListGen Generator in Then Actions Section.


API Request Parameters for Rule #2

{
  "api": [
    {
      "methodName": "generatorParametersSet",
      "parameters": {
        "attributeName": "Investment.age",
        "generatorPosition": "0",
        "parameterMap": {
          "startRange": "26",
          "endRange": "40"
        }
      }
    },
    {
      "methodName": "generatorParametersSet",
      "parameters": {
        "attributeName": "Investment.industry",
        "generatorPosition": "0",
        "parameterMap": {
          "list": [
            "banking",
            "pharma",
            "retail",
            "mining",
            "manufacturing",
            "oil",
            "motor insurance"
          ]
        }
      }
    }
  ]
}


Rule #3

  • For age 41-65, the investment industries should be 50% banking, 28% oil, 22% healthcare 


The GEN_VALUE is generated value from MultiWeightGen Generator in Then Actions Section.

API Request Parameters for Rule #3

{
  "api": [
    {
      "methodName": "generatorParametersSet",
      "parameters": {
        "attributeName": "Investment.age",
        "generatorPosition": "0",
        "parameterMap": {
          "startRange": "41",
          "endRange": "65"
        }
      }
    },
    {
      "methodName": "generatorsRemove",
      "parameters": {
        "attributeName": "Investment.industry"
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.industry",
        "generatorName": "com.genRocket.generator.MultiWeightGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "valueList": [
            "banking",
            "oil",
            "healthcare"
          ],
          "percentList": [
            "50",
            "28",
            "22"
          ],
          "exactPercentage": "True"
        }
      }
    }
  ]
}

Rule #4

  • For other industries than Banking and Oil:
    • If age is 18-25, transactions should be between 150-1000
    • If age is 26-40 it should be 1001-2500
    • If age is 41-65 transaction value should be between 2501-5000
    • If  age 65+ it should be 5001-10000


The GEN_VALUE is generated value from different Linked Generators in the Then Actions Section.


API Request Parameters for Rule #4

{
  "api": [
    {
      "methodName": "generatorsRemove",
      "parameters": {
        "attributeName": "Investment.transaction"
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "150",
          "endRange": "1000"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "1001",
          "endRange": "2500"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "2501",
          "endRange": "5000"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "5001",
          "endRange": "10000"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.EvalCaseActionGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "var1": "#{Investment.age}",
          "default": "0",
          "caseList": [
            "(var1 >= 18) && (var1 <= 25)",
            "(var1 >= 26) && (var1 <= 40)",
            "(var1 >= 41) && (var1 <= 65)",
            "var1 > 65"
          ],
          "actionList": [
            "#{self.Investment.transaction.gen1}",
            "#{self.Investment.transaction.gen2}",
            "#{self.Investment.transaction.gen3}",
            "#{self.Investment.transaction.gen4}"
          ]
        }
      }
    }
  ]
}


Rule #5

For banking and oil industry:

  • If the age is 18-25, transactions should be between 50-500.


The GEN_VALUE is generated value from RandomGen Generator in Then Actions Section.


Rule #6

  • For banking and oil industry:
    • If the age is 18-25, transactions should be between 50-500.


The GEN_VALUE is generated value from RandomGen Generator in Then Actions Section.

Rule #7

  • For banking and oil:
    • If age is 41+ it should be 2000-8000


The GEN_VALUE is generated value from RandomGen Generator in Then Actions Section.


API Request Parameters for Rule #5, Rule #6 & Rule #7 (Rule #4 Contd..

{
  "api": [
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "50",
          "endRange": "500"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "150",
          "endRange": "1000"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.RandomGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "startRange": "2000",
          "endRange": "8000"
        }
      }
    },
    {
      "methodName": "generatorAdd",
      "parameters": {
        "attributeName": "Investment.transaction",
        "generatorName": "com.genRocket.generator.EvalCaseActionGen",
        "setLoop": false,
        "requiredGeneratorParameters": {
          "var1": "#{Investment.age}",
          "var2": "#{Investment.industry}",
          "default": "#{self.Investment.transaction.gen5}",
          "caseList": [
            "( var1 == 'banking' OR var1 == 'oil' AND var2 >= 18 AND var2 <= 25 )",
            "( var1 == 'banking' OR var1 == 'oil' AND var2 >= 26 AND var2 <= 40 )",
            "( var1 == 'banking' OR var1 == 'oil' AND var2 >= 41 )"
          ],
          "actionList": [
            "#{self.Investment.transaction.gen6}",
            "#{self.Investment.transaction.gen7}",
            "#{self.Investment.transaction.gen8}"
          ]
        }
      }
    }
  ]
}


Sample Output


generatorPosition Parameter

The generatorPosition parameter starts at 0 (zero) against the Attribute Generator or Linked Generators, as shown below: