Package org.drools.brms.client.modeldriven.brl

Examples of org.drools.brms.client.modeldriven.brl.RuleModel


    public void testScopedVariables() {

        //setup the data...

        final RuleModel model = new RuleModel();
        model.lhs = new IPattern[3];
        final FactPattern x = new FactPattern( "Car" );
        model.lhs[0] = x;
        x.boundName = "x";

        final FactPattern y = new FactPattern( "Car" );
        model.lhs[1] = y;
        y.boundName = "y";
        final SingleFieldConstraint[] cons = new SingleFieldConstraint[2];
        y.constraintList = new CompositeFieldConstraint();
        y.constraintList.constraints = cons;
        cons[0] = new SingleFieldConstraint( "age" );
        cons[1] = new SingleFieldConstraint( "make" );
        cons[0].fieldBinding = "qbc";
        cons[0].connectives = new ConnectiveConstraint[1];
        cons[0].connectives[0] = new ConnectiveConstraint( "&",
                                                           "x" );
        cons[0].connectives[0].constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;

        final FactPattern other = new FactPattern( "House" );
        model.lhs[2] = other;
        other.boundName = "q";
        final SingleFieldConstraint[] cons2 = new SingleFieldConstraint[1];
        cons2[0] = new SingleFieldConstraint();
        other.constraintList = new CompositeFieldConstraint();
        other.constraintList.constraints = cons2;

        //check the results for correct scope
        List vars = model.getBoundVariablesInScope( cons[0] );
        assertEquals( 1,
                      vars.size() );
        assertEquals( "x",
                      vars.get( 0 ) );

        vars = model.getBoundVariablesInScope( cons[0].connectives[0] );
        assertEquals( 1,
                      vars.size() );
        assertEquals( "x",
                      vars.get( 0 ) );

        vars = model.getBoundVariablesInScope( cons[1] );
        assertEquals( 2,
                      vars.size() );
        assertEquals( "x",
                      vars.get( 0 ) );
        assertEquals( "qbc",
                      vars.get( 1 ) );

        vars = model.getBoundVariablesInScope( cons[0] );
        assertEquals( 1,
                      vars.size() );
        assertEquals( "x",
                      vars.get( 0 ) );

        vars = model.getBoundVariablesInScope( cons2[0] );
        assertEquals( 3,
                      vars.size() );
        assertEquals( "x",
                      vars.get( 0 ) );
        assertEquals( "qbc",
View Full Code Here


        assertEquals( "y",
                      vars.get( 2 ) );
    }
   
    public void testScopedVariablesWithCompositeFact() {
        RuleModel m = new RuleModel();
        FactPattern p = new FactPattern();
        CompositeFieldConstraint cf = new CompositeFieldConstraint();
        cf.addConstraint( new SingleFieldConstraint("x") );
        p.addConstraint( cf );
        SingleFieldConstraint sf = new SingleFieldConstraint("q");
        sf.fieldBinding = "abc";

        p.addConstraint( sf );
        SingleFieldConstraint sf2 = new SingleFieldConstraint("q");
        sf2.fieldBinding = "qed";
        cf.addConstraint( sf2 );
        m.addLhsItem( p );

        List vars = m.getAllVariables();
        assertEquals(1, vars.size());
        assertEquals("abc", vars.get( 0 ));
    }
View Full Code Here

        assertEquals(1, vars.size());
        assertEquals("abc", vars.get( 0 ));
    }

    public void testBindingList() {
        final RuleModel model = new RuleModel();

        model.lhs = new IPattern[3];
        final FactPattern x = new FactPattern( "Car" );
        model.lhs[0] = x;
        x.boundName = "x";

        final FactPattern y = new FactPattern( "Car" );
        model.lhs[1] = y;
        y.boundName = "y";

        final FactPattern other = new FactPattern( "House" );
        model.lhs[2] = other;

        final List b = model.getBoundFacts();
        assertEquals( 2,
                      b.size() );

        assertEquals( "x",
                      b.get( 0 ) );
View Full Code Here

                      b.get( 1 ) );

    }
   
    public void testAllVariableBindings() {
        final RuleModel model = new RuleModel();
        model.lhs = new IPattern[2];
        final FactPattern x = new FactPattern( "Car" );
        model.lhs[0] = x;
        x.boundName = "boundFact";       
       
        SingleFieldConstraint sfc = new SingleFieldConstraint("q");
        x.addConstraint( sfc );
        sfc.fieldBinding = "field1";
       
        SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
        x.addConstraint( sfc2 );
        sfc2.fieldBinding = "field2";
       
       
        model.lhs[1] = new CompositeFactPattern();
    
        List vars = model.getAllVariables();
        assertEquals(3, vars.size());
        assertEquals("boundFact", vars.get( 0 ));
        assertEquals("field1", vars.get( 1 ));
        assertEquals("field2", vars.get( 2 ));
       
        assertTrue(model.isVariableNameUsed( "field2" ));
       
    }
