Package org.drools.compiler.lang.descr

Examples of org.drools.compiler.lang.descr.PatternDescr


    }

    @Test
    public void testIsQuery() throws Exception {
        final String text = "rule X when ?person( \"Mark\", 42; ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertTrue( pattern.isQuery() );

        assertEquals( 2,
                      pattern.getDescrs().size() );
        ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get( 0 );
        assertEquals( "\"Mark\"",
                      fcd.getExpression() );
        assertEquals( 0,
                      fcd.getPosition() );
        assertEquals( ExprConstraintDescr.Type.POSITIONAL,
                      fcd.getType() );
        fcd = (ExprConstraintDescr) pattern.getDescrs().get( 1 );
        assertEquals( "42",
                      fcd.getExpression() );
        assertEquals( 1,
                      fcd.getPosition() );
        assertEquals( ExprConstraintDescr.Type.POSITIONAL,
View Full Code Here


        RuleDescr rule = (RuleDescr) parse( "rule",
                                             text );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Cheese",
                      pattern.getObjectType() );
        assertEquals( "from $cheesery",
                      pattern.getSource().getText() );
        assertFalse( pattern.isQuery() );

        pattern = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "person",
                      pattern.getObjectType() );
        assertTrue( pattern.isQuery() );

    }
View Full Code Here

        RuleDescr rule = (RuleDescr) parse( "rule",
                                             text );
        assertFalse( parser.getErrors().toString(),
                     parser.hasErrors() );

        PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Cheese",
                      pattern.getObjectType() );
        assertEquals( "from (isFull ? $cheesery : $market)",
                      pattern.getSource().getText() );
        assertFalse( pattern.isQuery() );

        pattern = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "person",
                      pattern.getObjectType() );
        assertTrue( pattern.isQuery() );

    }
View Full Code Here

    }

    @Test
    public void testPositionalsAndNamedConstraints() throws Exception {
        final String text = "rule X when Person( \"Mark\", 42; location == \"atlanta\" ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( 3,
                      pattern.getDescrs().size() );
        ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get( 0 );
        assertEquals( "\"Mark\"",
                      fcd.getExpression() );
        assertEquals( 0,
                      fcd.getPosition() );
        assertEquals( ExprConstraintDescr.Type.POSITIONAL,
                      fcd.getType() );
        fcd = (ExprConstraintDescr) pattern.getDescrs().get( 1 );
        assertEquals( "42",
                      fcd.getExpression() );
        assertEquals( 1,
                      fcd.getPosition() );
        assertEquals( ExprConstraintDescr.Type.POSITIONAL,
                      fcd.getType() );

        fcd = (ExprConstraintDescr) pattern.getDescrs().get( 2 );
        assertEquals( "location == \"atlanta\"",
                      fcd.getExpression() );
        assertEquals( 2,
                      fcd.getPosition() );
        assertEquals( ExprConstraintDescr.Type.NAMED,
View Full Code Here

    }

    @Test
    public void testUnificationBinding() throws Exception {
        final String text = "rule X when $p := Person( $name := name, $loc : location ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( "$p",
                      pattern.getIdentifier() );
        assertTrue( pattern.isUnification() );

        assertEquals( 2,
                      pattern.getDescrs().size() );
        ExprConstraintDescr bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get( 0 );
        assertEquals( "$name := name",
                      bindingDescr.getExpression() );

        bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get( 1 );
        assertEquals( "$loc : location",
                      bindingDescr.getExpression() );

    }
View Full Code Here

    public void testBigLiterals() throws Exception {
        final String text = "rule X when Primitives( bigInteger == (10I), " +
                        "                        bigDecimal == (10B), " +
                        "                        bigInteger < 50I, " +
                        "                        bigDecimal < 50B ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( 4,
                      pattern.getDescrs().size() );
        ExprConstraintDescr ecd = (ExprConstraintDescr) pattern.getDescrs().get( 0 );
        assertEquals( "bigInteger == (10I)",
                      ecd.getExpression() );

        ecd = (ExprConstraintDescr) pattern.getDescrs().get( 1 );
        assertEquals( "bigDecimal == (10B)",
                      ecd.getExpression() );

        ecd = (ExprConstraintDescr) pattern.getDescrs().get( 2 );
        assertEquals( "bigInteger < 50I",
                      ecd.getExpression() );

        ecd = (ExprConstraintDescr) pattern.getDescrs().get( 3 );
        assertEquals( "bigDecimal < 50B",
                      ecd.getExpression() );
    }
