final Declaration[] previousDeclarations = new Declaration[]{a, b};
final Declaration[] localDeclarations = new Declaration[]{};
final String[] requiredGlobals = new String[]{};
final ReturnValueRestriction returnValue = new ReturnValueRestriction( extractor,
previousDeclarations,
localDeclarations,
requiredGlobals,
context.getConfiguration().getEvaluatorRegistry().getEvaluator( ValueType.PINTEGER_TYPE,
Operator.EQUAL ) );
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
returnValueDescr,
returnValueDescr.getContent(),
new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap(), null, Cheese.class ) );
context.getBuildStack().push( patternB );
builder.build( context,
analysis.getBoundIdentifiers(),
previousDeclarations,
localDeclarations,
returnValue,
returnValueDescr,
analysis );
((MVELReturnValueExpression)returnValue.getExpression()).compile((MVELDialectRuntimeData) pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectRuntimeRegistry().getDialectData( "mvel" ));
ContextEntry retValContext = returnValue.createContextEntry();
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 );
final InternalFactHandle f0 = (InternalFactHandle) wm.insert( cheddar );
LeftTuple tuple = new LeftTuple( f0,
null,
true );
final InternalFactHandle f1 = (InternalFactHandle) wm.insert( stilton );
tuple = new LeftTuple( tuple,
new RightTuple( f1,
null ),
null,
true );
final Cheese brie = new Cheese( "brie",
20 );
final InternalFactHandle f2 = (InternalFactHandle) wm.insert( brie );
assertTrue( returnValue.isAllowed( extractor,
f2,
tuple,
wm,
retValContext ) );
brie.setPrice( 18 );
wm.update( f2,
brie );
assertFalse( returnValue.isAllowed( extractor,
f2,
tuple,
wm,
retValContext ) );
}