Package org.drools.core.reteoo

Examples of org.drools.core.reteoo.MockObjectSink


        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  this.entryPoint,
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach( buildContext );
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );

        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
View Full Code Here


        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  this.entryPoint,
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach( buildContext );
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
                                                            0,
                                                            buildContext );

        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        final Agenda agenda = ksession.getAgenda();

        final Consequence consequence = new Consequence() {
            private static final long serialVersionUID = 510l;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                LinkedList< LogicalDependency<M>> list = ((DefaultKnowledgeHelper)knowledgeHelper).getpreviousJustified();
                if ( list != null ) {
                    for ( SimpleLogicalDependency dep = ( SimpleLogicalDependency ) list.getFirst(); dep != null; dep =  ( SimpleLogicalDependency ) dep.getNext() ){
                        knowledgeHelper.insertLogical( dep.getObject(), dep.getMode() );
                    }
                }
            }

            public void readExternal(ObjectInput in) throws IOException,
                                                    ClassNotFoundException {

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }

            public String getName() {
                return "default";
            }
        };
        rule1.setConsequence( consequence );

        final DefaultFactHandle handle1 = new DefaultFactHandle( 1,
                                                                 "cheese" );
        final RuleTerminalNodeLeftTuple tuple1 = new RuleTerminalNodeLeftTuple( handle1,
                                                                                node,
                                                                                true );

        final PropagationContext context1 = pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, new DefaultFactHandle());

        // Test that a STATED assertion overrides a logical assertion
        node.assertLeftTuple( tuple1,
                              context1,
                              ksession );

        String logicalString1 = new String( "logical" );
        FactHandle logicalHandle1 = ksession.insert( logicalString1,
                                                          null,
                                                          false,
                                                          true,
                                                          rule1,
                                                          (Activation) tuple1.getObject() );

        // This assertion is stated and should override any previous justified
        // "equals" objects.
        String logicalString2 = new String( "logical" );
        FactHandle logicalHandle2 = ksession.insert( logicalString2 );

        node.retractLeftTuple( tuple1,
                               context1,
                               ksession );

        assertLength( 0,
                      sink.getRetracted() );

        //  we override and discard the original logical object
        assertSame( logicalHandle2,
                    logicalHandle1 );

        // so while new STATED assertion is equal
        assertEquals( logicalString1,
                      ksession.getObject( logicalHandle2 ) );
        // they are not identity same
        assertNotSame( logicalString1,
                       ksession.getObject( logicalHandle2 ) );

        // Test that a logical assertion cannot override a STATED assertion
        node.assertLeftTuple( tuple1,
                              context1,
                              ksession );

        logicalString2 = new String( "logical" );
        logicalHandle2 = ksession.insert( logicalString2 );

        // This logical assertion will be ignored as there is already
        // an equals STATED assertion.
        logicalString1 = new String( "logical" );
        logicalHandle1 = ksession.insert( logicalString1,
                                               null,
                                               false,
                                               true,
                                               rule1,
                                               (Activation) tuple1.getObject() );

        assertNull( logicalHandle1 );

        // Already identify same so return previously assigned handle
        logicalHandle1 = ksession.insert( logicalString2,
                                               null,
                                               false,
                                               false,
                                               rule1,
                                               (Activation) tuple1.getObject() );
        // return the matched handle

        assertSame( logicalHandle2,
                    logicalHandle1 );

        node.retractLeftTuple( tuple1,
                               context1,
                               ksession );

        assertLength( 0,
                      sink.getRetracted() );

        // Should keep the same handle when overriding
        assertSame( logicalHandle1,
                    logicalHandle2 );
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  this.entryPoint,
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach( buildContext );
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  this.entryPoint,
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach( buildContext );
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  this.entryPoint,
                                                                  new ClassObjectType( String.class ),
                                                                  buildContext );
        objectTypeNode.attach( buildContext );
        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink( sink );
        final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                            new MockTupleSource( idGenerator.getNextId() ),
                                                            rule1,
                                                            rule1.getLhs(),
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(idGenerator.getNextId(),
                                                                 entryPoint,
                                                                 new ClassObjectType(String.class),
                                                                 buildContext);

        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink(sink);

        final Object string1 = "cheese";

        final InternalFactHandle handle1 = (InternalFactHandle) workingMemory.insert(string1);

        // should assert as ObjectType matches
        objectTypeNode.assertObject(handle1,
                                    context,
                                    workingMemory);

        // make sure just string1 was asserted
        final List asserted = sink.getAsserted();
        assertLength(1,
                     asserted);
        assertSame(string1,
                   workingMemory.getObject((DefaultFactHandle) ((Object[]) asserted.get(0))[0]));
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
                                                                 entryPoint,
                                                                 new ClassObjectType(String.class),
                                                                 buildContext);

        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink(sink);

        final Object string1 = "cheese";

        final InternalFactHandle handle1 = (InternalFactHandle) workingMemory.insert(string1);

        // should assert as ObjectType matches
        objectTypeNode.assertObject(handle1,
                                    context,
                                    workingMemory);

        // make sure just string1 was asserted
        final List asserted = sink.getAsserted();
        assertLength(1,
                     asserted);
        assertSame(string1,
                   workingMemory.getObject((DefaultFactHandle) ((Object[]) asserted.get(0))[0]));
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(idGenerator.getNextId(),
                                                                 this.entryPoint,
                                                                 new ClassObjectType(String.class),
                                                                 buildContext);

        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink(sink);

        final Object string1 = "cheese";

        final DefaultFactHandle handle1 = new DefaultFactHandle(1,
                                                                string1);

        // should assert as ObjectType matches
        objectTypeNode.assertObject(handle1,
                                    context,
                                    workingMemory);
        // check asserted object was added to memory
        final ObjectTypeNodeMemory memory = (ObjectTypeNodeMemory) workingMemory.getNodeMemory(objectTypeNode);
        assertEquals(1,
                     memory.memory.size());

        // should retract as ObjectType matches
        objectTypeNode.retractObject(handle1,
                                     context,
                                     workingMemory);
        // check asserted object was removed from memory
        assertEquals(0,
                     memory.memory.size());

        // make sure its just the handle1 for string1 that was propagated
        final List retracted = sink.getRetracted();
        assertLength(1,
                     retracted);
        assertSame(handle1,
                   ((Object[]) retracted.get(0))[0]);
    }
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
                                                                 this.entryPoint,
                                                                 new ClassObjectType(String.class),
                                                                 buildContext);

        final MockObjectSink sink1 = new MockObjectSink();
        objectTypeNode.addObjectSink(sink1);

        final Object string1 = "cheese";

        final Object string2 = "bread";

        final DefaultFactHandle handle1 = new DefaultFactHandle(1,
                                                                string1);
        final DefaultFactHandle handle2 = new DefaultFactHandle(2,
                                                                string2);

        objectTypeNode.assertObject(handle1,
                                    context,
                                    workingMemory);

        objectTypeNode.assertObject(handle2,
                                    context,
                                    workingMemory);

        assertEquals(2,
                     sink1.getAsserted().size());

        final MockObjectSink sink2 = new MockObjectSink();
        objectTypeNode.addObjectSink(sink2);

        assertEquals(0,
                     sink2.getAsserted().size());

        objectTypeNode.updateSink(sink2,
                                  new PhreakPropagationContext(),
                                  workingMemory);

        assertEquals(2,
                     sink2.getAsserted().size());

        final Object string3 = "water";

        final DefaultFactHandle handle3 = new DefaultFactHandle(3,
                                                                string3);

        objectTypeNode.assertObject(handle3,
                                    context,
                                    workingMemory);

        assertEquals(3,
                     sink1.getAsserted().size());

        assertEquals(3,
                     sink2.getAsserted().size());

    }
View Full Code Here

        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
                                                                 this.entryPoint,
                                                                 new ClassObjectType(Cheese.class),
                                                                 buildContext);

        final MockObjectSink sink = new MockObjectSink();
        objectTypeNode.addObjectSink(sink);
        entryPoint.addObjectSink(objectTypeNode);

        final Object cheese = new Cheese("muzzarela",
                                         5);

        final InternalFactHandle handle1 = (InternalFactHandle) workingMemory.insert(cheese);

        // make sure just string1 was asserted
        final List asserted = sink.getAsserted();
        assertLength(1,
                     asserted);
        assertEquals(cheese,
                     ((InternalFactHandle) ((Object[]) asserted.get(0))[0]).getObject());
View Full Code Here

TOP

Related Classes of org.drools.core.reteoo.MockObjectSink

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.