[jboss-svn-commits] JBL Code SVN: r20070 - in labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools: lang/dsl and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 19 20:13:47 EDT 2008


Author: mattgeis
Date: 2008-05-19 20:13:47 -0400 (Mon, 19 May 2008)
New Revision: 20070

Added:
   labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DSLTokenizedMappingFileTest.java
Modified:
   labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/compiler/DrlParserTest.java
   labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java
Log:


Modified: labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/compiler/DrlParserTest.java
===================================================================
--- labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/compiler/DrlParserTest.java	2008-05-20 00:12:48 UTC (rev 20069)
+++ labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/compiler/DrlParserTest.java	2008-05-20 00:13:47 UTC (rev 20070)
@@ -5,6 +5,7 @@
 import org.drools.RuntimeDroolsException;
 import org.drools.lang.Expander;
 import org.drools.lang.dsl.DSLMappingFile;
+import org.drools.lang.dsl.DSLTokenizedMappingFile;
 import org.drools.lang.dsl.DefaultExpander;
 import org.drools.lang.dsl.DefaultExpanderResolver;
 
@@ -29,7 +30,7 @@
         DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
         
         
-        final DSLMappingFile file = new DSLMappingFile();
+        final DSLMappingFile file = new DSLTokenizedMappingFile();
         if ( file.parseAndLoad( new StringReader(dsl) ) ) {
             final Expander expander = new DefaultExpander();
             expander.addDSLMapping( file.getMapping() );

Added: labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DSLTokenizedMappingFileTest.java
===================================================================
--- labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DSLTokenizedMappingFileTest.java	                        (rev 0)
+++ labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DSLTokenizedMappingFileTest.java	2008-05-20 00:13:47 UTC (rev 20070)
@@ -0,0 +1,177 @@
+package org.drools.lang.dsl;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+public class DSLTokenizedMappingFileTest extends TestCase {
+    private DSLMappingFile file     = null;
+    private final String   filename = "test_metainfo.dsl";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testParseFile() {
+        try {
+            final Reader reader = new InputStreamReader( this.getClass().getResourceAsStream( this.filename ) );
+            this.file = new DSLTokenizedMappingFile();
+
+            final boolean parsingResult = this.file.parseAndLoad( reader );
+            reader.close();
+
+            assertTrue( this.file.getErrors().toString(),
+                        parsingResult );
+            assertTrue( this.file.getErrors().isEmpty() );
+
+            assertEquals( 31,
+                          this.file.getMapping().getEntries().size() );
+        } catch ( final IOException e ) {
+            e.printStackTrace();
+            fail( "Should not raise exception " );
+        }
+
+    }
+
+    public void testParseFileWithBrackets() {
+        String file = "[when][]ATTRIBUTE \"{attr}\" IS IN [{list}]=Attribute( {attr} in ({list}) )";
+        try {
+            final Reader reader = new StringReader( file );
+            this.file = new DSLTokenizedMappingFile();
+
+            final boolean parsingResult = this.file.parseAndLoad( reader );
+            reader.close();
+
+            assertTrue( this.file.getErrors().toString(),
+                        parsingResult );
+            assertTrue( this.file.getErrors().isEmpty() );
+
+            assertEquals( 1,
+                          this.file.getMapping().getEntries().size() );
+
+            DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get( 0 );
+
+            assertEquals( DSLMappingEntry.CONDITION,
+                          entry.getSection() );
+            assertEquals( DSLMappingEntry.EMPTY_METADATA,
+                          entry.getMetaData() );
+            assertEquals( "ATTRIBUTE \"{attr}\" IS IN [{list}]",
+                          entry.getMappingKey() );
+            assertEquals( "Attribute( {attr} in ({list}) )",
+                          entry.getMappingValue() );
+
+        } catch ( final IOException e ) {
+            e.printStackTrace();
+            fail( "Should not raise exception " );
+        }
+    }
+
+    public void testParseFileWithEscaptedBrackets() {
+        String file = "[when][]ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]=Attribute( {attr} in ({list}) )";
+        try {
+            final Reader reader = new StringReader( file );
+            this.file = new DSLTokenizedMappingFile();
+
+            final boolean parsingResult = this.file.parseAndLoad( reader );
+            reader.close();
+
+            assertTrue( this.file.getErrors().toString(),
+                        parsingResult );
+            assertTrue( this.file.getErrors().isEmpty() );
+
+            assertEquals( 1,
+                          this.file.getMapping().getEntries().size() );
+
+            DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get( 0 );
+
+            assertEquals( DSLMappingEntry.CONDITION,
+                          entry.getSection() );
+            assertEquals( DSLMappingEntry.EMPTY_METADATA,
+                          entry.getMetaData() );
+            assertEquals( "ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]",
+                          entry.getMappingKey() );
+            assertEquals( "Attribute( {attr} in ({list}) )",
+                          entry.getMappingValue() );
+
+        } catch ( final IOException e ) {
+            e.printStackTrace();
+            fail( "Should not raise exception " );
+        }
+
+    }
+
+    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 DSLTokenizedMappingFile();
+
+            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 " );
+        }
+
+    }
+
+    public void testParseFileWithEscaptedEquals() {
+        String file = "[when][]something:\\={value}=Attribute( something == \"{value}\" )";
+        try {
+            final Reader reader = new StringReader( file );
+            this.file = new DSLTokenizedMappingFile();
+
+            final boolean parsingResult = this.file.parseAndLoad( reader );
+            reader.close();
+
+            assertTrue( this.file.getErrors().toString(),
+                        parsingResult );
+            assertTrue( this.file.getErrors().isEmpty() );
+
+            assertEquals( 1,
+                          this.file.getMapping().getEntries().size() );
+
+            DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get( 0 );
+
+            assertEquals( DSLMappingEntry.CONDITION,
+                          entry.getSection() );
+            assertEquals( DSLMappingEntry.EMPTY_METADATA,
+                          entry.getMetaData() );
+            assertEquals( "something:={value}",
+                          entry.getMappingKey() );
+            assertEquals( "Attribute( something == \"{value}\" )",
+                          entry.getMappingValue() );
+
+        } catch ( final IOException e ) {
+            e.printStackTrace();
+            fail( "Should not raise exception " );
+        }
+
+    }
+}


