use of org.drools.modelcompiler.domain.ToysStore in project drools by kiegroup.
the class FromTest method testFromOr.
@Test
public void testFromOr() {
String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Address.class.getCanonicalName() + "\n" + "import " + Toy.class.getCanonicalName() + "\n" + "import " + ToysStore.class.getCanonicalName() + "\n" + "global java.util.List list;\n" + "rule R\n" + "when\n" + " Person($age : age)\n" + " Address($c : city)\n" + " $store : ToysStore(cityName == $c)\n" + " (or Toy( targetAge == $age ) from $store.firstFloorToys \n" + " Toy( targetAge == $age ) from $store.secondFloorToys\n" + " )\n" + "then\n" + " list.add($store.getStoreName());\n" + "end \n";
KieSession ksession = getKieSession(str);
List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
ksession.insert(new Person("Leonardo", 3));
ksession.insert(new Address("Milan"));
Toy car = new Toy("Car", 3);
Toy bicycle = new Toy("Bicycle", 3);
Toy computer = new Toy("Computer", 7);
ksession.insert(car);
ksession.insert(bicycle);
ksession.insert(computer);
ToysStore ts = new ToysStore("Milan", "Toystore1");
ts.getFirstFloorToys().add(car);
ts.getSecondFloorToys().addAll(Arrays.asList(bicycle, computer));
ksession.insert(ts);
ksession.fireAllRules();
Assertions.assertThat(list).contains("Toystore1");
}
Aggregations