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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 22 03:43:02 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-10-22 03:43:02 -0400 (Mon, 22 Oct 2007)
New Revision: 15979

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockFactHandle.java
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/TestingEventListener.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/TestingEventListenerTest.java
Log:
JBRULES-1271 removing cross module test dependencies

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java	2007-10-22 07:20:23 UTC (rev 15978)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java	2007-10-22 07:43:02 UTC (rev 15979)
@@ -2,7 +2,10 @@
 
 import static org.mvel.MVEL.eval;
 
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -50,9 +53,11 @@
 		}
 		this.populatedData = factData;
 
+		HashSet<String> ruleList = new HashSet<String>();
+		ruleList.addAll(Arrays.asList(scenario.ruleTrace.rules));
+		TestingEventListener listener = new TestingEventListener(ruleList, wm.getRuleBase(), scenario.ruleTrace.inclusive);
 
 
-
 		//now run the rules...
 		insertData(wm, this.populatedData);
 		wm.fireAllRules();

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/TestingEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/TestingEventListener.java	2007-10-22 07:20:23 UTC (rev 15978)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/TestingEventListener.java	2007-10-22 07:43:02 UTC (rev 15979)
@@ -42,28 +42,30 @@
      * The other rules will have their activation counted but not be allowed to fire.
      */
     public TestingEventListener(HashSet<String> ruleNames, RuleBase ruleBase, boolean inclusive) {
-    	if (inclusive) {
-    		Package[] pkgs = ruleBase.getPackages();
-    		for (int i = 0; i < pkgs.length; i++) {
-				Rule[] rules = pkgs[i].getRules();
-				for (int j = 0; j < rules.length; j++) {
-					Rule rule = rules[j];
-					if (!ruleNames.contains(rule.getName())) {
+    	if (ruleNames.size() > 0) {
+	    	if (inclusive) {
+	    		Package[] pkgs = ruleBase.getPackages();
+	    		for (int i = 0; i < pkgs.length; i++) {
+					Rule[] rules = pkgs[i].getRules();
+					for (int j = 0; j < rules.length; j++) {
+						Rule rule = rules[j];
+						if (!ruleNames.contains(rule.getName())) {
+							rule.setConsequence(new NilConsequence());
+						}
+					}
+				}
+	    	} else {
+	    		Package[] pkgs = ruleBase.getPackages();
+	    		for (int i = 0; i < pkgs.length; i++) {
+	    			Package pkg = pkgs[i];
+	    			for (Iterator iter = ruleNames.iterator(); iter.hasNext();) {
+						String name = (String) iter.next();
+						Rule rule = pkg.getRule(name);
 						rule.setConsequence(new NilConsequence());
 					}
-				}
-			}
-    	} else {
-    		Package[] pkgs = ruleBase.getPackages();
-    		for (int i = 0; i < pkgs.length; i++) {
-    			Package pkg = pkgs[i];
-    			for (Iterator iter = ruleNames.iterator(); iter.hasNext();) {
-					String name = (String) iter.next();
-					Rule rule = pkg.getRule(name);
-					rule.setConsequence(new NilConsequence());
-				}
 
-    		}
+	    		}
+	    	}
     	}
     	this.ruleNames = ruleNames;
     }

Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockFactHandle.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockFactHandle.java	2007-10-22 07:43:02 UTC (rev 15979)
@@ -0,0 +1,63 @@
+package org.drools.testframework;
+
+import org.drools.FactHandle;
+
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class MockFactHandle
+    implements
+    FactHandle {
+    /**
+     *
+     */
+    private static final long serialVersionUID = 400L;
+    private int               id;
+
+    public MockFactHandle(final int id) {
+        this.id = id;
+    }
+
+    public String toExternalForm() {
+        return "[fact:" + this.id + "]";
+    }
+
+    public int hashCode() {
+        return this.id;
+    }
+
+    public boolean equals(final Object object) {
+        if ( this == object ) {
+            return true;
+        }
+
+        if ( object == null || getClass() != object.getClass() ) {
+            return false;
+        }
+
+        return ((MockFactHandle) object).id == this.id;
+    }
+
+    public long getId() {
+        return this.id;
+    }
+
+    public long getRecency() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockFactHandle.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2007-10-22 07:20:23 UTC (rev 15978)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/MockWorkingMemory.java	2007-10-22 07:43:02 UTC (rev 15979)
@@ -7,7 +7,6 @@
 import org.drools.Agenda;
 import org.drools.FactException;
 import org.drools.FactHandle;
-import org.drools.MockFactHandle;
 import org.drools.ObjectFilter;
 import org.drools.QueryResults;
 import org.drools.RuleBase;

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/TestingEventListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/TestingEventListenerTest.java	2007-10-22 07:20:23 UTC (rev 15978)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/TestingEventListenerTest.java	2007-10-22 07:43:02 UTC (rev 15979)
@@ -1,7 +1,9 @@
 package org.drools.testframework;
 
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -81,5 +83,34 @@
 
 	}
 
+	public void testNoFilter() throws Exception {
+		HashSet<String> set = new HashSet<String>();
 
+
+        PackageBuilder builder = new PackageBuilder();
+        builder.addPackageFromDrl( new InputStreamReader(this.getClass().getResourceAsStream( "test_rules.drl" )) );
+
+        assertFalse(builder.getErrors().toString(), builder.hasErrors());
+
+        RuleBase rb = RuleBaseFactory.newRuleBase();
+        rb.addPackage(builder.getPackage());
+
+        TestingEventListener ls = new TestingEventListener(set, rb, false);
+
+        StatefulSession session = rb.newStatefulSession();
+        session.addEventListener(ls);
+
+        session.insert(new Cheese());
+
+        List<String> list = new ArrayList<String>();
+        session.setGlobal("list", list);
+        session.fireAllRules();
+
+        assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule1"));
+        assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule2"));
+        assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule3"));
+        assertEquals(1, list.size());
+	}
+
+
 }




More information about the jboss-svn-commits mailing list