final FieldTemplate[] fields = new FieldTemplate[]{cheeseName, cheesePrice};
final FactTemplate cheese = new FactTemplateImpl( pkg,
"Cheese",
fields );
final InternalReadAccessor extractName = new FactTemplateFieldExtractor( cheese,
0 );
final InternalReadAccessor extractPrice = new FactTemplateFieldExtractor( cheese,
1 );
final Fact stilton = cheese.createFact( 10 );
stilton.setFieldValue( "name",
"stilton" );
stilton.setFieldValue( "price",
new Integer( 200 ) );
assertEquals( "stilton",
extractName.getValue( null, stilton ) );
assertEquals( new Integer( 200 ),
extractPrice.getValue( null, stilton ) );
assertFalse( extractName.isNullValue( null, stilton ) );
stilton.setFieldValue( "name",
null );
assertTrue( extractName.isNullValue( null, stilton ) );
assertFalse( extractPrice.isNullValue( null, stilton ) );
final Fact brie = cheese.createFact( 12 );
brie.setFieldValue( "name",
"brie" );
brie.setFieldValue( "price",
new Integer( 55 ) );
assertEquals( "brie",
extractName.getValue( null, brie ) );
assertEquals( new Integer( 55 ),
extractPrice.getValue( null, brie ) );
assertFalse( extractName.isNullValue( null, brie ) );
brie.setFieldValue( "name",
null );
assertTrue( extractName.isNullValue( null, brie ) );
assertFalse( extractPrice.isNullValue( null, stilton ) );
}