Package org.drools.workbench.models.commons.shared.rule

Examples of org.drools.workbench.models.commons.shared.rule.RuleModel


    }

    @Test
    public void testNotInOperatorNumber() {

        RuleModel m = new RuleModel();
        m.name = "not in";

        FactPattern p = new FactPattern( "Person" );
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldType( DataType.TYPE_NUMERIC_INTEGER );
        con.setFieldName( "field1" );
        con.setOperator( "not in" );
        con.setValue( "55, 66" );
        con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        p.addConstraint( con );

        m.addLhsItem( p );

        String expected = "rule \"not in\" \n"
                + "dialect \"mvel\" \n"
                + "when \n"
                + "     Person(field1 not in ( 55, 66 ) ) \n"
View Full Code Here


        try {

            System.setProperty( "drools.dateformat",
                                "dd-MMM-yyyy" );

            RuleModel m = new RuleModel();
            m.name = "RHS Date";

            FactPattern p = new FactPattern( "Person" );
            SingleFieldConstraint con = new SingleFieldConstraint();
            con.setFieldType( DataType.TYPE_DATE );
            con.setFieldName( "dateOfBirth" );
            con.setOperator( "==" );
            con.setValue( "31-Jan-2000" );
            con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
            p.addConstraint( con );

            m.addLhsItem( p );

            ActionInsertFact ai = new ActionInsertFact( "Birthday" );
            ai.addFieldValue( new ActionFieldValue( "dob",
                                                    "31-Jan-2000",
                                                    DataType.TYPE_DATE ) );
            m.addRhsItem( ai );

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

            assertTrue( result.indexOf( "java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");" ) != -1 );
            assertTrue( result.indexOf( "fact0.setDob( sdf.parse(\"31-Jan-2000\"" ) != -1 );
View Full Code Here

        try {

            System.setProperty( "drools.dateformat",
                                "dd-MMM-yyyy" );

            RuleModel m = new RuleModel();
            m.name = "RHS Date";

            FactPattern p = new FactPattern( "Person" );
            p.setBoundName( "$p" );
            SingleFieldConstraint con = new SingleFieldConstraint();
            con.setFieldType( DataType.TYPE_DATE );
            con.setFieldName( "dateOfBirth" );
            con.setOperator( "==" );
            con.setValue( "31-Jan-2000" );
            con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
            p.addConstraint( con );

            m.addLhsItem( p );

            ActionUpdateField am = new ActionUpdateField( "$p" );
            am.addFieldValue( new ActionFieldValue( "dob",
                                                    "31-Jan-2000",
                                                    DataType.TYPE_DATE ) );
            m.addRhsItem( am );

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

            assertTrue( result.indexOf( "java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");" ) != -1 );
            assertTrue( result.indexOf( "$p.setDob( sdf.parse(\"31-Jan-2000\"" ) != -1 );
View Full Code Here

        try {

            System.setProperty( "drools.dateformat",
                                "dd-MMM-yyyy" );

            RuleModel m = new RuleModel();
            m.name = "RHS Date";

            FactPattern p = new FactPattern( "Person" );
            p.setBoundName( "$p" );
            SingleFieldConstraint con = new SingleFieldConstraint();
            con.setFieldType( DataType.TYPE_DATE );
            con.setFieldName( "dateOfBirth" );
            con.setOperator( "==" );
            con.setValue( "31-Jan-2000" );
            con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
            p.addConstraint( con );

            m.addLhsItem( p );

            ActionSetField au = new ActionSetField( "$p" );
            au.addFieldValue( new ActionFieldValue( "dob",
                                                    "31-Jan-2000",
                                                    DataType.TYPE_DATE ) );
            m.addRhsItem( au );

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

            assertTrue( result.indexOf( "java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");" ) != -1 );
            assertTrue( result.indexOf( "$p.setDob( sdf.parse(\"31-Jan-2000\"" ) != -1 );
View Full Code Here

    }

    @Test
    public void testRHSExecuteWorkItem1() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern p = new FactPattern( "Person" );
        p.setBoundName( "$p" );
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldType( DataType.TYPE_STRING );
        con.setFieldName( "name" );
        con.setOperator( "==" );
        con.setValue( "Michael" );
        con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        p.addConstraint( con );

        m.addLhsItem( p );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanParameter" );
        p1.setValue( Boolean.TRUE );
        pwd.addParameter( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatParameter" );
        p2.setValue( 123.456f );
        pwd.addParameter( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerParameter" );
        p3.setValue( 123 );
        pwd.addParameter( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringParameter" );
        p4.setValue( "hello" );
        pwd.addParameter( p4 );

        m.addRhsItem( awi );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

    }

    @Test
    public void testRHSExecuteWorkItem2() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern p = new FactPattern( "Person" );
        p.setBoundName( "$p" );
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldType( DataType.TYPE_STRING );
        con.setFieldName( "name" );
        con.setOperator( "==" );
        con.setValue( "Michael" );
        con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        p.addConstraint( con );

        m.addLhsItem( p );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanParameter" );
        p1.setValue( Boolean.TRUE );
        p1.setBinding( "" );
        pwd.addParameter( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatParameter" );
        p2.setValue( 123.456f );
        p2.setBinding( "" );
        pwd.addParameter( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerParameter" );
        p3.setValue( 123 );
        p3.setBinding( "" );
        pwd.addParameter( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringParameter" );
        p4.setValue( "hello" );
        p4.setBinding( "" );
        pwd.addParameter( p4 );

        m.addRhsItem( awi );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

    @Test
    //Test that WorkItem Parameters whose values are bound are created and
    //populated in the RHS if the Pattern is bound to the same variable
    public void testRHSExecuteWorkItemWithBindings() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern fp1 = new FactPattern( "Person" );
        fp1.setBoundName( "$p" );
        SingleFieldConstraint con1 = new SingleFieldConstraint();
        con1.setFieldType( DataType.TYPE_STRING );
        con1.setFieldName( "name" );
        con1.setOperator( "==" );
        con1.setValue( "Michael" );
        con1.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp1.addConstraint( con1 );
        m.addLhsItem( fp1 );

        FactPattern fp2 = new FactPattern( "Boolean" );
        fp2.setBoundName( "$b" );
        SingleFieldConstraint con2 = new SingleFieldConstraint();
        con2.setFieldType( DataType.TYPE_BOOLEAN );
        con2.setFieldName( "this" );
        con2.setOperator( "==" );
        con2.setValue( "true" );
        con2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp2.addConstraint( con2 );
        m.addLhsItem( fp2 );

        FactPattern fp3 = new FactPattern( "Float" );
        fp3.setBoundName( "$f" );
        SingleFieldConstraint con3 = new SingleFieldConstraint();
        con3.setFieldType( DataType.TYPE_NUMERIC_FLOAT );
        con3.setFieldName( "this" );
        con3.setOperator( "==" );
        con3.setValue( "123.456f" );
        con3.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp3.addConstraint( con3 );
        m.addLhsItem( fp3 );

        FactPattern fp4 = new FactPattern( "Integer" );
        fp4.setBoundName( "$i" );
        SingleFieldConstraint con4 = new SingleFieldConstraint();
        con4.setFieldType( DataType.TYPE_NUMERIC_INTEGER );
        con4.setFieldName( "this" );
        con4.setOperator( "==" );
        con4.setValue( "123" );
        con4.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp4.addConstraint( con4 );
        m.addLhsItem( fp4 );

        FactPattern fp5 = new FactPattern( "String" );
        fp5.setBoundName( "$s" );
        SingleFieldConstraint con5 = new SingleFieldConstraint();
        con5.setFieldType( DataType.TYPE_STRING );
        con5.setFieldName( "this" );
        con5.setOperator( "==" );
        con5.setValue( "hello" );
        con5.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp5.addConstraint( con5 );
        m.addLhsItem( fp5 );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanParameter" );
        p1.setBinding( "$b" );
        p1.setValue( Boolean.TRUE );
        pwd.addParameter( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatParameter" );
        p2.setBinding( "$f" );
        p2.setValue( 123.456f );
        pwd.addParameter( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerParameter" );
        p3.setBinding( "$i" );
        p3.setValue( 123 );
        pwd.addParameter( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringParameter" );
        p4.setBinding( "$s" );
        p4.setValue( "hello" );
        pwd.addParameter( p4 );

        m.addRhsItem( awi );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

    @Test
    //Test that WorkItem Parameters whose values are bound are *NOT* created or
    //populated in the RHS if the Pattern is *NOT* bound to the same variable
    public void testRHSExecuteWorkItemWithMissingBindings1() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern fp1 = new FactPattern( "Person" );
        fp1.setBoundName( "$p" );
        SingleFieldConstraint con1 = new SingleFieldConstraint();
        con1.setFieldType( DataType.TYPE_STRING );
        con1.setFieldName( "name" );
        con1.setOperator( "==" );
        con1.setValue( "Michael" );
        con1.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp1.addConstraint( con1 );
        m.addLhsItem( fp1 );

        FactPattern fp2 = new FactPattern( "Boolean" );
        fp2.setBoundName( "$b1" );
        SingleFieldConstraint con2 = new SingleFieldConstraint();
        con2.setFieldType( DataType.TYPE_BOOLEAN );
        con2.setFieldName( "this" );
        con2.setOperator( "==" );
        con2.setValue( "true" );
        con2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp2.addConstraint( con2 );
        m.addLhsItem( fp2 );

        FactPattern fp3 = new FactPattern( "Float" );
        fp3.setBoundName( "$f1" );
        SingleFieldConstraint con3 = new SingleFieldConstraint();
        con3.setFieldType( DataType.TYPE_NUMERIC_FLOAT );
        con3.setFieldName( "this" );
        con3.setOperator( "==" );
        con3.setValue( "123.456f" );
        con3.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp3.addConstraint( con3 );
        m.addLhsItem( fp3 );

        FactPattern fp4 = new FactPattern( "Integer" );
        fp4.setBoundName( "$i1" );
        SingleFieldConstraint con4 = new SingleFieldConstraint();
        con4.setFieldType( DataType.TYPE_NUMERIC_INTEGER );
        con4.setFieldName( "this" );
        con4.setOperator( "==" );
        con4.setValue( "123" );
        con4.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp4.addConstraint( con4 );
        m.addLhsItem( fp4 );

        FactPattern fp5 = new FactPattern( "String" );
        fp5.setBoundName( "$s1" );
        SingleFieldConstraint con5 = new SingleFieldConstraint();
        con5.setFieldType( DataType.TYPE_STRING );
        con5.setFieldName( "this" );
        con5.setOperator( "==" );
        con5.setValue( "hello" );
        con5.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp5.addConstraint( con5 );
        m.addLhsItem( fp5 );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanParameter" );
        p1.setBinding( "$b" );
        p1.setValue( Boolean.TRUE );
        pwd.addParameter( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatParameter" );
        p2.setBinding( "$f" );
        p2.setValue( 123.456f );
        pwd.addParameter( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerParameter" );
        p3.setBinding( "$i" );
        p3.setValue( 123 );
        pwd.addParameter( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringParameter" );
        p4.setBinding( "$s" );
        p4.setValue( "hello" );
        pwd.addParameter( p4 );

        m.addRhsItem( awi );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

    @Test
    //Test that WorkItem Parameters whose values are bound are *NOT* created or
    //populated in the RHS if the Pattern is *NOT* bound to the same variable
    public void testRHSExecuteWorkItemWithMissingBindings2() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern fp1 = new FactPattern( "Person" );
        fp1.setBoundName( "$p" );
        SingleFieldConstraint con1 = new SingleFieldConstraint();
        con1.setFieldType( DataType.TYPE_STRING );
        con1.setFieldName( "name" );
        con1.setOperator( "==" );
        con1.setValue( "Michael" );
        con1.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL );
        fp1.addConstraint( con1 );
        m.addLhsItem( fp1 );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanParameter" );
        p1.setBinding( "$b2" );
        p1.setValue( Boolean.TRUE );
        pwd.addParameter( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatParameter" );
        p2.setBinding( "$f2" );
        p2.setValue( 123.456f );
        pwd.addParameter( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerParameter" );
        p3.setBinding( "$i2" );
        p3.setValue( 123 );
        pwd.addParameter( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringParameter" );
        p4.setBinding( "$s2" );
        p4.setValue( "hello" );
        pwd.addParameter( p4 );

        m.addRhsItem( awi );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

    @Test
    //Test that WorkItem Parameters can be used to set fields on existing Facts
    public void testRHSActionWorkItemSetFields() {

        RuleModel m = new RuleModel();
        m.name = "WorkItem";

        FactPattern fp1 = new FactPattern( "Results" );
        fp1.setBoundName( "$r" );
        m.addLhsItem( fp1 );

        ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
        PortableWorkDefinition pwd = new PortableWorkDefinition();
        pwd.setName( "WorkItem" );
        awi.setWorkDefinition( pwd );

        PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
        p1.setName( "BooleanResult" );
        pwd.addResult( p1 );

        PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
        p2.setName( "FloatResult" );
        pwd.addResult( p2 );

        PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
        p3.setName( "IntegerResult" );
        pwd.addResult( p3 );

        PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
        p4.setName( "StringResult" );
        pwd.addResult( p4 );

        m.addRhsItem( awi );

        ActionSetField asf = new ActionSetField();
        asf.setVariable( "$r" );
        ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue( "ResultsBooleanResult",
                                                                     DataType.TYPE_BOOLEAN,
                                                                     "WorkItem",
                                                                     "BooleanResult",
                                                                     Boolean.class.getName() );
        asf.addFieldValue( fv1 );
        ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue( "ResultsFloatResult",
                                                                     DataType.TYPE_NUMERIC_FLOAT,
                                                                     "WorkItem",
                                                                     "FloatResult",
                                                                     Float.class.getName() );
        asf.addFieldValue( fv2 );
        ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue( "ResultsIntegerResult",
                                                                     DataType.TYPE_NUMERIC_INTEGER,
                                                                     "WorkItem",
                                                                     "IntegerResult",
                                                                     Integer.class.getName() );
        asf.addFieldValue( fv3 );
        ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue( "ResultsStringResult",
                                                                     DataType.TYPE_STRING,
                                                                     "WorkItem",
                                                                     "StringResult",
                                                                     String.class.getName() );
        asf.addFieldValue( fv4 );

        m.addRhsItem( asf );

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

        assertTrue( result.indexOf( "org.kie.internal.process.instance.WorkItemManager wim = (org.kie.internal.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();" ) != -1 );
        assertTrue( result.indexOf( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem = new org.kie.internal.process.instance.impl.WorkItemImpl();" ) != -1 );
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.commons.shared.rule.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.