workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
// all 3 in europe, so, 2 cheese
List cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 2,
cheeseList.size() );
// europe=[ 1, 2 ], america=[ 3 ]
p3.setStatus( "america" );
c3FactHandle = getFactHandle( c3FactHandle, workingMemory );
workingMemory.update( c3FactHandle,
p3 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 1,
cheeseList.size() );
// europe=[ 1 ], america=[ 2, 3 ]
p2.setStatus( "america" );
c2FactHandle = getFactHandle( c2FactHandle, workingMemory );
workingMemory.update( c2FactHandle,
p2 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 1,
cheeseList.size() );
// europe=[ ], america=[ 1, 2, 3 ]
p1.setStatus( "america" );
c1FactHandle = getFactHandle( c1FactHandle, workingMemory );
workingMemory.update( c1FactHandle,
p1 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 2,
cheeseList.size() );
// europe=[ 2 ], america=[ 1, 3 ]
p2.setStatus( "europe" );
c2FactHandle = getFactHandle( c2FactHandle, workingMemory );
workingMemory.update( c2FactHandle,
p2 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 1,
cheeseList.size() );
// europe=[ 1, 2 ], america=[ 3 ]
p1.setStatus( "europe" );
c1FactHandle = getFactHandle( c1FactHandle, workingMemory );
workingMemory.update( c1FactHandle,
p1 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 1,
cheeseList.size() );
// europe=[ 1, 2, 3 ], america=[ ]
p3.setStatus( "europe" );
c3FactHandle = getFactHandle( c3FactHandle, workingMemory );
workingMemory.update( c3FactHandle,
p3 );
workingMemory = getSerialisedStatefulSession( workingMemory );
workingMemory.fireAllRules();
workingMemory = getSerialisedStatefulSession( workingMemory );
cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class ) ) );
assertEquals( 2,
cheeseList.size() );
}