any( InternalFactHandle.class ) ) ).thenReturn( true );
when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ),
any( ContextEntry.class ) ) ).thenReturn( 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 LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true );
this.node.assertLeftTuple( tuple1,
this.context,
this.workingMemory );
final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory
.insert( "test2" );
final LeftTupleImpl tuple2 = new LeftTupleImpl( 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.getFirstRightTuple() ) );
// Retract an object, check propagations and memory
this.node.retractRightTuple( f0.getFirstRightTuple(),
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 LeftTupleImpl( tuple1, f0
.getFirstRightTuple(), this.sink, true ) ) );
assertTrue( tuples.contains( new LeftTupleImpl( tuple1, f0
.getFirstRightTuple(), this.sink, true ) ) );
// Now check the item is no longer in memory
assertFalse( memory.getRightTupleMemory().contains(
f0.getFirstRightTuple() ) );
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 LeftTupleImpl( tuple2, f3
.getFirstRightTuple(), this.sink, true ) ) );
assertTrue( tuples.contains( new LeftTupleImpl( tuple2, f4
.getFirstRightTuple(), this.sink, true ) ) );
}