Search in sources :

Example 6 with Primitives

use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.

the class AlphaNodeRangeIndexingTest method testNull.

@Test
public void testNull() {
    final String drl = "package org.drools.compiler.test\n" + "import " + Primitives.class.getCanonicalName() + "\n" + "rule test1\n when\n" + "   Primitives( bigDecimal >= null )\n" + "then\n end\n" + "rule test2\n when\n" + "   Primitives( bigDecimal < 25.0 )\n" + "then\n end\n" + "rule test3\n when\n" + "   Primitives( bigDecimal > 8.0 )\n" + "then\n end\n" + "rule test4\n when\n" + "   Primitives( bigDecimal < 60.0 )\n" + "then\n end\n" + "rule test5\n when\n" + "   Primitives( bigDecimal > 12.0 )\n" + "then\n end\n" + "rule test6\n when\n" + "   Primitives( bigDecimal <= 4.0 )\n" + "then\n end\n";
    final KieBase kbase = createKieBaseWithRangeIndexThresholdValue(drl, 3);
    final KieSession ksession = kbase.newKieSession();
    // [bigDecimal >= null]  is in OtherSinks
    assertSinks(kbase, Primitives.class, 6, 6, 0, 5);
    Primitives p1 = new Primitives();
    p1.setBigDecimal(new BigDecimal("18.0"));
    ksession.insert(p1);
    int fired = ksession.fireAllRules();
    assertEquals(4, fired);
    Primitives p2 = new Primitives();
    p2.setBigDecimal(null);
    ksession.insert(p2);
    fired = ksession.fireAllRules();
    // bigDecimal >= null is false
    assertEquals(0, fired);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Primitives(org.drools.testcoverage.common.model.Primitives) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with Primitives

use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.

the class ArrayTest method testContainsLongArray.

@Test
public void testContainsLongArray() {
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Long", false, "10"));
    final KieSession kieSession = kbase.newKieSession();
    try {
        final List list = new ArrayList();
        addGlobalsToSession(kieSession, list, 10L, new Long[] { 5L, 10L, 20L });
        final Primitives p1 = new Primitives();
        p1.setPrimitiveLongArray(new long[] { 5, 10, 20 });
        p1.setLongPrimitive(5);
        final Primitives p2 = new Primitives();
        p2.setLongPrimitive(10);
        p2.setPrimitiveLongArray(new long[] { 5, 10, 20 });
        testArrayContains(kieSession, p1, p2, list);
    } finally {
        kieSession.dispose();
    }
}
Also used : 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.testcoverage.common.model.Primitives) Test(org.junit.Test)

Example 8 with Primitives

use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.

the class ArrayTest method testEqualsOnIntArray.

@Test
public void testEqualsOnIntArray() {
    final String drl = "package org.drools.compiler;\n" + "import " + Primitives.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule \"contains in array\"\n" + "     salience 10\n" + "     when\n" + "         Primitives( primitiveIntArray[0] == 1 )\n" + "     then\n" + "        list.add( \"ok1\" );\n" + "end\n";
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, drl);
    final KieSession ksession = kbase.newKieSession();
    try {
        final List list = new ArrayList();
        ksession.setGlobal("list", list);
        final Primitives p1 = new Primitives();
        p1.setPrimitiveIntArray(new int[] { 1, 2 });
        ksession.insert(p1);
        ksession.fireAllRules();
        assertEquals(1, list.size());
    } finally {
        ksession.dispose();
    }
}
Also used : 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.testcoverage.common.model.Primitives) Test(org.junit.Test)

Example 9 with Primitives

use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.

the class ArrayTest method testContainsDoubleArray.

@Test
public void testContainsDoubleArray() {
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Double", false, "10"));
    final KieSession kieSession = kbase.newKieSession();
    try {
        final List list = new ArrayList();
        addGlobalsToSession(kieSession, list, 10.0d, new Double[] { 5d, 10d, 20d });
        final Primitives p1 = new Primitives();
        p1.setPrimitiveDoubleArray(new double[] { 5, 10, 20 });
        p1.setDoublePrimitive(5);
        final Primitives p2 = new Primitives();
        p2.setDoublePrimitive(10);
        p2.setPrimitiveDoubleArray(new double[] { 5, 10, 20 });
        testArrayContains(kieSession, p1, p2, list);
    } finally {
        kieSession.dispose();
    }
}
Also used : 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.testcoverage.common.model.Primitives) Test(org.junit.Test)

Example 10 with Primitives

use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.

the class ArrayTest method testNotContainsBooleanArray.

@Test
public void testNotContainsBooleanArray() {
    final String drl = "package org.drools.compiler;\n" + "import " + Primitives.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "global Boolean nGlobal;\n" + "global Object arrayGlobal;\n" + "rule \"contains in array\"\n" + "     salience 10\n" + "     when\n" + "         Primitives( $b : booleanPrimitive, intPrimitive == 10, $array1 :  primitiveBooleanArray ) \n" + "         Primitives( booleanPrimitive == false, intPrimitive != 10, $array2 : primitiveBooleanArray not contains nGlobal,  primitiveBooleanArray not contains $b, " + "                     booleanPrimitive not memberOf $array2, booleanPrimitive not memberOf $array1, booleanPrimitive not memberOf arrayGlobal )\n" + "     then\n" + "        list.add( \"ok1\" );\n" + "end\n";
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, drl);
    final KieSession kieSession = kbase.newKieSession();
    try {
        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);
    } finally {
        kieSession.dispose();
    }
}
Also used : 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.testcoverage.common.model.Primitives) Test(org.junit.Test)

Aggregations

Primitives (org.drools.testcoverage.common.model.Primitives)28 Test (org.junit.Test)28 KieBase (org.kie.api.KieBase)28 KieSession (org.kie.api.runtime.KieSession)28 ArrayList (java.util.ArrayList)24 List (java.util.List)22 BigDecimal (java.math.BigDecimal)6 Cheese (org.drools.testcoverage.common.model.Cheese)2 BigInteger (java.math.BigInteger)1 Person (org.drools.testcoverage.common.model.Person)1