Designing your first test scenarios

Designing the web shop rules and rule flow process has completed. Now it is time to test what you've have created to validate before putting it into production using the Decision Manager's test suite:

  • we will guide you through the first test
  • you will design a few more based on detailed descriptions
  • extra credit if you come up with more tests!

Free Shipping Promotion Test - Create first test

First, let's create a new test scenario for our Domain Specific Language (DSL) rule. Click on ADD ASSET -> TEST SCENARIO (LEGACY) for pop-up:
  • Design a test to validate our Domain Specific Language (DSL)
  • Our 'Guided Rule with DSL' is about giving free shipping
  • TEST SCENARIO: Free Shipping Promotion DSL Test
  • Fill in package as shown
  • Click on +OK to create test

Free Shipping Promotion Test - Free shipping over $75

Design a test to validate our DSL as follows:
  • if the shopping cart total value is $75 or more, free shipping
  • we have an empty test now in front of us
  • open tab 'Data Objects' to verify availability of our model

Free Shipping Promotion Test - Add data model

Add the data model objects (4x) for our test, using +NEW ITEM button until looks as shown:

Free Shipping Promotion Test - Given and expected

Now in Test Scenario tab we focus on these sections:

  • Given - define input fact objects
  • Expect - define method to call on given fact objects

Free Shipping Promotion Test - Given rules

Provide the test a given fact object:
  • Click on +GIVEN button in left top corner
  • assign field Activate rule flow group: promo-rules
  • click on ADD button next to field

Free Shipping Promotion Test - Adding a cart

Provide the test a given fact object:
  • Click on +GIVEN button in left top corner
  • assign field Insert a new fact: ShoppingCart
  • assign field Fact name: $sc1
  • click on ADD button next to field

Free Shipping Promotion Test - Add two fields

Adding two fields to shopping cart ($sc1):
  • click on Add a field for ShoppingCart[$sc1]
  • using menu, select cartItemTotal and click on +OK button
  • click on ShoppingCart[$sc1] to add a second field
  • using menu, select shippingTotal and click on +OK button

Free Shipping Promotion Test - Assign values to fields

Add values to both fields in shopping cart ($sc1):
  • click on pencil icon to add Literal value to cartItemTotal
  • enter values of 75
  • repeat to add Literal value to shippingTotal
  • enter values of 10.99

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • This is how it should look so far:

Free Shipping Promotion Test - Adding second cart

Add a second shopping cart ($sc2) with following fields and values:
  • cartItemTotal with a value of 74.99
  • shippingTotal with a value of 10.99
  • Note that fields already exist and can be used for new values for $sc2

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • This is how it should look so far:

Free Shipping Promotion Test - Expect section

Now let's define what we expect as the outcome of our tests:
  • click on +EXPECT
  • we want to add a rule expected to fire
  • insert this RULE: Free Shipping Promotion DSL
  • click on OK

Free Shipping Promotion Test - Expect cart 1

Now we need an expectation as to the outcome of the first shopping cart ($sc1):
  • click on +EXPECT
  • select from Fact value: $sc1
  • click on Add

Free Shipping Promotion Test - Expect cart 1 values

Then add field and set to the expected value of shipping total:
  • click on ShoppingCart $sc1
  • add field shippingTotal
  • click on +OK
  • as shopping cart value is 75 we expect value of 0

Free Shipping Promotion Test - Expect cart 2

Add expectation for the outcome of the second shopping cart ($sc2):
  • add the fact $sc2
  • add field shippingTotal
  • as shopping cart value is 74.99 we expect value of 10.99

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • This is how it should look so far:

Running test scenarios

We can now run our test scenario:
  • ensure under tab Settings that All rules may fire
  • click on Run scenario button in top right
  • want Test Results: Passed in Test Report pane

More testing output

Also note test output in Model tab:
  • looking for blue 100% passed in Test Report pane
  • EXPECT section validate results are marked with green check

Testing failures and tips

