use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsByteArray.
@Test
public void testContainsByteArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Byte", false, "1"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, (byte) 1, new Byte[] { 1, 2, 3 });
final Primitives p1 = new Primitives();
p1.setPrimitiveByteArray(new byte[] { 1, 2, 3 });
p1.setBytePrimitive((byte) 2);
final Primitives p2 = new Primitives();
p2.setPrimitiveByteArray(new byte[] { 1, 2, 3 });
p2.setBytePrimitive((byte) 1);
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsShortArray.
@Test
public void testContainsShortArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Short", false, "1"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, (short) 1, new Short[] { 1, 2, 3 });
final Primitives p1 = new Primitives();
p1.setPrimitiveShortArray(new short[] { 1, 2, 3 });
p1.setShortPrimitive((short) 2);
final Primitives p2 = new Primitives();
p2.setPrimitiveShortArray(new short[] { 1, 2, 3 });
p2.setShortPrimitive((short) 1);
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class ArrayTest method testNotContainsLongArray.
@Test
public void testNotContainsLongArray() throws Exception {
final KieSession kieSession = createKieSessionFromDrl(getDrl("Long", true, "10"));
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 10L, new Long[] { 40L, 50L, 60L });
final Primitives p1 = new Primitives();
p1.setPrimitiveLongArray(new long[] { 40, 50, 60 });
p1.setLongPrimitive(5);
final Primitives p2 = new Primitives();
p2.setLongPrimitive(10);
p2.setPrimitiveLongArray(new long[] { 40, 50, 60 });
testArrayContains(kieSession, p1, p2, list);
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class MarshallingTest method testSerializationOfIndexedWM.
@Test
public void testSerializationOfIndexedWM() throws Exception {
Collection<KiePackage> kpkgs = loadKnowledgePackages("../test_Serializable2.drl");
kpkgs = SerializationHelper.serializeObject(kpkgs);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) getKnowledgeBase();
kBase.addPackages(kpkgs);
kBase = SerializationHelper.serializeObject(kBase);
Map map = new HashMap();
map.put("x", kBase);
map = SerializationHelper.serializeObject(map);
kBase = (InternalKnowledgeBase) map.get("x");
org.kie.api.definition.rule.Rule[] rules = (org.kie.api.definition.rule.Rule[]) kBase.getPackage("org.drools.compiler").getRules().toArray(new org.kie.api.definition.rule.Rule[0]);
assertEquals(3, rules.length);
KieSession session = kBase.newKieSession();
session.setGlobal("list", new ArrayList());
final Primitives p = new Primitives();
p.setBytePrimitive((byte) 1);
p.setShortPrimitive((short) 2);
p.setIntPrimitive((int) 3);
session.insert(p);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, kBase, true);
assertEquals(1, session.getObjects().size());
assertEquals(p, IteratorToList.convert(session.getObjects().iterator()).get(0));
assertEquals(3, ((InternalAgenda) session.getAgenda()).agendaSize());
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.fireAllRules();
final List list = (List) session.getGlobal("list");
assertEquals(3, list.size());
// because of agenda-groups
assertEquals("1", list.get(0));
assertEquals("2", list.get(1));
assertEquals("3", list.get(2));
}
use of org.drools.compiler.Primitives in project drools by kiegroup.
the class NullTest method testNullConstraint.
@Test
public void testNullConstraint() throws Exception {
final KieBase kbase = loadKnowledgeBase("null_constraint.drl");
KieSession session = kbase.newKieSession();
final List foo = new ArrayList();
session.setGlobal("messages", foo);
final PersonInterface p1 = new Person(null, "food", 40);
final Primitives p2 = new Primitives();
p2.setArrayAttribute(null);
session.insert(p1);
session.insert(p2);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("messages")).size());
}
Aggregations