use of org.drools.modelcompiler.domain.Address in project drools by kiegroup.
the class MvelDialectTest method testMVELmultipleStatements.
@Test
public void testMVELmultipleStatements() {
String str = // keep the package.* in order for Address to be resolvable in the RHS.
"import " + Person.class.getPackage().getName() + ".*;\n" + "rule R\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " Address a = new Address(\"somewhere\");\n" + " insert(a);\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Matteo", 47));
ksession.fireAllRules();
List<Address> results = getObjectsIntoList(ksession, Address.class);
assertEquals(1, results.size());
}
use of org.drools.modelcompiler.domain.Address in project drools by kiegroup.
the class OOPathTest 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" + " $emp: Employee( $address: /address[ street == 'Elm' || city == 'Big City' ] )\n" + " Employee( this != $emp, /address[ street == 'Elm' || 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.Address in project drools by kiegroup.
the class OOPathTest method testOrConditionalElementNoBinding.
@Test
public void testOrConditionalElementNoBinding() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " $employee: (\n" + " Employee( /address[ city == 'Big City' ] )\n" + " or " + " Employee( /address[ city == 'Small City' ] )\n" + " )\n" + "then\n" + " list.add( $employee.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.Address in project drools by kiegroup.
the class OOPathTest method testOOPathMultipleConditions.
@Test
public void testOOPathMultipleConditions() {
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[ street == 'Elm', 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");
}
use of org.drools.modelcompiler.domain.Address in project drools by kiegroup.
the class OOPathTest method testOOPathMultipleConditionsWithBinding.
@Test
public void testOOPathMultipleConditionsWithBinding() {
final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "global java.util.List list\n" + "\n" + "rule R when\n" + " $employee: (\n" + " Employee( /address[ street == 'Elm', city == 'Big City' ] )\n" + " )\n" + "then\n" + " list.add( $employee.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("Alice");
}
Aggregations