}
@Test
public void processStatefulDispose() throws Exception
{
Message message = createMessageWithOrder( order );
ConfigTree configTree = new CBRConfigTreeBuilder( true ).ruleFile( "JBossESBStatefulDispose.drl" ).stateful( true ).messagePaths(messagePathList).build();
BusinessRulesProcessor processor = new BusinessRulesProcessor( configTree );
// process message
processor.process( message );
assertEquals( 20.0, order.getDiscount(), 0);
assertEquals( "20%" ,message.getBody().get("DiscountObject"));
Counter counter = (Counter) message.getBody().get("Counter");
assertEquals( 1 , counter.getCounter() );
// do not dispose after this call
message.getBody().remove("Order");
message.getProperties().setProperty( DISPOSE.getName(), Boolean.FALSE );
message.getProperties().setProperty( CONTINUE.getName(), Boolean.TRUE );
message.getBody().add("Counter", new Counter(counter.getCounter()));
processor.process( message );
counter = (Counter) message.getBody().get("Counter");
assertEquals( 2 , counter.getCounter() );
// now dispose after this call
message.getProperties().setProperty( DISPOSE.getName(), Boolean.TRUE );
message.getProperties().setProperty( CONTINUE.getName(), Boolean.TRUE );
message.getBody().add("Counter", new Counter(counter.getCounter()));
processor.process( message );
// If this assert fails then the second invocation disposed of the state when it shouldn't have
// and this one did not fire any rules.
counter = (Counter) message.getBody().get("Counter");
assertEquals( 3 , counter.getCounter() );
final Order order = new Order();
order.setQuantity(20);
order.setUnitPrice( new BigDecimal("20.0") );
message = createMessageWithOrder( order );
message.getProperties().setProperty( DISPOSE.getName(), Boolean.TRUE );
message.getProperties().setProperty( CONTINUE.getName(), Boolean.TRUE );
processor.process( message );
assertEquals( 20.0, order.getDiscount(), 0);
assertEquals( "20%" ,message.getBody().get("DiscountObject"));
counter = (Counter) message.getBody().get("Counter");
assertEquals( 1 , counter.getCounter() );
}