allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(true));
allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(true));
}} );
// setup 2 tuples 3 fact handles
final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.insert( "test0" );
this.node.assertObject( f0,
this.context,
this.workingMemory );
final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.insert( "test1" );
final LeftTuple tuple1 = new LeftTuple( f1,
this.node,
true );
this.node.assertLeftTuple( tuple1,
this.context,
this.workingMemory );
final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( "test2" );
final LeftTuple tuple2 = new LeftTuple( f2,
this.node,
true );
this.node.assertLeftTuple( tuple2,
this.context,
this.workingMemory );
final DefaultFactHandle f3 = (DefaultFactHandle) this.workingMemory.insert( "test3" );
this.node.assertObject( f3,
this.context,
this.workingMemory );
final DefaultFactHandle f4 = (DefaultFactHandle) this.workingMemory.insert( "test4" );
this.node.assertObject( f4,
this.context,
this.workingMemory );
assertLength( 6,
this.sink.getAsserted() );
// Double check the item is in memory
final BetaMemory memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
assertTrue( memory.getRightTupleMemory().contains( f0.getRightTuple() ) );
// Retract an object, check propagations and memory
this.node.retractRightTuple( f0.getRightTuple(),
this.context,
this.workingMemory );
assertLength( 2,
this.sink.getRetracted() );
List tuples = new ArrayList();
tuples.add( ((Object[]) this.sink.getRetracted().get( 0 ))[0] );
tuples.add( ((Object[]) this.sink.getRetracted().get( 1 ))[0] );
assertTrue( tuples.contains( new LeftTuple( tuple1,
f0.getRightTuple(),
this.sink,
true ) ) );
assertTrue( tuples.contains( new LeftTuple( tuple1,
f0.getRightTuple(),
this.sink,
true ) ) );
// Now check the item is no longer in memory
assertFalse( memory.getRightTupleMemory().contains( f0.getRightTuple() ) );
this.node.retractLeftTuple( tuple2,
this.context,
this.workingMemory );
assertEquals( 4,
this.sink.getRetracted().size() );
tuples = new ArrayList();
tuples.add( ((Object[]) this.sink.getRetracted().get( 2 ))[0] );
tuples.add( ((Object[]) this.sink.getRetracted().get( 3 ))[0] );
assertTrue( tuples.contains( new LeftTuple( tuple2,
f3.getRightTuple(),
this.sink,
true ) ) );
assertTrue( tuples.contains( new LeftTuple( tuple2,
f4.getRightTuple(),
this.sink,
true ) ) );
}