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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Apr 1 18:24:44 EDT 2010


Author: tirelli
Date: 2010-04-01 18:24:43 -0400 (Thu, 01 Apr 2010)
New Revision: 32364

Added:
   labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModify2Test.nodeTestCase
Modified:
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
   labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModifyTest.nodeTestCase
Log:
Fixing tests

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java	2010-04-01 22:08:42 UTC (rev 32363)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java	2010-04-01 22:24:43 UTC (rev 32364)
@@ -24,7 +24,11 @@
 import org.drools.reteoo.RightTupleSink;
 import org.drools.reteoo.Sink;
 import org.drools.spi.PropagationContext;
+import org.hamcrest.BaseMatcher;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
 import org.junit.Assert;
 import org.junit.matchers.JUnitMatchers;
 import org.mockito.ArgumentCaptor;
@@ -184,6 +188,11 @@
                           CoreMatchers.class );
         addStaticImports( pconf,
                           JUnitMatchers.class );
+        try {
+            pconf.addImport( "isTuple", IsTuple.class.getMethod( "isTuple", List.class ) );
+        } catch ( Exception e1 ) {
+            e1.printStackTrace();
+        }
         // add import for JUnit assert class
         pconf.addImport( "Assert",
                          Assert.class );
@@ -269,6 +278,11 @@
                           CoreMatchers.class );
         addStaticImports( pconf,
                           JUnitMatchers.class );
+        try {
+            pconf.addImport( "isTuple", IsTuple.class.getMethod( "isTuple", List.class ) );
+        } catch ( Exception e1 ) {
+            e1.printStackTrace();
+        }
         // add import for JUnit assert class
         pconf.addImport( "Assert",
                          Assert.class );
@@ -304,5 +318,35 @@
             }
         }
     }
+    
+    public static class IsTuple extends BaseMatcher<List<InternalFactHandle>> {
+        private final InternalFactHandle[] expected;
 
+        public IsTuple(List<InternalFactHandle> tupleAsList) {
+            expected = tupleAsList.toArray( new InternalFactHandle[tupleAsList.size()] );
+        }
+
+        public boolean matches(Object arg) {
+            if( arg == null || ! ( arg.getClass().isArray() && InternalFactHandle.class.isAssignableFrom( arg.getClass().getComponentType() ) ) ) {
+                return false;
+            }
+            InternalFactHandle[] actual = (InternalFactHandle[]) arg;
+            return Arrays.equals( expected, actual );
+        }
+
+        public void describeTo(Description description) {
+            description.appendValue(expected);
+        }
+        
+        /**
+         * Is the value equal to another value, as tested by the
+         * {@link java.lang.Object#equals} invokedMethod?
+         */
+        @Factory
+        public static Matcher<List<InternalFactHandle>> isTuple(List<InternalFactHandle> operand) {
+            return new IsTuple(operand);
+        }
+
+    }
+
 }

