Package org.drools.lang.descr

Examples of org.drools.lang.descr.RuleDescr


        assertFalse( this.parser.hasErrors() );
    }

    public void testEmptyRule() throws Exception {
        final RuleDescr rule = parseResource( "empty_rule.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "empty",
                      rule.getName() );
        assertNotNull( rule.getLhs() );
        assertNotNull( rule.getConsequence() );

        assertFalse( this.parser.getErrorMessages().toString(),
                     this.parser.hasErrors() );
    }
View Full Code Here


        assertTrue( this.parser.hasErrors() );

        final PackageDescr pkg = this.parser.getPackageDescr();
        assertEquals( 1,
                      pkg.getRules().size() );
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );

        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );
        final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );

        assertNotNull( pattern );
        assertEquals( "Bar",
                      pattern.getObjectType() );
        assertEquals( "foo3",
View Full Code Here

        final DRLParser parser = parseResource( "ternary_expression.drl" );

        parser.compilation_unit();
        final PackageDescr pkg = parser.getPackageDescr();
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      pkg.getRules().size() );

        assertFalse( parser.hasErrors() );
        assertEqualsIgnoreWhitespace( "if (speed > speedLimit ? true : false;) pullEmOver();",
                                      (String) rule.getConsequence() );
    }
View Full Code Here

        assertEquals( "foo",
                      pkg.getName() );
        assertEquals( 1,
                      pkg.getRules().size() );

        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );

        assertEqualsIgnoreWhitespace( "yourFunction(new String[3] {\"a\",\"b\",\"c\"});",
                                      (String) rule.getConsequence() );
        final FunctionDescr func = (FunctionDescr) pkg.getFunctions().get( 0 );

        assertEquals( "String[]",
                      func.getReturnType() );
        assertEquals( "args[]",
View Full Code Here

        assertEquals( "String",
                      func.getParameterTypes().get( 0 ) );
    }

    public void testAlmostEmptyRule() throws Exception {
        final RuleDescr rule = parseResource( "almost_empty_rule.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "almost_empty",
                      rule.getName() );
        assertNotNull( rule.getLhs() );
        assertEquals( "",
                      ((String) rule.getConsequence()).trim() );
        assertFalse( this.parser.hasErrors() );
    }
View Full Code Here

                      ((String) rule.getConsequence()).trim() );
        assertFalse( this.parser.hasErrors() );
    }

    public void testQuotedStringNameRule() throws Exception {
        final RuleDescr rule = parseResource( "quoted_string_name_rule.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "quoted string name",
                      rule.getName() );
        assertNotNull( rule.getLhs() );
        assertEquals( "",
                      ((String) rule.getConsequence()).trim() );
        assertFalse( this.parser.hasErrors() );
    }
View Full Code Here

                      ((String) rule.getConsequence()).trim() );
        assertFalse( this.parser.hasErrors() );
    }

    public void testNoLoop() throws Exception {
        final RuleDescr rule = parseResource( "no-loop.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "rule1",
                      rule.getName() );
        final AttributeDescr att = (AttributeDescr) rule.getAttributes().get( 0 );
        assertEquals( "false",
                      att.getValue() );
        assertEquals( "no-loop",
                      att.getName() );
        assertFalse( this.parser.getErrorMessages().toString(),
View Full Code Here

                     this.parser.hasErrors() );

    }

    public void testAutofocus() throws Exception {
        final RuleDescr rule = parseResource( "autofocus.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "rule1",
                      rule.getName() );
        final AttributeDescr att = (AttributeDescr) rule.getAttributes().get( 0 );
        assertEquals( "true",
                      att.getValue() );
        assertEquals( "auto-focus",
                      att.getName() );
View Full Code Here

        assertFalse( this.parser.hasErrors() );
    }

    public void testRuleFlowGroup() throws Exception {
        final RuleDescr rule = parseResource( "ruleflowgroup.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "rule1",
                      rule.getName() );
        final AttributeDescr att = (AttributeDescr) rule.getAttributes().get( 0 );
        assertEquals( "a group",
                      att.getValue() );
        assertEquals( "ruleflow-group",
                      att.getName() );
View Full Code Here

        assertFalse( this.parser.hasErrors() );
    }

    public void testConsequenceWithDeclaration() throws Exception {
        final RuleDescr rule = parseResource( "declaration-in-consequence.drl" ).rule();

        assertNotNull( rule );

        assertEquals( "myrule",
                      rule.getName() );

        final String expected = "int i = 0; i = 1; i / 1; i == 1; i(i); i = 'i'; i.i.i; i\\i; i<i; i>i; i=\"i\";  ++i;" + "i++; --i; i--; i += i; i -= i; i *= i; i /= i;" + "int i = 5;" + "for(int j; j<i; ++j) {" + "System.out.println(j);}"
                                + "Object o = new String(\"Hello\");" + "String s = (String) o;";

        assertEqualsIgnoreWhitespace( expected,
                                      (String) rule.getConsequence() );
        assertTrue( ((String) rule.getConsequence()).indexOf( "++" ) > 0 );
        assertTrue( ((String) rule.getConsequence()).indexOf( "--" ) > 0 );
        assertTrue( ((String) rule.getConsequence()).indexOf( "+=" ) > 0 );
        assertTrue( ((String) rule.getConsequence()).indexOf( "==" ) > 0 );

        //System.out.println(( String ) rule.getConsequence());
        //note, need to assert that "i++" is preserved as is, no extra spaces.

        assertFalse( this.parser.hasErrors() );
View Full Code Here

TOP

Related Classes of org.drools.lang.descr.RuleDescr

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.