Search in sources :

Example 6 with PersonInterface

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

the class ExecutionFlowControlTest method testSalienceIntegerAndLoadOrder.

@Test(timeout = 10000)
public void testSalienceIntegerAndLoadOrder() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "test_salienceIntegerRule.drl");
    KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final PersonInterface person = new Person("Edson", "cheese");
    ksession.insert(person);
    ksession.fireAllRules();
    assertEquals("Three rules should have been fired", 3, list.size());
    assertEquals("Rule 4 should have been fired first", "Rule 4", list.get(0));
    assertEquals("Rule 2 should have been fired second", "Rule 2", list.get(1));
    assertEquals("Rule 3 should have been fired third", "Rule 3", list.get(2));
}
Also used : PersonInterface(org.drools.mvel.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.mvel.compiler.Person) Test(org.junit.Test)

Example 7 with PersonInterface

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

the class NullTest method testNullBehaviour.

@Test
public void testNullBehaviour() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "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.mvel.compiler.PersonInterface) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 8 with PersonInterface

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

the class NullTest method testNullConstraint.

@Test
public void testNullConstraint() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "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.mvel.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.mvel.compiler.Primitives) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 9 with PersonInterface

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

the class DeleteTest method testAssertRetract.

@Test
public void testAssertRetract() throws Exception {
    // postponed while I sort out KnowledgeHelperFixer
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "assert_retract.drl");
    final KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final PersonInterface person = new org.drools.mvel.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.mvel.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.mvel.compiler.PersonInterface)9 Test (org.junit.Test)9 KieSession (org.kie.api.runtime.KieSession)9 Person (org.drools.mvel.compiler.Person)8 ArrayList (java.util.ArrayList)7 KieBase (org.kie.api.KieBase)7 List (java.util.List)5 Cheese (org.drools.mvel.compiler.Cheese)3 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)2 KiePackage (org.kie.api.definition.KiePackage)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 Person (org.drools.core.test.model.Person)1 Primitives (org.drools.mvel.compiler.Primitives)1