RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
ruleBase = SerializationHelper.serializeObject( ruleBase );
StatefulSession session = ruleBase.newStatefulSession();
List<Integer> inList = new ArrayList<Integer>();
List<Integer> outList = new ArrayList<Integer>();
session.setGlobal( "inList",
inList );
session.setGlobal( "outList",
outList );
inList.add( 1 );
inList.add( 3 );
inList.add( 6 );
inList.add( 25 );
FactHandle handle = session.insert( inList );
session.startProcess( "ConstraintDialects" );
assertEquals( 4,
outList.size() );
assertEquals( "MVELCodeConstraint was here",
outList.get( 0 ) );
assertEquals( "JavaCodeConstraint was here",
outList.get( 1 ) );
assertEquals( "MVELRuleConstraint was here",
outList.get( 2 ) );
assertEquals( "JavaRuleConstraint was here",
outList.get( 3 ) );
outList.clear();
inList.remove( new Integer( 1 ) );
session.update( handle,
inList );
session.startProcess( "ConstraintDialects" );
assertEquals( 3,
outList.size() );
assertEquals( "JavaCodeConstraint was here",
outList.get( 0 ) );
assertEquals( "MVELRuleConstraint was here",
outList.get( 1 ) );
assertEquals( "JavaRuleConstraint was here",
outList.get( 2 ) );
outList.clear();
inList.remove( new Integer( 6 ) );
session.update( handle,
inList );
session.startProcess( "ConstraintDialects" );
assertEquals( 2,
outList.size() );
assertEquals( "JavaCodeConstraint was here",
outList.get( 0 ) );
assertEquals( "JavaRuleConstraint was here",
outList.get( 1 ) );
outList.clear();
inList.remove( new Integer( 3 ) );
session.update( handle,
inList );
session.startProcess( "ConstraintDialects" );
assertEquals( 1,
outList.size() );
assertEquals( "JavaRuleConstraint was here",
outList.get( 0 ) );
outList.clear();
inList.remove( new Integer( 25 ) );
session.update( handle,
inList );
try {
session.startProcess( "ConstraintDialects" );
fail( "This should have thrown an exception" );
} catch ( Exception e ) {
}
}