Search in sources :

Example 1 with Primitives

use of org.drools.compiler.Primitives in project drools by kiegroup.

the class FieldAccessTest method testAccessClassTypeField.

@Test
public void testAccessClassTypeField() {
    final String str = "package org.drools.compiler\n" + "rule r1\n" + "when\n" + "    Primitives( classAttr == null )" + "then\n" + "end\n";
    final KieBase kbase = loadKnowledgeBaseFromString(str);
    final KieSession ksession = createKnowledgeSession(kbase);
    ksession.insert(new Primitives());
    final int rules = ksession.fireAllRules();
    assertEquals(1, rules);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Primitives(org.drools.compiler.Primitives) Test(org.junit.Test)

Example 2 with Primitives

use of org.drools.compiler.Primitives in project drools by kiegroup.

the class ContainsTest method testContainsInArray.

@Test
public void testContainsInArray() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_contains_in_array.drl"));
    final KieSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Primitives p = new Primitives();
    p.setStringArray(new String[] { "test1", "test3" });
    ksession.insert(p);
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertEquals("ok1", list.get(0));
    assertEquals("ok2", list.get(1));
}
Also used : 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)

Example 3 with Primitives

use of org.drools.compiler.Primitives in project drools by kiegroup.

the class EqualsTest method testCharComparisons.

@Test
public void testCharComparisons() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_charComparisons.drl"));
    final KieSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    Primitives p1 = new Primitives();
    p1.setCharPrimitive('a');
    p1.setStringAttribute("b");
    Primitives p2 = new Primitives();
    p2.setCharPrimitive('b');
    p2.setStringAttribute("a");
    ksession.insert(p1);
    ksession.insert(p2);
    ksession.fireAllRules();
    assertEquals(3, results.size());
    assertEquals("1", results.get(0));
    assertEquals("2", results.get(1));
    assertEquals("3", results.get(2));
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Primitives(org.drools.compiler.Primitives) Test(org.junit.Test)

Example 4 with Primitives

use of org.drools.compiler.Primitives in project drools by kiegroup.

the class EqualsTest method testNotEqualsOperator.

@Test
public void testNotEqualsOperator() {
    // JBRULES-3003: restriction evaluation returns 'false' for "trueField != falseField"
    final String str = "package org.drools.compiler\n" + "rule NotEquals\n" + "when\n" + "    Primitives( booleanPrimitive != booleanWrapper )\n" + "then\n" + "end";
    final KieBase kbase = loadKnowledgeBaseFromString(str);
    final KieSession ksession = createKnowledgeSession(kbase);
    final Primitives p = new Primitives();
    p.setBooleanPrimitive(true);
    p.setBooleanWrapper(Boolean.FALSE);
    ksession.insert(p);
    final int rules = ksession.fireAllRules();
    ksession.dispose();
    assertEquals(1, rules);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Primitives(org.drools.compiler.Primitives) Test(org.junit.Test)

Example 5 with Primitives

use of org.drools.compiler.Primitives in project drools by kiegroup.

the class JBRULESTest method testJBRULES_2995.

@Test
public void testJBRULES_2995() {
    final String str = "package org.drools.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";
    final KieBase kbase = loadKnowledgeBaseFromString(str);
    final KieSession ksession = createKnowledgeSession(kbase);
    final Primitives primitives = new Primitives();
    primitives.setClassAttr(String.class);
    ksession.insert(primitives);
    final int rules = ksession.fireAllRules();
    assertEquals(1, rules);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) 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