Search in sources :

Example 91 with Person

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

the class FirstOrderLogicTest method testMVELCollect.

@Test
public void testMVELCollect() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_MVELCollect.drl");
    KieSession wm = kbase.newKieSession();
    final List results = new ArrayList();
    wm.setGlobal("results", results);
    wm.insert(new Cheese("stilton", 10));
    wm.insert(new Cheese("stilton", 7));
    wm.insert(new Cheese("stilton", 8));
    wm.insert(new Cheese("brie", 5));
    wm.insert(new Cheese("provolone", 150));
    wm.insert(new Cheese("provolone", 20));
    wm.insert(new Person("Bob", "stilton"));
    wm.insert(new Person("Mark", "provolone"));
    wm.fireAllRules();
    assertEquals(1, results.size());
    assertEquals(6, ((List) results.get(0)).size());
}
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) Cheese(org.drools.mvel.compiler.Cheese) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 92 with Person

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

the class FirstOrderLogicTest method testNotWithBindings.

@Test
public void testNotWithBindings() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "not_with_bindings_rule_test.drl");
    KieSession wm = kbase.newKieSession();
    final List list = new ArrayList();
    wm.setGlobal("list", list);
    final Cheese stilton = new Cheese("stilton", 5);
    final FactHandle stiltonHandle = (FactHandle) wm.insert(stilton);
    final Cheese cheddar = new Cheese("cheddar", 7);
    final FactHandle cheddarHandle = (FactHandle) wm.insert(cheddar);
    final PersonInterface paul = new Person("paul", "stilton", 12);
    wm.insert(paul);
    wm.fireAllRules();
    assertEquals(0, list.size());
    wm.retract(stiltonHandle);
    wm.fireAllRules();
    assertEquals(1, list.size());
}
Also used : PersonInterface(org.drools.mvel.compiler.PersonInterface) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Cheese(org.drools.mvel.compiler.Cheese) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 93 with Person

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

the class FirstOrderLogicTest method testForall2.

@Test
public void testForall2() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Forall2.drl");
    KieSession ksession = kbase.newKieSession();
    final List<String> list = new ArrayList<String>();
    ksession.setGlobal("results", list);
    final State state = new State("SP");
    ksession.insert(state);
    final Person bob = new Person("Bob");
    bob.setStatus(state.getState());
    bob.setAlive(true);
    ksession.insert(bob);
    ksession.fireAllRules();
    assertEquals(0, list.size());
    final State qc = new State("QC");
    ksession.insert(qc);
    final Person john = new Person("John");
    john.setStatus(qc.getState());
    john.setAlive(false);
    ksession.insert(john);
    ksession.fireAllRules();
    assertEquals(1, list.size());
}
Also used : KieBase(org.kie.api.KieBase) State(org.drools.mvel.compiler.State) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) SpecialString(org.drools.mvel.compiler.SpecialString) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 94 with Person

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

the class FirstOrderLogicTest method testOr.

@Test
public void testOr() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrNesting.drl");
    KieSession workingMemory = kbase.newKieSession();
    final List list = new ArrayList();
    workingMemory.setGlobal("results", list);
    final Cheese cheddar = new Cheese("cheddar", 7);
    final Cheese provolone = new Cheese("provolone", 5);
    final Cheese brie = new Cheese("brie", 15);
    final Person mark = new Person("mark", "stilton");
    FactHandle ch = (FactHandle) workingMemory.insert(cheddar);
    FactHandle ph = (FactHandle) workingMemory.insert(provolone);
    FactHandle bh = (FactHandle) workingMemory.insert(brie);
    FactHandle markh = (FactHandle) workingMemory.insert(mark);
    workingMemory.fireAllRules();
    assertEquals(1, list.size());
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Cheese(org.drools.mvel.compiler.Cheese) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 95 with Person

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

the class FirstOrderLogicTest method testForall.

@Test
public void testForall() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Forall.drl");
    KieSession workingMemory = kbase.newKieSession();
    final List list = new ArrayList();
    workingMemory.setGlobal("results", list);
    final State state = new State("SP");
    workingMemory.insert(state);
    final Person bob = new Person("Bob");
    bob.setStatus(state.getState());
    bob.setLikes("stilton");
    workingMemory.insert(bob);
    workingMemory.fireAllRules();
    assertEquals(0, list.size());
    workingMemory.insert(new Cheese(bob.getLikes(), 10));
    workingMemory.fireAllRules();
    assertEquals(1, list.size());
}
Also used : KieBase(org.kie.api.KieBase) State(org.drools.mvel.compiler.State) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Cheese(org.drools.mvel.compiler.Cheese) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Aggregations

Person (org.drools.mvel.compiler.Person)196 Test (org.junit.Test)185 KieSession (org.kie.api.runtime.KieSession)178 KieBase (org.kie.api.KieBase)171 ArrayList (java.util.ArrayList)98 List (java.util.List)72 Cheese (org.drools.mvel.compiler.Cheese)46 FactHandle (org.kie.api.runtime.rule.FactHandle)38 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)34 Address (org.drools.mvel.compiler.Address)33 FactWithString (org.drools.mvel.integrationtests.facts.FactWithString)24 InternalFactHandle (org.drools.core.common.InternalFactHandle)23 KiePackage (org.kie.api.definition.KiePackage)18 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)16 IteratorToList (org.drools.mvel.integrationtests.IteratorToList)15 HashMap (java.util.HashMap)12 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)12 Collection (java.util.Collection)11 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)8 AlphaNode (org.drools.core.reteoo.AlphaNode)8