Search in sources :

Example 16 with Woman

use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.

the class OOPathReactiveTest method testAllNonReactiveAfterNonReactivePart.

@Test
public void testAllNonReactiveAfterNonReactivePart() {
    final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( $toy: ?/wife/children[age > 10]/toys )\n" + "then\n" + "  list.add( $toy.getName() );\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    KieSession ksession = kbase.newKieSession();
    final List<String> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    final Woman alice = new Woman("Alice", 38);
    final Man bob = new Man("Bob", 40);
    bob.setWife(alice);
    final Child charlie = new Child("Charles", 12);
    final Child debbie = new Child("Debbie", 10);
    alice.addChild(charlie);
    alice.addChild(debbie);
    charlie.addToy(new Toy("car"));
    charlie.addToy(new Toy("ball"));
    debbie.addToy(new Toy("doll"));
    ksession.insert(bob);
    ksession.fireAllRules();
    Assertions.assertThat(list).containsExactlyInAnyOrder("car", "ball");
    list.clear();
    charlie.addToy(new Toy("robot"));
    ksession.fireAllRules();
    Assertions.assertThat(list).isEmpty();
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.mvel.compiler.oopath.model.Man) Woman(org.drools.mvel.compiler.oopath.model.Woman) Child(org.drools.mvel.compiler.oopath.model.Child) Toy(org.drools.mvel.compiler.oopath.model.Toy) Test(org.junit.Test)

Example 17 with Woman

use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.

the class OOPathCastTest method testInlineCastWithConstraint.

@Test
public void testInlineCastWithConstraint() {
    final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( name == \"Bob\", $name: /wife/children#BabyGirl[ favoriteDollName.startsWith(\"A\") ].name )\n" + "then\n" + "  list.add( $name );\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    KieSession ksession = kbase.newKieSession();
    final List<String> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    final Woman alice = new Woman("Alice", 38);
    final Man bob = new Man("Bob", 40);
    bob.setWife(alice);
    final BabyBoy charlie = new BabyBoy("Charles", 12);
    final BabyGirl debbie = new BabyGirl("Debbie", 8, "Anna");
    final BabyGirl elisabeth = new BabyGirl("Elisabeth", 5, "Zoe");
    final BabyGirl farrah = new BabyGirl("Farrah", 3, "Agatha");
    alice.addChild(charlie);
    alice.addChild(debbie);
    alice.addChild(elisabeth);
    alice.addChild(farrah);
    ksession.insert(bob);
    ksession.fireAllRules();
    Assertions.assertThat(list).containsExactlyInAnyOrder("Debbie", "Farrah");
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) BabyBoy(org.drools.mvel.compiler.oopath.model.BabyBoy) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.mvel.compiler.oopath.model.Man) Woman(org.drools.mvel.compiler.oopath.model.Woman) BabyGirl(org.drools.mvel.compiler.oopath.model.BabyGirl) Test(org.junit.Test)

Example 18 with Woman

use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.

the class OOPathBindTest method testBindListWithConstraint.

@Test
public void testBindListWithConstraint() {
    final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( $toys: /wife/children[age > 10].toys )\n" + "then\n" + "  list.add( $toys.size() );\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    KieSession ksession = kbase.newKieSession();
    final List<Integer> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    final Woman alice = new Woman("Alice", 38);
    final Man bob = new Man("Bob", 40);
    bob.setWife(alice);
    final Child charlie = new Child("Charles", 12);
    final Child debbie = new Child("Debbie", 8);
    alice.addChild(charlie);
    alice.addChild(debbie);
    charlie.addToy(new Toy("car"));
    charlie.addToy(new Toy("ball"));
    debbie.addToy(new Toy("doll"));
    ksession.insert(bob);
    ksession.fireAllRules();
    Assertions.assertThat(list).containsExactlyInAnyOrder(2);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.mvel.compiler.oopath.model.Man) Woman(org.drools.mvel.compiler.oopath.model.Woman) Child(org.drools.mvel.compiler.oopath.model.Child) Toy(org.drools.mvel.compiler.oopath.model.Toy) Test(org.junit.Test)

Example 19 with Woman

use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.

the class OOPathBindTest method testBindList.

@Test
public void testBindList() {
    final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( $toys: /wife/children.toys )\n" + "then\n" + "  list.add( $toys.size() );\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    KieSession ksession = kbase.newKieSession();
    final List<Integer> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    final Woman alice = new Woman("Alice", 38);
    final Man bob = new Man("Bob", 40);
    bob.setWife(alice);
    final Child charlie = new Child("Charles", 12);
    final Child debbie = new Child("Debbie", 8);
    alice.addChild(charlie);
    alice.addChild(debbie);
    charlie.addToy(new Toy("car"));
    charlie.addToy(new Toy("ball"));
    debbie.addToy(new Toy("doll"));
    ksession.insert(bob);
    ksession.fireAllRules();
    Assertions.assertThat(list).containsExactlyInAnyOrder(1, 2);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.mvel.compiler.oopath.model.Man) Woman(org.drools.mvel.compiler.oopath.model.Woman) Child(org.drools.mvel.compiler.oopath.model.Child) Toy(org.drools.mvel.compiler.oopath.model.Toy) Test(org.junit.Test)

Example 20 with Woman

use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.

the class OOPathMultilevelTest method testScenarioTwoLevelPathWithConstraint.

private void testScenarioTwoLevelPathWithConstraint(final String drl) {
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
    KieSession ksession = kbase.newKieSession();
    final List<String> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    final Woman alice = new Woman("Alice", 38);
    final Man bob = new Man("Bob", 40);
    bob.setWife(alice);
    final Child charlie = new Child("Charlie", 12);
    alice.addChild(charlie);
    final Child debbie = new Child("Debbie", 8);
    alice.addChild(debbie);
    final Child eric = new Child("Eric", 15);
    alice.addChild(eric);
    charlie.addToy(new Toy("car"));
    charlie.addToy(new Toy("ball"));
    debbie.addToy(new Toy("doll"));
    eric.addToy(new Toy("bike"));
    ksession.insert(5);
    ksession.insert(bob);
    ksession.fireAllRules();
    Assertions.assertThat(list).containsExactlyInAnyOrder("car", "ball");
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.mvel.compiler.oopath.model.Man) Woman(org.drools.mvel.compiler.oopath.model.Woman) Child(org.drools.mvel.compiler.oopath.model.Child) Toy(org.drools.mvel.compiler.oopath.model.Toy)

Aggregations

Man (org.drools.mvel.compiler.oopath.model.Man)24 Woman (org.drools.mvel.compiler.oopath.model.Woman)24 ArrayList (java.util.ArrayList)23 KieBase (org.kie.api.KieBase)23 KieSession (org.kie.api.runtime.KieSession)23 Test (org.junit.Test)21 Child (org.drools.mvel.compiler.oopath.model.Child)18 Toy (org.drools.mvel.compiler.oopath.model.Toy)17 BabyBoy (org.drools.mvel.compiler.oopath.model.BabyBoy)2 BabyGirl (org.drools.mvel.compiler.oopath.model.BabyGirl)2 ClassObjectType (org.drools.core.base.ClassObjectType)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 EntryPointNode (org.drools.core.reteoo.EntryPointNode)1 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)1 LeftTuple (org.drools.core.reteoo.LeftTuple)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 ReactiveFromNode (org.drools.core.reteoo.ReactiveFromNode)1 TupleMemory (org.drools.core.reteoo.TupleMemory)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 Disease (org.drools.mvel.compiler.oopath.model.Disease)1