Search in sources :

Example 1 with PetPerson

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());
}
Also used : PetPerson(org.drools.modelcompiler.domain.PetPerson) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Pet(org.drools.modelcompiler.domain.Pet) Test(org.junit.Test)

Example 2 with PetPerson

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());
}
Also used : PetPerson(org.drools.modelcompiler.domain.PetPerson) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Pet(org.drools.modelcompiler.domain.Pet) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Pet (org.drools.modelcompiler.domain.Pet)2 PetPerson (org.drools.modelcompiler.domain.PetPerson)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2