Note that there is little feedback on test failures, this makes finding problems difficult at this time. Strong hint is to design tests a step at a time and validate by running:
  • if test works, move to next test
  • unable to run 'All Test Scenarios' when more tests available
  • have to run each tests in suite

Create four more tests

Create each of the following tests with less guidance:
  • Shipping Rules - One Cart Test
  • Shipping Rules Test
  • Total Shopping Cart Items Test
  • Total Shopping Cart Test

One Cart Test - Shipping 2.99

Outline for Shipping Rules - One Cart Test:
  • Add all four data objects in tab Data Objects
  • use shipping-rules as rule flow group and default package
  • add ShoppingCart data object
  • Given:
    • ShoppingCart ($sc) with cartItemTotal of 0.00
  • Expect:
    • expect rules Row 1 Shipping Rules to fire just 1 time
    • ShoppingCart [$sc] has shippingTotal value of 2.99

Verify results on next slide...

One Cart Test - Verify shipping 2.99

One Cart Test - Extend shipping 2.99

Use the MORE button to extend this test:
  • Given:
    • modify existing fact ShoppingCart [$sc]
    • set cartItemTotal to 24.00 & shippingTotal to 0
  • Expect:
    • expect rules Row 1 Shipping Rules to fire just 1 time
    • ShoppingCart [$sc] has shippingTotal value of 2.99

Verify results on next slide...

Shipping rules - verify extended one cart test

One Cart Test - Shipping 4.99 and 6.99

You've started to notice this is going to be a long test scenario, so the next test sections you create are based on the following images, using the MORE button, then save, and run the tests to validate:

One Cart Test - Shipping 8.99 and 10.99

Create two more test sections based on following images using MORE button, then save and run the tests to validate:

Shipping Rules Test - Create new test

Create a new test scenario called Shipping Rules Test:
  • add all four data objects in tab Data Objects
  • shipping-rules as rule flow group and default package
  • add ShoppingCart data object
  • Given:
    • add ShoppingCart ($sc1) - ShoppingCart ($sc9)
    • add cartItemTotal with values for each: 0.00, 24.99, 25, 49.99, 50, 74.99, 75, 99.99, 100

Shipping Rules Test - Setup expected rules

Setup EXPECT section as shown below:

Shipping Rules Test - Add expected values

Setup the expected outcome values for each of the fired rules as shown below:

Total Shopping Cart Items - New test

Create a new test scenario Total Shopping Cart Items Test:
  • PACKAGE: com.redhat.demo.retail.retail_webshop
  • use pricing-rules as rule flow group
  • Given:
    • setup given section of this rule based on image below

Total Shopping Cart Items - Setup expect section

Setup EXPECT section as shown below, save and run scenario to validate:

Total Shopping Cart - New test

Create a new test scenario Total Shopping Cart Test:
  • PACKAGE: default
  • use total-rules as rule flow group
  • GIVEN: setup given section of this rule based on image below

Total Shopping Cart - Setup expect section

Setup EXPECT section as shown below, save and run scenario to validate:

Total Shopping Cart - Failure!!!

Run 'Total Shopping Cart Test' test, it fails!? fix it!

Hint: Total shopping cart guided rule is totaling the cart to '0.0' and it should be adding together the shopping cart item total with the shipping total. Fix this by changing the literal field to formula:
  • $sc.cartItemTotal + $sc.shippingTotal

Total Shopping Cart - More failure!!!

After fixing 'Total Shopping Cart' guided rule, run the test scenario:
  • Note it still fails due to a rounding error, so fix by adjusting that field
  • Now the test scenario passes!!!

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
  • This completes the Shipping rules test scenarios

Lab results...

Shipping rules tests - Validate that project builds

Return to Asset view by clicking on retail-webshop project in bread crumb menu at top:
  • click 'Build' button at top
  • note green validation of build

Lab completed - Results

Eric D. Schabell
Portfolio Architect Director
@ericschabell
http://schabell.org
More Red Hat Decision Manager Workshops:

Red Hat Decision Manager Articles:

Red Hat Decision Manager Demos:

Up next...

Lab 10 - Deploying your retail web shop