Search in sources :

Example 11 with PersonInterface

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

the class NullTest method testNullBehaviour.

@Test
public void testNullBehaviour() throws Exception {
    final KieBase kbase = loadKnowledgeBase("null_behaviour.drl");
    KieSession session = kbase.newKieSession();
    final PersonInterface p1 = new Person("michael", "food", 40);
    final PersonInterface p2 = new Person(null, "drink", 30);
    session.insert(p1);
    session.insert(p2);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
}
Also used : PersonInterface(org.drools.compiler.PersonInterface) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 12 with PersonInterface

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

the class LiteralTest method testLiteralWithBoolean.

@Test
public void testLiteralWithBoolean() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("literal_with_boolean.drl"));
    KieSession session = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    session.setGlobal("list", list);
    final PersonInterface bill = new Person("bill", null, 12);
    bill.setAlive(true);
    session.insert(bill);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
    assertEquals(bill, ((List) session.getGlobal("list")).get(0));
}
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) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 13 with PersonInterface

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

the class PatternTest method testBigDecimal.

@Test
public void testBigDecimal() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("big_decimal_and_comparable.drl"));
    KieSession session = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    session.setGlobal("list", list);
    final PersonInterface bill = new Person("bill", null, 42);
    bill.setBigDecimal(new BigDecimal("42"));
    final PersonInterface ben = new Person("ben", null, 43);
    ben.setBigDecimal(new BigDecimal("43"));
    session.insert(bill);
    session.insert(new Cheese("gorgonzola", 43));
    session.insert(ben);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
    assertEquals(1, ((List) session.getGlobal("list")).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) Cheese(org.drools.compiler.Cheese) Person(org.drools.compiler.Person) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 14 with PersonInterface

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

the class DeleteTest method testAssertRetract.

@Test
public void testAssertRetract() throws Exception {
    // postponed while I sort out KnowledgeHelperFixer
    final KieBase kbase = loadKnowledgeBase("assert_retract.drl");
    final KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final PersonInterface person = new org.drools.compiler.Person("michael", "cheese");
    person.setStatus("start");
    ksession.insert(person);
    ksession.fireAllRules();
    final List<String> results = (List<String>) ksession.getGlobal("list");
    for (final String result : results) {
        logger.info(result);
    }
    assertEquals(5, results.size());
    assertTrue(results.contains("first"));
    assertTrue(results.contains("second"));
    assertTrue(results.contains("third"));
    assertTrue(results.contains("fourth"));
    assertTrue(results.contains("fifth"));
}
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) Person(org.drools.core.test.model.Person) Test(org.junit.Test)

Aggregations

PersonInterface (org.drools.compiler.PersonInterface)14 Test (org.junit.Test)14 KieSession (org.kie.api.runtime.KieSession)14 Person (org.drools.compiler.Person)13 ArrayList (java.util.ArrayList)12 KieBase (org.kie.api.KieBase)12 List (java.util.List)10 Cheese (org.drools.compiler.Cheese)4 BigDecimal (java.math.BigDecimal)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 KiePackage (org.kie.api.definition.KiePackage)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 BigInteger (java.math.BigInteger)1 Primitives (org.drools.compiler.Primitives)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 Person (org.drools.core.test.model.Person)1