Search in sources :

Example 26 with Primitives

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);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Primitives(org.drools.compiler.Primitives) Test(org.junit.Test)

Example 27 with Primitives

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));
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Primitives(org.drools.compiler.Primitives) Test(org.junit.Test)

Aggregations

Primitives (org.drools.compiler.Primitives)27 Test (org.junit.Test)27 KieSession (org.kie.api.runtime.KieSession)27 ArrayList (java.util.ArrayList)23 List (java.util.List)23 KieBase (org.kie.api.KieBase)10 FactHandle (org.kie.api.runtime.rule.FactHandle)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Person (org.drools.compiler.Person)1 PersonInterface (org.drools.compiler.PersonInterface)1 IteratorToList (org.drools.compiler.integrationtests.IteratorToList)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 KiePackage (org.kie.api.definition.KiePackage)1