use of org.drools.compiler.Cat in project drools by kiegroup.
the class AlphaNetworkModifyTest method testModifyWithLiaToEval.
@Test
public void testModifyWithLiaToEval() {
String str = "";
str += "package org.simple \n";
str += "import " + Person.class.getCanonicalName() + "\n";
str += "import " + Cheese.class.getCanonicalName() + "\n";
str += "import " + Cat.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule x1 \n";
str += "when \n";
str += " $pe : Person() \n";
str += " $ch : Cheese() \n";
str += " $ca : Cat() \n";
str += "then \n";
str += "end \n";
str += "rule x2 \n";
str += "when \n";
str += " $ch : Cheese() \n";
str += " $ca : Cat() \n";
str += " $pe : Person() \n";
str += "then \n";
str += "end \n";
str += "rule x3 \n";
str += "when \n";
str += " $ch : Cheese() \n";
str += "then \n";
str += "end \n";
str += "rule x4 \n";
str += "when \n";
str += " $ch : Cheese() \n";
str += " eval( $ch != null ) \n";
str += "then \n";
str += "end \n";
KieBase kbase = loadKnowledgeBaseFromString(str);
KieSession wm = kbase.newKieSession();
ObjectTypeNode otnPerson = getObjectTypeNode(kbase, "Person");
ObjectTypeNode otnCheese = getObjectTypeNode(kbase, "Cheese");
ObjectTypeNode otnCat = getObjectTypeNode(kbase, "Cat");
assertEquals(0, otnPerson.getOtnIdCounter());
assertEquals(0, otnCheese.getOtnIdCounter());
assertEquals(0, otnCat.getOtnIdCounter());
wm.insert(new Person());
wm.insert(new Cat("yyy"));
wm.insert(new Cheese());
wm.fireAllRules();
assertEquals(2, otnPerson.getOtnIdCounter());
assertEquals(4, otnCheese.getOtnIdCounter());
assertEquals(2, otnCat.getOtnIdCounter());
}
use of org.drools.compiler.Cat in project drools by kiegroup.
the class FieldAccessTest method testAccessFieldsFromSubClass.
@Test
public // unless typesafe=false is used
void testAccessFieldsFromSubClass() throws Exception {
String rule = "";
rule += "package org.drools.compiler;\n";
rule += "import org.drools.compiler.Person;\n";
rule += "import org.drools.compiler.Pet;\n";
rule += "import org.drools.compiler.Cat;\n";
rule += "declare Person @typesafe(false) end\n";
rule += "rule \"Test Rule\"\n";
rule += "when\n";
rule += " Person(\n";
rule += " pet.breed == \"Siamise\"\n";
rule += " )\n";
rule += "then\n";
rule += " System.out.println(\"hello person\");\n";
rule += "end";
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBaseFromString(rule));
final KieSession session = createKnowledgeSession(kbase);
final Person person = new Person();
person.setPet(new Cat("Mittens"));
session.insert(person);
session.fireAllRules();
}
Aggregations