use of org.drools.compiler.Primitives in project drools by kiegroup.
the class LiteralTest method testBigLiterals.
@Test
public void testBigLiterals() {
final String str = "package org.drools.compiler\n" + "rule X\n" + "when\n" + " Primitives( bigInteger == 10I, bigInteger < (50I), bigDecimal == 10B, bigDecimal < (50B) )\n" + "then\n" + "end\n";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = createKnowledgeSession(kbase);
final Primitives p = new Primitives();
p.setBigDecimal(BigDecimal.valueOf(10));
p.setBigInteger(BigInteger.valueOf(10));
ksession.insert(p);
final int rulesFired = ksession.fireAllRules();
assertEquals(1, rulesFired);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class TypeCoercionTest method testRuntimeTypeCoercion2.
@Test
public void testRuntimeTypeCoercion2() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_RuntimeTypeCoercion2.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
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