}
public void testSequentialAgenda() {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setSequential( true );
InternalRuleBase ruleBase = ( InternalRuleBase ) RuleBaseFactory.newRuleBase( conf );
// create the consequence
final Consequence consequence = new Consequence() {
/**
*
*/
private static final long serialVersionUID = 400L;
public void evaluate(KnowledgeHelper knowledgeHelper,
WorkingMemory workingMemory) {
// do nothing
}
};
final ReteTuple tuple = new ReteTuple( new DefaultFactHandle( 1,
"cheese" ) );
// create a rule for each agendaGroup
final Rule rule0 = new Rule( "test-rule0" );
final RuleTerminalNode node0 = new RuleTerminalNode( 3,
new MockTupleSource( 2 ),
rule0,
rule0.getLhs() );
node0.setSequence( 72 );
rule0.setConsequence( consequence );
final PropagationContext context0 = new PropagationContextImpl( 0,
PropagationContext.ASSERTION,
rule0,
null );
final Rule rule1 = new Rule( "test-rule1",
"agendaGroup1" );
final RuleTerminalNode node1 = new RuleTerminalNode( 5,
new MockTupleSource( 4 ),
rule1,
rule1.getLhs() );
node1.setSequence( 10 );
rule1.setConsequence( consequence );
final PropagationContext context1 = new PropagationContextImpl( 0,
PropagationContext.ASSERTION,
rule1,
null );
final Rule rule2 = new Rule( "test-rule2",
"agendaGroup1" );
final RuleTerminalNode node2 = new RuleTerminalNode( 7,
new MockTupleSource( 6 ),
rule2,
rule2.getLhs() );
node2.setSequence( 7 );
rule2.setConsequence( consequence );
final PropagationContext context2 = new PropagationContextImpl( 0,
PropagationContext.ASSERTION,
rule2,
null );
final Rule rule3 = new Rule( "test-rule3",
"agendaGroup2" );
final RuleTerminalNode node3 = new RuleTerminalNode( 9,
new MockTupleSource( 8 ),
rule3,
rule3.getLhs() );
node3.setSequence( 0 );
rule3.setConsequence( consequence );
final PropagationContext context3 = new PropagationContextImpl( 0,
PropagationContext.ASSERTION,
rule3,
null );
ruleBase.getAgendaGroupRuleTotals().put( "MAIN", new Integer( 100 ) );
ruleBase.getAgendaGroupRuleTotals().put( "agendaGroup1", new Integer( 10 ) );
ruleBase.getAgendaGroupRuleTotals().put( "agendaGroup2", new Integer( 1 ) );
InternalWorkingMemory workingMemory = new ReteooWorkingMemory(0, ruleBase);
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();