Search in sources :

Example 26 with Person

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

the class AlphaNodeTest method testAlphaModifyDelete.

@Test
public void testAlphaModifyDelete() {
    String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setName(\"Mark\")}" + "end\n" + "rule R2 when\n" + "  $p : Person(name == \"Mark\")\n" + "then\n" + "  delete($p);" + "end\n" + "rule R3 when\n" + "  not( Person() )\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("Mario"));
    assertEquals(3, ksession.fireAllRules());
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 27 with Person

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

the class AlphaNodeTest method testSharedAlpha.

@Test
public void testSharedAlpha() {
    String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "end\n" + "rule R2 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("Mario"));
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 28 with Person

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

the class AlphaNodeTest method test3Alpha.

@Test
public void test3Alpha() {
    String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setAge(2) }" + "  modify($p) { setAge(2) }" + "end\n" + "rule R3 when\n" + "  $p : Person(age > 1)\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("Mario", 0));
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 29 with Person

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

the class AlphaNodeTest method testBetaModifyWithAlpha.

@Test
public void testBetaModifyWithAlpha() {
    String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "  $s : String(this == $p.name)\n" + "then\n" + "  modify($p) { setName(\"Mark\") }" + "end\n" + "rule R2 when\n" + "  $p : Person(name == \"Mark\")\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("Mario"));
    ksession.insert("Mario");
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 30 with Person

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

the class AlphaNodeTest method testAlphaModifyWithBeta.

@Test
public void testAlphaModifyWithBeta() {
    String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setName(\"Mark\") }" + "end\n" + "rule R2 when\n" + "  $p : Person(name == \"Mark\")\n" + "  $s : String(this == $p.name)\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("Mario"));
    ksession.insert("Mark");
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) 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