Package org.drools.common

Examples of org.drools.common.DefaultFactHandle


        final MockLeftTupleSink sink = new MockLeftTupleSink();
        node.addTupleSink( sink );

        // Create the Tuple
        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "stilton" );
        final LeftTuple tuple0 = new LeftTuple( f0, sink,
                                                true );

        // Tuple should fail and not propagate
        node.assertLeftTuple( tuple0,
                          this.context,
                          this.workingMemory );

        // Create the Tuple
        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
                                                            "cheddar" );
        final LeftTuple tuple1 = new LeftTuple( f1, sink,
                                                true );

        // Tuple should fail and not propagate
View Full Code Here


        // Add the first tuple sink and assert a tuple and object
        // The sink has no memory
        final MockLeftTupleSink sink1 = new MockLeftTupleSink( 2 );
        node.addTupleSink( sink1 );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "string0" );

        final LeftTuple tuple1 = new LeftTuple( f0, sink1,
                                                true );
View Full Code Here

        final MockLeftTupleSink sink = new MockLeftTupleSink();
        node.addTupleSink( sink );

        // Create the Tuple
        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "stilton" );
        final LeftTuple tuple0 = new LeftTuple( f0, sink,
                                                true );

        // Tuple should pass and propagate
View Full Code Here

            // allowed calls and return values
            allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(true));
            allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(true));
        }} );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "cheese" );
        final LeftTuple tuple0 = new LeftTuple( f0,
                                                this.node,
                                                true );

        // assert tuple, should add one to left memory
        this.node.assertLeftTuple( tuple0,
                                   this.context,
                                   this.workingMemory );
        // check memories, left memory is populated, right memory is emptys
        assertEquals( 1,
                      this.memory.getLeftTupleMemory().size() );
        assertEquals( 0,
                      this.memory.getRightTupleMemory().size() );

        // assert tuple, should add left memory should be 2
        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
                                                            "cheese" );
        final LeftTuple tuple1 = new LeftTuple( f1,
                                                this.node,
                                                true );
        this.node.assertLeftTuple( tuple1,
View Full Code Here

        this.node.addTupleSink( this.sink );

        this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "cheese" );
        final LeftTuple tuple0 = new LeftTuple( f0,
                                                this.node,
                                                true );

        this.node.assertObject( f0,
                                this.context,
                                this.workingMemory );

        // assert tuple
        this.node.assertLeftTuple( tuple0,
                                   this.context,
                                   this.workingMemory );

        assertEquals( 1,
                      this.sink.getAsserted().size() );

        assertNull( this.memory.getLeftTupleMemory() );

        assertEquals( 1,
                      this.memory.getRightTupleMemory().size() );

        assertEquals( new LeftTuple( tuple0,
                                     f0.getRightTuple(),
                                     this.sink,
                                     true ),
                      ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
    }
View Full Code Here

            // allowed calls and return values
            allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(true));
            allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(true));
        }} );

        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.insert( "test0" );

        // assert object, should add one to right memory
        this.node.assertObject( f0,
                                this.context,
                                this.workingMemory );
        assertEquals( 0,
                      this.memory.getLeftTupleMemory().size() );
        assertEquals( 1,
                      this.memory.getRightTupleMemory().size() );

        // check new objects/handles still assert
        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.insert( "test1" );
        this.node.assertObject( f1,
                                this.context,
                                this.workingMemory );
        assertEquals( 2,
                      this.memory.getRightTupleMemory().size() );
View Full Code Here

            allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(true));
            allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(true));
        }} );

        // 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 LeftTuple tuple1 = new LeftTuple( f1,
                                                this.node,
                                                true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );

        assertEquals( 1,
                      this.sink.getAsserted().size() );

        assertEquals( new LeftTuple( tuple1,
                                     f0.getRightTuple(),
                                     this.sink,
                                     true ),
                      ((Object[]) this.sink.getAsserted().get( 0 ))[0] );

        final DefaultFactHandle f2 = new DefaultFactHandle( 2,
                                                            "cheese" );
        final LeftTuple tuple2 = new LeftTuple( f2,
                                                this.node,
                                                true );
        this.node.assertLeftTuple( tuple2,
                                   this.context,
                                   this.workingMemory );

        assertEquals( 2,
                      this.sink.getAsserted().size() );
        assertEquals( new LeftTuple( tuple2,
                                     f0.getRightTuple(),
                                     this.sink,
                                     true ),
                      ((Object[]) this.sink.getAsserted().get( 1 ))[0] );

        final DefaultFactHandle f3 = (DefaultFactHandle) this.workingMemory.insert( "test2" );
        this.node.assertObject( f3,
                                this.context,
                                this.workingMemory );

        assertEquals( 4,
                      this.sink.getAsserted().size() );

        final List tuples = new ArrayList();
        tuples.add( ((Object[]) this.sink.getAsserted().get( 2 ))[0] );
        tuples.add( ((Object[]) this.sink.getAsserted().get( 3 ))[0] );

        assertTrue( tuples.contains( new LeftTuple( tuple1,
                                                    f3.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );
        assertTrue( tuples.contains( new LeftTuple( tuple2,
                                                    f3.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );
    }
View Full Code Here

            allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(true));
            allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(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 LeftTuple tuple1 = new LeftTuple( f1,
                                                this.node,
                                                true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );

        final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( "test2" );
        final LeftTuple tuple2 = new LeftTuple( 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.getRightTuple() ) );

        // Retract an object, check propagations  and memory
        this.node.retractRightTuple( f0.getRightTuple(),
                                     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 LeftTuple( tuple1,
                                                    f0.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );
        assertTrue( tuples.contains( new LeftTuple( tuple1,
                                                    f0.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );

        // Now check the item  is no longer in memory
        assertFalse( memory.getRightTupleMemory().contains( f0.getRightTuple() ) );

        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 LeftTuple( tuple2,
                                                    f3.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );
        assertTrue( tuples.contains( new LeftTuple( tuple2,
                                                    f4.getRightTuple(),
                                                    this.sink,
                                                    true ) ) );
    }
View Full Code Here

            allowing( constraint ).isAllowedCachedLeft( with(any(ContextEntry.class)), with(any(InternalFactHandle.class)) ); will(returnValue(false));
            allowing( constraint ).isAllowedCachedRight( with(any(LeftTuple.class)), with(any(ContextEntry.class)) ); will(returnValue(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 LeftTuple tuple1 = new LeftTuple( f1,
                                                this.node,
                                                true );
        this.node.assertLeftTuple( tuple1,
View Full Code Here

        // Add the first tuple sink and assert a tuple and object
        // The sink has no memory
        final MockLeftTupleSink sink1 = new MockLeftTupleSink( 2 );
        joinNode.addTupleSink( sink1 );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            "string0" );

        final LeftTuple tuple1 = new LeftTuple( f0,
                                                this.node,
                                                true );

        joinNode.assertLeftTuple( tuple1,
                                  this.context,
                                  workingMemory );

        final String string1 = "string1";
        final DefaultFactHandle string1Handle = new DefaultFactHandle( 1,
                                                                       string1 );

        joinNode.assertObject( string1Handle,
                               this.context,
                               workingMemory );
View Full Code Here

TOP

Related Classes of org.drools.common.DefaultFactHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.