[jboss-svn-commits] JBL Code SVN: r14967 - in labs/jbossrules/trunk/drools-compiler/src/test: resources/org/drools/integrationtests and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Sep 9 11:02:33 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-09-09 11:02:33 -0400 (Sun, 09 Sep 2007)
New Revision: 14967

Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/literal_rule_test.drl
Log:
JBRULES-1165 StatelessSessionResult should have getGlobal
-Added an Export capability, with unit tests, for a StatelessSession to export globals.

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java	2007-09-09 15:02:23 UTC (rev 14966)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java	2007-09-09 15:02:33 UTC (rev 14967)
@@ -5,19 +5,27 @@
 import java.util.List;
 
 import org.drools.Cheese;
+import org.drools.Cheesery;
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
 import org.drools.StatelessSession;
 import org.drools.StatelessSessionResult;
 import org.drools.WorkingMemory;
+import org.drools.base.CopyIdentifiersGlobalExporter;
+import org.drools.base.MapGlobalResolver;
+import org.drools.base.ReferenceOriginalGlobalExporter;
 import org.drools.compiler.PackageBuilder;
 import org.drools.rule.Package;
+import org.drools.spi.GlobalExporter;
+import org.drools.spi.GlobalResolver;
 
 import junit.framework.TestCase;
 
 public class StatelessSessionTest extends TestCase {
     final List list = new ArrayList();
+    final Cheesery cheesery = new Cheesery();
+    final GlobalResolver globalResolver = new MapGlobalResolver();
 
     protected RuleBase getRuleBase() throws Exception {
 
@@ -72,6 +80,9 @@
     public void testSingleObjectAssertWithResults() throws Exception {
         StatelessSession session = getSession();
 
+        // notice I don't export Cheessery
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter( new String[]{"list"} ) );
+
         final Cheese stilton = new Cheese( "stilton",
                                            5 );
 
@@ -79,11 +90,20 @@
 
         assertSame( stilton,
                     result.iterateObjects().next() );
+
+        assertEquals( "stilton",
+                      ((List) result.getGlobal( "list" )).get( 0 ) );
+
+        // cheesery should be null
+        assertNull( result.getGlobal( "cheesery" ) );
     }
 
     public void testArrayObjectAssertWithResults() throws Exception {
         StatelessSession session = getSession();
 
+        // notice I don't export Cheessery
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter( new String[]{"list"} ) );
+
         final Cheese stilton = new Cheese( "stilton",
                                            5 );
 
@@ -91,11 +111,20 @@
 
         assertSame( stilton,
                     result.iterateObjects().next() );
+
+        assertEquals( "stilton",
+                      ((List) result.getGlobal( "list" )).get( 0 ) );
+
+        // cheesery should be null
+        assertNull( result.getGlobal( "cheesery" ) );
     }
 
     public void testCollectionObjectAssertWithResults() throws Exception {
         StatelessSession session = getSession();
 
+        // notice I don't export Cheessery
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter( new String[]{"list"} ) );
+
         final Cheese stilton = new Cheese( "stilton",
                                            5 );
 
@@ -105,6 +134,12 @@
 
         assertSame( stilton,
                     result.iterateObjects().next() );
+
+        assertEquals( "stilton",
+                      ((List) result.getGlobal( "list" )).get( 0 ) );
+
+        // cheesery should be null
+        assertNull( result.getGlobal( "cheesery" ) );
     }
 
     public void testAsynSingleOjbectcAssert() throws Exception {
@@ -150,7 +185,77 @@
         assertEquals( "stilton",
                       list.get( 0 ) );
     }
+    
+    public void testCopyIdentifierGlobalExporterOneValue() throws Exception {
+        StatelessSession session = getSession();       
 
+        // notice I don't export Cheessery
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter( new String[]{"list"} ) );
+
+        StatelessSessionResult result = session.executeWithResults( (Object) null );
+
+        assertSame( this.list,
+                    result.getGlobal( "list" ) );
+
+        // cheesery should be null
+        assertNull( result.getGlobal( "cheesery" ) );
+        
+        assertNotSame( this.globalResolver, result.getGlobalResolver() );
+    }
+    
+    public void testCopyIdentifierGlobalExporterTwoValues() throws Exception {
+        StatelessSession session = getSession();
+
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter( new String[]{"list", "cheesery"} ) );
+
+        StatelessSessionResult result = session.executeWithResults( (Object) null );
+
+        assertSame( this.list,
+                    result.getGlobal( "list" ) );
+
+        // cheesery should be null
+        assertSame( this.cheesery,
+                    result.getGlobal( "cheesery" ) );
+        
+        assertNotSame( this.globalResolver, result.getGlobalResolver() );        
+    }    
+    
+    public void testCopyIdentifierGlobalExporterAllValues() throws Exception {
+        StatelessSession session = getSession();
+
+        // I've not specified any identifiers, so it should do them alll
+        session.setGlobalExporter( new CopyIdentifiersGlobalExporter() );
+
+        StatelessSessionResult result = session.executeWithResults( (Object) null );
+
+        assertSame( this.list,
+                    result.getGlobal( "list" ) );
+
+        // cheesery should be null
+        assertSame( this.cheesery,
+                    result.getGlobal( "cheesery" ) );
+        
+        assertNotSame( this.globalResolver, result.getGlobalResolver() );        
+    }     
+    
+    public void testReferenceOriginalGlobalExporter() throws Exception {
+        StatelessSession session = getSession();
+
+        // I've not specified any identifiers, so it should do them alll
+        session.setGlobalExporter( new ReferenceOriginalGlobalExporter() );
+
+        StatelessSessionResult result = session.executeWithResults( (Object) null );
+
+        assertSame( this.list,
+                    result.getGlobal( "list" ) );
+
+        // cheesery should be null
+        assertSame( this.cheesery,
+                    result.getGlobal( "cheesery" ) );
+        
+        assertSame( this.globalResolver, result.getGlobalResolver() );        
+    }        
+
     private StatelessSession getSession() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "literal_rule_test.drl" ) ) );
@@ -159,9 +264,13 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
         final StatelessSession session = ruleBase.newStatelessSession();
+        
+        session.setGlobalResolver( this.globalResolver );
 
         session.setGlobal( "list",
                            this.list );
+        session.setGlobal( "cheesery",
+                           this.cheesery );
         return session;
     }
 }

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/literal_rule_test.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/literal_rule_test.drl	2007-09-09 15:02:23 UTC (rev 14966)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/literal_rule_test.drl	2007-09-09 15:02:33 UTC (rev 14967)
@@ -1,8 +1,10 @@
 package org.drools.test;
 
 import org.drools.Cheese;
+import org.drools.Cheesery
 
 global java.util.List list;
+global Cheesery cheesery;
 
 rule "literal test rule"
     when




More information about the jboss-svn-commits mailing list