Lab 09 - Create Test Scenarios
Lab Goal
To create test scenarios to validate our rules, events, and process for the Cool Store
Creating Test Scenarios
- Designing rules, events, and process has completed
- Now it is time to test what we have created
- JBoss BRMS provides you with an online test scenario creation
- 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...
Creating Test Scenarios
- Design a test to validate our Domain Specific Language (DSL)
- Our 'Guided Rule with DSL' is about giving free shipping
Free Shipping Promotion DSL Test:
- if the shopping cart total value is $75 or more, free shipping
Creating Test Scenarios
- We will create a new test scenario
AUTHORING -> PROJECT AUTHORING -> NEW ITEM -> TEST SCENARIO
RESOURCE NAME: Free Shipping Promotion DSL Test
Creating Test Scenarios
- Tab at bottom of test scenario to access designers:
'Test Scenario'
- editor for test designer
'Config'
- editor to manage test data model
Creating Test Scenarios
- First we need to add a Shopping Cart object to populate our test
- using the 'Config' tab, we add the object
- click on the'NEW ITEM' button
- select 'ShoppingCart' from the menu
- select 'OK'
Creating Test Scenarios
- Now in Test Scenario tab we focus on these sections:
'Given'
- define input fact objects
'Expect'
- define method to call on given fact objects
Creating Test Scenarios
- Provide the tests given fact objects
- Click on 'GIVEN' button in left top corner
- assign field 'Activate rule flow group: promo-rules'
- click on'ADD' button next to field
Creating Test Scenarios
- 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
Creating Test Scenarios
- Add cartItemTotal & shippingTotal fields to shopping cart ($sc1):
- click on
'Add a field'
to '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
Creating Test Scenarios
- Add values to cartItemTotal & shippingTotal fields to shopping cart ($sc1):
- click on pencil icon to add
'Literal value'
to 'cartItemTotal'
- enter values of 75
- click on pencil icon to add
'Literal value'
to 'shippingTotal'
- enter values of 10.99
Creating Test Scenarios
- Add a second shopping cart ($sc2) with following fields & values:
'cartItemTotal'
with a value of 74.99
'shippingTotal'
with a value of 10.99
Creating Test Scenarios
- Detail what we expect as the outcome of our test:
- click on
'+EXPECT'
- we want to add a rule expected to fire
- select from right menu,
'Free Shipping Promotion DSL'
- click on
'OK'
- Now restrict rule to just one time
Creating Test Scenarios
- Now we have an expectation as to the outcome of first shopping cart ($sc1)
- click on
'+EXPECT'
- select from
'Fact value:'
menu, '$sc1'
- click on
'Add'
Creating Test Scenarios
- Then add field
'shippingTotal'
by clicking little green arrow icon
- add field
'shippingTotal'
- click on
'OK'
- as shopping cart value is
75
, expect value of 0.0
Creating Test Scenarios
- Now put in our expectation for the second shopping cart ($sc2)
- add the fact
'$sc2'
- add field
'shippingTotal'
- as shopping cart value is
74.99
, expect value of 10.99
(see decision table)
Creating Test Scenarios
- We can now save and run our test scenario:
- ensure configuration set to
'All rules may fire'
- click on
'Save'
button and 'Run scenario'
- looking for green
'Success'
in 'Report'
pane, otherwise fix test
Creating Test Scenarios
- Note that there is little feedback on test failures
- This makes finding problems difficult at this time
- Strong hint is to design a test at a time
- if test works, move to next test
- run
'All Test Scenarios'
when more tests available
- ensures no breakage of other tests in suite
Creating Test Scenarios
- Save your test scenario each time you create a new one
- Also ensure your package builds:
TOOLS -> PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
Creating Test Scenarios
- Now create each of the following tests
Shipping Rules Test - One Cart
Shipping Rules Test
Total Shopping Cart Items Test
Total Shopping Cart Test
Creating Test Scenarios
- Outline for
Shipping Rules Test - One Cart
test:
- use
shipping-rules
as rule flow group
- 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
- (continued on next slide...)
Creating Test Scenarios
- Use the
MORE
button to extend this test
- Given:
- modify and existing fact
ShoppingCart [$sc]
- set
cartItemTotal
to 24.00
& shippingTotal
to 0.0
- Expect:
- expect rules
Row 1 Shipping Rules
to fire just 1
time
ShoppingCart [$sc]
has shippingTotal
value of 2.99
- (continued on next slide...)
Creating Test Scenarios
- Add each of these test (use images) of the test using `MORE` button:
- (continued on next slide...)
Creating Test Scenarios
- Add each of these test (use images) of the test using `MORE` button
- then save and run the test
Creating Test Scenarios
- Outline for
Shipping Rules Test
test:
- use
shipping-rules
as rule flow group
- add
ShoppingCart
data object
- Given:
- add
ShoppingCart ($sc1)
through ShoppingCart ($sc9)
- add
cartItemTotal
with values 0.00
, 24.99
, 25
, 49.99
, 50
, 74.99
, 75
, 99.99
, 100
Creating Test Scenarios
- Expect:
- setup rules to fire as shown in image below
Creating Test Scenarios
- Finish the Expect section:
- the carts $sc1 through $sc9 to have the results as show in image below
- save and test rule
Creating Test Scenarios
- Outline for
Total Shopping Cart Items Test
test:
- use
pricing-rules
as rule flow group
- add
ShoppingCart
and ShoppingCartItems
data objects
- Given:
- setup given section of this rule based on image below
Creating Test Scenarios
- Outline for
Total Shopping Cart Items Test
test:
- Expect:
- setup given section of this rule based on image below
Creating Test Scenarios
Total Shopping Cart Test
test:
- use
total-rules
as rule flow group
- add
ShoppingCart
data object
- Given:
- setup given section of this rule based on image below
Creating Test Scenarios
Total Shopping Cart Test
test:
- Expect:
- setup given section of this rule based on image below
Creating Test Scenarios
- Run the
'Total Shopping Cart Test'
test, it fails!? fix it! :-)
Creating Test Scenarios
- Now all test scenarios are finished
- Also ensure your package builds:
TOOLS -> PROJECT EDITOR -> BUILD & DEPLOY
(should see green pop-up 'Build Successful')
- JBoss BRMS & BPM Suite Articles
- JBoss BPM Suite Demos
- JBoss bpmPaaS Demos