use of org.drools.mvel.compiler.Primitives in project drools by kiegroup.
the class JBRULESTest method testJBRULES_2995.
@Test
public void testJBRULES_2995() {
final String str = "package org.drools.mvel.compiler\n" + "rule r1\n" + "when\n" + " Primitives( classAttr == java.lang.String.class, \n" + " eval(classAttr.equals( java.lang.String.class ) ),\n" + " classAttr == String.class )\n" + "then\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final Primitives primitives = new Primitives();
primitives.setClassAttr(String.class);
ksession.insert(primitives);
final int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.drools.mvel.compiler.Primitives in project drools by kiegroup.
the class FieldAccessTest method testAccessClassTypeField.
@Test
public void testAccessClassTypeField() {
final String str = "package org.drools.mvel.compiler\n" + "rule r1\n" + "when\n" + " Primitives( classAttr == null )" + "then\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
ksession.insert(new Primitives());
final int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.drools.mvel.compiler.Primitives in project drools by kiegroup.
the class MarshallingTest method testSerializationOfIndexedWM.
@Test
public void testSerializationOfIndexedWM() throws Exception {
Collection<KiePackage> kpkgs = loadKnowledgePackages("test_Serializable2.drl");
kpkgs = SerializationHelper.serializeObject(kpkgs);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) getKnowledgeBase();
kBase.addPackages(kpkgs);
org.kie.api.definition.rule.Rule[] rules = (org.kie.api.definition.rule.Rule[]) kBase.getPackage("org.drools.compiler").getRules().toArray(new org.kie.api.definition.rule.Rule[0]);
assertEquals(3, rules.length);
KieSession session = kBase.newKieSession();
session.setGlobal("list", new ArrayList());
final Primitives p = new Primitives();
p.setBytePrimitive((byte) 1);
p.setShortPrimitive((short) 2);
p.setIntPrimitive((int) 3);
session.insert(p);
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
assertEquals(1, session.getObjects().size());
Assert.assertEquals(p, IteratorToList.convert(session.getObjects().iterator()).get(0));
assertEquals(3, ((InternalAgenda) session.getAgenda()).getAgendaGroupsManager().agendaSize());
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.fireAllRules();
final List list = (List) session.getGlobal("list");
assertEquals(3, list.size());
// because of agenda-groups
assertEquals("1", list.get(0));
assertEquals("2", list.get(1));
assertEquals("3", list.get(2));
}
use of org.drools.mvel.compiler.Primitives in project drools by kiegroup.
the class NullTest method testNullConstraint.
@Test
public void testNullConstraint() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "null_constraint.drl");
KieSession session = kbase.newKieSession();
final List foo = new ArrayList();
session.setGlobal("messages", foo);
final PersonInterface p1 = new Person(null, "food", 40);
final Primitives p2 = new Primitives();
p2.setArrayAttribute(null);
session.insert(p1);
session.insert(p2);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("messages")).size());
}
use of org.drools.mvel.compiler.Primitives in project drools by kiegroup.
the class TypeCoercionTest method testRuntimeTypeCoercion2.
@Test
public void testRuntimeTypeCoercion2() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_RuntimeTypeCoercion2.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("results", list);
final Primitives fact = new Primitives();
fact.setBooleanPrimitive(true);
fact.setBooleanWrapper(Boolean.TRUE);
fact.setObject(Boolean.TRUE);
fact.setCharPrimitive('X');
final FactHandle handle = ksession.insert(fact);
ksession.fireAllRules();
int index = 0;
assertEquals(list.toString(), 4, list.size());
assertEquals("boolean", list.get(index++));
assertEquals("boolean wrapper", list.get(index++));
assertEquals("boolean object", list.get(index++));
assertEquals("char", list.get(index++));
fact.setBooleanPrimitive(false);
fact.setBooleanWrapper(null);
fact.setCharPrimitive('\0');
fact.setObject('X');
ksession.update(handle, fact);
ksession.fireAllRules();
assertEquals(5, list.size());
assertEquals("char object", list.get(index++));
fact.setObject(null);
ksession.update(handle, fact);
ksession.fireAllRules();
assertEquals(6, list.size());
assertEquals("null object", list.get(index));
}
Aggregations