final Package pkg = builder.getPackage();
RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
ruleBase = SerializationHelper.serializeObject( ruleBase );
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
final List<String> list = new ArrayList<String>();
workingMemory.setGlobal( "list",
list );
final List<Activation> activations = new ArrayList<Activation>();
AgendaEventListener listener = new DefaultAgendaEventListener() {
public void activationCancelled(ActivationCancelledEvent event,
WorkingMemory workingMemory) {
activations.add( event.getActivation() );
}
};
workingMemory.addEventListener( listener );
DefaultAgenda agenda = (DefaultAgenda) workingMemory.getAgenda();
assertEquals( 0,
agenda.getRuleFlowGroup( "flowgroup-1" ).size() );
// We need to call fireAllRules here to get the InitialFact into the system, to the eval(true)'s kick in
workingMemory.fireAllRules();
// Now we have 4 in the RuleFlow, but not yet in the agenda
assertEquals( 4,
agenda.getRuleFlowGroup( "flowgroup-1" ).size() );
// Check they aren't in the Agenda
assertEquals( 0,
agenda.getAgendaGroup( "MAIN" ).size() );
// Start the process, which shoudl populate the Agenda
workingMemory.startProcess( "ruleFlowClear" );
assertEquals( 4,
agenda.getAgendaGroup( "MAIN" ).size() );
// Check we have 0 activation cancellation events
assertEquals( 0,
activations.size() );
workingMemory.getAgenda().clearAndCancelRuleFlowGroup( "flowgroup-1" );
// Check the AgendaGroup and RuleFlowGroup are now empty
assertEquals( 0,
agenda.getAgendaGroup( "MAIN" ).size() );
assertEquals( 0,