use of org.drools.modelcompiler.domain.PetPerson in project drools by kiegroup.
the class FromTest method testGlobalInFromExpression.
@Test
public void testGlobalInFromExpression() {
// DROOLS-4999
String str = "package org.drools.compiler.test \n" + "import " + PetPerson.class.getCanonicalName() + "\n" + "import " + Pet.class.getCanonicalName() + "\n" + "global String petName;\n" + "rule R\n" + "when\n" + " $p : PetPerson ( )\n" + " $pet : Pet ( type == Pet.PetType.dog ) from $p.getPet(petName)\n" + "then\n" + "end \n";
KieSession ksession = getKieSession(str);
ksession.setGlobal("petName", "Dog");
PetPerson petPerson = new PetPerson("me");
Map<String, Pet> petMap = new HashMap<>();
petMap.put("Dog", new Pet(Pet.PetType.dog));
petMap.put("Cat", new Pet(Pet.PetType.cat));
petPerson.setPets(petMap);
ksession.insert(petPerson);
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.PetPerson in project drools by kiegroup.
the class FromTest method testFromMapValues.
@Test
public void testFromMapValues() {
// DROOLS-3661
String str = "package org.drools.compiler.test \n" + "import " + PetPerson.class.getCanonicalName() + "\n" + "import " + Pet.class.getCanonicalName() + "\n" + "rule R\n" + "when\n" + " $p : PetPerson ( )\n" + " $pet : Pet ( type == Pet.PetType.dog ) from $p.getPets().values()\n\n" + "then\n" + "end \n";
KieSession ksession = getKieSession(str);
PetPerson petPerson = new PetPerson("me");
Map<String, Pet> petMap = new HashMap<>();
petMap.put("Dog", new Pet(Pet.PetType.dog));
petMap.put("Cat", new Pet(Pet.PetType.cat));
petPerson.setPets(petMap);
ksession.insert(petPerson);
assertEquals(1, ksession.fireAllRules());
}
Aggregations