try {
List<String[]> cmds = step.getCommands();
List<InternalFactHandle> handles = (List<InternalFactHandle>) context.get( "Handles" );
BetaMemory memory = null;
if ( node instanceof AccumulateNode ) {
AccumulateMemory accmem = (AccumulateMemory) wm.getNodeMemory( node );
memory = accmem.betaMemory;
} else {
memory = (BetaMemory) 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 );
LeftTupleMemory leftMemory = memory.getLeftTupleMemory();
if ( expectedLeftTuples.isEmpty() && leftMemory.size() != 0 ) {
throw new AssertionFailedError( "line " + step.getLine()
+ ": left Memory expected [] actually "
+ print( leftMemory,
lrUnlinkingEnabled ) );
} else if ( expectedLeftTuples.isEmpty()
&& leftMemory.size() == 0 ) {
continue;
}
// we always lookup from the first element, in case it's indexed
List<InternalFactHandle> first = (List<InternalFactHandle>) expectedLeftTuples.get( 0 );
LeftTuple firstTuple = new LeftTupleImpl( first.get( 0 ),
null,
false);
for ( int i = 1; i < first.size(); i++ ) {
firstTuple = new LeftTupleImpl( firstTuple,
new RightTuple( first.get( i )),
null,
false );
}
List<LeftTuple> leftTuples = new ArrayList<LeftTuple>();
for ( LeftTuple leftTuple = getFirst(memory.getLeftTupleMemory(), firstTuple); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
leftTuples.add( leftTuple );
}
if ( lrUnlinkingEnabled ) {
// When L&R Unlinking is active, we need to sort the
// tuples here,
// because we might have asserted things in the wrong
// order,
// since linking a node's side means populating its
// memory
// from the OTN which stores things in a hash-set, so
// insertion order is not kept.
Collections.sort( leftTuples,
new LeftTupleComparator() );
}
List<List<InternalFactHandle>> actualLeftTuples = getHandlesList( leftTuples );
if ( !expectedLeftTuples.equals( actualLeftTuples ) ) {
throw new AssertionError( "line " + step.getLine() + ": left Memory expected " + expectedLeftTuples + " actually " + actualLeftTuples );
}
} else if ( cmd[0].equals( "rightMemory" ) ) {
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< ? > expectedFactHandles = (List< ? >) MVEL.eval( listString,
vars );
RightTupleMemory rightMemory = memory.getRightTupleMemory();
if ( expectedFactHandles.isEmpty() && rightMemory.size() != 0 ) {
throw new AssertionError( "line " + step.getLine() + ": right Memory expected [] actually " + print( rightMemory ));
} else if ( expectedFactHandles.isEmpty() && rightMemory.size() == 0 ) {
continue;
}
RightTuple first = new RightTuple( (InternalFactHandle) expectedFactHandles.get( 0 ) );
List<RightTuple> actualRightTuples = new ArrayList<RightTuple>();
for ( RightTuple rightTuple = getFirst(memory.getRightTupleMemory(), first); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
actualRightTuples.add( rightTuple );
}
if ( expectedFactHandles.size() != actualRightTuples.size() ) {
throw new AssertionError( "line " + step.getLine() + ": right Memory expected " + print( expectedFactHandles )