Search in sources :

Example 16 with Primitives

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

the class ArrayTest method testContainsFloatArray.

@Test
public void testContainsFloatArray() throws Exception {
    final KieSession kieSession = createKieSessionFromDrl(getDrl("Float", false, "10"));
    final List list = new ArrayList();
    addGlobalsToSession(kieSession, list, 10.0f, new Float[] { 5f, 10f, 20f });
    final Primitives p1 = new Primitives();
    p1.setFloatPrimitive(5);
    p1.setPrimitiveFloatArray(new float[] { 5, 10, 20 });
    final Primitives p2 = new Primitives();
    p2.setFloatPrimitive(10);
    p2.setPrimitiveFloatArray(new float[] { 5, 10, 20 });
    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 17 with Primitives

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

the class ArrayTest method testNotContainsCharArray.

@Test
public void testNotContainsCharArray() throws Exception {
    final KieSession kieSession = createKieSessionFromDrl(getDrl("Character", true, "'c'"));
    final List list = new ArrayList();
    addGlobalsToSession(kieSession, list, 'c', new Character[] { 'd', 'e', 'f' });
    final Primitives p1 = new Primitives();
    p1.setPrimitiveCharArray(new char[] { 'd', 'e', 'f' });
    p1.setCharPrimitive('a');
    final Primitives p2 = new Primitives();
    p2.setPrimitiveCharArray(new char[] { 'd', 'e', 'f' });
    p2.setCharPrimitive('c');
    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 18 with Primitives

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

the class ArrayTest method testNotContainsDoubleArray.

@Test
public void testNotContainsDoubleArray() throws Exception {
    final KieSession kieSession = createKieSessionFromDrl(getDrl("Double", true, "10"));
    final List list = new ArrayList();
    addGlobalsToSession(kieSession, list, 10.0d, new Double[] { 40d, 50d, 60d });
    final Primitives p1 = new Primitives();
    p1.setPrimitiveDoubleArray(new double[] { 40, 50, 60 });
    p1.setDoublePrimitive(5);
    final Primitives p2 = new Primitives();
    p2.setDoublePrimitive(10);
    p2.setPrimitiveDoubleArray(new double[] { 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 19 with Primitives

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

the class ArrayTest method testNotContainsFloatArray.

@Test
public void testNotContainsFloatArray() throws Exception {
    final KieSession kieSession = createKieSessionFromDrl(getDrl("Float", true, "10"));
    final List list = new ArrayList();
    addGlobalsToSession(kieSession, list, 10.0f, new Float[] { 40f, 50f, 60f });
    final Primitives p1 = new Primitives();
    p1.setFloatPrimitive(5);
    p1.setPrimitiveFloatArray(new float[] { 40, 50, 60 });
    final Primitives p2 = new Primitives();
    p2.setFloatPrimitive(10);
    p2.setPrimitiveFloatArray(new float[] { 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 20 with Primitives

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

the class ArrayTest method testPrimitiveArray.

@Test
public void testPrimitiveArray() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_primitiveArray.drl"));
    KieSession session = createKnowledgeSession(kbase);
    List result = new ArrayList();
    session.setGlobal("result", result);
    final Primitives p1 = new Primitives();
    p1.setPrimitiveIntArray(new int[] { 1, 2, 3 });
    p1.setArrayAttribute(new String[] { "a", "b" });
    session.insert(p1);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    result = (List) session.getGlobal("result");
    session.fireAllRules();
    assertEquals(3, result.size());
    assertEquals(3, ((Integer) result.get(0)).intValue());
    assertEquals(2, ((Integer) result.get(1)).intValue());
    assertEquals(3, ((Integer) result.get(2)).intValue());
}
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)

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