}
public void testTripleAlphaCharacterConstraint() {
final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
"charType",
this.getClass().getClassLoader() );
final LiteralConstraint lit = new LiteralConstraint( extractor,
CharacterFactory.getInstance().getEvaluator( Operator.EQUAL ),
new LongFieldImpl( 65 ) ); // chars are handled as integers
final AlphaNode al = new AlphaNode( buildContext.getNextId(),
lit,
new MockObjectSource( buildContext.getNextId() ),
buildContext );
ad.addObjectSink( al );
assertNull( ad.otherSinks );
assertNotNull( ad.hashedFieldIndexes );
assertEquals( 1,
ad.hashableSinks.size() );
assertEquals( al,
ad.getSinks()[0] );
final LiteralConstraint lit2 = new LiteralConstraint( extractor,
CharacterFactory.getInstance().getEvaluator( Operator.EQUAL ),
new LongFieldImpl( 66 ) );
final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
lit2,
new MockObjectSource( buildContext.getNextId() ),
buildContext );
ad.addObjectSink( al2 );
assertNull( ad.hashedSinkMap );
assertEquals( 2,
ad.hashableSinks.size() );
final LiteralConstraint lit3 = new LiteralConstraint( extractor,
CharacterFactory.getInstance().getEvaluator( Operator.EQUAL ),
new LongFieldImpl( 67 ) );
final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
lit3,
new MockObjectSource( buildContext.getNextId() ),
buildContext );
ad.addObjectSink( al3 );
//this should now be nicely hashed.
assertNotNull( ad.hashedSinkMap );
assertNull( ad.hashableSinks );
// test propagation
Cheese cheese = new Cheese();
cheese.setCharType( 'B' );
CompositeObjectSinkAdapter.HashKey hashKey = new CompositeObjectSinkAdapter.HashKey();
// should find this
hashKey.setValue( extractor.getIndex(),
cheese,
extractor );
ObjectSink sink = (ObjectSink) ad.hashedSinkMap.get( hashKey );
assertSame( al2, sink );
// should not find this one
cheese.setCharType( 'X' );
hashKey.setValue( extractor.getIndex(),
cheese,
extractor );
sink = (ObjectSink) ad.hashedSinkMap.get( hashKey );
assertNull( sink );