// Dumper dumper = new Dumper( ruleBase );
// dumper.dumpReteToDot( System.err );
workingMemory = getWorkingMemory( ruleBase );
workingMemory.addEventListener( new TestWorkingMemoryEventListener( ) );
workingMemory.setApplicationData( "fibtotal",
new FibTotal( ) );
// Assert the facts, and fire the rules.
Fibonacci fibonacci = new Fibonacci( 50 );
workingMemory.assertObject( fibonacci );
// test serialization
workingMemory = serializeWorkingMemory( workingMemory );
workingMemory = serializeWorkingMemory( workingMemory );
workingMemory.fireAllRules( );
// test serialization
workingMemory = serializeWorkingMemory( workingMemory );
workingMemory = serializeWorkingMemory( workingMemory );
// test context after serlisation
assertNull( workingMemory.getRuleBase( ).getRuleBaseContext( ).get( "java-classLoader" ) );
// test application ran correctly
assertEquals( 2,
workingMemory.getObjects( ).size( ) );
Fibonacci a = (Fibonacci) workingMemory.getObjects( ).get( 0 );
Fibonacci b = (Fibonacci) workingMemory.getObjects( ).get( 1 );
assertEquals( 50,
a.getSequence( ) );
assertEquals( 49,
b.getSequence( ) );
assertEquals( 12586269025L,
a.getValue( ) );
assertEquals( 7778742049L,
b.getValue( ) );
// test application data
FibTotal total = (FibTotal) workingMemory.getApplicationData( "fibtotal" );
assertEquals( 50,
total.getTotal( ) );
// test listener
TestWorkingMemoryEventListener listener = (TestWorkingMemoryEventListener) workingMemory.getEventListeners( ).get( 0 );
assertEquals( 50,
listener.asserted );
assertEquals( 48,
listener.retracted );
assertEquals( 50,