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

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


        try {

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

            RuleModel m = new RuleModel();
            m.name = "RHS SetMethodCallsMethod";
            m.addAttribute( new RuleAttribute( "dialect",
                                               "java" ) );

            FactPattern p = new FactPattern( "Person" );
            p.setBoundName( "$p" );
            m.addLhsItem( p );

            ActionCallMethod acm = new ActionCallMethod();
            acm.setMethodName( "method" );
            acm.setVariable( "$p" );
            acm.addFieldValue( new ActionFieldFunction( "f1",
                                                        "String",
                                                        DataType.TYPE_STRING ) );
            acm.addFieldValue( new ActionFieldFunction( "f2",
                                                        "true",
                                                        DataType.TYPE_BOOLEAN ) );
            acm.addFieldValue( new ActionFieldFunction( "f3",
                                                        "31-Jan-2012",
                                                        DataType.TYPE_DATE ) );
            acm.addFieldValue( new ActionFieldFunction( "f4",
                                                        "100",
                                                        DataType.TYPE_NUMERIC_INTEGER ) );
            acm.addFieldValue( new ActionFieldFunction( "f5",
                                                        "100",
                                                        DataType.TYPE_NUMERIC_BIGDECIMAL ) );

            m.addRhsItem( acm );

            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.method( \"String\", true, sdf.parse(\"31-Jan-2012\"), 100, new java.math.BigDecimal(\"100\") );" ) != -1 );
View Full Code Here


    }

    @Test
    public void testFromAccumulateWithEmbeddedFromEntryPoint() {
        RuleModel m = new RuleModel();
        m.name = "r1";

        SingleFieldConstraint sfc = new SingleFieldConstraint( "bar" );
        sfc.setFactType( DataType.TYPE_NUMERIC_INTEGER );
        sfc.setFieldBinding( "$a" );
        sfc.setOperator( "==" );
        sfc.setValue( "777" );

        FactPattern fp = new FactPattern( "Foo" );
        fp.addConstraint( sfc );

        FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
        fep.setEntryPointName( "ep" );
        fep.setFactPattern( fp );
        FromAccumulateCompositeFactPattern fac = new FromAccumulateCompositeFactPattern();
        fac.setSourcePattern( fep );
        fac.setFactPattern( new FactPattern( "java.util.List" ) );
        fac.setFunction( "max($a)" );
        m.addLhsItem( fac );

        String expected = "rule \"r1\"\n"
                + "dialect \"mvel\"\n"
                + "when\n"
                + "java.util.List( ) from accumulate ( Foo( $a : bar == 777 ) from entry-point \"ep\", \n"
View Full Code Here

                                 m );
    }

    @Test
    public void testFromCollectWithEmbeddedFromEntryPoint() {
        RuleModel m = new RuleModel();
        m.name = "r1";

        SingleFieldConstraint sfc = new SingleFieldConstraint( "bar" );
        sfc.setFactType( DataType.TYPE_NUMERIC_INTEGER );
        sfc.setFieldBinding( "$a" );
        sfc.setOperator( "==" );
        sfc.setValue( "777" );

        FactPattern fp = new FactPattern( "Foo" );
        fp.addConstraint( sfc );

        FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
        fep.setEntryPointName( "ep" );
        fep.setFactPattern( fp );
        FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
        fac.setRightPattern( fep );
        fac.setFactPattern( new FactPattern( "java.util.List" ) );
        m.addLhsItem( fac );

        String expected = "rule \"r1\"\n"
                + "dialect \"mvel\"\n"
                + "when\n"
                + "java.util.List( ) from collect ( Foo( $a : bar == 777 ) from entry-point \"ep\" ) \n"
View Full Code Here

                                 m );
    }

    @Test
    public void testCompositeFactPatternWithFromWithDSL() {
        final RuleModel m = new RuleModel();
        m.name = "model";

        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( "A DSL phrase" );
        m.addLhsItem( sen );

        final FactPattern fp1 = new FactPattern( "Data" );
        fp1.setBoundName( "$d" );
        m.addLhsItem( fp1 );

        final CompositeFactPattern cp = new CompositeFactPattern( CompositeFactPattern.COMPOSITE_TYPE_NOT );

        final FactPattern fp2 = new FactPattern( "Person" );
        final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
        ffp1.setExpression( new ExpressionFormLine( new ExpressionVariable( fp1 ) ) );
        ffp1.setFactPattern( fp2 );
        cp.addFactPattern( ffp1 );
        m.addLhsItem( cp );

        final String actual = BRDRLPersistence.getInstance().marshal( m );
        final String expected = "rule \"model\"\n" +
                "dialect \"mvel\"\n" +
                "when\n" +
View Full Code Here

                "dialect \"mvel\"" +
                "when\n" +
                "then\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        assertEquals( 1,
                      m.getImports().getImports().size() );
        assertEquals( "java.util.ArrayList",
                      m.getImports().getImports().get( 0 ).getType() );
    }
View Full Code Here

                "$a : Applicant( )\n" +
                "then\n" +
                "$a.setName( \"Michael\" );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
View Full Code Here

                "$a : Applicant( )\n" +
                "then\n" +
                "$a.addName( \"Michael\" );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
View Full Code Here

                        "$a : Applicant( )\n" +
                        "then\n" +
                        "list.add( $a );\n" +
                        "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshalUsingDSL( drl, Arrays.asList( global ) );

        assertNotNull( m );
        assertEqualsIgnoreWhitespace( drl, BRDRLPersistence.getInstance().marshal( m ) );

        //LHS
View Full Code Here

                "Here's something typed by the user as free-format DRL\n" +
                "$b : Bananna( )\n" +
                "then\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 3,
                      m.lhs.length );
View Full Code Here

                "$a.setName( \"Michael\" );\n" +
                "Here's something typed by the user as free-format DRL\n" +
                "$a.setAge( 40 );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
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.