final Package pkg = builder.getPackage();
RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
ruleBase = SerializationHelper.serializeObject(ruleBase);
StatefulSession workingMemory = ruleBase.newStatefulSession();
List list;
final Person a = new Person( "a" );
final Cheese cheese = new Cheese( "brie",
1 );
workingMemory.setGlobal( "cheese",
cheese );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
list = IteratorToList.convert( workingMemory.iterateObjects() );
assertEquals( "i was not asserted by not a => i.",
1,
list.size() );
assertEquals( "i was not asserted by not a => i.",
cheese,
list.get( 0 ) );
FactHandle h = workingMemory.insert( a );
workingMemory = getSerialisedStatefulSession( workingMemory );
// no need to fire rules, assertion alone removes justification for i,
// so it should be retracted.
// workingMemory.fireAllRules();
list = IteratorToList.convert( workingMemory.iterateObjects() );
assertEquals( "a was not asserted or i not retracted.",
1,
list.size() );
assertEquals( "a was asserted.",
a,
list.get( 0 ) );
assertFalse( "i was not rectracted.",
list.contains( cheese ) );
// no rules should fire, but nevertheless...
// workingMemory.fireAllRules();
assertEquals( "agenda should be empty.",
0,
workingMemory.getAgenda().agendaSize() );
h = getFactHandle( h, workingMemory );
workingMemory.retract( h );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
list = IteratorToList.convert( workingMemory.iterateObjects() );
assertEquals( "i was not asserted by not a => i.",
1,
list.size() );
assertEquals( "i was not asserted by not a => i.",
cheese,