final List list = new ArrayList();
workingMemory.setGlobal( "events",
list );
// asserting the sensor object
final Sensor sensor = new Sensor( 150,
100 );
FactHandle sensorHandle = workingMemory.insert( sensor );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
// alarm must sound
assertEquals( 2,
list.size() );
assertEquals( 2,
IteratorToList.convert( workingMemory.iterateObjects() ).size() );
// modifying sensor
sensor.setTemperature( 125 );
sensorHandle = getFactHandle( sensorHandle, workingMemory );
workingMemory.update( sensorHandle,
sensor );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
// alarm must continue to sound
assertEquals( 3,
list.size() );
assertEquals( 2,
IteratorToList.convert( workingMemory.iterateObjects() ).size() );
// modifying sensor
sensor.setTemperature( 80 );
sensorHandle = getFactHandle( sensorHandle, workingMemory );
workingMemory.update( sensorHandle,
sensor );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();