[jboss-svn-commits] JBL Code SVN: r30918 - in labs/jbossrules/branches/true_modify_20100104/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
Mon Jan 4 21:15:29 EST 2010
Author: tirelli
Date: 2010-01-04 21:15:29 -0500 (Mon, 04 Jan 2010)
New Revision: 30918
Added:
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/CollectNodeTest.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.data
Modified:
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
Log:
JBRULES-2240: adding collect node step to the test framework and starting implementation of collect node tests
Added: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/CollectNodeTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/CollectNodeTest.java (rev 0)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/CollectNodeTest.java 2010-01-05 02:15:29 UTC (rev 30918)
@@ -0,0 +1,52 @@
+package org.drools.reteoo.test;
+
+import junit.framework.TestCase;
+
+public class CollectNodeTest extends TestCase {
+
+ public void testAssertRetract() {
+ ReteDslTestEngineHelper.executeDsl( "CollectNodeAssertRetractTest.data" );
+ }
+
+// public void testModify() {
+// executeDsl( "JoinNodeModifyTest.data" );
+// }
+//
+// public void testindex() {
+// executeDsl( "JoinNodeIndexTest.data" );
+// }
+
+ /*
+ public void testIndexedAssert() {
+ executeDsl( "JoinNodeIndexedAssertTest.data" );
+ }
+
+ public void testIndexedAssertRetract() {
+ executeDsl( new String[]{"JoinNodeIndexedAssertTest.data",
+ "JoinNodeIndexedAssertRetractTest.data"} );
+ }
+
+ public void testIndexedAssertRetractModify() {
+ executeDsl( new String[]{"JoinNodeIndexedAssertTest.data",
+ "JoinNodeIndexedAssertRetractTest.data",
+ "JoinNodeIndexedAssertRetractModifyTest.data"} );
+ }
+
+ public void testNotIndexedAssert() {
+ executeDsl( "JoinNodeNotIndexedAssertTest.data" );
+ }
+
+ public void testNotIndexedAssertRetract() {
+ executeDsl( new String[]{"JoinNodeNotIndexedAssertTest.data",
+ "JoinNodeNotIndexedAssertRetractTest.data"} );
+ }
+
+ public void testNotIndexedAssertRetractModify() {
+ executeDsl( new String[]{"JoinNodeNotIndexedAssertTest.data",
+ "JoinNodeNotIndexedAssertRetractTest.data",
+ "JoinNodeNotIndexedAssertRetractModifyTest.data"} );
+ }
+
+ */
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/CollectNodeTest.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java 2010-01-05 01:10:54 UTC (rev 30917)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java 2010-01-05 02:15:29 UTC (rev 30918)
@@ -23,12 +23,14 @@
import org.drools.base.ValueType;
import org.drools.base.evaluators.EvaluatorRegistry;
import org.drools.base.evaluators.Operator;
+import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.PropagationContextImpl;
import org.drools.common.SingleBetaConstraints;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.CollectNode;
import org.drools.reteoo.EntryPointNode;
import org.drools.reteoo.ExistsNode;
import org.drools.reteoo.JoinNode;
@@ -48,12 +50,14 @@
import org.drools.reteoo.RuleTerminalNode;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.BehaviorManager;
+import org.drools.rule.Collect;
import org.drools.rule.Declaration;
import org.drools.rule.GroupElement;
import org.drools.rule.Package;
import org.drools.rule.Pattern;
import org.drools.rule.Rule;
import org.drools.rule.VariableConstraint;
+import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.BetaNodeFieldConstraint;
import org.drools.spi.Consequence;
import org.drools.spi.Evaluator;
@@ -86,6 +90,8 @@
new NotNodeStep( this.reteTesterHelper ) );
this.steps.put( "ExistsNode",
new ExistsNodeStep( this.reteTesterHelper ) );
+ this.steps.put( "CollectNode",
+ new CollectNodeStep( this.reteTesterHelper ) );
this.steps.put( "RuleTerminalNode",
new RuleTerminalNodeStep( this.reteTesterHelper ) );
this.steps.put( "Facts",
@@ -94,11 +100,11 @@
new WithStep( this.reteTesterHelper ) );
this.steps.put( "ForallNodeStep",
new ForallNodeStep( this.reteTesterHelper ) );
-
+
}
- public Map run(List<DslStep> steps) {
- Map context = new HashMap();
+ public Map<String, Object> run(List<DslStep> steps) {
+ Map<String, Object> context = new HashMap<String, Object>();
RuleBaseConfiguration conf = new RuleBaseConfiguration();
@@ -166,7 +172,7 @@
private void betaNode(DslStep step,
BetaNode node,
- Map context,
+ Map<String, Object> context,
InternalWorkingMemory wm) {
try {
String[] cmds = step.getCommands().toArray( new String[0] );
@@ -176,16 +182,16 @@
for ( String cmd : cmds ) {
if ( cmd.trim().startsWith( "leftMemory" ) ) {
int pos = cmd.indexOf( "[" );
- String nodeName = cmd.substring( 0,
- pos ).trim();
+ cmd.substring( 0,
+ pos ).trim();
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
- List expectedLeftTuples = (List) MVEL.eval( listString,
- vars );
+ List< ? > expectedLeftTuples = (List< ? >) MVEL.eval( listString,
+ vars );
LeftTupleMemory leftMemory = memory.getLeftTupleMemory();
@@ -211,7 +217,7 @@
for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( firstTuple ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
leftTuples.add( leftTuple );
}
- List actualLeftTuples = new ArrayList( leftTuples.size() );
+ List<List<InternalFactHandle>> actualLeftTuples = new ArrayList<List<InternalFactHandle>>( leftTuples.size() );
for ( LeftTuple leftTuple : leftTuples ) {
List<InternalFactHandle> tupleHandles = Arrays.asList( leftTuple.toFactHandles() );
actualLeftTuples.add( tupleHandles );
@@ -223,16 +229,16 @@
} else if ( cmd.trim().startsWith( "rightMemory" ) ) {
int pos = cmd.indexOf( "[" );
- String nodeName = cmd.substring( 0,
- pos ).trim();
+ cmd.substring( 0,
+ pos ).trim();
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
- List expectedFactHandles = (List) MVEL.eval( listString,
- vars );
+ List< ? > expectedFactHandles = (List< ? >) MVEL.eval( listString,
+ vars );
RightTupleMemory rightMemory = memory.getRightTupleMemory();
@@ -243,7 +249,7 @@
}
RightTuple first = new RightTuple( (InternalFactHandle) expectedFactHandles.get( 0 ) );
- List<RightTuple> actualRightTuples = new ArrayList();
+ List<RightTuple> actualRightTuples = new ArrayList<RightTuple>();
for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( first ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
actualRightTuples.add( rightTuple );
}
@@ -270,7 +276,7 @@
private void ruleTerminalNode(DslStep step,
RuleTerminalNode node,
- Map context,
+ Map<String, Object> context,
InternalWorkingMemory wm) {
try {
String[] cmds = step.getCommands().toArray( new String[0] );
@@ -285,11 +291,11 @@
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
- List expectedLeftTuples = (List) MVEL.eval( listString,
- vars );
+ List< ? > expectedLeftTuples = (List< ? >) MVEL.eval( listString,
+ vars );
if ( expectedLeftTuples.isEmpty() && memory.size() != 0 ) {
throw new AssertionError( "line " + step.getLine() + ": left Memory expected [] actually " + memory );
@@ -310,7 +316,7 @@
List<LeftTuple> leftTuples = new ArrayList<LeftTuple>( memory );
- List actualLeftTuples = new ArrayList( leftTuples.size() );
+ List<List<InternalFactHandle>> actualLeftTuples = new ArrayList<List<InternalFactHandle>>( leftTuples.size() );
for ( LeftTuple leftTuple : leftTuples ) {
List<InternalFactHandle> tupleHandles = Arrays.asList( leftTuple.toFactHandles() );
actualLeftTuples.add( tupleHandles );
@@ -331,7 +337,7 @@
}
private void assertObject(DslStep step,
- Map context,
+ Map<String, Object> context,
InternalWorkingMemory wm) {
try {
String[] cmds = step.getCommands().toArray( new String[0] );
@@ -349,7 +355,7 @@
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
List<InternalFactHandle> list = (List<InternalFactHandle>) MVEL.eval( listString,
@@ -385,7 +391,7 @@
}
private void retractObject(DslStep step,
- Map context,
+ Map<String, Object> context,
InternalWorkingMemory wm) {
try {
String[] cmds = step.getCommands().toArray( new String[0] );
@@ -403,7 +409,7 @@
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
List<InternalFactHandle> list = (List<InternalFactHandle>) MVEL.eval( listString,
@@ -444,7 +450,7 @@
}
private void modifyObject(DslStep step,
- Map context,
+ Map<String, Object> context,
InternalWorkingMemory wm) {
try {
String[] cmds = step.getCommands().toArray( new String[0] );
@@ -462,7 +468,7 @@
String args = cmd.substring( pos ).trim();
String listString = args.replaceAll( "h(\\d+)",
"h[$1]" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
List<InternalFactHandle> list = (List<InternalFactHandle>) MVEL.eval( listString,
@@ -674,7 +680,7 @@
}
public static interface Step {
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args);
}
@@ -688,7 +694,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
String name;
@@ -735,7 +741,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
String name;
@@ -769,7 +775,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
String name;
@@ -789,10 +795,8 @@
field = c[3].trim();
try {
- ClassTypeResolver typeResolver = new ClassTypeResolver( new HashSet<String>(),
- getClass().getClassLoader() );
- Pattern pattern = new Pattern( Integer.parseInt( index ),
- new ClassObjectType( typeResolver.resolveType( type ) ) );
+ Pattern pattern = reteTesterHelper.getPattern( Integer.parseInt( index ),
+ type );
final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
ClassFieldAccessorStore store = (ClassFieldAccessorStore) context.get( "ClassFieldAccessorStore" );
@@ -816,6 +820,7 @@
throw new IllegalArgumentException( "Cannot arguments " + Arrays.asList( args ) );
}
}
+
}
public static class JoinNodeStep
@@ -828,7 +833,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
@@ -899,7 +904,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
@@ -959,85 +964,84 @@
}
}
}
-
+
public static class ForallNodeStep
- implements
- Step {
+ implements
+ Step {
- private ReteTesterHelper reteTesterHelper;
+ private ReteTesterHelper reteTesterHelper;
- public ForallNodeStep(ReteTesterHelper reteTesterHelper) {
- this.reteTesterHelper = reteTesterHelper;
- }
+ public ForallNodeStep(ReteTesterHelper reteTesterHelper) {
+ this.reteTesterHelper = reteTesterHelper;
+ }
- public void execute(Map context,
- String[] args) {
- BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
+ public void execute(Map<String, Object> context,
+ String[] args) {
+ BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
- if ( args.length != 0 ) {
-// String[] a = args[0].split( "," );
-// String name = a[0].trim();
-// String leftInput = a[1].trim();
-// String rightInput = a[2].trim();
-//
-// LeftTupleSource leftTupleSource;
-// if ( "mock".equals( leftInput ) ) {
-// leftTupleSource = new MockTupleSource( buildContext.getNextId() );
-// } else {
-// leftTupleSource = (LeftTupleSource) context.get( leftInput );
-// }
-//
-// ObjectSource rightObjectSource;
-// if ( "mock".equals( rightInput ) ) {
-// rightObjectSource = new MockObjectSource( buildContext.getNextId() );
-// } else {
-// rightObjectSource = (ObjectSource) context.get( rightInput );
-// }
-//
-// a = args[1].split( "," );
-// String fieldName = a[0].trim();
-// String operator = a[1].trim();
-// String var = a[2].trim();
-//
-// //Declaration declr = (Declaration) context.get( var );
-//
-// BetaNodeFieldConstraint betaConstraint;
-// try {
-// betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( declr.getPattern(),
-// fieldName,
-// declr,
-// operator );
-// } catch ( IntrospectionException e ) {
-// throw new IllegalArgumentException();
-// }
-//
-// SingleBetaConstraints constraints = new SingleBetaConstraints( betaConstraint,
-// buildContext.getRuleBase().getConfiguration() );
-// // * not*( $bus : Bus( ) and not ( Bus( this == $bus, color == RED ) ) )
-//
-// //new JoinNode()
-//
-//
-//
-// new ForallNotNode();
-//
-//// NotNode notNode = new NotNode( buildContext.getNextId(),
-//// leftTupleSource,
-//// rightObjectSource,
-//// constraints,
-//// BehaviorManager.NO_BEHAVIORS,
-//// buildContext );
-//// notNode.attach();
-//// context.put( name,
-//// notNode );
+ if ( args.length != 0 ) {
+ // String[] a = args[0].split( "," );
+ // String name = a[0].trim();
+ // String leftInput = a[1].trim();
+ // String rightInput = a[2].trim();
+ //
+ // LeftTupleSource leftTupleSource;
+ // if ( "mock".equals( leftInput ) ) {
+ // leftTupleSource = new MockTupleSource( buildContext.getNextId() );
+ // } else {
+ // leftTupleSource = (LeftTupleSource) context.get( leftInput );
+ // }
+ //
+ // ObjectSource rightObjectSource;
+ // if ( "mock".equals( rightInput ) ) {
+ // rightObjectSource = new MockObjectSource( buildContext.getNextId() );
+ // } else {
+ // rightObjectSource = (ObjectSource) context.get( rightInput );
+ // }
+ //
+ // a = args[1].split( "," );
+ // String fieldName = a[0].trim();
+ // String operator = a[1].trim();
+ // String var = a[2].trim();
+ //
+ // //Declaration declr = (Declaration) context.get( var );
+ //
+ // BetaNodeFieldConstraint betaConstraint;
+ // try {
+ // betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( declr.getPattern(),
+ // fieldName,
+ // declr,
+ // operator );
+ // } catch ( IntrospectionException e ) {
+ // throw new IllegalArgumentException();
+ // }
+ //
+ // SingleBetaConstraints constraints = new SingleBetaConstraints( betaConstraint,
+ // buildContext.getRuleBase().getConfiguration() );
+ // // * not*( $bus : Bus( ) and not ( Bus( this == $bus, color == RED ) ) )
+ //
+ // //new JoinNode()
+ //
+ //
+ //
+ // new ForallNotNode();
+ //
+ //// NotNode notNode = new NotNode( buildContext.getNextId(),
+ //// leftTupleSource,
+ //// rightObjectSource,
+ //// constraints,
+ //// BehaviorManager.NO_BEHAVIORS,
+ //// buildContext );
+ //// notNode.attach();
+ //// context.put( name,
+ //// notNode );
- } else {
- throw new IllegalArgumentException( "Cannot arguments " + args );
+ } else {
+ throw new IllegalArgumentException( "Cannot arguments " + args );
+ }
}
}
-}
-
public static class ExistsNodeStep
implements
@@ -1049,7 +1053,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
@@ -1120,7 +1124,7 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
@@ -1163,6 +1167,96 @@
}
}
+ public static class CollectNodeStep
+ implements
+ Step {
+
+ private ReteTesterHelper reteTesterHelper;
+
+ public CollectNodeStep(ReteTesterHelper reteTesterHelper) {
+ this.reteTesterHelper = reteTesterHelper;
+ }
+
+ public void execute(Map<String, Object> context,
+ String[] args) {
+ BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
+
+ if ( args.length != 0 ) {
+ String[] a = args[0].split( "," );
+ String name = a[0].trim();
+ String leftInput = a[1].trim();
+ String rightInput = a[2].trim();
+ String returnType = a[3].trim();
+
+ LeftTupleSource leftTupleSource;
+ if ( "mock".equals( leftInput ) ) {
+ leftTupleSource = new MockTupleSource( buildContext.getNextId() );
+ } else {
+ leftTupleSource = (LeftTupleSource) context.get( leftInput );
+ }
+
+ ObjectSource rightObjectSource;
+ if ( "mock".equals( rightInput ) ) {
+ rightObjectSource = new MockObjectSource( buildContext.getNextId() );
+ } else {
+ rightObjectSource = (ObjectSource) context.get( rightInput );
+ }
+
+ a = args[1].split( "," );
+ String fieldName = a[0].trim();
+ String operator = a[1].trim();
+ String var = a[2].trim();
+
+ Declaration declr = (Declaration) context.get( var );
+
+ BetaNodeFieldConstraint betaConstraint;
+ try {
+ betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( declr.getPattern(),
+ fieldName,
+ declr,
+ operator );
+ } catch ( IntrospectionException e ) {
+ throw new IllegalArgumentException();
+ }
+
+ SingleBetaConstraints constraints = new SingleBetaConstraints( betaConstraint,
+ buildContext.getRuleBase().getConfiguration() );
+
+ Pattern sourcePattern;
+ Pattern resultPattern;
+ try {
+ sourcePattern = reteTesterHelper.getPattern( 0,
+ ((ClassObjectType) ((ObjectTypeNode) rightObjectSource).getObjectType()).getClassName() );
+ resultPattern = reteTesterHelper.getPattern( buildContext.getNextId(),
+ returnType );
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException();
+ }
+
+ Collect collect = new Collect( sourcePattern,
+ resultPattern );
+
+ CollectNode collectNode = new CollectNode( buildContext.getNextId(),
+ leftTupleSource,
+ rightObjectSource,
+ new AlphaNodeFieldConstraint[0],
+ constraints,
+ new EmptyBetaConstraints(),
+ BehaviorManager.NO_BEHAVIORS,
+ collect,
+ false,
+ buildContext );
+ collectNode.attach();
+ context.put( name,
+ collectNode );
+
+ } else {
+ throw new IllegalArgumentException( "Cannot arguments " + args );
+
+ }
+ }
+ }
+
public static class FactsStep
implements
Step {
@@ -1173,22 +1267,22 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
if ( args.length >= 1 ) {
WorkingMemory wm = (WorkingMemory) context.get( "WorkingMemory" );
- List handles = (List) context.get( "Handles" );
+ List<FactHandle> handles = (List<FactHandle>) context.get( "Handles" );
if ( handles == null ) {
- handles = new ArrayList();
+ handles = new ArrayList<FactHandle>();
context.put( "Handles",
handles );
}
for ( String str : args ) {
- List objects = (List) MVEL.eval( "[" + str + "]" );
+ List< ? > objects = (List< ? >) MVEL.eval( "[" + str + "]" );
for ( Object object : objects ) {
FactHandle handle = wm.insert( object );
handles.add( handle );
@@ -1210,11 +1304,11 @@
this.reteTesterHelper = reteTesterHelper;
}
- public void execute(Map context,
+ public void execute(Map<String, Object> context,
String[] args) {
BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
List<InternalFactHandle> handles = (List<InternalFactHandle>) context.get( "Handles" );
- Map vars = new HashMap();
+ Map<String, Object> vars = new HashMap<String, Object>();
vars.put( "h",
handles );
@@ -1256,12 +1350,15 @@
private Package pkg;
private ClassFieldAccessorStore store;
private EvaluatorRegistry registry = new EvaluatorRegistry();
+ private final ClassTypeResolver typeResolver;
public ReteTesterHelper() {
this.pkg = new Package( "org.drools.examples.manners" );
this.pkg.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) );
this.store = this.pkg.getClassFieldAccessorStore();
this.store.setEagerWire( true );
+ this.typeResolver = new ClassTypeResolver( new HashSet<String>(),
+ getClass().getClassLoader() );
}
public Package getPkg() {
@@ -1300,6 +1397,14 @@
Operator.determineOperator( operator,
false ) );
}
+
+ public Pattern getPattern(int index,
+ String type) throws ClassNotFoundException {
+ Pattern pattern = new Pattern( index,
+ new ClassObjectType( typeResolver.resolveType( type ) ) );
+ return pattern;
+ }
+
}
public static class InstrumentedRuleTerminalNode extends RuleTerminalNode {
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-01-05 01:10:54 UTC (rev 30917)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngineTest.java 2010-01-05 02:15:29 UTC (rev 30918)
@@ -4,12 +4,12 @@
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import junit.framework.TestCase;
+
import org.drools.FactHandle;
import org.drools.Person;
import org.drools.RuleBaseConfiguration;
@@ -22,27 +22,17 @@
import org.drools.common.NodeMemory;
import org.drools.common.PropagationContextImpl;
import org.drools.reteoo.BetaMemory;
-import org.drools.reteoo.BetaNode;
import org.drools.reteoo.JoinNode;
import org.drools.reteoo.LeftInputAdapterNode;
import org.drools.reteoo.LeftTuple;
-import org.drools.reteoo.LeftTupleSource;
-import org.drools.reteoo.MockLeftTupleSink;
-import org.drools.reteoo.MockObjectSource;
-import org.drools.reteoo.MockTupleSource;
import org.drools.reteoo.ObjectTypeNode;
import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.ReteooWorkingMemory;
import org.drools.reteoo.RuleTerminalNode;
-import org.drools.reteoo.builder.BuildContext;
import org.drools.reteoo.test.ReteDslTestEngine.DslStep;
import org.drools.rule.Declaration;
-import org.drools.rule.GroupElement;
-import org.drools.rule.Rule;
import org.drools.spi.PropagationContext;
-import junit.framework.TestCase;
-
public class ReteDslTestEngineTest extends TestCase {
public void testIndentPos() {
ReteDslTestEngine tester = new ReteDslTestEngine();
Added: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.data
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.data (rev 0)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.data 2010-01-05 02:15:29 UTC (rev 30918)
@@ -0,0 +1,201 @@
+ObjectTypeNode
+ otnLeft1, org.drools.Person
+LeftInputAdapterNode
+ lian0, otnLeft1
+ObjectTypeNode
+ otnRight1, org.drools.Cheese
+Binding
+ l1, 0, org.drools.Person, likes
+CollectNode
+ col1, lian0, otnRight1, java.util.ArrayList
+ type, ==, l1
+Facts
+ new org.drools.Person('darth', 35), new org.drools.Person('bobba', 36)
+ new org.drools.Person('yoda', 37), new org.drools.Person('luke', 38)
+ new org.drools.Person('dave', 33), new org.drools.Person('bob', 32)
+
+/**
+ * check single left assertion and retraction
+ */
+assert
+ otnLeft1 [h0]
+join1
+ leftMemory [[h0]]
+join2
+ leftMemory []
+retract
+ otnLeft1 [h0]
+/**
+ * check single right assertion and retraction
+ */
+assert
+ otnRight1 [h1]
+join1
+ rightMemory [h1]
+join2
+ leftMemory []
+retract
+ otnRight1 [h1]
+
+/**
+ * check single left then right assertion
+ */
+assert
+ otnLeft1 [h0]
+ otnRight1 [h1]
+join1
+ leftMemory [[h0]]
+ rightMemory [h1]
+join2
+ leftMemory [[h0, h1]]
+retract
+ otnLeft1 [h0]
+ otnRight1 [h1]
+
+/**
+ * check single right then left assertion
+ */
+assert
+ otnRight1 [h1]
+ otnLeft1 [h0]
+join1
+ leftMemory [[h0]]
+ rightMemory [h1]
+join2
+ leftMemory [[h0, h1]]
+retract
+ otnLeft1 [h0]
+ otnRight1 [h1]
+
+/**
+ * assert two left and two right, with incremental first removal
+ */
+assert
+ otnLeft1 [h0, h1]
+ otnRight1 [h2, h3]
+join1
+ leftMemory [[h0], [h1]]
+ rightMemory [h2, h3]
+join2
+ leftMemory [[h0, h2], [h1, h2],
+ [h0, h3], [h1, h3]]
+retract
+ otnLeft1 [h0]
+join1
+ leftMemory [[h1]]
+ rightMemory [h2, h3]
+join2
+ leftMemory [[h1, h2],
+ [h1, h3]]
+retract
+ otnRight1 [h2]
+join1
+ leftMemory [[h1]]
+ rightMemory [h3]
+join2
+ leftMemory [[h1, h3]]
+retract
+ otnLeft1 [h1]
+ otnRight1 [h3]
+join1
+ leftMemory []
+ rightMemory []
+join2
+ leftMemory []
+
+/**
+ * assert two right and two left, with incremental last removal
+ */
+assert
+ otnRight1 [h2, h3]
+ otnLeft1 [h0, h1]
+join1
+ leftMemory [[h0], [h1]]
+ rightMemory [h2, h3]
+join2
+ leftMemory [[h0, h2], [h0, h3],
+ [h1, h2], [h1, h3]]
+retract
+ otnLeft1 [h1]
+join1
+ leftMemory [[h0]]
+ rightMemory [h2, h3]
+join2
+ leftMemory [[h0, h2], [h0, h3]]
+retract
+ otnRight1 [h3]
+join1
+ leftMemory [[h0]]
+ rightMemory [h2]
+join2
+ leftMemory [[h0, h2]]
+retract
+ otnLeft1 [h0]
+ otnRight1 [h2]
+join1
+ leftMemory []
+ rightMemory []
+join2
+ leftMemory []
+
+/**
+ * assert three left and three right, middle two are removed, and then iterated in reverse order
+ */
+assert
+ otnLeft1 [h0, h5, h2]
+ otnRight1 [h3, h4, h1]
+join1
+ leftMemory [[h0], [h5], [h2]]
+ rightMemory [h3, h4, h1]
+join2
+ leftMemory [[h0, h3], [h5, h3], [h2, h3],
+ [h0, h4], [h5, h4], [h2, h4],
+ [h0, h1], [h5, h1], [h2, h1]]
+ rightMemory []
+retract
+ otnLeft1 [h5]
+join1
+ leftMemory [[h0], [h2]]
+ rightMemory [h3, h4, h1]
+join2
+ leftMemory [[h0, h3], [h2, h3],
+ [h0, h4], [h2, h4],
+ [h0, h1], [h2, h1]]
+ rightMemory []
+retract
+ otnRight1 [h4]
+join1
+ leftMemory [[h0], [h2]]
+ rightMemory [h3, h1]
+join2
+ leftMemory [[h0, h3], [h2, h3],
+ [h0, h1], [h2, h1]]
+ rightMemory []
+assert
+ otnLeft1 [h5]
+ otnRight1 [h4]
+join1
+ leftMemory [[h0], [h2], [h5]]
+ rightMemory [h3, h1, h4]
+join2
+ leftMemory [[h0, h3], [h2, h3],
+ [h0, h1], [h2, h1],
+ [h5, h3], [h5, h1],
+ [h0, h4], [h2, h4], [h5, h4] ]
+retract
+ otnRight1 [h4]
+join1
+ leftMemory [[h0], [h2], [h5]]
+ rightMemory [h3, h1]
+join2
+ leftMemory [[h0, h3], [h2, h3],
+ [h0, h1], [h2, h1],
+ [h5, h3], [h5, h1] ]
+retract
+ otnLeft1 [h5]
+join1
+ leftMemory [[h0], [h2]]
+ rightMemory [h3, h1]
+join2
+ leftMemory [[h0, h3], [h2, h3],
+ [h0, h1], [h2, h1]]
\ No newline at end of file
Property changes on: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.data
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-svn-commits
mailing list