rule1.getLhs(),
0,
buildContext );
final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
final Consequence consequence = new Consequence() {
private static final long serialVersionUID = 510l;
public void evaluate(KnowledgeHelper knowledgeHelper,
WorkingMemory workingMemory) {
LinkedList< LogicalDependency > list = ((DefaultKnowledgeHelper)knowledgeHelper).getpreviousJustified();
if ( list != null ) {
for ( SimpleLogicalDependency dep = ( SimpleLogicalDependency ) list.getFirst(); dep != null; dep = ( SimpleLogicalDependency ) dep.getNext() ){
knowledgeHelper.insertLogical( dep.getObject(), dep.getValue() );
}
}
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
public String getName() {
return "default";
}
};
rule1.setConsequence( consequence );
final DefaultFactHandle handle1 = (DefaultFactHandle) workingMemory.insert( "o1" );
final LeftTupleImpl tuple1 = new LeftTupleImpl( handle1,
null,
true );
final PropagationContext context1 = new PropagationContextImpl( 0,
PropagationContext.INSERTION,
null,
null,
new DefaultFactHandle() );
// Test single activation for a single logical assertions
node.assertLeftTuple( tuple1,
context1,
workingMemory );
final String logicalString = new String( "logical" );
InternalFactHandle logicalHandle = (InternalFactHandle) workingMemory.insert( logicalString,
null,
false,
true,
rule1,
(Activation) tuple1.getObject() );
new RightTuple( logicalHandle,
sink );
context1.setFactHandle( handle1 );
// Retract the tuple and test the logically asserted fact was also retracted
node.retractLeftTuple( tuple1,
context1,
workingMemory );
workingMemory.executeQueuedActions();
assertLength( 1,
sink.getRetracted() );
Object[] values = (Object[]) sink.getRetracted().get( 0 );
assertSame( logicalHandle,
((RightTuple) values[0]).getFactHandle() );
// Test single activation for a single logical assertions. This also
// tests that logical assertions live on after the related Activation
// has fired.
node.assertLeftTuple( tuple1,
context1,
workingMemory );
logicalHandle = (InternalFactHandle) workingMemory.insert( logicalString,
null,
false,
true,
rule1,
(Activation) tuple1.getObject() );
new RightTuple( logicalHandle,
sink );
agenda.fireNextItem( null );
node.retractLeftTuple( tuple1,
context1,
workingMemory );