use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testEqualsOnIntArray.
@Test
public void testEqualsOnIntArray() throws Exception {
String str = "";
str += "package org.drools.compiler;\n";
str += "global java.util.List list;\n";
str += "rule \"contains in array\"\n";
str += " salience 10\n";
str += " when\n";
str += " Primitives( primitiveIntArray[0] == 1 )\n";
str += " then\n";
str += " list.add( \"ok1\" );\n";
str += "end\n";
KieBase kbase = loadKnowledgeBaseFromString(str);
kbase = SerializationHelper.serializeObject(kbase);
final KieSession ksession = createKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Primitives p1 = new Primitives();
p1.setPrimitiveIntArray(new int[] { 1, 2 });
final FactHandle p1h = ksession.insert(p1);
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsCharArray.
@Test
public void testContainsCharArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Character", false, "'c'"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 'c', new Character[] { 'a', 'b', 'c' });
final Primitives p1 = new Primitives();
p1.setPrimitiveCharArray(new char[] { 'a', 'b', 'c' });
p1.setCharPrimitive('a');
final Primitives p2 = new Primitives();
p2.setPrimitiveCharArray(new char[] { 'a', 'b', 'c' });
p2.setCharPrimitive('c');
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testNotContainsBooleanArray.
@Test
public void testNotContainsBooleanArray() throws Exception {
String str = "";
str += "package org.drools.compiler;\n";
str += "global java.util.List list;\n";
str += "global Boolean nGlobal;\n";
str += "global Object arrayGlobal;\n";
str += "rule \"contains in array\"\n";
str += " salience 10\n";
str += " when\n";
str += " Primitives( $b : booleanPrimitive, intPrimitive == 10, $array1 : primitiveBooleanArray ) \n";
str += " Primitives( booleanPrimitive == false, intPrimitive != 10, $array2 : primitiveBooleanArray not contains nGlobal, primitiveBooleanArray not contains $b, ";
str += " booleanPrimitive not memberOf $array2, booleanPrimitive not memberOf $array1, booleanPrimitive not memberOf arrayGlobal )\n";
str += " then\n";
str += " list.add( \"ok1\" );\n";
str += "end\n";
final KieSession kieSession = createKieSessionFromDrl(str);
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, false, new Boolean[] { true, true });
final Primitives p1 = new Primitives();
p1.setIntPrimitive(10);
p1.setPrimitiveBooleanArray(new boolean[] { true, true });
p1.setBooleanPrimitive(false);
final Primitives p2 = new Primitives();
p2.setPrimitiveBooleanArray(new boolean[] { true, true });
p2.setBooleanPrimitive(false);
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsIntArray.
@Test
public void testContainsIntArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Integer", false, "10"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 10, new Integer[] { 5, 10, 20 });
final Primitives p1 = new Primitives();
p1.setPrimitiveIntArray(new int[] { 5, 10, 20 });
p1.setIntPrimitive(5);
final Primitives p2 = new Primitives();
p2.setPrimitiveIntArray(new int[] { 5, 10, 20 });
p2.setIntPrimitive(10);
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsBooleanArray.
@Test
public void testContainsBooleanArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Boolean", false, "true"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, true, new Boolean[] { true, false });
final Primitives p1 = new Primitives();
p1.setPrimitiveBooleanArray(new boolean[] { true, false });
p1.setBooleanPrimitive(false);
final Primitives p2 = new Primitives();
p2.setPrimitiveBooleanArray(new boolean[] { true, false });
p2.setBooleanPrimitive(true);
testArrayContains(kieSession, p1, p2, list);
}
Aggregations