PathMemory rtn1Rs = (PathMemory) wm.getNodeMemory( rtn1 );
PathMemory rtn2Rs = (PathMemory) wm.getNodeMemory( rtn2 );
PathMemory rtn3Rs = (PathMemory) wm.getNodeMemory( rtn3 );
DefaultFactHandle f1 = (DefaultFactHandle) wm.insert( "test1" );
lian.assertObject( f1, context, wm );
n1.assertObject( f1, context, wm );
n3.assertObject( f1, context, wm );
n4.assertObject( f1, context, wm );
n8.assertObject( f1, context, wm );
assertFalse( rtn1Rs.isRuleLinked() );
assertFalse( rtn2Rs.isRuleLinked() );
assertFalse( rtn3Rs.isRuleLinked() );
// Link in Rule1
bm = (BetaMemory) wm.getNodeMemory( n2 );
assertFalse( bm.getSegmentMemory().isSegmentLinked() );
DefaultFactHandle f2 = (DefaultFactHandle) wm.insert( "test2" );
n2.assertObject( f2, context, wm );
assertTrue( bm.getSegmentMemory().isSegmentLinked() );
assertTrue( rtn1Rs.isRuleLinked() );
assertFalse( rtn2Rs.isRuleLinked() );
assertFalse( rtn3Rs.isRuleLinked() );
// Link in Rule2
bm = (BetaMemory) wm.getNodeMemory( n5 );
assertFalse( bm.getSegmentMemory().isSegmentLinked() );
n5.assertObject( f1, context, wm );
assertTrue( bm.getSegmentMemory().isSegmentLinked() );
assertTrue( rtn1Rs.isRuleLinked() );
assertTrue( rtn2Rs.isRuleLinked() );
assertFalse( rtn3Rs.isRuleLinked() );
// Link in Rule3
n6.assertObject( f1, context, wm );
n7.assertObject( f1, context, wm );
assertTrue( bm.getSegmentMemory().isSegmentLinked() );
assertTrue( rtn1Rs.isRuleLinked() );
assertTrue( rtn2Rs.isRuleLinked() );
assertTrue( rtn3Rs.isRuleLinked() );
// retract n2, should unlink all rules
n2.retractRightTuple( f2.getFirstRightTuple(), context, wm );
assertFalse( rtn1Rs.isRuleLinked() );
assertFalse( rtn2Rs.isRuleLinked() );
assertFalse( rtn3Rs.isRuleLinked() );
}