public void testSegmentNodeReferencesToSegments() {
setUp( JOIN_NODE );
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kconf.setOption( RuleEngineOption.PHREAK );
AbstractWorkingMemory wm = new AbstractWorkingMemory( 1, (ReteooRuleBase) RuleBaseFactory.newRuleBase((RuleBaseConfiguration)kconf) );
BetaMemory bm = null;
List<PathMemory> list;
PathMemory rtn1Rs = (PathMemory) wm.getNodeMemory( rtn1 );
PathMemory rtn2Rs = (PathMemory) wm.getNodeMemory( rtn2 );
PathMemory rtn3Rs = (PathMemory) wm.getNodeMemory( rtn3 );
// lian
SegmentUtilities.createSegmentMemory( lian, wm );
LeftInputAdapterNode.LiaNodeMemory lmem = (LeftInputAdapterNode.LiaNodeMemory) wm.getNodeMemory( lian );
assertEquals( 1, lmem.getNodePosMaskBit() );
// n1
SegmentUtilities.createSegmentMemory( n1, wm );
bm = (BetaMemory) wm.getNodeMemory( n1 );
assertEquals( 2, bm.getNodePosMaskBit() );
assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 1, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 3, list.size());
assertTrue( list.contains( rtn1Rs ) );
assertTrue( list.contains( rtn2Rs ) );
assertTrue( list.contains( rtn3Rs ) );
// n2
bm = (BetaMemory) wm.getNodeMemory( n2 );
assertEquals( 4, bm.getNodePosMaskBit() );
assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 1, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 3, list.size());
assertTrue( list.contains( rtn1Rs ) );
assertTrue( list.contains( rtn2Rs ) );
assertTrue( list.contains( rtn3Rs ) );
// n3
bm = (BetaMemory) wm.getNodeMemory( n3 );
assertEquals( 8, bm.getNodePosMaskBit() );
assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 1, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 3, list.size());
assertTrue( list.contains( rtn1Rs ) );
assertTrue( list.contains( rtn2Rs ) );
assertTrue( list.contains( rtn3Rs ) );
// n4
SegmentUtilities.createSegmentMemory( n4, wm );
bm = (BetaMemory) wm.getNodeMemory( n4 );
assertEquals( 1, bm.getNodePosMaskBit() );
assertEquals( 3, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 2, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 2, list.size());
assertTrue( list.contains( rtn2Rs ) );
assertTrue( list.contains( rtn3Rs ) );
// n5
bm = (BetaMemory) wm.getNodeMemory( n5 );
assertEquals( 2, bm.getNodePosMaskBit() );
assertEquals( 3, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 2, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 2, list.size());
assertTrue( list.contains( rtn2Rs ) );
assertTrue( list.contains( rtn3Rs ) );
// n6
SegmentUtilities.createSegmentMemory( n6, wm );
bm = (BetaMemory) wm.getNodeMemory( n6 );
assertEquals( 1, bm.getNodePosMaskBit() );
assertEquals( 7, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 4, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 1, list.size());
assertTrue( list.contains( rtn3Rs ) );
// n7
bm = (BetaMemory) wm.getNodeMemory( n7 );
assertEquals( 2, bm.getNodePosMaskBit() );
assertEquals( 7, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 4, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 1, list.size());
assertTrue( list.contains( rtn3Rs ) );
// n8
bm = (BetaMemory) wm.getNodeMemory( n8 );
assertEquals( 4, bm.getNodePosMaskBit() );
assertEquals( 7, bm.getSegmentMemory().getAllLinkedMaskTest() );
assertEquals( 4, bm.getSegmentMemory().getSegmentPosMaskBit() );
list = bm.getSegmentMemory().getPathMemories();
assertEquals( 1, list.size());