StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal( "list", list );
Person p = new Person("yoda");
p.getNamedAddresses().put( TestEnum.ONE, new Address("s1") );
ksession.insert( p );
ksession.fireAllRules();
assertEquals( "r1", list.get(0) );
// Check it was built with MVELReturnValueExpression constraint
List<ObjectTypeNode> nodes = ((InternalRuleBase)((KnowledgeBaseImpl)kbase).ruleBase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for ( ObjectTypeNode n : nodes ) {
if ( ((ClassObjectType)n.getObjectType()).getClassType() == Person.class ) {
node = n;
break;
}
}
AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];
AlphaNodeFieldConstraint constraint = alphanode.getConstraint();
if (constraint instanceof MvelConstraint) {
assertTrue( (( MvelConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
assertEquals( new Address("s1"), (( MvelConstraint ) alphanode.getConstraint()).getField().getValue() );
}
alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];
constraint = alphanode.getConstraint();
if (constraint instanceof MvelConstraint) {
assertTrue( (( MvelConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
assertEquals( new Address("s1").getStreet(), (( MvelConstraint ) alphanode.getConstraint()).getField().getValue() );
}
}