PropagationContext.INSERTION,
rule0,
null,
new DefaultFactHandle() );
final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
final RuleFlowGroup ruleFlowGroup1 = agenda.getRuleFlowGroup( "rule-flow-group-1" );
final RuleFlowGroup ruleFlowGroup2 = agenda.getRuleFlowGroup( "rule-flow-group-2" );
final LeftTupleImpl tuple0 = new LeftTupleImpl( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node0.assertLeftTuple( tuple0,
context0,
workingMemory );
final LeftTupleImpl tuple1 = new LeftTupleImpl( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node0.assertLeftTuple( tuple1,
context0,
workingMemory );
final LeftTupleImpl tuple2 = new LeftTupleImpl( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node1.assertLeftTuple( tuple2,
context0,
workingMemory );
final LeftTupleImpl tuple3 = new LeftTupleImpl( new DefaultFactHandle( 1,
"cheese" ),
null,
true );
node2.assertLeftTuple( tuple3,
context0,
workingMemory );
agenda.unstageActivations();
// RuleFlowGroups should be populated, but the agenda shouldn't be
assertEquals( 2,
ruleFlowGroup0.size() );
assertEquals( 1,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 0,
agenda.agendaSize() );
// Activate the RuleFlowGroup, the nodes stay in the group, but should now also be in the Agenda
agenda.activateRuleFlowGroup( "rule-flow-group-0" );
assertEquals( 2,
ruleFlowGroup0.size() );
assertEquals( 2,
agenda.agendaSize() );
// As we fire each rule they are removed from both the Agenda and the RuleFlowGroup
agenda.fireNextItem( null );
assertEquals( 1,
ruleFlowGroup0.size() );
assertEquals( 1,
agenda.agendaSize() );
// After firing all activations of RuleFlowGroup 0, the agenda is empty
agenda.fireNextItem( null );
assertEquals( 0,
ruleFlowGroup0.size() );
assertEquals( 0,
agenda.agendaSize() );
// Now we activate two RuleFlowGroups together
// All their activations should be added to the agenda.
agenda.activateRuleFlowGroup( "rule-flow-group-1" );
agenda.activateRuleFlowGroup( "rule-flow-group-2" );
assertEquals( 1,
ruleFlowGroup1.size() );
assertEquals( 1,
ruleFlowGroup2.size() );
assertEquals( 2,
agenda.agendaSize() );
// we set the salience higher on rule2, so it sould fire first and empty ruleFlowGroup2
agenda.fireNextItem( null );
assertEquals( 1,
ruleFlowGroup1.size() );
assertEquals( 0,
ruleFlowGroup2.size() );
assertEquals( 1,
agenda.agendaSize() );
// this is the last activation, so everything should be empty after this
agenda.fireNextItem( null );
assertEquals( 0,
ruleFlowGroup0.size() );
assertEquals( 0,
ruleFlowGroup1.size() );
assertEquals( 0,
ruleFlowGroup2.size() );
assertEquals( 0,
agenda.agendaSize() );
}