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

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


    public void testConnective() {
       
        RuleModel m = new RuleModel();
        m.name = "test literal strings";
       
        FactPattern p = new FactPattern("Person");
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.fieldName = "field1";
        con.operator = "==";
        con.value = "goo";
        con.constraintValueType = SingleFieldConstraint.TYPE_VARIABLE;
        p.addConstraint( con );

        ConnectiveConstraint connective = new ConnectiveConstraint();
        connective.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
        connective.operator = "|| ==";
        connective.value = "blah";
View Full Code Here


    public void testBasics() {
        String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" +
                          "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n";
        final RuleModel m = new RuleModel();
        m.addLhsItem( new FactPattern( "Person" ) );
        m.addLhsItem( new FactPattern( "Accident" ) );
        m.addAttribute( new RuleAttribute( "no-loop",
                                           "true" ) );

        m.addRhsItem( new ActionInsertFact( "Report" ) );
        m.name = "my rule";
View Full Code Here

    //
   
    private RuleModel getModelWithNoConstraints() {
        final RuleModel m = new RuleModel();
        m.name = "Complex Rule";
        final FactPattern pat = new FactPattern();
        pat.boundName = "p1";
        pat.factType = "Person";
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.fieldBinding = "f1";
        con.fieldName = "age";
//        con.operator = "<";
//        con.value = "42";
        pat.addConstraint( con );

        m.addLhsItem( pat );
       
        return m;
    }
View Full Code Here

        m.addAttribute( new RuleAttribute( "salience",
                                           "-10" ) );
        m.addAttribute( new RuleAttribute( "agenda-group",
                                           "aGroup" ) );

        final FactPattern pat = new FactPattern();
        pat.boundName = "p1";
        pat.factType = "Person";
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.fieldBinding = "f1";
        con.fieldName = "age";
        con.operator = "<";
        con.value = "42";
        pat.addConstraint( con );

        m.addLhsItem( pat );

        final CompositeFactPattern comp = new CompositeFactPattern( "not" );
        comp.addFactPattern( new FactPattern( "Cancel" ) );
        m.addLhsItem( comp );

        final ActionUpdateField set = new ActionUpdateField();
        set.variable = "p1";
        set.addFieldValue( new ActionFieldValue( "status",
View Full Code Here

   
    public void testCompositeConstraints() {
        RuleModel m = new RuleModel();
        m.name = "with composite";
   
        FactPattern p1 = new FactPattern("Person");
        p1.boundName = "p1";
        m.addLhsItem( p1 );
       
        FactPattern p = new FactPattern("Goober");
        m.addLhsItem( p );
        CompositeFieldConstraint comp = new CompositeFieldConstraint();
        comp.compositeJunctionType = CompositeFieldConstraint.COMPOSITE_TYPE_OR;
        p.addConstraint( comp );
       
        final SingleFieldConstraint X = new SingleFieldConstraint();
        X.fieldName = "goo";
        X.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
        X.value = "foo";
        X.operator = "==";
        X.connectives = new ConnectiveConstraint[1];
        X.connectives[0] = new ConnectiveConstraint();
        X.connectives[0].constraintValueType = ConnectiveConstraint.TYPE_LITERAL;
        X.connectives[0].operator = "|| ==";
        X.connectives[0].value = "bar";
        comp.addConstraint( X );
       
        final SingleFieldConstraint Y = new SingleFieldConstraint();
        Y.fieldName = "goo2";
        Y.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
        Y.value = "foo";
        Y.operator = "==";
        comp.addConstraint( Y );

        CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
        comp2.compositeJunctionType = CompositeFieldConstraint.COMPOSITE_TYPE_AND;
        final SingleFieldConstraint Q1 = new SingleFieldConstraint();
        Q1.fieldName = "goo";
        Q1.operator = "==";
        Q1.value = "whee";
        Q1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
       
        comp2.addConstraint( Q1 );
       
        final SingleFieldConstraint Q2 = new SingleFieldConstraint();
        Q2.fieldName = "gabba";
        Q2.operator = "==";
        Q2.value = "whee";
        Q2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
       
        comp2.addConstraint( Q2 );
       
        //now nest it
        comp.addConstraint( comp2 );
       
       
       
        final SingleFieldConstraint Z = new SingleFieldConstraint();
        Z.fieldName = "goo3";
        Z.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
        Z.value = "foo";
        Z.operator = "==";
       
        p.addConstraint( Z );
       
        ActionInsertFact ass = new ActionInsertFact("Whee");
        m.addRhsItem( ass );
       
        String actual = BRDRLPersistence.getInstance().marshal( m );
View Full Code Here

   
    public void testFieldsDeclaredButNoConstraints() {
        RuleModel m = new RuleModel();
        m.name = "boo";
       
        FactPattern p = new FactPattern();
        p.factType = "Person";
       
        //this isn't an effective constraint, so it should be ignored.
        p.addConstraint( new SingleFieldConstraint("field1") );

        m.addLhsItem( p );
       
        String actual = BRDRLPersistence.getInstance().marshal( m );
View Full Code Here

    public void testLiteralStrings() {
       
        RuleModel m = new RuleModel();
        m.name = "test literal strings";
       
        FactPattern p = new FactPattern("Person");
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.fieldName = "field1";
        con.operator = "==";
        con.value = "goo";
        con.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
        p.addConstraint( con );
       
       
        SingleFieldConstraint con2 = new SingleFieldConstraint();
        con2.fieldName = "field2";
        con2.operator = "==";
        con2.value = "variableHere";
        con2.constraintValueType = SingleFieldConstraint.TYPE_VARIABLE;
        p.addConstraint( con2 );
       
       
       
        m.addLhsItem( p );
       
View Full Code Here

        final RuleModel model = new RuleModel();

        assertNull( model.getBoundFact( "x" ) );
        model.lhs = new IPattern[3];

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

        assertNotNull( model.getBoundFact( "x" ) );
        assertEquals( x,
                      model.getBoundFact( "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( y,
                      model.getBoundFact( "y" ) );
        assertEquals( x,
View Full Code Here

        //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();
View Full Code Here

                      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 );
View Full Code Here

TOP

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

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.