[jboss-svn-commits] JBL Code SVN: r14543 - labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 24 20:32:29 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-08-24 20:32:29 -0400 (Fri, 24 Aug 2007)
New Revision: 14543

Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
Log:
JBRULES-1123 Custom Consequence Exception handlers
-users can now use the property "drools.consequenceExceptionHandler" or the RuleBaseconfiguration.setConsequenceExceptionHandler to specify a custom user defined handler for consequence exceptions.

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2007-08-24 23:25:17 UTC (rev 14542)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2007-08-25 00:32:29 UTC (rev 14543)
@@ -103,6 +103,8 @@
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
 import org.drools.rule.builder.dialect.java.JavaDialectConfiguration;
+import org.drools.spi.Activation;
+import org.drools.spi.ConsequenceExceptionHandler;
 import org.drools.xml.XmlDumper;
 
 /** Run all the tests with the ReteOO engine implementation */
@@ -1158,7 +1160,45 @@
                           e.getCause().getMessage() );
         }
     }
+    
+    public void testCustomConsequenceException() throws Exception {        
+        final PackageBuilder builder = new PackageBuilder();
+        builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_ConsequenceException.drl" ) ) );
+        final Package pkg = builder.getPackage();
 
+        RuleBaseConfiguration conf = new RuleBaseConfiguration();
+        CustomConsequenceExceptionHandler handler = new CustomConsequenceExceptionHandler();
+        conf.setConsequenceExceptionHandler( handler );
+        
+        final RuleBase ruleBase = getRuleBase(conf);
+        ruleBase.addPackage( pkg );
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
+
+        final Cheese brie = new Cheese( "brie",
+                                        12 );
+        workingMemory.insert( brie );
+
+        workingMemory.fireAllRules();
+        
+        assertTrue( handler.isCalled() );
+    }
+    
+    public static class CustomConsequenceExceptionHandler implements ConsequenceExceptionHandler {
+        
+        private boolean called;
+
+        public void handleException(Activation activation,
+                                    WorkingMemory workingMemory,
+                                    Exception exception) {
+            this.called = true;            
+        }
+        
+        public boolean isCalled() {
+            return this.called;
+        }
+        
+    }
+
     public void testFunctionException() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_FunctionException.drl" ) ) );




More information about the jboss-svn-commits mailing list