RuleBase ruleBase = new RuleBaseImpl( new Rete( ) );
WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory( );
final Agenda agenda = workingMemory.getAgenda( );
final Rule rule = new Rule( "test-rule" );
// add consequence
rule.setConsequence( new org.drools.spi.Consequence( )
{
public void invoke(org.drools.spi.Tuple tuple)
{
agenda.addToAgenda( (ReteTuple) tuple,
rule );
}
} );
ReteTuple tuple = new ReteTuple( workingMemory );
assertEquals( 0,
agenda.size( ) );
/*
* Add to agenda
*/
rule.setNoLoop( false );
agenda.addToAgenda( tuple,
rule );
assertEquals( 1,
agenda.size( ) );
agenda.fireNextItem( null );
assertEquals( 1,
agenda.size( ) );
agenda.clearAgenda( );
/*
* True filter, activations should always add
*/
AgendaFilter filterTrue = new AgendaFilter( )
{
public boolean accept(Activation item)
{
return true;
}
};
rule.setNoLoop( false );
agenda.addToAgenda( tuple,
rule );
assertEquals( 1,
agenda.size( ) );
agenda.fireNextItem( filterTrue );
assertEquals( 1,
agenda.size( ) );
agenda.clearAgenda( );
/*
* False filter, activations should always be denied
*/
AgendaFilter filterFalse = new AgendaFilter( )
{
public boolean accept(Activation item)
{
return false;
}
};
rule.setNoLoop( false );
agenda.addToAgenda( tuple,
rule );
assertEquals( 1,
agenda.size( ) );
agenda.fireNextItem( filterFalse );