View Full Code Here

    }

    @Test
    public void testBindingComposite() throws Exception {
        final String text = "rule X when Person( $name : name == \"Bob\" || $loc : location == \"Montreal\" ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( "Person",
                      pattern.getObjectType() );
        assertFalse( pattern.isUnification() );

        //        assertEquals( 2,
        //                      pattern.getDescrs().size() );
        //        BindingDescr bindingDescr = pattern.getDescrs().get( 0 );
        //        assertEquals( "$name",
        //                      bindingDescr.getVariable() );
        //        assertEquals( "name",
        //                      bindingDescr.getExpression() );
        //        assertFalse( bindingDescr.isUnification() );
        //
        //        bindingDescr = pattern.getDescrs().get( 1 );
        //        assertEquals( "$loc",
        //                      bindingDescr.getVariable() );
        //        assertEquals( "location",
        //                      bindingDescr.getExpression() );
        //        assertFalse( bindingDescr.isUnification() );

        // embedded bindings are extracted at compile time
        List< ? > constraints = pattern.getDescrs();
        assertEquals( 1,
                      constraints.size() );
        assertEquals( "$name : name == \"Bob\" || $loc : location == \"Montreal\"",
                      ((ExprConstraintDescr) constraints.get( 0 )).getExpression() );
    }
View Full Code Here

    }

    @Test
    public void testBindingCompositeWithMethods() throws Exception {
        final String text = "rule X when Person( $name : name.toUpperCase() == \"Bob\" || $loc : location[0].city == \"Montreal\" ) then end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( "Person",
                      pattern.getObjectType() );
        assertFalse( pattern.isUnification() );

        //        assertEquals( 2,
        //                      pattern.getDescrs().size() );
        //        BindingDescr bindingDescr = pattern.getDescrs().get( 0 );
        //        assertEquals( "$name",
        //                      bindingDescr.getVariable() );
        //        assertEquals( "name.toUpperCase()",
        //                      bindingDescr.getExpression() );
        //        assertFalse( bindingDescr.isUnification() );
        //
        //        bindingDescr = pattern.getDescrs().get( 1 );
        //        assertEquals( "$loc",
        //                      bindingDescr.getVariable() );
        //        assertEquals( "location[0].city",
        //                      bindingDescr.getExpression() );
        //        assertFalse( bindingDescr.isUnification() );

        // embedded bindings are extracted at compile time
        List< ? > constraints = pattern.getDescrs();
        assertEquals( 1,
                      constraints.size() );
        assertEquals( "$name : name.toUpperCase() == \"Bob\" || $loc : location[0].city == \"Montreal\"",
                      ((ExprConstraintDescr) constraints.get( 0 )).getExpression() );
    }
View Full Code Here

                            "    dialect \"mvel\"\n" +
                            "when\n" +
                            "    exists (TelephoneCall( this finishes [1m] \"25-May-2011\" ))\n" +
                            "then\n" +
                            "end";
        PatternDescr pattern = (PatternDescr) ((ExistsDescr) ((RuleDescr) parse( "rule",
                                                                                 text )).getLhs().getDescrs().get( 0 )).getDescrs().get( 0 );

        assertEquals( "TelephoneCall",
                      pattern.getObjectType() );
        ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get( 0 );
        assertEquals( "this finishes [1m] \"25-May-2011\"",
                      constr.getText() );

    }
View Full Code Here

        final String text = "rule \"inline eval\"\n" +
                            "when\n" +
                            "    Person( eval( name.startsWith(\"b\") && name.finishesWith(\"b\")) )\n" +
                            "then\n" +
                            "end";
        PatternDescr pattern = (PatternDescr) ((RuleDescr) parse( "rule",
                                                                  text )).getLhs().getDescrs().get( 0 );

        assertEquals( "Person",
                      pattern.getObjectType() );
        ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get( 0 );
        assertEquals( "eval( name.startsWith(\"b\") && name.finishesWith(\"b\"))",
                      constr.getText() );

    }
View Full Code Here

TOP

Related Classes of org.drools.compiler.lang.descr.PatternDescr

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.