Package org.drools.core.base

Examples of org.drools.core.base.DefaultKnowledgeHelper


        AgendaItem item3 = new RuleTerminalNodeLeftTuple();
        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
       
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( ksession );
        kcontext.setActivation( item1 );
       
        // set blockers
        kcontext.blockMatch( item2 );
        kcontext.blockMatch( item3 );
       
        assertNull( item1.getBlockers() );
        assertEquals( 2, item1.getBlocked().size() );
        assertEquals( 1, item2.getBlockers().size() );
        assertEquals( 1, item3.getBlockers().size() );
       
        kcontext.reset();
        kcontext.setActivation( item2 );
        kcontext.blockMatch( item3 );
        assertEquals( 2, item1.getBlocked().size() );
       
        assertEquals( 1, item2.getBlocked().size() );
        assertEquals( 1, item2.getBlockers().size() );
        assertEquals( 2, item3.getBlockers().size() );       
View Full Code Here


        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( ksession );
        kcontext.setActivation( item1 );
       
        // set blockers
        kcontext.blockMatch( item2 );
        kcontext.blockMatch( item3 );
       
         // set blocked
        kcontext.reset();
        kcontext.setActivation( item2 );
        kcontext.blockMatch( item3 );
       
        // Check all references are updated correctly when item1 is deleted
        item1.removeAllBlockersAndBlocked(agenda);
        assertEquals( 0, item2.getBlockers().size() );       
        assertEquals( 1, item2.getBlocked().size() );
        assertEquals(1, item3.getBlockers().size());
        assertNull(item3.getBlocked());
        assertSame( item2, ((LogicalDependency)item2.getBlocked().getFirst()).getJustifier() );
        assertSame( item3, ((LogicalDependency)item2.getBlocked().getFirst()).getJustified() );
       
        // now retract item2
        item2.removeAllBlockersAndBlocked(agenda);
        assertEquals( 0, item3.getBlockers().size() );
        assertNull( item3.getBlocked() );
         
        assertNull( item2.getBlocked() );
        assertNull( item2.getBlocked() );
         
        assertNull( item1.getBlocked() );
        assertNull( item1.getBlocked() );
       
        // reblock with item2, so that we can retract item3
        kcontext.blockMatch( item3 );
        assertNull( item2.getBlockers() );       
        assertEquals( 1, item2.getBlocked().size() );
        assertEquals(1, item3.getBlockers().size());
        assertNull(item3.getBlocked());
        assertSame( item2, ((LogicalDependency)item2.getBlocked().getFirst()).getJustifier() );
View Full Code Here

        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( ksession );
        kcontext.setActivation( item1 );
        kcontext.blockMatch( item3 );
       
        kcontext.reset();
        kcontext.setActivation( item2 );
        kcontext.blockMatch( item3 );

        kcontext.unblockAllMatches( item3 );
           
        assertEquals( 0, item3.getBlockers().size() );
        assertNull( item3.getBlocked() );
         
        assertEquals( 0, item2.getBlocked().size() );
View Full Code Here

        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item4, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( ksession );
        kcontext.setActivation( item1 );
       
        // set blockers
        kcontext.blockMatch( item2 );
        kcontext.blockMatch( item3 );
       
         // set blocked
        kcontext.reset();
        kcontext.setActivation( item1 );
        kcontext.blockMatch( item4 );
        kcontext.cancelRemainingPreviousLogicalDependencies();
       
        // check only item4 is blocked
        assertEquals( 1, item1.getBlocked().size() );
        assertEquals( item4, ((LogicalDependency)item1.getBlocked().getFirst()).getJustified() );
       
View Full Code Here

        rtn.setSalienceDeclarations( context.getDeclarationResolver().getDeclarations( context.getRule() ).values().toArray( new Declaration[1] ) );
        AgendaItem item = new AgendaItem(0, tuple, 0, null, rtn, null);


        assertEquals( 25,
                      context.getRule().getSalience().getValue( new DefaultKnowledgeHelper( item, wm ),
                                                                context.getRule(),
                                                                wm ) );

    }
View Full Code Here

        public void run() {
            try {
                Thread.sleep( 1000 );
                for ( int i = 0; i < iterations && !halt; i++ ) {
                    assertEquals( result,
                                  salience.getValue( new DefaultKnowledgeHelper( item, wm ),
                                                     rule,
                                                     wm ) );
                    Thread.currentThread().yield();
                }
            } catch ( Throwable e ) {
View Full Code Here

                                                                            1,
                                                                            null,
                                                                            tuple,
                                                                            null ),
                                                new RuleTerminalNode(0, new CompositeObjectSinkAdapterTest.MockBetaNode(), context.getRule(), subrule, 0, new BuildContext( (InternalRuleBase) ruleBase, null )), null);
        final DefaultKnowledgeHelper kbHelper = new DefaultKnowledgeHelper( wm );
        kbHelper.setActivation( item );
        ((MVELConsequence) context.getRule().getConsequence()).compile(  (MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ));
        context.getRule().getConsequence().evaluate( kbHelper,
                                                     wm );

        assertEquals( 5,
View Full Code Here

        final AgendaItem item = new AgendaItem( 0,
                                                tuple,
                                                10,
                                                null,
                                                null, null);
        final DefaultKnowledgeHelper kbHelper = new DefaultKnowledgeHelper( wm );
        kbHelper.setActivation( item );
        try {
            ((MVELConsequence) context.getRule().getConsequence()).compile( (MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ) );
            context.getRule().getConsequence().evaluate( kbHelper,
                                                         wm );
            fail( "should throw an exception, as 'if' is not allowed" );
View Full Code Here

        final Activation activation = new MockActivation( rule,
                                                          0,
                                                          rule.getLhs(),
                                                          tuple );

        DefaultKnowledgeHelper knowledgeHelper = new org.drools.core.base.DefaultKnowledgeHelper( workingMemory );
        knowledgeHelper.setActivation( activation );

        rule.getConsequence().evaluate( knowledgeHelper,
                                        workingMemory );
        assertEquals( new Integer( 1 ),
                      map.get( "value" ) );

        ruleDescr.setConsequence( "map.put(\"value\", new Integer(2) );" );
        pkg.removeRule( rule );

        // Make sure the compiled classes are also removed
        assertEquals( 0,
                      ((JavaDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( "java" )).list().length );

        builder.addPackage( packageDescr );

        pkg = builder.getPackage();

        rule = pkg.getRule( "rule-1" );

        knowledgeHelper = new org.drools.core.base.DefaultKnowledgeHelper( workingMemory );
        knowledgeHelper.setActivation( activation );

        rule.getConsequence().evaluate( knowledgeHelper,
                                        workingMemory );
        assertEquals( new Integer( 2 ),
                      map.get( "value" ) );
View Full Code Here

        final Activation activation = new MockActivation( newRule,
                                                          0,
                                                          newRule.getLhs(),
                                                          tuple );

        final DefaultKnowledgeHelper knowledgeHelper = new org.drools.core.base.DefaultKnowledgeHelper( workingMemory );
        knowledgeHelper.setActivation( activation );

        newRule.getConsequence().evaluate( knowledgeHelper,
                                           workingMemory );
        assertEquals( new Integer( 1 ),
                      map.get( "value" ) );
View Full Code Here

TOP

Related Classes of org.drools.core.base.DefaultKnowledgeHelper

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.