Property changes on: labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DSLTokenizedMappingFileTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java
===================================================================
--- labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java	2008-05-20 00:12:48 UTC (rev 20069)
+++ labs/jbossrules/branches/mattgeis/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultExpanderTest.java	2008-05-20 00:13:47 UTC (rev 20070)
@@ -17,7 +17,7 @@
     protected void setUp() throws Exception {
         final String filename = "test_metainfo.dsl";
         final Reader reader = new InputStreamReader( this.getClass().getResourceAsStream( filename ) );
-        this.file = new DSLMappingFile();
+        this.file = new DSLTokenizedMappingFile();
         this.file.parseAndLoad( reader );
         reader.close();
 
@@ -43,7 +43,7 @@
 
     
     public void testExpandParts() throws Exception {
-        DSLMappingFile file = new DSLMappingFile();
+        DSLMappingFile file = new DSLTokenizedMappingFile();
         String dsl = "[when]foo=Foo()\n[then]bar {num}=baz({num});";
         file.parseAndLoad( new StringReader( dsl ) );
         assertEquals( 0,
@@ -56,7 +56,7 @@
     
     public void testExpandFailure() throws Exception {
 
-        DSLMappingFile file = new DSLMappingFile();
+        DSLMappingFile file = new DSLTokenizedMappingFile();
         String dsl = "[when]foo=Foo()\n[then]bar {num}=baz({num});";
         file.parseAndLoad( new StringReader( dsl ) );
         assertEquals( 0,
@@ -82,7 +82,7 @@
 
     public void testExpandWithKeywordClashes() throws Exception {
 
-        DSLMappingFile file = new DSLMappingFile();
+        DSLMappingFile file = new DSLTokenizedMappingFile();
         String dsl = "[when]Invoke rule executor=ruleExec: RuleExecutor()\n" + "[then]Execute rule \"{id}\"=ruleExec.ExecuteSubRule( new Long({id}));";
         file.parseAndLoad( new StringReader( dsl ) );
         assertEquals( 0,
@@ -102,7 +102,7 @@
 
 
     public void testLineNumberError() throws Exception {
-        DSLMappingFile file = new DSLMappingFile();
+        DSLMappingFile file = new DSLTokenizedMappingFile();
         String dsl = "[when]foo=Foo()\n[then]bar {num}=baz({num});";
         file.parseAndLoad( new StringReader( dsl ) );
 




More information about the jboss-svn-commits mailing list