private BetaNode createBetaNode(int id, int type, LeftTupleSource leftTupleSource) { MockObjectSource mockObjectSource = new MockObjectSource( 8 ); BetaNode betaNode = null; switch ( type ) { case JOIN_NODE : { betaNode = new JoinNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); break; } case EXISTS_NODE : { betaNode = new ExistsNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); break; } case NOT_NODE : { betaNode = new NotNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); break; } } mockObjectSource.attach(buildContext); betaNode.attach(buildContext); return betaNode; }
@Test public void testAttach() throws Exception { when(constraint.isAllowedCachedLeft(any(ContextEntry.class), any(InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true ); final Field objectFfield = ObjectSource.class.getDeclaredField( "sink" ); objectFfield.setAccessible( true ); ObjectSinkPropagator objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource ); final Field tupleField = LeftTupleSource.class.getDeclaredField( "sink" ); tupleField.setAccessible( true ); LeftTupleSinkPropagator tupleSink = (LeftTupleSinkPropagator) tupleField.get( this.tupleSource ); assertEquals( 15, this.node.getId() ); assertNotNull( objectSink ); assertNotNull( tupleSink ); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); BuildContext context = new BuildContext(kBase, kBase.getReteooBuilder().getIdGenerator() ); this.node.attach(context); objectSink = (ObjectSinkPropagator) objectFfield.get( this.objectSource ); tupleSink = (LeftTupleSinkPropagator) tupleField.get( this.tupleSource ); assertEquals( 1, objectSink.getSinks().length ); assertEquals( 1, tupleSink.getSinks().length ); assertSame( this.node, objectSink.getSinks()[0] ); assertSame( this.node, tupleSink.getSinks()[0] ); }