use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.
the class OOPathTest method testOrConditionalElement.
@Test
public void testOrConditionalElement() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Employee( $address: /address[ city == 'Big City' ] )\n" + " or " + " Employee( $address: /address[ city == 'Small City' ] )\n" + "then\n" + " list.add( $address.getCity() );\n" + "end\n";
KieSession kieSession = getKieSession(drl);
List<String> results = new ArrayList<>();
kieSession.setGlobal("list", results);
final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
kieSession.insert(bruno);
final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
kieSession.insert(alice);
kieSession.fireAllRules();
Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.
the class OOPathTest method testOrConstraintNoBinding.
@Test
public void testOrConstraintNoBinding() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " $emp: Employee( /address[ street == 'Elm' || city == 'Big City' ] )\n" + " Employee( this != $emp, /address[ street == 'Elm' || city == 'Big City' ] )\n" + "then\n" + " list.add( $emp.getName() );\n" + "end\n";
KieSession kieSession = getKieSession(drl);
List<String> results = new ArrayList<>();
kieSession.setGlobal("list", results);
final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
kieSession.insert(bruno);
final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
kieSession.insert(alice);
kieSession.fireAllRules();
Assertions.assertThat(results).containsExactlyInAnyOrder("Bruno", "Alice");
}
use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.
the class OOPathTest method testOrConstraintWithJoin.
@Test
public void testOrConstraintWithJoin() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " $emp: Employee( $address: /address[ street == 'Elm' || city == 'Big City' ] )\n" + " Employee( this != $emp, /address[ street == $address.street || city == 'Big City' ] )\n" + "then\n" + " list.add( $address.getCity() );\n" + "end\n";
KieSession kieSession = getKieSession(drl);
List<String> results = new ArrayList<>();
kieSession.setGlobal("list", results);
final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
kieSession.insert(bruno);
final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
kieSession.insert(alice);
kieSession.fireAllRules();
Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.
the class OrTest method testOrConstraint.
@Test
public void testOrConstraint() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Employee( $address: address, ( address.city == 'Big City' || address.city == 'Small City' ) )\n" + "then\n" + " list.add( $address.getCity() );\n" + "end\n";
KieSession kieSession = getKieSession(drl);
List<String> results = new ArrayList<>();
kieSession.setGlobal("list", results);
final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
kieSession.insert(bruno);
final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
kieSession.insert(alice);
kieSession.fireAllRules();
Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
use of org.drools.modelcompiler.domain.Employee in project drools by kiegroup.
the class OrTest method testOrConditional.
@Test
public void testOrConditional() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Employee( $address: address, address.city == 'Big City' )\n" + " or " + " Employee( $address: address, address.city == 'Small City' )\n" + "then\n" + " list.add( $address.getCity() );\n" + "end\n";
KieSession kieSession = getKieSession(drl);
List<String> results = new ArrayList<>();
kieSession.setGlobal("list", results);
final Employee bruno = createEmployee("Bruno", new Address("Elm", 10, "Small City"));
kieSession.insert(bruno);
final Employee alice = createEmployee("Alice", new Address("Elm", 10, "Big City"));
kieSession.insert(alice);
kieSession.fireAllRules();
Assertions.assertThat(results).containsExactlyInAnyOrder("Big City", "Small City");
}
Aggregations