use of org.drools.mvel.accessors.ClassFieldReader in project drools by kiegroup.
the class ClassFieldAccessorTest method testBasic.
@Test
public void testBasic() throws Exception {
final Object[] objArray = new Object[1];
final TestBean obj = new TestBean();
obj.setBlah(false);
obj.setSomething("no");
obj.setObjArray(objArray);
final ClassFieldReader ext = store.getReader(TestBean.class, "blah");
assertEquals(false, ((Boolean) ext.getValue(null, obj)).booleanValue());
final ClassFieldReader ext2 = store.getReader(TestBean.class, "fooBar");
assertEquals("fooBar", ext2.getValue(null, obj));
final ClassFieldReader ext3 = store.getReader(TestBean.class, "objArray");
assertEquals(objArray, ext3.getValue(null, obj));
}
use of org.drools.mvel.accessors.ClassFieldReader in project drools by kiegroup.
the class ClassFieldAccessorTest method testLong.
@Test
public void testLong() throws Exception {
final ClassFieldReader ext = store.getReader(TestBean.class, "longField");
final TestBean bean = new TestBean();
assertEquals(424242, ((Number) ext.getValue(null, bean)).longValue());
}
use of org.drools.mvel.accessors.ClassFieldReader in project drools by kiegroup.
the class MVELTest method testNewConstructor.
@Test
public void testNewConstructor() {
final String str = "" + "package org.drools.mvel.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Address.class.getCanonicalName() + "\n" + "global java.util.List list \n" + "rule \"show\" \n" + "when \n" + " $m : Person( address == new Address('s1')) \n" + "then \n" + " list.add('r1'); \n" + "end \n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Person p = new Person("yoda");
p.setAddress(new Address("s1"));
ksession.insert(p);
ksession.fireAllRules();
assertEquals("r1", list.get(0));
// Check it was built with MVELReturnValueExpression constraint
final List<ObjectTypeNode> nodes = ((InternalKnowledgeBase) kbase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for (final ObjectTypeNode n : nodes) {
if (((ClassObjectType) n.getObjectType()).getClassType() == Person.class) {
node = n;
break;
}
}
final AlphaNode alphanode = (AlphaNode) node.getObjectSinkPropagator().getSinks()[0];
final AlphaNodeFieldConstraint constraint = alphanode.getConstraint();
if (constraint instanceof MVELConstraint) {
assertTrue(((MVELConstraint) constraint).getFieldExtractor() instanceof ClassFieldReader);
}
}
use of org.drools.mvel.accessors.ClassFieldReader in project drools by kiegroup.
the class ClassFieldAccessorTest method testInherited.
@Test
public void testInherited() throws Exception {
final ClassFieldReader ext = store.getReader(BeanInherit.class, "text");
final BeanInherit obj = new BeanInherit();
assertEquals("hola", (String) ext.getValue(null, obj));
}
use of org.drools.mvel.accessors.ClassFieldReader in project drools by kiegroup.
the class ClassFieldAccessorTest method testInterface.
@Test
public void testInterface() throws Exception {
final TestInterface obj = new TestInterfaceImpl();
final ClassFieldReader ext = store.getReader(TestInterface.class, "something");
assertEquals("foo", (String) ext.getValue(null, obj));
}
Aggregations