@Test public void testMemory() { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true ); final StatefulKnowledgeSessionImpl workingMemory = new StatefulKnowledgeSessionImpl( 1L, (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase()); final MockObjectSource objectSource = new MockObjectSource( 1 ); final MockTupleSource tupleSource = new MockTupleSource( 1 ); InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); BuildContext buildContext = new BuildContext( kBase, kBase.getReteooBuilder().getIdGenerator() ); final JoinNode joinNode = new JoinNode( 2, tupleSource, objectSource, EmptyBetaConstraints.getInstance(), buildContext ); final BetaMemory memory = (BetaMemory) workingMemory .getNodeMemory( joinNode ); assertNotNull( memory ); }
final ContextEntry c = mock(ContextEntry.class); when(constraint.createContextEntry()).thenReturn(c);
@Test public void testConstraintPropagations() throws Exception { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( false ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( false ); // assert first right object final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory .insert( "test0" ); this.node.assertObject( f0, this.context, this.workingMemory ); // assert tuple, should add left memory should be 2 final DefaultFactHandle f1 = new DefaultFactHandle( 1, "cheese" ); final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true ); this.node.assertLeftTuple( tuple1, this.context, this.workingMemory ); // Should be no assertions assertLength( 0, this.sink.getAsserted() ); this.node.retractRightTuple( f0.getFirstRightTuple(), this.context, this.workingMemory ); assertLength( 0, this.sink.getRetracted() ); }
@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] ); }
@Test public void testAssertTuple() throws Exception { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
@Test public void testUpdateSink() { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
@Test public void testRetractTuple() throws Exception { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
@Test public void testAssertTupleSequentialMode() throws Exception { when( constraint.isAllowedCachedLeft( any( ContextEntry.class ), any( InternalFactHandle.class ) ) ).thenReturn( true ); when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ), any( ContextEntry.class ) ) ).thenReturn( true );
PropagationContext contextPass2And3 = pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, null, 0, 0, EntryPointId.DEFAULT, new LongBitMask(6)); when( constraint.isAllowedCachedLeft(any(ContextEntry.class), any(InternalFactHandle.class))).thenReturn(true); when( constraint.isAllowedCachedRight(any(LeftTupleImpl.class), any(ContextEntry.class))).thenReturn(true);