[jboss-svn-commits] JBL Code SVN: r31560 - in labs/jbossrules/branches/true_modify_20100104: drools-compiler/src/test/java/org/drools/integrationtests and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 10 17:41:15 EST 2010
Author: tirelli
Date: 2010-02-10 17:41:14 -0500 (Wed, 10 Feb 2010)
New Revision: 31560
Added:
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/BetaNodeStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/DSLMock.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
Removed:
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSourceStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockBetaNodeStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSourceStep.java
Modified:
labs/jbossrules/branches/true_modify_20100104/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
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/dsl/FactsStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/InstrumentedRuleTerminalNode.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSinkStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/NodeTestCaseResult.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSinkStep.java
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeAssertRetractTest.nodeTestCase
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeModifyTest.nodeTestCase
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase
labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/RIANodeTest.nodeTestCase
labs/jbossrules/branches/true_modify_20100104/pom.xml
Log:
JBRULES-2339: JBRULES-2340: more fixes
Modified: labs/jbossrules/branches/true_modify_20100104/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -1,5 +1,6 @@
package org.drools.integrationtests;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -465,13 +465,13 @@
if ( childLeftTuple == null || childLeftTuple.getLeftParent() == leftTuple ) {
// we must re-add this to ensure deterministic iteration
childLeftTuple.reAddRight();
- removeMatch( rightTuple,
- childLeftTuple,
- workingMemory,
- memory,
- accctx,
+ removeMatch( rightTuple,
+ childLeftTuple,
+ workingMemory,
+ memory,
+ accctx,
true );
-
+
}
// add a new match
addMatch( leftTuple,
@@ -785,7 +785,9 @@
accctx.context,
leftTuple,
workingMemory );
- for ( LeftTuple childMatch = leftTuple.firstChild; childMatch != null; childMatch = childMatch.getLeftParentNext() ) {
+ for ( LeftTuple childMatch = getFirstMatch( leftTuple,
+ accctx,
+ false ); childMatch != null; childMatch = childMatch.getLeftParentNext() ) {
InternalFactHandle childHandle = childMatch.getRightParent().getFactHandle();
if ( this.unwrapRightObject ) {
childHandle = ((LeftTuple) childHandle.getObject()).getLastHandle();
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/ObjectSinkPropagator.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -25,8 +25,8 @@
public int size();
public void propagateModifyObject(InternalFactHandle factHandle,
- ModifyPreviousTuples modifyPreviousTuples,
- PropagationContext context,
- InternalWorkingMemory workingMemory);
+ ModifyPreviousTuples modifyPreviousTuples,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory);
}
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -172,15 +172,22 @@
ModifyPreviousTuples modifyPreviousTuples,
PropagationContext context,
InternalWorkingMemory workingMemory) {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException( "This method should never be called" );
}
public void modifyLeftTuple(LeftTuple leftTuple,
PropagationContext context,
InternalWorkingMemory workingMemory) {
- // TODO Auto-generated method stub
+ final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
+ // add it to a memory mapping
+ InternalFactHandle handle = (InternalFactHandle) memory.get( leftTuple );
+ // propagate it
+ for ( RightTuple rightTuple = handle.getFirstRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
+ rightTuple.getRightTupleSink().modifyRightTuple( rightTuple,
+ context,
+ workingMemory );
+ }
}
public void attach() {
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-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/ReteDslTestEngine.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -36,6 +36,7 @@
import org.drools.reteoo.ObjectSink;
import org.drools.reteoo.ObjectTypeNode;
import org.drools.reteoo.ReteooRuleBase;
+import org.drools.reteoo.RightInputAdapterNode;
import org.drools.reteoo.RightTuple;
import org.drools.reteoo.RightTupleMemory;
import org.drools.reteoo.RuleTerminalNode;
@@ -44,21 +45,21 @@
import org.drools.reteoo.CollectNode.CollectMemory;
import org.drools.reteoo.builder.BuildContext;
import org.drools.reteoo.test.dsl.AccumulateNodeStep;
+import org.drools.reteoo.test.dsl.BetaNodeStep;
import org.drools.reteoo.test.dsl.BindingStep;
import org.drools.reteoo.test.dsl.CollectNodeStep;
+import org.drools.reteoo.test.dsl.DSLMock;
import org.drools.reteoo.test.dsl.DslStep;
import org.drools.reteoo.test.dsl.ExistsNodeStep;
import org.drools.reteoo.test.dsl.FactsStep;
import org.drools.reteoo.test.dsl.JoinNodeStep;
import org.drools.reteoo.test.dsl.LeftInputAdapterNodeStep;
import org.drools.reteoo.test.dsl.LeftTupleSinkStep;
-import org.drools.reteoo.test.dsl.LeftTupleSourceStep;
-import org.drools.reteoo.test.dsl.MockBetaNodeStep;
+import org.drools.reteoo.test.dsl.MockitoHelper;
import org.drools.reteoo.test.dsl.NodeTestCase;
import org.drools.reteoo.test.dsl.NodeTestCaseResult;
import org.drools.reteoo.test.dsl.NodeTestDef;
import org.drools.reteoo.test.dsl.NotNodeStep;
-import org.drools.reteoo.test.dsl.ObjectSourceStep;
import org.drools.reteoo.test.dsl.ObjectTypeNodeStep;
import org.drools.reteoo.test.dsl.RIANodeStep;
import org.drools.reteoo.test.dsl.ReteTesterHelper;
@@ -72,6 +73,9 @@
import org.drools.reteoo.test.parser.NodeTestDSLTree;
import org.drools.reteoo.test.parser.NodeTestDSLParser.compilation_unit_return;
import org.drools.spi.PropagationContext;
+import org.drools.util.Iterator;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashMap.ObjectEntry;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
@@ -92,10 +96,8 @@
private static final String WITH = "With";
private static final String FACTS = "Facts";
private static final String RIGHT_INPUT_ADAPTER_NODE = "RightInputAdapterNode";
- private static final String LEFT_TUPLE_SOURCE_STEP = "LeftTupleSource";
- private static final String OBJECT_SOURCE_STEP = "ObjectSource";
private static final String LEFT_TUPLE_SINK_STEP = "LeftTupleSink";
- private static final String MOCK_BETA_NODE_STEP = "MockBetaNodeStep";
+ private static final String BETA_NODE_STEP = "BetaNodeStep";
private ReteTesterHelper reteTesterHelper;
private Map<String, Object> steps;
@@ -132,12 +134,8 @@
new WithStep( this.reteTesterHelper ) );
this.steps.put( LEFT_TUPLE_SINK_STEP,
new LeftTupleSinkStep( this.reteTesterHelper ) );
- this.steps.put( LEFT_TUPLE_SOURCE_STEP,
- new LeftTupleSourceStep( this.reteTesterHelper ) );
- this.steps.put( OBJECT_SOURCE_STEP,
- new ObjectSourceStep( this.reteTesterHelper ) );
- this.steps.put( MOCK_BETA_NODE_STEP,
- new MockBetaNodeStep( this.reteTesterHelper ) );
+ this.steps.put( BETA_NODE_STEP,
+ new BetaNodeStep( this.reteTesterHelper ) );
}
public NodeTestCaseResult run(NodeTestCase testCase,
@@ -253,23 +251,27 @@
throw new IllegalArgumentException( "line " + step.getLine() + ": step " + name + " does not exist" );
}
- if ( node instanceof BetaNode ) {
+ if ( node instanceof DSLMock ) {
+ // it is a mock
+ MockitoHelper.process( step,
+ (LeftTupleSink) node,
+ context,
+ wm );
+ } else if ( node instanceof BetaNode ) {
betaNode( step,
(BetaNode) node,
context,
wm );
+ } else if ( node instanceof RightInputAdapterNode ) {
+ riaNode( step,
+ (RightInputAdapterNode) node,
+ context,
+ wm );
} else if ( node instanceof RuleTerminalNode ) {
ruleTerminalNode( step,
(RuleTerminalNode) node,
context,
wm );
- } else if ( node instanceof LeftTupleSink ) {
- LeftTupleSinkStep impl = (LeftTupleSinkStep) this.steps.get( LEFT_TUPLE_SINK_STEP );
- // it might be a mock
- impl.process( step,
- (LeftTupleSink) node,
- context,
- wm );
} else {
throw new IllegalArgumentException( "line " + step.getLine() + ": unknown node " + node );
}
@@ -386,6 +388,74 @@
}
}
+ private void riaNode(DslStep step,
+ RightInputAdapterNode node,
+ Map<String, Object> context,
+ InternalWorkingMemory wm) {
+ try {
+ List<String[]> cmds = step.getCommands();
+ List<InternalFactHandle> handles = (List<InternalFactHandle>) context.get( "Handles" );
+
+ final ObjectHashMap memory = (ObjectHashMap) wm.getNodeMemory( node );
+ for ( String[] cmd : cmds ) {
+ if ( cmd[0].equals( "leftMemory" ) ) {
+ String args = cmd[1];
+ String listString = args.replaceAll( "h(\\d+)",
+ "h[$1]" );
+ Map<String, Object> vars = new HashMap<String, Object>();
+ vars.put( "h",
+ handles );
+ List< ? > expectedLeftTuples = (List< ? >) MVEL.eval( listString,
+ vars );
+
+ if ( expectedLeftTuples.isEmpty() && memory.size() != 0 ) {
+ throw new AssertionError( "line " + step.getLine() + ": left Memory expected [] actually " + memory );
+ } else if ( expectedLeftTuples.isEmpty() && memory.size() == 0 ) {
+ return;
+ }
+
+ // create expected tuples
+ List<LeftTuple> leftTuples = new ArrayList<LeftTuple>();
+ for ( List<InternalFactHandle> tlist : (List<List<InternalFactHandle>>) expectedLeftTuples ) {
+ LeftTuple tuple = new LeftTuple( tlist.get( 0 ),
+ null,
+ false );
+ for ( int i = 1; i < tlist.size(); i++ ) {
+ tuple = new LeftTuple( tuple,
+ new RightTuple( tlist.get( i ) ),
+ null,
+ false );
+ }
+ leftTuples.add( tuple );
+
+ }
+
+ // get actual tuples
+ final List<LeftTuple> actualTuples = new ArrayList<LeftTuple>();
+ final Iterator it = memory.iterator();
+ for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+ actualTuples.add( (LeftTuple) entry.getKey() );
+ }
+
+ // iterate over expected tuples and compare with actual tuples
+ for ( LeftTuple tuple : leftTuples ) {
+ if ( !actualTuples.remove( tuple ) ) {
+ throw new AssertionError( "line " + step.getLine() + ": left Memory expected " + tuple + " not found in memory." );
+ }
+ }
+ if ( !actualTuples.isEmpty() ) {
+ throw new AssertionError( "line " + step.getLine() + ": left Memory unexpected tuples in the node memory " + actualTuples );
+ }
+ } else {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": command does not exist " + Arrays.toString( cmd ) );
+ }
+ }
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": unable to execute step " + step,
+ e );
+ }
+ }
+
private void ruleTerminalNode(DslStep step,
RuleTerminalNode node,
Map<String, Object> context,
Added: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/BetaNodeStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/BetaNodeStep.java (rev 0)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/BetaNodeStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2008 Red Hat
+ *
+ * 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.
+ *
+ */
+package org.drools.reteoo.test.dsl;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.LeftTupleSource;
+import org.drools.reteoo.ObjectSource;
+import org.drools.reteoo.RightTuple;
+import org.drools.spi.PropagationContext;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.mockito.Mockito.*;
+
+public class BetaNodeStep
+ implements
+ Step {
+
+ public BetaNodeStep(ReteTesterHelper reteTesterHelper) {
+ }
+
+ public void execute(Map<String, Object> context,
+ List<String[]> args) {
+ if ( args.size() == 1 ) {
+
+ // The first argument list is the node parameters
+ String[] a = args.get( 0 );
+ String name = a[0];
+ String leftInput = a[1];
+ String rightInput = a[2];
+
+ BetaNode betaNode = Mockito.mock( BetaNode.class, Mockito.withSettings().extraInterfaces( DSLMock.class ) );
+ Mockito.doAnswer( new Answer<Object>() {
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ InternalFactHandle handle = (InternalFactHandle) args[0];
+ BetaNode node = (BetaNode) invocation.getMock();
+ // creating child RightTuple
+ new RightTuple(handle, node);
+ return null;
+ }
+ }).when( betaNode ).assertObject( any(InternalFactHandle.class),
+ any(PropagationContext.class),
+ any(InternalWorkingMemory.class) );
+ context.put( name,
+ betaNode );
+
+ if ( ! "mock".equals( leftInput ) ) {
+ LeftTupleSource leftTupleSource = (LeftTupleSource) context.get( leftInput );
+ leftTupleSource.addTupleSink( betaNode );
+ }
+
+ if ( ! "mock".equals( rightInput ) ) {
+ ObjectSource rightObjectSource = (ObjectSource) context.get( rightInput );
+ rightObjectSource.addObjectSink( betaNode );
+ }
+
+ } else {
+ StringBuilder msgBuilder = new StringBuilder();
+ msgBuilder.append( "Can not parse MockBetaNode step arguments: \n" );
+ for ( String[] arg : args ) {
+ msgBuilder.append( " " );
+ msgBuilder.append( Arrays.toString( arg ) );
+ msgBuilder.append( "\n" );
+ }
+ throw new IllegalArgumentException( msgBuilder.toString() );
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/BetaNodeStep.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/DSLMock.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/DSLMock.java (rev 0)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/DSLMock.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2008 Red Hat
+ *
+ * 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.
+ *
+ */
+package org.drools.reteoo.test.dsl;
+
+/**
+ * A markup interface for the mocks we created
+ *
+ * @author etirelli
+ */
+public interface DSLMock {
+
+}
Property changes on: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/DSLMock.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/FactsStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/FactsStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/FactsStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -27,7 +27,6 @@
import org.mvel2.MVEL;
import org.mvel2.ParserConfiguration;
import org.mvel2.ParserContext;
-import org.mvel2.compiler.CompiledExpression;
public class FactsStep
implements
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/InstrumentedRuleTerminalNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/InstrumentedRuleTerminalNode.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/InstrumentedRuleTerminalNode.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -43,6 +43,7 @@
context );
}
+ @SuppressWarnings("unchecked")
@Override
public void assertLeftTuple(LeftTuple leftTuple,
PropagationContext context,
@@ -54,6 +55,7 @@
workingMemory );
}
+ @SuppressWarnings("unchecked")
@Override
public void retractLeftTuple(LeftTuple leftTuple,
PropagationContext context,
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSinkStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSinkStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSinkStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -16,37 +16,12 @@
*/
package org.drools.reteoo.test.dsl;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.same;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.reteoo.LeftTuple;
import org.drools.reteoo.LeftTupleSink;
import org.drools.reteoo.LeftTupleSource;
-import org.drools.spi.PropagationContext;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
-import org.junit.matchers.JUnitMatchers;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
-import org.mockito.exceptions.base.MockitoAssertionError;
-import org.mockito.internal.verification.api.VerificationMode;
-import org.mvel2.MVEL;
-import org.mvel2.ParserConfiguration;
-import org.mvel2.ParserContext;
-import org.mvel2.PropertyAccessException;
public class LeftTupleSinkStep
implements
@@ -64,7 +39,8 @@
LeftTupleSource leftTupleSource = (LeftTupleSource) context.get( leftInput );
- LeftTupleSink mockedSink = Mockito.mock( LeftTupleSink.class );
+ LeftTupleSink mockedSink = Mockito.mock( LeftTupleSink.class,
+ Mockito.withSettings().extraInterfaces( DSLMock.class ) );
leftTupleSource.addTupleSink( mockedSink );
@@ -76,235 +52,4 @@
}
}
-
- public void process(DslStep step,
- LeftTupleSink node,
- Map<String, Object> context,
- InternalWorkingMemory wm) {
- try {
- List<String[]> cmds = step.getCommands();
-
- for ( String[] cmd : cmds ) {
- if ( cmd[0].equals( "verify" ) ) {
- if ( "count".equals( cmd[2] ) ) {
- verifyCount( step,
- node,
- wm,
- cmd,
- context );
- } else if ( "exec".equals( cmd[2] ) ) {
- verifyExec( step,
- node,
- wm,
- cmd,
- context );
- } else if ( cmd.length == 3 || cmd.length == 4 ) {
- verifyExpression( step,
- node,
- wm,
- cmd,
- context );
- } else {
- throw new IllegalArgumentException( "line " + step.getLine() + ": command '" + cmd[2] + "' does not exist in " + Arrays.toString( cmd ) );
- }
- } else {
- throw new IllegalArgumentException( "line " + step.getLine() + ": command does not exist " + Arrays.toString( cmd ) );
- }
- }
- } catch ( Exception e ) {
- throw new IllegalArgumentException( "line " + step.getLine() + ": unable to execute step " + step,
- e );
- }
- }
-
- private void verifyCount(DslStep step,
- LeftTupleSink node,
- InternalWorkingMemory wm,
- String[] cmd,
- Map<String, Object> context) throws AssertionError {
- int times = Integer.valueOf( cmd[3] );
- VerificationMode counter;
- if ( times >= 0 ) {
- counter = times( times );
- } else {
- counter = atLeastOnce();
- }
- try {
- ArgumentCaptor<LeftTuple> captor = ArgumentCaptor.forClass( LeftTuple.class );
- if ( "assert".equals( cmd[1] ) ) {
- verify( node,
- counter ).assertLeftTuple( captor.capture(),
- any( PropagationContext.class ),
- same( wm ) );
- } else if ( "retract".equals( cmd[1] ) ) {
- verify( node,
- counter ).retractLeftTuple( captor.capture(),
- any( PropagationContext.class ),
- same( wm ) );
- } else if ( "modify".equals( cmd[1] ) ) {
- verify( node,
- counter ).modifyLeftTuple( captor.capture(),
- any( PropagationContext.class ),
- same( wm ) );
- } else {
- throw new IllegalArgumentException( "line " + step.getLine() + ": command does not exist " + Arrays.toString( cmd ) );
- }
- String key = getCaptorKey( node,
- cmd );
- context.put( key,
- captor );
- } catch ( MockitoAssertionError e ) {
- AssertionError ae = new AssertionError( "line " + step.getLine() + ": verify failed: " + e.getMessage() );
- ae.setStackTrace( e.getStackTrace() );
- throw ae;
- }
- }
-
- private String getCaptorKey(LeftTupleSink node,
- String[] cmd) {
- return System.identityHashCode( node ) + "." + cmd[1] + ".captor";
- }
-
- private void verifyExpression(DslStep step,
- LeftTupleSink node,
- InternalWorkingMemory wm,
- String[] cmd,
- Map<String, Object> context) throws AssertionError {
- // check that the captor already exists:
- String key = getCaptorKey( node,
- cmd );
- ArgumentCaptor<LeftTuple> captor = (ArgumentCaptor<LeftTuple>) context.get( key );
- if ( captor == null ) {
- // create the captor
- verifyCount( step,
- node,
- wm,
- new String[]{"verify", cmd[1], "count", "-1"},
- context );
- captor = (ArgumentCaptor<LeftTuple>) context.get( key );
- }
-
- // create a map with all captured tuples as variables
- Map<String, Object> vars = new HashMap<String, Object>();
- int i = 0;
- for ( LeftTuple tuple : captor.getAllValues() ) {
- vars.put( "tuple" + (i++),
- tuple.toFactHandles() );
- }
- // add all context variables, just in case
- vars.putAll( context );
-
- // add the static imports for hamcrest matchers
- ParserConfiguration pconf = new ParserConfiguration();
- addStaticImports( pconf,
- CoreMatchers.class );
- addStaticImports( pconf,
- JUnitMatchers.class );
- // add import for JUnit assert class
- pconf.addImport( "Assert",
- Assert.class );
-
- // compile MVEL expression
- ParserContext mvelctx = new ParserContext( pconf );
- String expression;
- if ( cmd.length == 3 ) {
- expression = "Assert.assertTrue( " + cmd[2].replaceAll( "h(\\d+)",
- "Handles[$1]" ) + " );";
- } else {
- String val = cmd[2].replaceAll( "h(\\d+)",
- "Handles[$1]" );
- String matcher = cmd[3].replaceAll( "h(\\d+)",
- "Handles[$1]" );
- expression = "Assert.assertThat( " + val + ", " + matcher + " );";
- }
- try {
- Serializable compiled = MVEL.compileExpression( expression,
- mvelctx );
-
- // execute the expression
- MVEL.executeExpression( compiled,
- vars );
- } catch ( PropertyAccessException e ) {
- String message;
- if ( e.getCause() instanceof InvocationTargetException ) {
- message = ((InvocationTargetException) e.getCause()).getTargetException().toString();
- } else {
- message = e.getMessage();
- }
-
- Assert.fail( "[ERROR] line " + step.getLine() + " - Executing expression: '" + expression + "'\n" + message );
- }
- }
-
- private void verifyExec(DslStep step,
- LeftTupleSink node,
- InternalWorkingMemory wm,
- String[] cmd,
- Map<String, Object> context) throws AssertionError {
- // check that the captor already exists:
- String key = getCaptorKey( node,
- cmd );
- ArgumentCaptor<LeftTuple> captor = (ArgumentCaptor<LeftTuple>) context.get( key );
- if ( captor == null ) {
- // create the captor
- verifyCount( step,
- node,
- wm,
- new String[]{"verify", cmd[1], "count", "-1"},
- context );
- captor = (ArgumentCaptor<LeftTuple>) context.get( key );
- }
-
- // create a map with all captured tuples as variables
- Map<String, Object> vars = new HashMap<String, Object>();
- int i = 0;
- for ( LeftTuple tuple : captor.getAllValues() ) {
- vars.put( "tuple" + (i++),
- tuple.toFactHandles() );
- }
- // add all context variables, just in case
- vars.putAll( context );
-
- // add the static imports for hamcrest matchers
- ParserConfiguration pconf = new ParserConfiguration();
- addStaticImports( pconf,
- CoreMatchers.class );
- addStaticImports( pconf,
- JUnitMatchers.class );
- // add import for JUnit assert class
- pconf.addImport( "Assert",
- Assert.class );
-
- // compile MVEL expression
- ParserContext mvelctx = new ParserContext( pconf );
- String expression = cmd[3].replaceAll( "h(\\d+)",
- "Handles[$1]" );
- try {
- Serializable compiled = MVEL.compileExpression( expression,
- mvelctx );
- // execute the expression
- MVEL.executeExpression( compiled,
- vars );
- } catch ( PropertyAccessException e ) {
- String message;
- if ( e.getCause() instanceof InvocationTargetException ) {
- message = ((InvocationTargetException) e.getCause()).getTargetException().toString();
- } else {
- message = e.getMessage();
- }
-
- Assert.fail( "[ERROR] line " + step.getLine() + " - Executing expression: '" + expression + "'\n" + message );
- }
- }
-
- private void addStaticImports(ParserConfiguration pconf,
- Class< ? > clazz) {
- for ( Method m : clazz.getMethods() ) {
- if ( Modifier.isStatic( m.getModifiers() ) ) {
- pconf.addImport( m.getName(),
- m );
- }
- }
- }
-
}
\ No newline at end of file
Deleted: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSourceStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSourceStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/LeftTupleSourceStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -1,49 +0,0 @@
-/*
- * Copyright 2008 Red Hat
- *
- * 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.
- *
- */
-package org.drools.reteoo.test.dsl;
-
-import java.util.List;
-import java.util.Map;
-
-import org.drools.reteoo.LeftTupleSource;
-import org.mockito.Mockito;
-
-public class LeftTupleSourceStep
- implements
- Step {
-
- public LeftTupleSourceStep(ReteTesterHelper reteTesterHelper) {
- }
-
- public void execute(Map<String, Object> context,
- List<String[]> args) {
- if ( args.size() == 1 ) {
- String[] a = args.get( 0 );
- String name = a[0].trim();
-
- LeftTupleSource mockedSource = Mockito.mock( LeftTupleSource.class );
-
- context.put( name,
- mockedSource );
-
- } else {
- throw new IllegalArgumentException( "Cannot parse arguments " + args );
-
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockBetaNodeStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockBetaNodeStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockBetaNodeStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -1,71 +0,0 @@
-/*
- * Copyright 2008 Red Hat
- *
- * 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.
- *
- */
-package org.drools.reteoo.test.dsl;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.drools.reteoo.BetaNode;
-import org.drools.reteoo.LeftTupleSource;
-import org.drools.reteoo.ObjectSource;
-import org.mockito.Mockito;
-
-public class MockBetaNodeStep
- implements
- Step {
-
- public MockBetaNodeStep(ReteTesterHelper reteTesterHelper) {
- }
-
- public void execute(Map<String, Object> context,
- List<String[]> args) {
- if ( args.size() == 1 ) {
-
- // The first argument list is the node parameters
- String[] a = args.get( 0 );
- String name = a[0];
- String leftInput = a[1];
- String rightInput = a[2];
-
- BetaNode betaNode = Mockito.mock( BetaNode.class );
- context.put( name,
- betaNode );
-
- if ( ! "mock".equals( leftInput ) ) {
- LeftTupleSource leftTupleSource = (LeftTupleSource) context.get( leftInput );
- leftTupleSource.addTupleSink( betaNode );
- }
-
- if ( ! "mock".equals( rightInput ) ) {
- ObjectSource rightObjectSource = (ObjectSource) context.get( rightInput );
- rightObjectSource.addObjectSink( betaNode );
- }
-
- } else {
- StringBuilder msgBuilder = new StringBuilder();
- msgBuilder.append( "Can not parse MockBetaNode step arguments: \n" );
- for ( String[] arg : args ) {
- msgBuilder.append( " " );
- msgBuilder.append( Arrays.toString( arg ) );
- msgBuilder.append( "\n" );
- }
- throw new IllegalArgumentException( msgBuilder.toString() );
- }
- }
-
-}
\ No newline at end of file
Added: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java (rev 0)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -0,0 +1,308 @@
+package org.drools.reteoo.test.dsl;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.ObjectSinkNode;
+import org.drools.reteoo.RightTuple;
+import org.drools.reteoo.RightTupleSink;
+import org.drools.reteoo.Sink;
+import org.drools.spi.PropagationContext;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.matchers.JUnitMatchers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.exceptions.base.MockitoAssertionError;
+import org.mockito.internal.verification.api.VerificationMode;
+import org.mvel2.MVEL;
+import org.mvel2.ParserConfiguration;
+import org.mvel2.ParserContext;
+import org.mvel2.PropertyAccessException;
+
+/**
+ * A helper class to process mock related commands in the DSL
+ *
+ * @author etirelli
+ */
+public class MockitoHelper {
+
+ public static void process(DslStep step,
+ Sink node,
+ Map<String, Object> context,
+ InternalWorkingMemory wm) {
+ try {
+ List<String[]> cmds = step.getCommands();
+
+ for ( String[] cmd : cmds ) {
+ if ( cmd[0].equals( "verify" ) ) {
+ if ( "count".equals( cmd[2] ) ) {
+ verifyCount( step,
+ node,
+ wm,
+ cmd,
+ context );
+ } else if ( "exec".equals( cmd[2] ) ) {
+ verifyExec( step,
+ node,
+ wm,
+ cmd,
+ context );
+ } else if ( cmd.length == 3 || cmd.length == 4 ) {
+ verifyExpression( step,
+ node,
+ wm,
+ cmd,
+ context );
+ } else {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": command '" + cmd[2] + "' does not exist in " + Arrays.toString( cmd ) );
+ }
+ } else {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": command does not exist " + Arrays.toString( cmd ) );
+ }
+ }
+ } catch ( Exception e ) {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": unable to execute step " + step,
+ e );
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void verifyCount(DslStep step,
+ Sink node,
+ InternalWorkingMemory wm,
+ String[] cmd,
+ Map<String, Object> context) throws AssertionError {
+ int times = Integer.valueOf( cmd[3] );
+ VerificationMode counter;
+ if ( times >= 0 ) {
+ counter = times( times );
+ } else {
+ counter = atLeastOnce();
+ }
+ try {
+ ArgumentCaptor< ? > captor = null;
+ if ( "assertLeft".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( LeftTuple.class );
+ verify( (LeftTupleSink) node,
+ counter ).assertLeftTuple( ((ArgumentCaptor<LeftTuple>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else if ( "retractLeft".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( LeftTuple.class );
+ verify( (LeftTupleSink) node,
+ counter ).retractLeftTuple( ((ArgumentCaptor<LeftTuple>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else if ( "modifyLeft".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( LeftTuple.class );
+ verify( (LeftTupleSink) node,
+ counter ).modifyLeftTuple( ((ArgumentCaptor<LeftTuple>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else if ( "assertRight".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( InternalFactHandle.class );
+ verify( (ObjectSinkNode) node,
+ counter ).assertObject( ((ArgumentCaptor<InternalFactHandle>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else if ( "modifyRight".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( RightTuple.class );
+ verify( (RightTupleSink) node,
+ counter ).modifyRightTuple( ((ArgumentCaptor<RightTuple>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else if ( "retractRight".equals( cmd[1] ) ) {
+ captor = ArgumentCaptor.forClass( RightTuple.class );
+ verify( (RightTupleSink) node,
+ counter ).retractRightTuple( ((ArgumentCaptor<RightTuple>) captor).capture(),
+ any( PropagationContext.class ),
+ same( wm ) );
+ } else {
+ throw new IllegalArgumentException( "line " + step.getLine() + ": command does not exist " + Arrays.toString( cmd ) );
+ }
+ String key = getCaptorKey( node,
+ cmd );
+ context.put( key,
+ captor );
+ } catch ( MockitoAssertionError e ) {
+ AssertionError ae = new AssertionError( "line " + step.getLine() + ": verify failed: " + e.getMessage() );
+ ae.setStackTrace( e.getStackTrace() );
+ throw ae;
+ }
+ }
+
+ private static String getCaptorKey(Sink node,
+ String[] cmd) {
+ return System.identityHashCode( node ) + "." + cmd[1] + ".captor";
+ }
+
+ private static void verifyExpression(DslStep step,
+ Sink node,
+ InternalWorkingMemory wm,
+ String[] cmd,
+ Map<String, Object> context) throws AssertionError {
+ // check that the captor already exists:
+ String key = getCaptorKey( node,
+ cmd );
+ ArgumentCaptor<?> captor = (ArgumentCaptor<?>) context.get( key );
+ if ( captor == null ) {
+ // create the captor
+ verifyCount( step,
+ node,
+ wm,
+ new String[]{"verify", cmd[1], "count", "-1"},
+ context );
+ captor = (ArgumentCaptor<?>) context.get( key );
+ }
+
+ // create a map with all captured tuples as variables
+ Map<String, Object> vars = new HashMap<String, Object>();
+ populateCapturedArguments( captor,
+ vars );
+ // add all context variables, just in case
+ vars.putAll( context );
+
+ // add the static imports for hamcrest matchers
+ ParserConfiguration pconf = new ParserConfiguration();
+ addStaticImports( pconf,
+ CoreMatchers.class );
+ addStaticImports( pconf,
+ JUnitMatchers.class );
+ // add import for JUnit assert class
+ pconf.addImport( "Assert",
+ Assert.class );
+
+ // compile MVEL expression
+ ParserContext mvelctx = new ParserContext( pconf );
+ String expression;
+ if ( cmd.length == 3 ) {
+ expression = "Assert.assertTrue( " + cmd[2].replaceAll( "h(\\d+)",
+ "Handles[$1]" ) + " );";
+ } else {
+ String val = cmd[2].replaceAll( "h(\\d+)",
+ "Handles[$1]" );
+ String matcher = cmd[3].replaceAll( "h(\\d+)",
+ "Handles[$1]" );
+ expression = "Assert.assertThat( " + val + ", " + matcher + " );";
+ }
+ try {
+ Serializable compiled = MVEL.compileExpression( expression,
+ mvelctx );
+
+ // execute the expression
+ MVEL.executeExpression( compiled,
+ vars );
+ } catch ( PropertyAccessException e ) {
+ String message;
+ if ( e.getCause() instanceof InvocationTargetException ) {
+ message = ((InvocationTargetException) e.getCause()).getTargetException().toString();
+ } else {
+ message = e.getMessage();
+ }
+
+ Assert.fail( "[ERROR] line " + step.getLine() + " - Executing expression: '" + expression + "'\n" + message );
+ }
+ }
+
+ private static void populateCapturedArguments(ArgumentCaptor< ? > captor,
+ Map<String, Object> vars) {
+ int i = 0;
+ for ( Object obj : captor.getAllValues() ) {
+ if( obj instanceof LeftTuple ) {
+ vars.put( "tuple" + (i++),
+ ((LeftTuple)obj).toFactHandles() );
+ } else if( obj instanceof RightTuple ) {
+ vars.put( "handle" + (i++),
+ ((RightTuple)obj).getFactHandle() );
+ } else if( obj instanceof InternalFactHandle ) {
+ vars.put( "handle" + (i++),
+ obj );
+ }
+ }
+ }
+
+ private static void verifyExec(DslStep step,
+ Sink node,
+ InternalWorkingMemory wm,
+ String[] cmd,
+ Map<String, Object> context) throws AssertionError {
+ // check that the captor already exists:
+ String key = getCaptorKey( node,
+ cmd );
+ ArgumentCaptor<?> captor = (ArgumentCaptor<?>) context.get( key );
+ if ( captor == null ) {
+ // create the captor
+ verifyCount( step,
+ node,
+ wm,
+ new String[]{"verify", cmd[1], "count", "-1"},
+ context );
+ captor = (ArgumentCaptor<?>) context.get( key );
+ }
+
+ // create a map with all captured tuples as variables
+ Map<String, Object> vars = new HashMap<String, Object>();
+ populateCapturedArguments( captor,
+ vars );
+ // add all context variables, just in case
+ vars.putAll( context );
+
+ // add the static imports for hamcrest matchers
+ ParserConfiguration pconf = new ParserConfiguration();
+ addStaticImports( pconf,
+ CoreMatchers.class );
+ addStaticImports( pconf,
+ JUnitMatchers.class );
+ // add import for JUnit assert class
+ pconf.addImport( "Assert",
+ Assert.class );
+
+ // compile MVEL expression
+ ParserContext mvelctx = new ParserContext( pconf );
+ String expression = cmd[3].replaceAll( "h(\\d+)",
+ "Handles[$1]" );
+ try {
+ Serializable compiled = MVEL.compileExpression( expression,
+ mvelctx );
+ // execute the expression
+ MVEL.executeExpression( compiled,
+ vars );
+ } catch ( PropertyAccessException e ) {
+ String message;
+ if ( e.getCause() instanceof InvocationTargetException ) {
+ message = ((InvocationTargetException) e.getCause()).getTargetException().toString();
+ } else {
+ message = e.getMessage();
+ }
+
+ Assert.fail( "[ERROR] line " + step.getLine() + " - Executing expression: '" + expression + "'\n" + message );
+ }
+ }
+
+ private static void addStaticImports(ParserConfiguration pconf,
+ Class< ? > clazz) {
+ for ( Method m : clazz.getMethods() ) {
+ if ( Modifier.isStatic( m.getModifiers() ) ) {
+ pconf.addImport( m.getName(),
+ m );
+ }
+ }
+ }
+
+}
Property changes on: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/NodeTestCaseResult.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/NodeTestCaseResult.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/NodeTestCaseResult.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -20,8 +20,6 @@
import java.util.List;
import java.util.Map;
-import org.omg.PortableInterceptor.SUCCESSFUL;
-
/**
* A class to store the results of the execution of a NodeTestCase
*
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSinkStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSinkStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSinkStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -65,7 +65,8 @@
ObjectSource objectSource = (ObjectSource) context.get( leftInput );
- ObjectSink mockedSink = Mockito.mock( ObjectSink.class );
+ ObjectSink mockedSink = Mockito.mock( ObjectSink.class,
+ Mockito.withSettings().extraInterfaces( DSLMock.class ) );
objectSource.addObjectSink( mockedSink );
@@ -138,8 +139,8 @@
same( wm ) );
} else if ( "modify".equals( cmd[1] ) ) {
verify( node,
- counter ).modifyObject( captor.capture(),
- any( ModifyPreviousTuples.class ),
+ counter ).modifyObject( captor.capture(),
+ any( ModifyPreviousTuples.class ),
any( PropagationContext.class ),
same( wm ) );
} else {
Deleted: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSourceStep.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSourceStep.java 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/java/org/drools/reteoo/test/dsl/ObjectSourceStep.java 2010-02-10 22:41:14 UTC (rev 31560)
@@ -1,49 +0,0 @@
-/*
- * Copyright 2008 Red Hat
- *
- * 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.
- *
- */
-package org.drools.reteoo.test.dsl;
-
-import java.util.List;
-import java.util.Map;
-
-import org.drools.reteoo.ObjectSource;
-import org.mockito.Mockito;
-
-public class ObjectSourceStep
- implements
- Step {
-
- public ObjectSourceStep(ReteTesterHelper reteTesterHelper) {
- }
-
- public void execute(Map<String, Object> context,
- List<String[]> args) {
- if ( args.size() == 1 ) {
- String[] a = args.get( 0 );
- String name = a[0].trim();
-
- ObjectSource mockedSource = Mockito.mock( ObjectSource.class );
-
- context.put( name,
- mockedSource );
-
- } else {
- throw new IllegalArgumentException( "Cannot parse arguments " + args );
-
- }
- }
-
-}
\ No newline at end of file
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeAssertRetractTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeAssertRetractTest.nodeTestCase 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeAssertRetractTest.nodeTestCase 2010-02-10 22:41:14 UTC (rev 31560)
@@ -30,13 +30,13 @@
acc:
leftMemory, [[h0]];
sink:
- verify, assert, count, 0;
+ verify, assertLeft, count, 0;
retract:
acc, [[h0]];
acc:
leftMemory, [];
sink:
- verify, retract, count, 0;
+ verify, retractLeft, count, 0;
/**
* check single right assertion and retraction
@@ -51,8 +51,8 @@
acc:
rightMemory, [];
sink:
- verify, assert, count, 0;
- verify, retract, count, 0;
+ verify, assertLeft, count, 0;
+ verify, retractLeft, count, 0;
/**
* check single left then right assertion
@@ -61,24 +61,24 @@
assert:
acc, [[h0]];
sink:
- verify, assert, count, 0;
+ verify, assertLeft, count, 0;
assert:
acc, [h3];
acc:
leftMemory, [[h0]];
rightMemory, [h3];
sink:
- verify, assert, count, 1;
- verify, assert, tuple0[1].object.intValue() == 12;
- verify, modify, count, 0;
- verify, retract, count, 0;
+ verify, assertLeft, count, 1;
+ verify, assertLeft, tuple0[1].object.intValue() == 12;
+ verify, modifyLeft, count, 0;
+ verify, retractLeft, count, 0;
retract:
acc, [[h0]];
acc, [h3];
sink:
- verify, retract, count, 1;
- verify, modify, count, 0; // still 0, so calls on modify
- verify, assert, count, 1; // checking just in case
+ verify, retractLeft, count, 1;
+ verify, modifyLeft, count, 0; // still 0, so calls on modify
+ verify, assertLeft, count, 1; // checking just in case
/**
* check single right then left assertion
@@ -91,9 +91,9 @@
leftMemory, [[h1]];
rightMemory, [h2];
sink:
- verify, assert, count, 0;
- verify, modify, count, 0; // checking, just in case
- verify, retract, count, 0;
+ verify, assertLeft, count, 0;
+ verify, modifyLeft, count, 0; // checking, just in case
+ verify, retractLeft, count, 0;
retract:
acc, [[h1]];
acc, [h2];
@@ -101,9 +101,9 @@
leftMemory, [];
rightMemory, [];
sink:
- verify, retract, count, 0;
- verify, modify, count, 0;
- verify, assert, count, 0;
+ verify, retractLeft, count, 0;
+ verify, modifyLeft, count, 0;
+ verify, assertLeft, count, 0;
/**
* assert two left and two right, with incremental first removal
@@ -117,10 +117,10 @@
leftMemory, [[h1]];
rightMemory, [h2, h3];
sink:
- verify, assert, count, 1; // only h0 matches and propagates
- verify, modify, count, 0; // still no modifies
- verify, assert, tuple0[0], is( h0 );
- verify, assert, tuple0[1].object == 22; // that is the result of the sum
+ verify, assertLeft, count, 1; // only h0 matches and propagates
+ verify, modifyLeft, count, 0; // still no modifies
+ verify, assertLeft, tuple0[0], is( h0 );
+ verify, assertLeft, tuple0[1].object == 22; // that is the result of the sum
assert:
acc, [h4, h5];
acc:
@@ -129,19 +129,19 @@
rightMemory, [h2, h3, h5];
rightMemory, [h4];
sink:
- verify, assert, count, 2; // h4 also matched h1 now, so we got a new assert
- verify, assert, tuple1[0], is( h1 );
- verify, assert, tuple1[1].object == 15; // that is the result of the sum of h4
- verify, modify, count, 1; // h5 causes a modify call
- verify, modify, tuple0[0], is( h0 );
- verify, modify, tuple0[1].object == 34;
- verify, retract, count, 0; // checking just in case
+ verify, assertLeft, count, 2; // h4 also matched h1 now, so we got a new assert
+ verify, assertLeft, tuple1[0], is( h1 );
+ verify, assertLeft, tuple1[1].object == 15; // that is the result of the sum of h4
+ verify, modifyLeft, count, 1; // h5 causes a modify call
+ verify, modifyLeft, tuple0[0], is( h0 );
+ verify, modifyLeft, tuple0[1].object == 34;
+ verify, retractLeft, count, 0; // checking just in case
retract:
acc, [h2];
sink:
- verify, modify, count, 2; // h5 causes a modify call
- verify, modify, tuple1[0], is( h0 );
- verify, modify, tuple1[1].object == 24;
+ verify, modifyLeft, count, 2; // h5 causes a modify call
+ verify, modifyLeft, tuple1[0], is( h0 );
+ verify, modifyLeft, tuple1[1].object == 24;
acc:
leftMemory, [[h0]];
leftMemory, [[h1]];
@@ -151,9 +151,9 @@
acc, [[h0]];
acc, [[h1]];
sink:
- verify, retract, count, 2;
- verify, retract, tuple0[0], is( h0 );
- verify, retract, tuple1[0], is( h1 );
+ verify, retractLeft, count, 2;
+ verify, retractLeft, tuple0[0], is( h0 );
+ verify, retractLeft, tuple1[0], is( h1 );
acc:
leftMemory, [];
rightMemory, [h3, h5];
@@ -165,8 +165,8 @@
rightMemory, [];
sink:
// checking final totals
- verify, assert, count, 2;
- verify, modify, count, 2;
- verify, retract, count, 2;
+ verify, assertLeft, count, 2;
+ verify, modifyLeft, count, 2;
+ verify, retractLeft, count, 2;
\ No newline at end of file
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeModifyTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeModifyTest.nodeTestCase 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/AccumulateNodeModifyTest.nodeTestCase 2010-02-10 22:41:14 UTC (rev 31560)
@@ -32,17 +32,17 @@
leftMemory, [[h0]];
rightMemory, [h3];
sink:
- verify, assert, count, 1;
- verify, assert, tuple0[0], is(h0);
- verify, assert, tuple0[1].object == 12;
- verify, modify, count, 0;
+ verify, assertLeft, count, 1;
+ verify, assertLeft, tuple0[0], is(h0);
+ verify, assertLeft, tuple0[1].object == 12;
+ verify, modifyLeft, count, 0;
modify:
acc, [[h0]];
sink:
- verify, assert, count, 1; // still 1
- verify, modify, count, 1; // modify was propagated
- verify, modify, tuple0[0], is( h0 );
- verify, modify, tuple0[1].object == 12;
+ verify, assertLeft, count, 1; // still 1
+ verify, modifyLeft, count, 1; // modify was propagated
+ verify, modifyLeft, tuple0[0], is( h0 );
+ verify, modifyLeft, tuple0[1].object == 12;
/**
* test left modifications
@@ -56,35 +56,35 @@
rightMemory, [h2, h3, h5];
rightMemory, [h4];
sink:
- verify, assert, count, 1; // only for h0
- verify, modify, count, 1; // for the sum h2+h3+h5
- verify, modify, tuple0[1].object == 34;
+ verify, assertLeft, count, 1; // only for h0
+ verify, modifyLeft, count, 1; // for the sum h2+h3+h5
+ verify, modifyLeft, tuple0[1].object == 34;
With:
h0, likes = "stilton";
modify:
acc, [[h0]];
sink:
- verify, assert, count, 1; // still 1
- verify, modify, count, 2; // modify was propagated
- verify, modify, tuple1[1].object == 15; // it now matches "stilton"
- verify, retract, count, 0; // just in case
+ verify, assertLeft, count, 1; // still 1
+ verify, modifyLeft, count, 2; // modify was propagated
+ verify, modifyLeft, tuple1[1].object == 15; // it now matches "stilton"
+ verify, retractLeft, count, 0; // just in case
With:
h0, likes = "muzzarella";
modify:
acc, [[h0]];
sink:
- verify, assert, count, 1; // still 1
- verify, modify, count, 2; // still 2
- verify, retract, count, 1; // matches nothing now ("muzzarella")
+ verify, assertLeft, count, 1; // still 1
+ verify, modifyLeft, count, 2; // still 2
+ verify, retractLeft, count, 1; // matches nothing now ("muzzarella")
With:
h0, likes = "brie";
modify:
acc, [[h0]];
sink:
- verify, assert, count, 2; // since a new match happened, propagate as assert
- verify, assert, tuple1[1].object == 34; // it now matches "brie"
- verify, modify, count, 2; // still 2
- verify, retract, count, 1; // still 1
+ verify, assertLeft, count, 2; // since a new match happened, propagate as assert
+ verify, assertLeft, tuple1[1].object == 34; // it now matches "brie"
+ verify, modifyLeft, count, 2; // still 2
+ verify, retractLeft, count, 1; // still 1
/**
* test right modifications
@@ -98,18 +98,18 @@
rightMemory, [h2, h3, h5];
rightMemory, [h4];
sink:
- verify, assert, count, 1; // only for h0
- verify, modify, count, 1; // for the sum h2+h3+h5
- verify, modify, tuple0[1].object, is( 34.0 );
+ verify, assertLeft, count, 1; // only for h0
+ verify, modifyLeft, count, 1; // for the sum h2+h3+h5
+ verify, modifyLeft, tuple0[1].object, is( 34.0 );
With:
h3, price = 50;
modify:
acc, [h3];
sink:
- verify, assert, count, 1; // still 1
- verify, modify, count, 2; // modify was propagated
- verify, modify, tuple1[1].object, is( 72.0 );
- verify, retract, count, 0; // just in case
+ verify, assertLeft, count, 1; // still 1
+ verify, modifyLeft, count, 2; // modify was propagated
+ verify, modifyLeft, tuple1[1].object, is( 72.0 );
+ verify, retractLeft, count, 0; // just in case
With:
h5, type = "muzzarella";
h3, type = "muzzarella";
@@ -121,17 +121,17 @@
rightMemory, [h4];
leftMemory, [[h0]];
sink:
- verify, assert, count, 1; // still 1
- verify, modify, count, 3; // modified h5
- verify, retract, count, 1; // modified h3
- verify, retract, tuple0[1].object, is( 10.0 );
+ verify, assertLeft, count, 1; // still 1
+ verify, modifyLeft, count, 3; // modified h5
+ verify, retractLeft, count, 1; // modified h3
+ verify, retractLeft, tuple0[1].object, is( 10.0 );
With:
h0, likes = "stilton";
modify:
acc, [[h0]];
sink:
- verify, assert, count, 2; // since a new match happened, propagate as assert
- verify, assert, tuple1[1].object, is( 15.0 ); // it now matches "brie"
- verify, modify, count, 3; // still 3
- verify, retract, count, 1; // still 1
+ verify, assertLeft, count, 2; // since a new match happened, propagate as assert
+ verify, assertLeft, tuple1[1].object, is( 15.0 ); // it now matches "brie"
+ verify, modifyLeft, count, 3; // still 3
+ verify, retractLeft, count, 1; // still 1
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/CollectNodeAssertRetractTest.nodeTestCase 2010-02-10 22:41:14 UTC (rev 31560)
@@ -28,17 +28,17 @@
col1:
leftMemory, [[h0]];
sink1:
- verify, assert, count, 1;
- verify, assert, tuple0[0], sameInstance(h0);
- verify, assert, tuple0[1].object, instanceOf( java.util.Collection );
- verify, assert, tuple0[1].object.isEmpty();
+ verify, assertLeft, count, 1;
+ verify, assertLeft, tuple0[0], sameInstance(h0);
+ verify, assertLeft, tuple0[1].object, instanceOf( java.util.Collection );
+ verify, assertLeft, tuple0[1].object.isEmpty();
retract:
otnLeft1, [h0];
col1:
leftMemory, [];
sink1:
- verify, retract, count, 1;
- verify, retract, tuple0[0], sameInstance(h0);
+ verify, retractLeft, count, 1;
+ verify, retractLeft, tuple0[0], sameInstance(h0);
/**
* check single right assertion and retraction
@@ -53,8 +53,8 @@
col1:
rightMemory, [];
sink1:
- verify, assert, count, 0;
- verify, retract, count, 0;
+ verify, assertLeft, count, 0;
+ verify, retractLeft, count, 0;
/**
* check single left then right assertion
@@ -63,23 +63,23 @@
assert:
otnLeft1, [h0];
sink1:
- verify, assert, count, 1;
- verify, assert, tuple0[1].object.isEmpty();
+ verify, assertLeft, count, 1;
+ verify, assertLeft, tuple0[1].object.isEmpty();
assert:
otnRight1, [h2];
col1:
leftMemory, [[h0]];
rightMemory, [h2];
sink1:
- verify, modify, count, 1;
- verify, modify, tuple0[1].object, hasItem( h2.object );
+ verify, modifyLeft, count, 1;
+ verify, modifyLeft, tuple0[1].object, hasItem( h2.object );
retract:
otnLeft1, [h0];
otnRight1, [h2];
sink1:
- verify, retract, count, 1;
- verify, modify, count, 1; // still 1, so no new calls on the retract
- verify, assert, count, 1; // checking just in case
+ verify, retractLeft, count, 1;
+ verify, modifyLeft, count, 1; // still 1, so no new calls on the retract
+ verify, assertLeft, count, 1; // checking just in case
/**
* check single right then left assertion
@@ -92,15 +92,15 @@
leftMemory, [[h1]];
rightMemory, [h2];
sink1:
- verify, assert, count, 1;
- verify, assert, tuple0[1].object.isEmpty();
- verify, modify, count, 0; // checking, just in case
+ verify, assertLeft, count, 1;
+ verify, assertLeft, tuple0[1].object.isEmpty();
+ verify, modifyLeft, count, 0; // checking, just in case
retract:
otnLeft1, [h1];
otnRight1, [h2];
sink1:
- verify, retract, count, 1;
- verify, modify, count, 0;
+ verify, retractLeft, count, 1;
+ verify, modifyLeft, count, 0;
/**
* assert two left and two right, with incremental first removal
@@ -114,33 +114,33 @@
leftMemory, [[h1]];
rightMemory, [h2, h3];
sink1:
- verify, assert, count, 2;
- verify, modify, count, 2;
- verify, assert, tuple0[0], is( h0 );
- verify, assert, tuple1[0], is( h1 );
- verify, modify, tuple1[1].object.size() == 2;
- verify, modify, tuple1[1].object, hasItem( h2.object );
- verify, modify, tuple1[1].object, hasItem( h3.object );
+ verify, assertLeft, count, 2;
+ verify, modifyLeft, count, 2;
+ verify, assertLeft, tuple0[0], is( h0 );
+ verify, assertLeft, tuple1[0], is( h1 );
+ verify, modifyLeft, tuple1[1].object.size() == 2;
+ verify, modifyLeft, tuple1[1].object, hasItem( h2.object );
+ verify, modifyLeft, tuple1[1].object, hasItem( h3.object );
retract:
otnLeft1, [h0];
col1:
leftMemory, [[h1]];
rightMemory, [h2, h3];
sink1:
- verify, retract, count, 1;
- verify, retract, tuple0[0], is( h0 );
+ verify, retractLeft, count, 1;
+ verify, retractLeft, tuple0[0], is( h0 );
retract:
otnRight1, [h2];
col1:
leftMemory, [[h1]];
rightMemory, [h3];
sink1:
- verify, retract, count, 1; // still 1, so no retracts were called
- verify, modify, count, 2; // still 2, so no modifies were called
+ verify, retractLeft, count, 1; // still 1, so no retracts were called
+ verify, modifyLeft, count, 2; // still 2, so no modifies were called
retract:
otnLeft1, [h1];
sink1:
- verify, retract, count, 2;
+ verify, retractLeft, count, 2;
retract:
otnRight1, [h3];
col1:
Modified: labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/RIANodeTest.nodeTestCase
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/RIANodeTest.nodeTestCase 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/drools-core/src/test/resources/org/drools/reteoo/test/RIANodeTest.nodeTestCase 2010-02-10 22:41:14 UTC (rev 31560)
@@ -6,7 +6,7 @@
Setup
RightInputAdapterNode:
ria, mock;
- MockBetaNodeStep:
+ BetaNodeStep:
sink, mock, ria;
Facts:
new Person('darth', 35, "brie"), // h0
@@ -23,142 +23,43 @@
ria:
leftMemory, [[h0, h2]];
sink:
- verify, assert, count, 1;
+ verify, assertRight, count, 1;
+ // since it is a right assert, the tuple is wrapped into a fact handle
+ verify, assertRight, handle0.object.toFactHandles()[0], is( h0 );
+ verify, assertRight, handle0.object.toFactHandles()[1], is( h2 );
retract:
ria, [[h0, h2]];
ria:
leftMemory, [];
sink:
- verify, retract, count, 1;
+ verify, retractRight, count, 1;
/**
* check single right assertion and retraction
- *
-Test "Single right assertion and retraction"
+ */
+Test "RIA assert, modify, retract"
assert:
- acc, [h2];
- acc:
- rightMemory, [h2];
- retract:
- acc, [h2];
- acc:
- rightMemory, [];
+ ria, [[h0, h2]];
+ ria:
+ leftMemory, [[h0, h2]];
sink:
- verify, assert, count, 0;
- verify, retract, count, 0;
-
-/**
- * check single left then right assertion
- *
- Test "single left then right assertion"
- assert:
- acc, [[h0]];
+ verify, assertRight, count, 1;
+ // since it is a right assert, the tuple is wrapped into a fact handle
+ verify, assertRight, handle0.object.toFactHandles()[0], is( h0 );
+ verify, assertRight, handle0.object.toFactHandles()[1], is( h2 );
+ modify:
+ ria, [[h0, h2]];
sink:
- verify, assert, count, 0;
- assert:
- acc, [h3];
- acc:
- leftMemory, [[h0]];
- rightMemory, [h3];
- sink:
- verify, assert, count, 1;
- verify, assert, tuple0[1].object.intValue() == 12;
- verify, modify, count, 0;
- verify, retract, count, 0;
+ verify, assertRight, count, 1; // still 1
+ verify, modifyRight, count, 1;
+ verify, modifyRight, handle0.object.toFactHandles()[0], is( h0 );
+ verify, modifyRight, handle0.object.toFactHandles()[1], is( h2 );
retract:
- acc, [[h0]];
- acc, [h3];
+ ria, [[h0, h2]];
+ ria:
+ leftMemory, [];
sink:
- verify, retract, count, 1;
- verify, modify, count, 0; // still 0, so calls on modify
- verify, assert, count, 1; // checking just in case
-
-/**
- * check single right then left assertion
- *
-Test "single right then left assertion"
- assert:
- acc, [h2];
- acc, [[h1]];
- acc:
- leftMemory, [[h1]];
- rightMemory, [h2];
- sink:
- verify, assert, count, 0;
- verify, modify, count, 0; // checking, just in case
- verify, retract, count, 0;
- retract:
- acc, [[h1]];
- acc, [h2];
- acc:
- leftMemory, [];
- rightMemory, [];
- sink:
- verify, retract, count, 0;
- verify, modify, count, 0;
- verify, assert, count, 0;
+ verify, assertRight, count, 1; // still 1
+ verify, modifyRight, count, 1; // still 1
+ verify, retractRight, count, 1;
-/**
- * assert two left and two right, with incremental first removal
- *
-Test "testing modifies"
- assert:
- acc, [[h0], [h1]];
- acc, [h2, h3];
- acc:
- leftMemory, [[h0]];
- leftMemory, [[h1]];
- rightMemory, [h2, h3];
- sink:
- verify, assert, count, 1; // only h0 matches and propagates
- verify, modify, count, 0; // still no modifies
- verify, assert, tuple0[0], is( h0 );
- verify, assert, tuple0[1].object == 22; // that is the result of the sum
- assert:
- acc, [h4, h5];
- acc:
- leftMemory, [[h0]];
- leftMemory, [[h1]];
- rightMemory, [h2, h3, h5];
- rightMemory, [h4];
- sink:
- verify, assert, count, 2; // h4 also matched h1 now, so we got a new assert
- verify, assert, tuple1[0], is( h1 );
- verify, assert, tuple1[1].object == 15; // that is the result of the sum of h4
- verify, modify, count, 1; // h5 causes a modify call
- verify, modify, tuple0[0], is( h0 );
- verify, modify, tuple0[1].object == 34;
- verify, retract, count, 0; // checking just in case
- retract:
- acc, [h2];
- sink:
- verify, modify, count, 2; // h5 causes a modify call
- verify, modify, tuple1[0], is( h0 );
- verify, modify, tuple1[1].object == 24;
- acc:
- leftMemory, [[h0]];
- leftMemory, [[h1]];
- rightMemory, [h3, h5];
- rightMemory, [h4];
- retract:
- acc, [[h0]];
- acc, [[h1]];
- sink:
- verify, retract, count, 2;
- verify, retract, tuple0[0], is( h0 );
- verify, retract, tuple1[0], is( h1 );
- acc:
- leftMemory, [];
- rightMemory, [h3, h5];
- rightMemory, [h4];
- retract:
- acc, [h3, h4, h5];
- acc:
- leftMemory, [];
- rightMemory, [];
- sink:
- // checking final totals
- verify, assert, count, 2;
- verify, modify, count, 2;
- verify, retract, count, 2;
-*/
\ No newline at end of file
Modified: labs/jbossrules/branches/true_modify_20100104/pom.xml
===================================================================
--- labs/jbossrules/branches/true_modify_20100104/pom.xml 2010-02-10 21:05:36 UTC (rev 31559)
+++ labs/jbossrules/branches/true_modify_20100104/pom.xml 2010-02-10 22:41:14 UTC (rev 31560)
@@ -13,7 +13,7 @@
<url>http://www.jboss.com/products/rules</url>
<properties>
- <mvel.dep.version>2.0.16-SNAPSHOT</mvel.dep.version>
+ <mvel.dep.version>2.0.16</mvel.dep.version>
</properties>
<prerequisites>
More information about the jboss-svn-commits
mailing list