Added: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModify2Test.nodeTestCase
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModify2Test.nodeTestCase	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModify2Test.nodeTestCase	2010-04-01 22:24:43 UTC (rev 32364)
@@ -0,0 +1,96 @@
+TestCase "Join Node modify 2 test case"
+
+import org.drools.Person;
+
+Setup
+	Binding:
+	     p1, 0, org.drools.Person, age;
+	JoinNode:
+	    join1, mock, mock;
+	    age, !=, p1;
+	LeftTupleSink:
+	    sink, join1;
+	Facts:
+	    new Person('darth', 34), // h0
+	    new Person('bobba', 35), // h1
+	    new Person('yoda', 36),  // h2
+	    new Person('luke', 37),  // h3
+	    new Person('dave', 38),  // h4
+	    new Person('bob', 39);   // h5
+
+/**
+ * insert all and the modify: h0 breaking and re-creating each join, to simulate left modifies
+ */
+Test "Join node duplications check"	     
+	assert:
+	    join1, [[h0], [h1], [h2]]; // asserting tuples on the left
+	    join1, [h3, h4, h5];       // asserting facts on the right
+	sink:
+	    verify, assertLeft, count, 9; // cross product
+
+	With:
+	    h0, age = 37;
+	modify:
+	    join1, [[h0]]; 
+	join1:
+	    leftMemory, [[h1], [h2], [h0]]; // notice that h0 moves to the end
+	sink:    
+	    verify, assertLeft, count, 9; // no new asserts
+	    verify, modifyLeft, count, 2; // 2 tuples where modified: [h0, h4] and [h0, h5]
+	    verify, modifyLeft, tuple0, isTuple( [h0, h4] );
+	    verify, modifyLeft, tuple1, isTuple( [h0, h5] );
+	    verify, retractLeft, count, 1; // [h0, h3] was retracted
+	    verify, retractLeft, tuple0, isTuple( [h0, h3] );
+	    
+	With:
+	    h0, age = 38;
+	modify:
+	    join1, [[h0]]; 
+	join1:
+	    leftMemory, [[h1], [h2], [h0]];
+	sink:    
+	    verify, assertLeft, count, 10; // one new assert
+	    verify, assertLeft, tuple9, isTuple( [h0, h3] );
+	    verify, modifyLeft, count, 3;  
+	    verify, modifyLeft, tuple2, isTuple( [h0, h5] );
+	    verify, retractLeft, count, 2; 
+	    verify, retractLeft, tuple1, isTuple( [h0, h4] );
+
+	With:
+	    h0, age = 39;
+	modify:
+	    join1, [[h0]]; 
+	join1:
+	    leftMemory, [[h1], [h2], [h0]];
+	sink:    
+	    verify, assertLeft, count, 11; // one new assert
+	    verify, assertLeft, tuple10, isTuple( [h0, h4] );
+	    verify, modifyLeft, count, 4;  
+	    verify, modifyLeft, tuple3, isTuple( [h0, h3] );
+	    verify, retractLeft, count, 3; 
+	    verify, retractLeft, tuple2, isTuple( [h0, h5] );
+
+	With:
+	    h0, age = 34;
+	modify:
+	    join1, [[h0]]; 
+	join1:
+	    leftMemory, [[h1], [h2], [h0]];
+	sink:    
+	    verify, assertLeft, count, 12; // one new assert
+	    verify, assertLeft, tuple11, isTuple( [h0, h5] );
+	    verify, modifyLeft, count, 6;  
+	    verify, modifyLeft, tuple4, isTuple( [h0, h3] );
+	    verify, modifyLeft, tuple5, isTuple( [h0, h4] );
+	    verify, retractLeft, count, 3; // no retract this time 
+
+	retract:
+	    join1, [[h0], [h1], [h2]]; // retracting tuples on the left
+	    join1, [h3, h4, h5];       // retracting facts on the right
+
+	sink:    
+	    verify, assertLeft, count, 12;  // checking just in case
+	    verify, modifyLeft, count, 6;  
+	    verify, retractLeft, count, 12; // all tuples retracted 
+	    
+	    
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModify2Test.nodeTestCase
___________________________________________________________________
Name: svn:executable
   + *

Modified: labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModifyTest.nodeTestCase
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModifyTest.nodeTestCase	2010-04-01 22:08:42 UTC (rev 32363)
+++ labs/jbossrules/trunk/drools-core/src/test/resources/org/drools/reteoo/test/JoinNodeModifyTest.nodeTestCase	2010-04-01 22:24:43 UTC (rev 32364)
@@ -86,6 +86,7 @@
 	    leftMemory, [];
 	    rightMemory, [];  
 	
+Test "Join Node Modify test 2"	     
 	/**
 	 * insert all and the modify: h0 breaking and re-creating each join, to simulate left modifies
 	 */



More information about the jboss-svn-commits mailing list