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

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


    @Test
    public void testEnumTypeBoolean() {
        //A legacy "Guvnor" enums (i.e pick-list of underlying field data-type)
        String expected = "rule \"my rule\"\n\tdialect \"mvel\"\n\twhen\n\t\tCheese( smelly == true )\n"
                + "\tthen\n\t\tinsert( new Report() );\nend\n";
        final RuleModel m = new RuleModel();
        final FactPattern pat = new FactPattern( "Cheese" );

        m.addLhsItem( pat );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldName( "smelly" );
        con.setOperator( "==" );
        con.setValue( "true" );
        con.setFieldType( DataType.TYPE_BOOLEAN );
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_ENUM );
        pat.addConstraint( con );

        m.addRhsItem( new ActionInsertFact( "Report" ) );
        m.name = "my rule";

        checkMarshallUnmarshall( expected, m );
    }
View Full Code Here


    @Test
    public void testEnumTypeDate() {
        //A legacy "Guvnor" enums (i.e pick-list of underlying field data-type)
        String expected = "rule \"my rule\"\n\tdialect \"mvel\"\n\twhen\n\t\tCheese( dateMade == \"31-Jan-2010\" )\n"
                + "\tthen\n\t\tinsert( new Report() );\nend\n";
        final RuleModel m = new RuleModel();
        final FactPattern pat = new FactPattern( "Cheese" );

        m.addLhsItem( pat );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldName( "dateMade" );
        con.setOperator( "==" );
        con.setValue( "31-Jan-2010" );
        con.setFieldType( DataType.TYPE_DATE );
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_ENUM );
        pat.addConstraint( con );

        m.addRhsItem( new ActionInsertFact( "Report" ) );
        m.name = "my rule";

        checkMarshallUnmarshall( expected, m );
    }
View Full Code Here

    @Test
    public void testEnumTypeComparable() {
        //Java 1.5+ "true" enums are of type Comparable
        String expected = "rule \"my rule\"\n\tdialect \"mvel\"\n\twhen\n\t\tCheese( type == Cheese.CHEDDAR )\n"
                + "\tthen\n\t\tinsert( new Report() );\nend\n";
        final RuleModel m = new RuleModel();
        final FactPattern pat = new FactPattern( "Cheese" );

        m.addLhsItem( pat );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldName( "type" );
        con.setOperator( "==" );
        con.setValue( "Cheese.CHEDDAR" );
        con.setFieldType( DataType.TYPE_COMPARABLE );
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_ENUM );
        pat.addConstraint( con );

        m.addRhsItem( new ActionInsertFact( "Report" ) );
        m.name = "my rule";

        checkMarshallUnmarshall( expected, m );
    }
View Full Code Here

        checkMarshallUnmarshall( expected, m );
    }

    @Test
    public void testMoreComplexRendering() {
        final RuleModel m = getComplexModel( false );
        String expected = "rule \"Complex Rule\"\n" + "\tno-loop true\n"
                + "\tsalience -10\n" + "\tagenda-group \"aGroup\"\n"
                + "\tdialect \"mvel\"\n" + "\twhen\n"
                + "\t\tp1 : Person( f1 : age < 42 )\n"
                + "\t\tnot (Cancel( )) \n" + "\tthen\n"
View Full Code Here

        checkMarshallUnmarshall( expected, m );
    }

    @Test
    public void testMoreComplexRenderingWithDsl() {
        final RuleModel m = getComplexModel( true );
        String expected = "rule \"Complex Rule\"\n" + "\tno-loop true\n"
                + "\tsalience -10\n" + "\tagenda-group \"aGroup\"\n"
                + "\tdialect \"mvel\"\n" + "\twhen\n"
                + "\t\t>p1 : Person( f1 : age < 42 )\n"
                + "\t\t>not (Cancel( )) \n" + "\tthen\n"
                + "\t\t>p1.setStatus( \"rejected\" );\n"
                + "\t\t>update( p1 );\n" + "\t\t>retract( p1 );\n"
                + "\t\tSend an email to administrator\n" + "end\n";

        checkMarshallUnmarshall( expected, m );

        String drl = brlPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected, drl );

        String dslFile = "[then]Send an email to {administrator}=sendMailTo({administrator});";

        RuleModel unmarshalledModel = brlPersistence.unmarshalUsingDSL( drl, null, dslFile );

        IAction[] actions = unmarshalledModel.rhs;
        DSLSentence dslSentence = (DSLSentence) actions[ actions.length - 1 ];
        assertEquals( "Send an email to {administrator}", dslSentence.getDefinition() );
View Full Code Here

        assertEquals( "The credit rating is AA",
                      expansion );
        assertEquals( dsl.getDefinition(),
                      dslDefinition );

        final RuleModel m = new RuleModel();
        m.name = "Rule With DSL";
        m.addLhsItem( dsl );

        String drl = brlPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected, drl );

        String dslFile = "[when]" + dslDefinition + "=Credit( rating == {rating} )";

        RuleModel unmarshalledModel = brlPersistence.unmarshalUsingDSL( drl,
                                                                        null,
                                                                        dslFile );

        DSLSentence dslSentence = (DSLSentence) unmarshalledModel.lhs[ 0 ];
        assertEquals( dslDefinition,
View Full Code Here

        assertEquals( "When the ages is less than 57",
                      expansion );
        assertEquals( dsl.getDefinition(),
                      dslDefinition );

        final RuleModel m = new RuleModel();
        m.name = "RegexDslRule";
        m.addLhsItem( dsl );

        String drl = brlPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected,
                                      drl );

        String dslFile = "[when]" + dslDefinition + "=applicant:Applicant(age<{num})";

        RuleModel model = brlPersistence.unmarshalUsingDSL( drl,
                                                            null,
                                                            dslFile );

        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];
        assertEquals( dslDefinition,
View Full Code Here

        dsl.setDefinition( dslDefinition );
        //The following line is normally performed by the UI when the user sets values
        dsl.getValues().get( 0 ).setValue( "AA" );

        //Append DSL to RuleModel to check marshalling
        final RuleModel m = new RuleModel();
        m.name = "r1";
        m.addLhsItem( dsl );

        final String drlActual = brlPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( drlExpected,
                                      drlActual );
    }
View Full Code Here

        assertEqualsIgnoreWhitespace( drlExpected,
                                      drlActual );
    }

    private RuleModel getComplexModel( boolean useDsl ) {
        final RuleModel m = new RuleModel();
        m.name = "Complex Rule";

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

        final FactPattern pat = new FactPattern( "Person" );
        pat.setBoundName( "p1" );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldBinding( "f1" );
        con.setFieldName( "age" );
        con.setOperator( "<" );
        con.setValue( "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.setVariable( "p1" );
        set.addFieldValue( new ActionFieldValue( "status",
                                                 "rejected",
                                                 DataType.TYPE_STRING ) );
        m.addRhsItem( set );

        final ActionRetractFact ret = new ActionRetractFact( "p1" );
        m.addRhsItem( ret );

        if ( useDsl ) {
            final DSLSentence sen = new DSLSentence();
            sen.setDefinition( "Send an email to {administrator}" );
            m.addRhsItem( sen );
        }

        return m;
    }
View Full Code Here

    }

    @Test
    public void testFieldBindingWithNoConstraints() {
        // to satisfy JBRULES-850
        RuleModel m = getModelWithNoConstraints();
        String s = BRDRLPersistence.getInstance().marshal( m );
        // System.out.println(s);
        assertTrue( s.contains( "Person( f1 : age)" ) );

        checkMarshallUnmarshall( s, m );
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.