final MVELPredicateBuilder builder = new MVELPredicateBuilder();
final Declaration[] previousDeclarations = new Declaration[]{a};
final Declaration[] localDeclarations = new Declaration[]{b};
final PredicateConstraint predicate = new PredicateConstraint( null,
localDeclarations );
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
predicateDescr,
predicateDescr.getContent(),
new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap(), null, Cheese.class ) );
builder.build( context,
new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap() ),
previousDeclarations,
localDeclarations,
predicate,
predicateDescr,
analysis );
( (MVELPredicateExpression) predicate.getPredicateExpression()).compile( (MVELDialectRuntimeData) pkgRegistry.getDialectRuntimeRegistry().getDialectData( "mvel" ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();
final Cheese stilton = new Cheese( "stilton",
10 );
final Cheese cheddar = new Cheese( "cheddar",
10 );
MockLeftTupleSink sink = new MockLeftTupleSink();
final InternalFactHandle f0 = (InternalFactHandle) wm.insert( cheddar );
final InternalFactHandle f1 = (InternalFactHandle) wm.insert( stilton );
final LeftTupleImpl tuple = new LeftTupleImpl( f0, sink, true );
final PredicateContextEntry predicateContext = (PredicateContextEntry) predicate.createContextEntry();
predicateContext.leftTuple = tuple;
predicateContext.workingMemory = wm;
assertTrue( predicate.isAllowedCachedLeft( predicateContext,
f1 ) );
cheddar.setPrice( 9 );
wm.update( f0,
cheddar );
assertFalse( predicate.isAllowedCachedLeft( predicateContext,
f1 ) );
}