[jboss-jira] [JBoss JIRA] Closed: (JBRULES-1312) DSL mapping in JBossRules doesn't always work correctly.

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Mon Nov 5 10:14:07 EST 2007


     [ http://jira.jboss.com/jira/browse/JBRULES-1312?page=all ]

Edson Tirelli closed JBRULES-1312.
----------------------------------

    Resolution: Rejected
      Assignee: Edson Tirelli

Davy, 

Drools 4.0.x works with pseudo-regex in the mapping keys, as detailed in the upgrade tips of the manual (please see section 1.2.4: http://downloads.jboss.com/drools/docs/4.0.3.15993.GA/html/index.html).
So, in your case, you are using the following characters "()+" that are special characters for regexps, and as so, they must be escaped:

[when][]code {code1} occurs and sum of all digit not equal \( {code2} \+ {code3} \)=AAAA

Anyway, I added a test to our integration tests to make sure we didn't have a regression:

    public void testParseFileWithEscapes() {
        String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");\n" + 
                      "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))\n" + 
                      "[when]code {code1} occurs=BBBB\n";
        try {
            final Reader reader = new StringReader( file );
            this.file = new DSLMappingFile();

            final boolean parsingResult = this.file.parseAndLoad( reader );
            reader.close();

            assertTrue( this.file.getErrors().toString(),
                        parsingResult );
            assertTrue( this.file.getErrors().isEmpty() );
            
            final String LHS = "code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )";
            final String rule = "rule \"x\"\nwhen\n" + LHS + "\nthen\nTEST\nend";

            DefaultExpander de = new DefaultExpander();
            de.addDSLMapping(this.file.getMapping());
                    
            final String ruleAfterExpansion = de.expand(rule);
            
            final String expected = "rule \"x\"\nwhen\nAAAA( cd1 == 1041, cd2 != ( 1034 + 1035 ))\nthen\nSystem.out.println(\"DO_SOMETHING\");\nend\n";
            
            assertEquals( expected, ruleAfterExpansion );
            
        } catch ( final IOException e ) {
            e.printStackTrace();
            fail( "Should not raise exception " );
        }

    }

So, escaping the characters must work for you. Let me know please if it doesn't.

Edson

> DSL mapping in JBossRules doesn't always work correctly.
> --------------------------------------------------------
>
>                 Key: JBRULES-1312
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-1312
>             Project: JBoss Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 4.0.3
>         Environment: - Windows XP
> - tested with JDK 1.4 and JDK 1.5
>            Reporter: Davy Toch
>         Assigned To: Edson Tirelli
>         Attachments: DroolsExpansionUnitTest.java
>
>
> DSL mapping in 4.0.3 doesn't seem to work as expected (cf included JUnit testcase).
> ruleBeforeExpansion : 
> rule "x"
> when
> code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )
> then
> TEST
> end
> ruleAfterExpansion : 
> rule "x"
> when
> BBBBand sum of all digit not equal ( 1034 + 1035 )
> then
> System.out.println("DO_SOMETHING");
> end
> So the LHS matches the wrong 'when' DSL. As a comparison I did a test with JBossRules 3.0.6, which didn't pose a problem.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list