List list = new ArrayList();
session.setGlobal( "list",
list );
final Cheese mycheese = new Cheese( "cheddar",
4 );
FactHandle handle = session.insert( mycheese );
session.fireAllRules();
assertEquals( 2,
list.size() );
assertEquals( "rule 4",
list.get( 0 ) );
assertEquals( "rule 2b",
list.get( 1 ) );
//Test 2nd level (parent) to make sure rule honors the extend rule
list = new ArrayList();
session.setGlobal( "list",
list );
session.retract( handle );
final Cheese mycheese2 = new Cheese( "notcheddar",
4 );
FactHandle handle2 = session.insert( mycheese2 );
session.fireAllRules();
assertEquals( "rule 4",
list.get( 0 ) );
assertEquals( 1,
list.size() );
//Test 3 levels of inheritance, all levels
list = new ArrayList();
session.setGlobal( "list",
list );
session.retract( handle2 );
final Cheese mycheese3 = new Cheese( "stilton",
6 );
FactHandle handle3 = session.insert( mycheese3 );
session.fireAllRules();
//System.out.println(list.toString());
assertEquals( "rule 3",
list.get( 0 ) );
assertEquals( 1,
list.size() );
//Test 3 levels of inheritance, third only
list = new ArrayList();
session.setGlobal( "list",
list );
session.retract( handle3 );
final Cheese mycheese4 = new Cheese( "notstilton",
6 );
FactHandle handle4 = session.insert( mycheese4 );
session.fireAllRules();
//System.out.println(((List) session.getGlobal( "list" )).toString());
assertTrue( ((List) session.getGlobal( "list" )).size() == 0 );
//Test 3 levels of inheritance, 2nd only
list = new ArrayList();
session.setGlobal( "list",
list );
session.retract( handle4 );
final Cheese mycheese5 = new Cheese( "stilton",
7 );
FactHandle handle5 = session.insert( mycheese5 );
session.fireAllRules();
//System.out.println(((List) session.getGlobal( "list" )).toString());
assertEquals( 0,
list.size() );