Search in sources :

Example 21 with Primitives

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);
}
Also used : 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 22 with Primitives

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);
}
Also used : 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 23 with Primitives

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);
}
Also used : 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 24 with Primitives

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePackage(org.kie.api.definition.KiePackage) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) IteratorToList(org.drools.compiler.integrationtests.IteratorToList) Primitives(org.drools.compiler.Primitives) Map(java.util.Map) HashMap(java.util.HashMap) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 25 with Primitives

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());
}
Also used : PersonInterface(org.drools.compiler.PersonInterface) 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) Person(org.drools.compiler.Person) 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