list );
// Adding person in advance. There is no Person() object
// type node in memory yet, but the rule engine is supposed
// to handle that correctly
final PersonInterface bob = new Person( "bob",
"stilton" );
bob.setStatus( "Not evaluated" );
workingMemory.insert( bob );
final Cheese stilton = new Cheese( "stilton",
5 );
workingMemory.insert( stilton );
final Cheese cheddar = new Cheese( "cheddar",
5 );
workingMemory.insert( cheddar );
workingMemory.fireAllRules();
assertEquals( 1,
list.size() );
assertEquals( "stilton",
list.get( 0 ) );
reader = new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic2.drl" ) );
builder = new PackageBuilder();
builder.addPackageFromDrl( reader );
final Package pkg2 = serialisePackage( builder.getPackage() );
ruleBase.addPackage( pkg2 );
assertEquals( 3,
list.size() );
assertEquals( "stilton",
list.get( 0 ) );
assertTrue( "cheddar".equals( list.get( 1 ) ) || "cheddar".equals( list.get( 2 ) ) );
assertTrue( "stilton".equals( list.get( 1 ) ) || "stilton".equals( list.get( 2 ) ) );
list.clear();
reader = new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic3.drl" ) );
builder = new PackageBuilder();
builder.addPackageFromDrl( reader );
final Package pkg3 = serialisePackage( builder.getPackage() );
ruleBase.addPackage( pkg3 );
// Package 3 has a rule working on Person instances.
// As we added person instance in advance, rule should fire now
Assert.assertEquals( "Rule from package 3 should have been fired",
"match Person ok",
bob.getStatus() );
assertEquals( 1,
list.size() );
assertEquals( bob,
list.get( 0 ) );
reader = new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic4.drl" ) );
builder = new PackageBuilder();
builder.addPackageFromDrl( reader );
final Package pkg4 = serialisePackage( builder.getPackage() );
ruleBase.addPackage( pkg4 );
Assert.assertEquals( "Rule from package 4 should have been fired",
"Who likes Stilton ok",
bob.getStatus() );
assertEquals( 2,
list.size() );
assertEquals( bob,