[jboss-svn-commits] JBL Code SVN: r15898 - in labs/jbossrules/branches/4.0.x/drools-compiler/src: test/java/org/drools/xml and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 17 14:41:29 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-10-17 14:41:29 -0400 (Wed, 17 Oct 2007)
New Revision: 15898

Modified:
   labs/jbossrules/branches/4.0.x/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
   labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTest.java
   labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java
   labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.drl
   labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.xml
Log:
JBRULES-1252 DrlDumper does not dump functions
-Fixed function dumper issues
-added tests for various other globals, imports etc.
-updated to add quotes to other attributes like date-effective." C:/dev/jbossrules/4.1.0/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java

Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-10-17 18:29:49 UTC (rev 15897)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-10-17 18:41:29 UTC (rev 15898)
@@ -16,8 +16,12 @@
  * limitations under the License.
  */
 
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.drools.lang.descr.AccumulateDescr;
 import org.drools.lang.descr.AndDescr;
@@ -80,12 +84,24 @@
             this.template = "";
         }
     }
+    
+    private static Set needsQuotes = new HashSet();
+    static {
+        needsQuotes.add( "agenda-group" );
+        needsQuotes.add( "activation-group" );
+        needsQuotes.add( "ruleflow-group" );
+        needsQuotes.add( "date-effective" );
+        needsQuotes.add( "date-expires" );
+        needsQuotes.add( "dialect" );
+    }
+    
 
     public void visitAttributeDescr(final AttributeDescr attributeDescr) {
         this.template = new String();
         final String name = attributeDescr.getName();
         String value = null;
-        if ( name.equals( "agenda-group" ) || name.equals( "activation-group" ) || name.equals( "ruleflow-group" ) ) {
+                        
+        if ( needsQuotes.contains( name) ) {
             // These attributes may need quotes around them, if they have spaces, so add anyway
             value = "\"" + attributeDescr.getValue() + "\"";
         } else {
@@ -489,7 +505,7 @@
         for ( final Iterator it = imports.iterator(); it.hasNext(); ) {
             final String importString = ((FunctionImportDescr) it.next()).getTarget();
             final String importTemplate = "import function " + importString + ";" + DrlDumper.eol;
-            importList = importTemplate;
+            importList += importTemplate;
         }
         return importList + DrlDumper.eol;
     }

Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTest.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTest.java	2007-10-17 18:29:49 UTC (rev 15897)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTest.java	2007-10-17 18:41:29 UTC (rev 15898)
@@ -75,6 +75,16 @@
         DumperTestHelper.XmlFile( "test_ParseComplex.xml" );
     }
     
-
+    public static void testStaticMethod1() {
+        System.out.println( "testStaticMethod1" ) ;
+    }
     
+    public static void testStaticMethod2() {
+        System.out.println( "testStaticMethod2" ) ;
+    }
+    
+    public static void testStaticMethod3() {
+        System.out.println( "testStaticMethod3" ) ;
+    }    
+    
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java	2007-10-17 18:29:49 UTC (rev 15897)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/xml/DumperTestHelper.java	2007-10-17 18:41:29 UTC (rev 15898)
@@ -5,6 +5,7 @@
 
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.StringReader;
 
 import junit.framework.Assert;
 
@@ -40,13 +41,12 @@
         DrlParser parser = new DrlParser();
         final PackageDescr pkgOriginal = parser.parse( new InputStreamReader( DumperTestHelper.class.getResourceAsStream( filename ) ) );
         final DrlDumper dumper = new DrlDumper();
-        final String result = dumper.dump( pkgOriginal );
+        String result = dumper.dump( pkgOriginal );
 
         parser = new DrlParser();
         String buffer = readFile( filename );
         assertEqualsIgnoreWhitespace( buffer.toString(),
-                                      result );
-
+                                      result );                 
     }
 
     private static void assertEqualsIgnoreWhitespace(final String expected,

Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.drl
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.drl	2007-10-17 18:29:49 UTC (rev 15897)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.drl	2007-10-17 18:41:29 UTC (rev 15898)
@@ -1,10 +1,27 @@
 package foo;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.utilArrayList;
+
+global HashMap m;
+global HashSet s;
+global org.drools.Person p;
+
+import function org.drools.xml.DumperTest.testStaticMethod1;
+import function org.drools.xml.DumperTest.testStaticMethod2;
+import function org.drools.xml.DumperTest.testStaticMethod3;
+
 rule "simple_rule"
   salience 10
   no-loop true
   agenda-group "agenda-group"
   activation-group "activation-group"
+  ruleflow-group "xxx"
+  lock-on-active true
+  auto-focus true
+  date-effective "01-Jan-2007"
+  date-expires "01-Feb-2007"    
   when
     foo2 : Bar( a ( > 60 && < 70 ) || ( > 50 && < 55 ) && a3 == "black" || a == 40 && a3 == "pink" || a == 12 && a3 == "yellow" || a3 == "blue")
     foo3 : Bar( a == 3 || == 4, a3 == "hello", a4 == null )    
@@ -21,4 +38,24 @@
     retract( foo4 );
   } 
   System.out.println( a4 );
