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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 20 08:55:29 EDT 2008


Author: tirelli
Date: 2008-03-20 08:55:29 -0400 (Thu, 20 Mar 2008)
New Revision: 19137

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AlphaCompositeConstraints.drl
Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndConstraint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrConstraint.java
Log:
JBRULES-1519: fixing bug with alpha only composite constraints

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	2008-03-20 12:36:36 UTC (rev 19136)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2008-03-20 12:55:29 UTC (rev 19137)
@@ -4870,12 +4870,33 @@
                       list.size() );
     }
 
-    public void testModifyBlock() throws Exception {
+    public void testAlphaCompositeConstraints() throws Exception {
         final PackageBuilder builder = new PackageBuilder();
-        builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_ModifyBlock.drl" ) ) );
+        builder.addPackageFromDrl(new InputStreamReader(getClass()
+                .getResourceAsStream("test_AlphaCompositeConstraints.drl")));
         final Package pkg = builder.getPackage();
 
         final RuleBase ruleBase = getRuleBase();
+        ruleBase.addPackage(pkg);
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
+
+        final List list = new ArrayList();
+        workingMemory.setGlobal("results", list);
+
+        Person bob = new Person( "bob", 30 );
+
+        workingMemory.insert(bob);
+        workingMemory.fireAllRules();
+
+        assertEquals( 1, list.size());
+    }
+
+	public void testModifyBlock() throws Exception {
+		final PackageBuilder builder = new PackageBuilder();
+		builder.addPackageFromDrl(new InputStreamReader(getClass()
+				.getResourceAsStream("test_ModifyBlock.drl")));
+		final Package pkg = builder.getPackage();
+        final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
         final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 

Copied: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AlphaCompositeConstraints.drl (from rev 19136, labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_AlphaCompositeConstraints.drl)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AlphaCompositeConstraints.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AlphaCompositeConstraints.drl	2008-03-20 12:55:29 UTC (rev 19137)
@@ -0,0 +1,10 @@
+package org.drools;
+
+global java.util.List results;
+
+rule "test alpha composite constraints"
+when
+    Person( eval( age == 25 ) || ( eval( name.equals( "bob" ) ) && eval( age == 30 ) ) )
+then
+    results.add( "OK" );
+end
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndConstraint.java	2008-03-20 12:36:36 UTC (rev 19136)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndConstraint.java	2008-03-20 12:55:29 UTC (rev 19137)
@@ -44,13 +44,11 @@
     public boolean isAllowed(InternalFactHandle handle,
                              InternalWorkingMemory workingMemory,
                              final ContextEntry ctx) {
-        if ( this.alphaConstraints.length > 0 ) {
-            for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
-                if ( !this.alphaConstraints[i].isAllowed( handle,
-                                                          workingMemory,
-                                                          ctx ) ) {
-                    return false;
-                }
+        for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
+            if ( !this.alphaConstraints[i].isAllowed( handle,
+                                                      workingMemory,
+                                                      ((MultiFieldConstraintContextEntry) ctx).alphas[i] ) ) {
+                return false;
             }
         }
         return true;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrConstraint.java	2008-03-20 12:36:36 UTC (rev 19136)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrConstraint.java	2008-03-20 12:55:29 UTC (rev 19137)
@@ -50,7 +50,7 @@
             for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
                 if ( this.alphaConstraints[i].isAllowed( handle,
                                                          workingMemory,
-                                                         ctx ) ) {
+                                                         ((MultiFieldConstraintContextEntry) ctx).alphas[i] ) ) {
                     return true;
                 }
             }




More information about the jboss-svn-commits mailing list