View Full Code Here

        assertTrue(model.isVariableNameUsed( "field2" ));
       
    }
   
    public void testGetVariableNameForRHS() {
        RuleModel m = new RuleModel();
        m.name = "blah";
       
        FactPattern pat = new FactPattern();
        pat.boundName = "pat";
        pat.factType = "Person";
       
        m.addLhsItem( pat );
       
        List l = m.getAllVariables();
        assertEquals( 1, l.size() );
        assertEquals("pat", l.get( 0 ));
       
    }
View Full Code Here

        assertEquals("pat", l.get( 0 ));
       
    }

    public void testRemoveItemLhs() {
        final RuleModel model = new RuleModel();

        model.lhs = new IPattern[3];
        final FactPattern x = new FactPattern( "Car" );
        model.lhs[0] = x;
        x.boundName = "x";

        final FactPattern y = new FactPattern( "Car" );
        model.lhs[1] = y;
        y.boundName = "y";

        final FactPattern other = new FactPattern( "House" );
        model.lhs[2] = other;

        assertEquals( 3,
                      model.lhs.length );
        assertEquals( x,
                      model.lhs[0] );

        model.removeLhsItem( 0 );

        assertEquals( 2,
                      model.lhs.length );
        assertEquals( y,
                      model.lhs[0] );
View Full Code Here

        assertEquals( y,
                      model.lhs[0] );
    }

    public void testRemoveItemRhs() {
        final RuleModel model = new RuleModel();

        model.rhs = new IAction[3];
        final ActionRetractFact r0 = new ActionRetractFact( "x" );
        final ActionRetractFact r1 = new ActionRetractFact( "y" );
        final ActionRetractFact r2 = new ActionRetractFact( "z" );

        model.rhs[0] = r0;
        model.rhs[1] = r1;
        model.rhs[2] = r2;

        model.removeRhsItem( 1 );

        assertEquals( 2,
                      model.rhs.length );
        assertEquals( r0,
                      model.rhs[0] );
View Full Code Here

        assertEquals( r2,
                      model.rhs[1] );
    }

    public void testAddItemLhs() {
        final RuleModel model = new RuleModel();
        final FactPattern x = new FactPattern();
        model.addLhsItem( x );
        assertEquals( 1,
                      model.lhs.length );

        final FactPattern y = new FactPattern();
        model.addLhsItem( y );

        assertEquals( 2,
                      model.lhs.length );
        assertEquals( x,
                      model.lhs[0] );
View Full Code Here

                      model.lhs[1] );

    }

    public void testAddItemRhs() {
        final RuleModel model = new RuleModel();
        final IAction a0 = new ActionSetField();
        final IAction a1 = new ActionSetField();

        model.addRhsItem( a0 );

        assertEquals( 1,
                      model.rhs.length );
        model.addRhsItem( a1 );

        assertEquals( 2,
                      model.rhs.length );

        assertEquals( a0,
View Full Code Here

        assertEquals( a1,
                      model.rhs[1] );
    }

    public void testAttributes() {
        final RuleModel m = new RuleModel();
        final RuleAttribute at = new RuleAttribute( "salience",
                                              "42" );
        m.addAttribute( at );
        assertEquals( 1,
                      m.attributes.length );
        assertEquals( at,
                      m.attributes[0] );

        final RuleAttribute at2 = new RuleAttribute( "agenda-group",
                                               "x" );
        m.addAttribute( at2 );
        assertEquals( 2,
                      m.attributes.length );
        assertEquals( at2,
                      m.attributes[1] );

        m.removeAttribute( 0 );
        assertEquals( 1,
                      m.attributes.length );
        assertEquals( at2,
                      m.attributes[0] );
    }
View Full Code Here

TOP

Related Classes of org.drools.brms.client.modeldriven.brl.RuleModel

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.