Package org.drools.workbench.models.datamodel.rule

Examples of org.drools.workbench.models.datamodel.rule.DSLSentence


        assertNotNull( m );

        assertTrue( m.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 0,
                      dslSentence.getValues().size() );

        DSLSentence dslSentence2 = (DSLSentence) m.lhs[ 1 ];
        assertEquals( dslDefinition2,
                      dslSentence2.getDefinition() );
        assertEquals( 1,
                      dslSentence2.getValues().size() );

        assertTrue( dslSentence2.getValues().get( 0 ) instanceof DSLVariableValue );

        DSLVariableValue dslComplexVariableValue = dslSentence2.getValues().get( 0 );
        assertEquals( "123",
                      dslComplexVariableValue.getValue() );
    }
View Full Code Here


                                                                                             new ArrayList<String>(),
                                                                                             dmo,
                                                                                             new String[]{ dslFile } );

        assertEquals( 1, model.lhs.length );
        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];
        assertEquals( "test", dslSentence.getValues().get( 0 ).getValue() );
        assertEquals( "111", dslSentence.getValues().get( 1 ).getValue() );

    }
View Full Code Here

                                                                                             new ArrayList<String>(),
                                                                                             dmo,
                                                                                             new String[]{ dslFile } );

        assertEquals( 1, model.lhs.length );
        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];

        assertEquals( "Price is ${p}", dslSentence.getDefinition() );
        assertEquals( "111", dslSentence.getValues().get( 0 ).getValue() );

    }
View Full Code Here

        assertNotNull( m );

        assertTrue( m.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "AA",
                      dslComplexVariableValue.getValue() );
        assertEquals( "ENUM:Applicant.creditRating",
                      dslComplexVariableValue.getId() );
    }
View Full Code Here

        assertEquals( "$a",
                      pattern.getBoundName() );

        assertTrue( m.rhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.rhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "Bob",
                      dslComplexVariableValue.getValue() );
        assertEquals( "\\w+ \\w+",
                      dslComplexVariableValue.getId() );
    }
View Full Code Here

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

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

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

        checkMarshallUnmarshallUsingDsl( expected,
                                         unmarshalledModel );
    }
View Full Code Here

                        "\t\tThe credit rating is AA\n" +
                        "\tthen\n" +
                        "end\n";
        final String dslDefinition = "The credit rating is {rating:ENUM:Applicant.creditRating}";

        final DSLSentence dsl = new DSLSentence();
        dsl.setDefinition( dslDefinition );

        //Check values are correctly parsed
        final List<DSLVariableValue> values = dsl.getValues();
        assertEquals( 1,
                      values.size() );
        assertTrue( values.get( 0 ) instanceof DSLComplexVariableValue );
        assertEquals( "rating",
                      values.get( 0 ).getValue() );
        assertEquals( "ENUM:Applicant.creditRating",
                      ( (DSLComplexVariableValue) values.get( 0 ) ).getId() );

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

        //Check interpolation
        final String expansion = dsl.interpolate();

        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 = ruleModelPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected, drl );

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

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

        DSLSentence dslSentence = (DSLSentence) unmarshalledModel.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "AA",
                      dslComplexVariableValue.getValue() );
        assertEquals( "ENUM:Applicant.creditRating",
                      dslComplexVariableValue.getId() );
View Full Code Here

                        "When the ages is less than  57\n" +
                        "then\n" +
                        "end\n";
        final String dslDefinition = "When the ages is less than {num:1?[0-9]?[0-9]}";

        final DSLSentence dsl = new DSLSentence();
        dsl.setDefinition( dslDefinition );

        //Check values are correctly parsed
        final List<DSLVariableValue> values = dsl.getValues();
        assertEquals( 1,
                      values.size() );
        assertTrue( values.get( 0 ) instanceof DSLComplexVariableValue );
        assertEquals( "num",
                      values.get( 0 ).getValue() );
        assertEquals( "1?[0-9]?[0-9]",
                      ( (DSLComplexVariableValue) values.get( 0 ) ).getId() );

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

        //Check interpolation
        final String expansion = dsl.interpolate();

        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 = ruleModelPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected,
                                      drl );

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

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

        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "57",
                      dslComplexVariableValue.getValue() );
        assertEquals( "1?[0-9]?[0-9]",
                      dslComplexVariableValue.getId() );
View Full Code Here

                        "when\n" +
                        "The credit rating is AA\n" +
                        "then\n" +
                        "end";

        final DSLSentence dsl = new DSLSentence();
        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 );
View Full Code Here

        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

TOP

Related Classes of org.drools.workbench.models.datamodel.rule.DSLSentence

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.