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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations