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

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


        assertEquals( at2,
                      m.attributes[0] );
    }
   
    public void testIsDSLEnhanced() throws Exception {
        RuleModel m = new RuleModel();
       
        assertFalse(m.hasDSLSentences());
       
        m.addLhsItem( new FactPattern() );
        assertFalse(m.hasDSLSentences());
       
        m.addRhsItem( new ActionSetField("q") );
       
        assertFalse(m.hasDSLSentences());
       
        m.addLhsItem( new DSLSentence() );
        assertTrue(m.hasDSLSentences());
       
        m.addRhsItem( new DSLSentence() );
        assertTrue(m.hasDSLSentences());
       
        m = new RuleModel();
       
        m.addLhsItem( new DSLSentence() );
        assertTrue(m.hasDSLSentences());
       
        m = new RuleModel();
        m.addRhsItem( new DSLSentence() );
        assertTrue(m.hasDSLSentences());
       
    }
View Full Code Here


    }


    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";

        con.connectives = new ConnectiveConstraint[1];
        con.connectives[0] = connective;

        m.addLhsItem( p );

        String result = BRDRLPersistence.getInstance().marshal( m );

        String expected = "rule \"test literal strings\" " +
            "\tdialect \"mvel\"\n when " +
View Full Code Here


    }

    public void testInvalidComposite() throws Exception {
        RuleModel m = new RuleModel();
        CompositeFactPattern com = new CompositeFactPattern("not");
        m.addLhsItem( com );

        String s = BRDRLPersistence.getInstance().marshal( m );
        assertNotNull(s);

        m.addLhsItem( new CompositeFactPattern("or") );
        m.addLhsItem( new CompositeFactPattern("exists") );
        s = BRDRLPersistence.getInstance().marshal( m );
        assertNotNull(s);
    }
View Full Code Here

        s = BRDRLPersistence.getInstance().marshal( m );
        assertNotNull(s);
    }

    public void testAssertWithDSL() throws Exception {
        RuleModel m = new RuleModel();
        DSLSentence sen = new DSLSentence();
        sen.sentence = "I CAN HAS DSL";
        m.addRhsItem( sen );
        ActionInsertFact ins = new ActionInsertFact("Shizzle");
        ActionFieldValue val = new ActionFieldValue("goo", "42", "Numeric");
        ins.fieldValues = new ActionFieldValue[1];
        ins.fieldValues[0] = val;
        m.addRhsItem( ins );

        ActionInsertLogicalFact insL = new ActionInsertLogicalFact("Shizzle");
        ActionFieldValue valL = new ActionFieldValue("goo", "42", "Numeric");
        insL.fieldValues = new ActionFieldValue[1];
        insL.fieldValues[0] = valL;
        m.addRhsItem( insL );

        String result = BRDRLPersistence.getInstance().marshal( m );
        assertTrue(result.indexOf( ">insert" ) > -1);
        System.err.println(result);
        assertTrue(result.indexOf( ">insertLogical" ) > -1);
View Full Code Here

        System.err.println(result);
        assertTrue(result.indexOf( ">insertLogical" ) > -1);
    }

    public void testDefaultMVEL() {
        RuleModel m = new RuleModel();

        String s = BRDRLPersistence.getInstance().marshal( m );
        assertTrue(s.indexOf( "mvel" ) > -1);

        m.addAttribute( new RuleAttribute("dialect", "goober") );
        s = BRDRLPersistence.getInstance().marshal( m );
        assertFalse(s.indexOf( "mvel" ) > -1);
        assertTrue(s.indexOf( "goober" ) > -1);

    }
View Full Code Here

public class BRLPersitenceTest extends TestCase {

    public void testGenerateEmptyXML() {
        final BRLPersistence p = BRXMLPersistence.getInstance();
        final String xml = p.marshal( new RuleModel() );
        assertNotNull( xml );
        assertFalse( xml.equals( "" ) );

        assertTrue( xml.startsWith( "<rule>" ) );
        assertTrue( xml.endsWith( "</rule>" ) );
View Full Code Here

        assertTrue( xml.endsWith( "</rule>" ) );
    }

    public void testBasics() {
        final BRLPersistence p = BRXMLPersistence.getInstance();
        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";
        final String xml = p.marshal( m );
        //System.out.println(xml);
        assertTrue( xml.indexOf( "Person" ) > -1 );
        assertTrue( xml.indexOf( "Accident" ) > -1 );
View Full Code Here

    }

    public void testMoreComplexRendering() {
        final BRLPersistence p = BRXMLPersistence.getInstance();
        final RuleModel m = getComplexModel();

        final String xml = p.marshal( m );
        System.out.println( xml );

        assertTrue( xml.indexOf( "org.drools" ) == -1 );
View Full Code Here

        assertTrue( xml.indexOf( "org.drools" ) == -1 );

    }

    public void testRoundTrip() {
        final RuleModel m = getComplexModel();

        final String xml = BRXMLPersistence.getInstance().marshal( m );

        final RuleModel m2 = BRXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull( m2 );
        assertEquals( m.name,
                      m2.name );
        assertEquals( m.lhs.length,
                      m2.lhs.length );
View Full Code Here

                      newXML );

    }
   
    public void testCompositeConstraintsRoundTrip() throws Exception {
        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 xml = BRXMLPersistence.getInstance().marshal( m );
        //System.err.println(xml);
       
        RuleModel m2 = BRXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull(m2);
        assertEquals("with composite", m2.name);
       
        assertEquals(m2.lhs.length, m.lhs.length);
        assertEquals(m2.rhs.length, m.rhs.length);
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.