cheeseConfiguration );
tuple = new MockTuple( );
rule.setImporter( new DefaultImporter( ) );
tuple.setRule( rule );
tuple.setWorkingMemory( new MockWorkingMemory( ) );
// simple condition checks
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 0
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 1
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 2
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 3
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 4
Declaration camembertDecl = rule.addParameterDeclaration( "camembert",
cheeseType );
Declaration stiltonDecl = rule.addParameterDeclaration( "stilton",
cheeseType );
rule.setImporter( this.importer );
// condition check with a single declaration
tuple.put( camembertDecl,
new Cheese( "camembert" ) );
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 5
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 6
// condition check with a single declaration
tuple = new MockTuple( );
rule.setImporter( this.importer );
tuple.setRule( rule );
tuple.setWorkingMemory( new MockWorkingMemory( ) );
tuple.put( stiltonDecl,
new Cheese( "stilton" ) );
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 7
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 8
// condition check with two declarations
tuple = new MockTuple( );
rule.setImporter( this.importer );
tuple.setRule( rule );
tuple.setWorkingMemory( new MockWorkingMemory( ) );
tuple.put( stiltonDecl,
new Cheese( "stilton" ) );
tuple.put( camembertDecl,
new Cheese( "camembert" ) );
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 9
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 10
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 11
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 12
// condition check with 2 declarations and application data
WorkingMemory workingMemory = new MockWorkingMemory( );
workingMemory.setApplicationData( "bites",
new Integer( 3 ) );
workingMemory.setApplicationData( "favouriteCheese",
new Cheese( "camembert" ) );
tuple.setWorkingMemory( workingMemory );
HashMap applicationData = new HashMap( );
applicationData.put( "bites",
Integer.class );
applicationData.put( "favouriteCheese",
Cheese.class );
rule.setApplicationData( applicationData );
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 13
assertFalse( testCondition( testNumber++,
tuple,
rule ) ); // 14
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 15
// test code works no matter what the order of decl are
tuple = new MockTuple( );
rule.setImporter( this.importer );
rule.setApplicationData( new HashMap( ) );
tuple.setRule( rule );
workingMemory = new MockWorkingMemory( );
tuple.setWorkingMemory( workingMemory );
DefaultConfiguration stringConfiguration = new DefaultConfiguration( "test2" );
stringConfiguration.setText( String.class.getName( ) );
ObjectType stringType = objectTypeFactory.newObjectType( rule,
this.ruleBaseContext,
stringConfiguration );
Declaration favouriteCheeseDecl = rule.addParameterDeclaration( "favouriteCheese",
stringType );
tuple.put( favouriteCheeseDecl,
"camembert" );
tuple.put( camembertDecl,
new Cheese( "camembert" ) );
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 16
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 17
// test condition syntax with commas - Drools Issue #77
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 18
// test exceptions
rule.setImporter( this.importer );
tuple.setRule( rule );
try
{
testCondition( testNumber++,
tuple,
rule );
fail( "Condition should throw an exception" );
}
catch ( ConditionException e )
{
// expected
}
// need to add a test for declaration order
// 20
// test imports
tuple = new MockTuple( );
rule.setImporter( this.importer );
tuple.setRule( rule );
workingMemory = new MockWorkingMemory( );
tuple.setWorkingMemory( workingMemory );
assertTrue( testCondition( testNumber++,
tuple,
rule ) ); // 20