+  testStaticMethod1();
+  testStaticMethod2();
+  testStaticMethod3();
+end
+
+rule "simple_rule2"
+  salience (10 + a)
+  dialect "mvel"    
+  when    
+    foo4 : Bar( a4 : a != 4 && != 5)
+  then
+  if ( a == b ) {
+    assert( foo3 );
+  } else {
+    retract( foo4 );
+  } 
+  System.out.println( a4 );
+  testStaticMethod1();  
+  testStaticMethod2();
+  testStaticMethod3();  
 end
\ No newline at end of file

Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.xml
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.xml	2007-10-17 18:29:49 UTC (rev 15897)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/xml/test_RoundTrip.xml	2007-10-17 18:41:29 UTC (rev 15898)
@@ -1,209 +1,217 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<package name="com.sample"
-         xmlns="http://drools.org/drools-4.0"
-         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
-         xs:schemaLocation="http://drools.org/drools-4.0 drools-4.0.xsd">
-
-	<import name="java.util.HashMap" />
-	<import name="org.drools.*" />
-
-	<global identifier="x" type="com.sample.X" />
-	<global identifier="yada" type="com.sample.Yada" />
-	
-	<function return-type="void" name="myFunc">
-	    <parameter identifier="foo" type="Bar" />
-	    <parameter identifier="bada" type="Bing" />
-
-	    <body>
-	    	System.out.println("hello world");
-		</body>
-	</function>
-
-<rule name="simple_rule">
-	<rule-attribute name="salience" value="10" />
-	<rule-attribute name="no-loop" value="true" />
-	<rule-attribute name="agenda-group" value="agenda-group" />
-	<rule-attribute name="activation-group" value="activation-group" />
-
-	<lhs>
-        <pattern identifier="cheese" object-type="Cheese" >
-            <field-constraint field-name="type">
-                <literal-restriction evaluator="==" value="1"/>
-            </field-constraint>
-            <from>
-                <collect>
-                    <pattern object-type="Person">
-                        <field-constraint field-name="hair">
-                            <literal-restriction evaluator="==" value="pink" />
-                        </field-constraint>
-                    </pattern>
-                </collect>
-            </from>
-        </pattern>
-
-        <pattern identifier="cheese" object-type="Cheese">
-            <from>
-                <accumulate>
-                    <pattern object-type="Person"></pattern>
-                    <init>
-                        int total = 0;
-                    </init>
-                    <action>
-                        total += $cheese.getPrice();
-                    </action>
-                    <result>
-                        new Integer( total ) );
-                    </result>
-                </accumulate>
-            </from>
-        </pattern>
-
-        <pattern identifier="foo2" object-type="Bar" >
-            <or-constraint-connective>
-                <and-constraint-connective>
-					<field-constraint field-name="a">
-                        <or-restriction-connective>
-                            <and-restriction-connective>
-                                <literal-restriction evaluator="&gt;" value="60" />
-                                <literal-restriction evaluator="&lt;" value="70" />
-                            </and-restriction-connective>
-                            <and-restriction-connective>
-                                <literal-restriction evaluator="&lt;" value="50" />
-                                <literal-restriction evaluator="&gt;" value="55" />
-                            </and-restriction-connective>
-                        </or-restriction-connective>
-					</field-constraint>
-
-					<field-constraint field-name="a3">
-                        <literal-restriction evaluator="==" value="black" />
-                    </field-constraint>
-                </and-constraint-connective>
-
-                <and-constraint-connective>
-                    <field-constraint field-name="a">
-                        <literal-restriction evaluator="==" value="40" />
-                    </field-constraint>
-
-                    <field-constraint field-name="a3">
-                        <literal-restriction evaluator="==" value="pink" />
-                    </field-constraint>
-                </and-constraint-connective>
-
-                <and-constraint-connective>
-                    <field-constraint field-name="a">
-                        <literal-restriction evaluator="==" value="12"/>
-                    </field-constraint>
-
-                    <field-constraint field-name="a3">
-                        <or-restriction-connective>
-                            <literal-restriction evaluator="==" value="yellow"/>
-                            <literal-restriction evaluator="==" value="blue" />
-                        </or-restriction-connective>
-                    </field-constraint>
-                </and-constraint-connective>
-            </or-constraint-connective>
-        </pattern>
-
-		<forall>
-            <pattern object-type="State">
-                <field-binding field-name="state" identifier="state" />
-            </pattern>
-
-            <pattern object-type="Person">
-                <field-constraint field-name="status">
-                    <variable-restriction evaluator="==" identifier="state" />
-                </field-constraint>
-                <field-binding field-name="likes" identifier="likes" />
-            </pattern>
-
-            <pattern object-type="Cheese">
-                <field-binding field-name="type" identifier="likes" />
-            </pattern>
-        </forall>
-
-        <not>
-            <pattern object-type="Person">
-                <field-constraint field-name="likes">
-                    <variable-restriction evaluator="==" identifier="type"/>
-                </field-constraint>
-            </pattern>
-
-            <exists>
-                <pattern object-type="Person">
-                    <field-constraint field-name="likes">
-                        <variable-restriction evaluator="==" identifier="type"/>
-                    </field-constraint>
-                </pattern>                
-            </exists>
-        </not>
-
-        <exists>
-            <pattern object-type="Person">
-                <field-constraint field-name="likes">
-                    <variable-restriction evaluator="==" identifier="type"/>
-                </field-constraint>
-            </pattern>
-        </exists>
-
-        <or-conditional-element>
-            <pattern identifier="foo3" object-type="Bar" >
-                <field-constraint field-name="a">
-                    <or-restriction-connective>
-                        <literal-restriction evaluator="==" value="3" />
-                        <literal-restriction evaluator="==" value="4" />
-                    </or-restriction-connective>
-                </field-constraint>
-                <field-constraint field-name="a3">
-                    <literal-restriction evaluator="==" value="hello" />
-                </field-constraint>
-                <field-constraint field-name="a4">
-                    <literal-restriction evaluator="==" value="null" />
-                </field-constraint>
-            </pattern>
-
-            <pattern identifier="foo4" object-type="Bar" >
-                <field-binding field-name="a" identifier="a4" />
-                <field-constraint field-name="a">
-                    <literal-restriction evaluator="!=" value="4" />
-                    <literal-restriction evaluator="!=" value="5" />
-                </field-constraint>
-            </pattern>
-        </or-conditional-element>
-
-        <pattern identifier="foo5" object-type="Bar" >
-            <field-constraint field-name="b">
-                <or-restriction-connective>
-                    <return-value-restriction evaluator="==" >a4 + 1</return-value-restriction>
-                    <variable-restriction evaluator="&gt;" identifier="a4" />
-                    <qualified-identifier-restriction evaluator="==">
-                        org.drools.Bar.BAR_ENUM_VALUE
-                    </qualified-identifier-restriction>
-                </or-restriction-connective>
-            </field-constraint>            
-        </pattern>
-
-        <pattern identifier="foo6" object-type="Bar" >
-			<field-binding field-name="a" identifier="a4" />
-			<field-constraint field-name="b">
-				<literal-restriction evaluator="==" value="6" />
-			</field-constraint>
-		</pattern>
-
-		<pattern identifier="foo7" object-type="Bar" >
-			<field-binding field-name="a" identifier="a4" />
-			<field-binding field-name="b" identifier="b4" />
-		</pattern>
-		<pattern object-type="Baz" > </pattern>
-	</lhs>
-	<rhs>
-		  if ( a == b ) {
-		    assert( foo3 );
-		  } else {
-		    retract( foo4 );
-		  }
-		  System.out.println( a4 );
-	</rhs>
-</rule>
-
-</package>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<package name="foo"  
+	xmlns="http://drools.org/drools-4.0" 
+	xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
+	xs:schemaLocation="http://drools.org/drools-4.0 drools-4.0.xsd"> 
+<import name="java.util.HashMap" /> 
+<import name="java.util.HashSet" /> 
+<import name="java.utilArrayList" /> 
+
+<global identifier="m" type="HashMap" />
+<global identifier="s" type="HashSet" />
+<global identifier="p" type="org.drools.Person" />
+
+<importfunction name="org.drools.xml.DumperTest.testStaticMethod1"/>
+<importfunction name="org.drools.xml.DumperTest.testStaticMethod2"/>
+<importfunction name="org.drools.xml.DumperTest.testStaticMethod3"/>
+
+
+<rule name="simple_rule">
+<rule-attribute name="salience" value="10" />
+<rule-attribute name="no-loop" value="true" />
+<rule-attribute name="agenda-group" value="agenda-group" />
+<rule-attribute name="activation-group" value="activation-group" />
+<rule-attribute name="ruleflow-group" value="xxx" />
+<rule-attribute name="lock-on-active" value="true" />
+<rule-attribute name="auto-focus" value="true" />
+<rule-attribute name="date-effective" value="01-Jan-2007" />
+<rule-attribute name="date-expires" value="01-Feb-2007" />
+
+<lhs><pattern identifier="foo2" object-type="Bar" >
+<or-constraint-connective><and-constraint-connective><field-constraint field-name="a"> 
+<or-restriction-connective><and-restriction-connective><literal-restriction evaluator="&gt;" value="60" />
+
+<literal-restriction evaluator="&lt;" value="70" />
+
+
+</and-restriction-connective>
+<and-restriction-connective><literal-restriction evaluator="&gt;" value="50" />
+
+<literal-restriction evaluator="&lt;" value="55" />
+
+
+</and-restriction-connective>
+
+</or-restriction-connective>
+</field-constraint>
+<field-constraint field-name="a3"> 
+<literal-restriction evaluator="==" value="black" />
+
+</field-constraint>
+
+</and-constraint-connective>
+<and-constraint-connective><field-constraint field-name="a"> 
+<literal-restriction evaluator="==" value="40" />
+
+</field-constraint>
+<field-constraint field-name="a3"> 
+<literal-restriction evaluator="==" value="pink" />
+
+</field-constraint>
+
+</and-constraint-connective>
+<and-constraint-connective><field-constraint field-name="a"> 
+<literal-restriction evaluator="==" value="12" />
+
+</field-constraint>
+<field-constraint field-name="a3"> 
+<literal-restriction evaluator="==" value="yellow" />
+
+</field-constraint>
+
+</and-constraint-connective>
+<field-constraint field-name="a3"> 
+<literal-restriction evaluator="==" value="blue" />
+
+</field-constraint>
+
+</or-constraint-connective>
+
+
+</pattern>
+
+<pattern identifier="foo3" object-type="Bar" >
+<field-constraint field-name="a"> 
+<or-restriction-connective><literal-restriction evaluator="==" value="3" />
+
+<literal-restriction evaluator="==" value="4" />
+
+
+</or-restriction-connective>
+</field-constraint>
+<field-constraint field-name="a3"> 
+<literal-restriction evaluator="==" value="hello" />
+
+</field-constraint>
+<field-constraint field-name="a4"> 
+<literal-restriction evaluator="==" value="null" />
+
+</field-constraint>
+
+
+</pattern>
+
+<pattern identifier="foo4" object-type="Bar" >
+<field-binding field-name="a" identifier="a4" />
+
+<field-constraint field-name="a"> 
+<literal-restriction evaluator="!=" value="4" />
+<literal-restriction evaluator="!=" value="5" />
+
+</field-constraint>
+
+
+</pattern>
+
+<pattern identifier="foo5" object-type="Bar" >
+<field-constraint field-name="b"> 
+<or-restriction-connective><return-value-restriction evaluator="==" >a4 + 1</return-value-restriction>
+
+<variable-restriction evaluator="&gt;" identifier="a4" />
+
+
+</or-restriction-connective>
+</field-constraint>
+
+
+</pattern>
+
+<pattern identifier="foo6" object-type="Bar" >
+<field-binding field-name="a" identifier="a4" />
+
+<field-constraint field-name="b"> 
+<literal-restriction evaluator="==" value="6" />
+
+</field-constraint>
+
+
+</pattern>
+
+<pattern identifier="foo7" object-type="Bar" >
+<field-binding field-name="a" identifier="a4" />
+
+<field-binding field-name="b" identifier="b4" />
+
+
+
+</pattern>
+
+<pattern identifier="$cheeseList" object-type="ArrayList" >
+<field-constraint field-name="size"> 
+<literal-restriction evaluator="&gt;" value="2" />
+
+</field-constraint>
+
+
+<from> <collect><pattern object-type="Cheese" >
+<field-constraint field-name="type"> 
+<variable-restriction evaluator="==" identifier="$likes" />
+
+</field-constraint>
+
+
+</pattern>
+ </collect> </from> </pattern>
+
+<pattern object-type="Baz" >
+
+
+</pattern>
+
+
+</lhs>
+
+<rhs>  if ( a == b ) {
+    assert( foo3 );
+  } else {
+    retract( foo4 );
+  } 
+  System.out.println( a4 );
+  testStaticMethod1();
+  testStaticMethod2();
+  testStaticMethod3();
+</rhs>
+
+
+</rule>
+
+<rule name="simple_rule2">
+<rule-attribute name="salience" value="(10 + a)" />
+<rule-attribute name="dialect" value="mvel" />
+
+<lhs><pattern identifier="foo4" object-type="Bar" >
+<field-binding field-name="a" identifier="a4" />
+
+<field-constraint field-name="a"> 
+<literal-restriction evaluator="!=" value="4" />
+<literal-restriction evaluator="!=" value="5" />
+
+</field-constraint>
+
+
+</pattern>
+
+
+</lhs><rhs>  if ( a == b ) {
+    assert( foo3 );
+  } else {
+    retract( foo4 );
+  } 
+  System.out.println( a4 );
+  testStaticMethod1();  
+  testStaticMethod2();
+  testStaticMethod3();  
+</rhs>
+</rule>
+</package>




More information about the jboss-svn-commits mailing list