use of org.drools.compiler.oopath.model.BabyBoy 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");
}
use of org.drools.compiler.oopath.model.BabyBoy 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");
}
Aggregations