use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.
the class OOPathBindTest method testScenarioBindString.
private void testScenarioBindString(final String drl, final String... expectedResults) {
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("Bob", 40);
final Woman alice = new Woman("Alice", 38);
ksession.insert(bob);
ksession.insert(alice);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder(expectedResults);
}
use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.
the class OOPathMultilevelTest method testClassThreeLevelPath.
@Test
public void testClassThreeLevelPath() {
final String drl = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toyName: /wife/children/toys/name )\n" + "then\n" + " list.add( $toyName );\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);
alice.addChild(charlie);
charlie.addToy(new Toy("car"));
charlie.addToy(new Toy("ball"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("car", "ball");
}
use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.
the class OOPathTest method testWithExists.
@Test
public void testWithExists() {
String header = "import org.drools.mvel.compiler.oopath.model.*;\n" + "global java.util.List list\n\n";
String drl1 = "rule R1 when\n" + " exists( Man( $m: /wife[age == 25] ) )\n" + "then\n" + " list.add(\"Found\");\n" + "end\n\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, header + drl1);
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("John", 25);
bob.setWife(new Woman("Jane", 25));
ksession.insert(bob);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Found", list.get(0));
list.clear();
}
use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.
the class OOPathTest method testBackReferenceConstraint.
@Test
public void testBackReferenceConstraint() {
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/toys[ name.length == ../name.length ] )\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("Carl", 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"));
debbie.addToy(new Toy("guitar"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("ball", "guitar");
}
use of org.drools.mvel.compiler.oopath.model.Woman in project drools by kiegroup.
the class OOPathTest method testIndexedAccess.
@Test
public void testIndexedAccess() {
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[0]/toys[1] )\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", 11);
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("ball");
}
Aggregations