Search in sources :

Example 26 with Primitives

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

the class ArrayTest method testContainsShortArray.

@Test
public void testContainsShortArray() {
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Short", false, "1"));
    final KieSession kieSession = kbase.newKieSession();
    try {
        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);
    } 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 27 with Primitives

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

the class LiteralTest method testBigLiterals.

@Test
public void testBigLiterals() {
    final String drl = "package org.drools.compiler.integrationtests.drl;\n" + "import " + Primitives.class.getCanonicalName() + ";\n" + "rule X\n" + "when\n" + "    Primitives( bigInteger == 10I, bigInteger < (50I), bigDecimal == 10B, bigDecimal < (50B) )\n" + "then\n" + "end\n";
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("literal-test", kieBaseTestConfiguration, drl);
    final KieSession session = kbase.newKieSession();
    try {
        final Primitives p = new Primitives();
        p.setBigDecimal(BigDecimal.valueOf(10));
        p.setBigInteger(BigInteger.valueOf(10));
        session.insert(p);
        final int rulesFired = session.fireAllRules();
        assertEquals(1, rulesFired);
    } finally {
        session.dispose();
    }
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Primitives(org.drools.testcoverage.common.model.Primitives) Test(org.junit.Test)

Example 28 with Primitives

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

the class PatternTest method testBigDecimal.

@Test
public void testBigDecimal() {
    final String drl = "package org.drools.compiler.integrationtests.drl;\n" + "\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Primitives.class.getCanonicalName() + ";\n" + "import java.math.BigDecimal;\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule \"BigDec\"\n" + "\n" + "    when\n" + "        Cheese($price : price)\n" + "        p : Primitives(bigDecimal < $price)\n" + "    then\n" + "        list.add( p );\n" + "end";
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("pattern-test", kieBaseTestConfiguration, drl);
    final KieSession session = kbase.newKieSession();
    try {
        final List list = new ArrayList();
        session.setGlobal("list", list);
        final Primitives bill = new Primitives();
        bill.setBigDecimal(new BigDecimal("42"));
        final Primitives ben = new Primitives();
        ben.setBigDecimal(new BigDecimal("43"));
        session.insert(bill);
        session.insert(new Cheese("gorgonzola", 43));
        session.insert(ben);
        session.fireAllRules();
        assertEquals(1, ((List) session.getGlobal("list")).size());
    } finally {
        session.dispose();
    }
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) Cheese(org.drools.testcoverage.common.model.Cheese) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Primitives(org.drools.testcoverage.common.model.Primitives) BigDecimal(java.math.BigDecimal) 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