Package org.drools.rule

Examples of org.drools.rule.Rule


            {
            }
        };
       
               
        Rule rule1 = new Rule( "rule1" );
        rule1.setSalience( 50 );
        rule1.setXorGroup( "group1" );

        /* this rule should fire first and be the only rule to fire */
        Rule rule2 = new Rule( "rule2" );
        rule2.setConsequence( consequence );
        rule2.setXorGroup( "group1" );
        rule2.setSalience( 100 );
       
        Rule rule3 = new Rule( "rule3" );
        rule3.setDuration( 1000 );
        rule3.setSalience( 40 );       
        rule3.setXorGroup( "group1" );
       
        Rule rule4 = new Rule( "rule4" );
        rule4.setSalience( 30 );       
        rule4.setXorGroup( "group2" );     
       
        Rule rule5 = new Rule( "rule5" );
        rule4.setSalience( 20 );
        rule5.setXorGroup( null );                              

        ReteTuple tuple = new ReteTuple( workingMemory );


        agenda.addToAgenda( tuple,
View Full Code Here


        RuleBase ruleBase = new RuleBaseImpl( new Rete( ) );

        WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory( );
        final Agenda agenda = workingMemory.getAgenda( );

        final Rule rule = new Rule( "test-rule" );

        // add consequence
        rule.setConsequence( new org.drools.spi.Consequence( )
        {
            public void invoke(org.drools.spi.Tuple tuple)
            {
                agenda.addToAgenda( (ReteTuple) tuple,
                                    rule );
            }
        } );

        ReteTuple tuple = new ReteTuple( workingMemory );

        assertEquals( 0,
                      agenda.size( ) );

        /*
         * Add to agenda
         */
        rule.setNoLoop( false );
        agenda.addToAgenda( tuple,
                            rule );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.fireNextItem( null );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.clearAgenda( );

        /*
         * True filter, activations should always add
         */
        AgendaFilter filterTrue = new AgendaFilter( )
        {
            public boolean accept(Activation item)
            {
                return true;
            }
        };
        rule.setNoLoop( false );
        agenda.addToAgenda( tuple,
                            rule );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.fireNextItem( filterTrue );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.clearAgenda( );

        /*
         * False filter, activations should always be denied
         */
        AgendaFilter filterFalse = new AgendaFilter( )
        {
            public boolean accept(Activation item)
            {
                return false;
            }
        };
        rule.setNoLoop( false );
        agenda.addToAgenda( tuple,
                            rule );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.fireNextItem( filterFalse );
View Full Code Here

        RuleBase ruleBase = new RuleBaseImpl( new Rete( ) );

        WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory( );
        final Agenda agenda = workingMemory.getAgenda( );

        final Rule rule = new Rule( "test-rule" );

        // add consequence
        rule.setConsequence( new org.drools.spi.Consequence( )
        {
            public void invoke(org.drools.spi.Tuple tuple)
            {
                WorkingMemory workingMemory = tuple.getWorkingMemory( );

                agenda.addToAgenda( (ReteTuple) tuple,
                                    rule );
                workingMemory.clearAgenda( );
            }
        } );

        ReteTuple tuple = new ReteTuple( workingMemory );

        assertEquals( 0,
                      agenda.size( ) );

        /*
         * This is recursive so a rule should be able to activate itself But
         * then we clear the agenda afterwards to size should still be 0
         */
        rule.setNoLoop( false );
        agenda.addToAgenda( tuple,
                            rule );
        assertEquals( 1,
                      agenda.size( ) );
        agenda.fireNextItem( null );
View Full Code Here

public class RuleIntegrationExceptionTest extends TestCase
{
    public void testConstruct()
    {
        Rule rule = new Rule( "cheese" );

        RuleIntegrationException e = new RuleIntegrationException( rule );

        assertSame( rule, e.getRule( ) );
View Full Code Here

    }

    public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception
    {
        WorkingMemoryImpl workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete() ) );
        Rule rule = new Rule( "test-rule" );
        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                             null,
                                                             null );

        MockObjectSource source = new MockObjectSource( 15 );
View Full Code Here

    }

    public void testLiteralConstraintAssertObjectWithMemory() throws Exception
    {
        WorkingMemoryImpl workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete() ) );
        Rule rule = new Rule( "test-rule" );
        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                             null,
                                                             null );

        MockObjectSource source = new MockObjectSource( 15 );
View Full Code Here

     * dont need to test with and without memory on this, as it was already done on the previous two tests. This just test AlphaNode With a different Constraint type.
     */
    public void testReturnValueConstraintAssertObject() throws Exception
    {
        WorkingMemoryImpl workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete() ) );
        Rule rule = new Rule( "test-rule" );
        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                             null,
                                                             null );

        MockObjectSource source = new MockObjectSource( 15 );
View Full Code Here

    }

    public void testRetractObjectWithoutMemory() throws Exception
    {
        WorkingMemoryImpl workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete() ) );
        Rule rule = new Rule( "test-rule" );
        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                             null,
                                                             null );

        MockObjectSource source = new MockObjectSource( 15 );
View Full Code Here

    }

    public void testRetractObjectWithMemory() throws Exception
    {
        WorkingMemoryImpl workingMemory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete() ) );
        Rule rule = new Rule( "test-rule" );
        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                             null,
                                                             null );

        MockObjectSource source = new MockObjectSource( 15 );
View Full Code Here

        RuleBase ruleBase = new RuleBaseImpl( new Rete() );

        WorkingMemoryImpl workingMemory = (WorkingMemoryImpl) ruleBase.newWorkingMemory();
        final Scheduler scheduler = Scheduler.getInstance();

        final Rule rule = new Rule( "test-rule" );
        final List data = new ArrayList();

        // add consequence
        rule.setConsequence( new org.drools.spi.Consequence()
        {
            public void invoke(Activation activation)
            {
                data.add( "tested" );
            }
        } );

        /* 1/10th of a second */
        Duration duration = new Duration()
        {
            public long getDuration(Tuple tuple)
            {
                return 100;
            }

        };
        rule.setDuration( duration );

        PropagationContext context = new PropagationContextImpl( PropagationContext.ASSERTION,
                                                                 null,
                                                                 null );

View Full Code Here

TOP

Related Classes of org.drools.rule.Rule

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.