Search in sources :

Example 1 with BabyGirl

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

the class OOPathCastTest method testInlineCast.

@Test
public void testInlineCast() {
    final String drl = "import org.drools.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( $toy: /wife/children#BabyGirl/toys )\n" + "then\n" + "  list.add( $toy.getName() );\n" + "end\n";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().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);
    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("doll");
}
Also used : ArrayList(java.util.ArrayList) BabyBoy(org.drools.compiler.oopath.model.BabyBoy) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.compiler.oopath.model.Man) Woman(org.drools.compiler.oopath.model.Woman) BabyGirl(org.drools.compiler.oopath.model.BabyGirl) Toy(org.drools.compiler.oopath.model.Toy) Test(org.junit.Test)

Example 2 with BabyGirl

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

the class OOPathCastTest method testInlineCastWithConstraint.

@Test
public void testInlineCastWithConstraint() {
    final String drl = "import org.drools.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";
    final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().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 : ArrayList(java.util.ArrayList) BabyBoy(org.drools.compiler.oopath.model.BabyBoy) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Man(org.drools.compiler.oopath.model.Man) Woman(org.drools.compiler.oopath.model.Woman) BabyGirl(org.drools.compiler.oopath.model.BabyGirl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 BabyBoy (org.drools.compiler.oopath.model.BabyBoy)2 BabyGirl (org.drools.compiler.oopath.model.BabyGirl)2 Man (org.drools.compiler.oopath.model.Man)2 Woman (org.drools.compiler.oopath.model.Woman)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 KieHelper (org.kie.internal.utils.KieHelper)2 Toy (org.drools.compiler.oopath.model.Toy)1