use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class EvalTest method testEvalWith2BindingsInvokingMethod.
@Test
public void testEvalWith2BindingsInvokingMethod() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p1 : Person( age == 40 )\n" + " $p2 : Person( age == 38 )\n" + " eval( $p1.getName().equals( $p2.getName() ) )\n" + "then\n" + " insert(new Result($p1.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mario", 40));
ksession.insert(new Person("Mario", 38));
ksession.insert(new Person("Edson", 35));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next().getValue());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class EvalTest method testEvalWithDeclaration.
@Test
public void testEvalWithDeclaration() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p1 : Person( $a1 : age )\n" + " eval( $a1 > 39 )\n" + "then\n" + " insert(new Result($p1.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mario", 40));
ksession.insert(new Person("Mark", 38));
ksession.insert(new Person("Edson", 35));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next().getValue());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class EvalTest method testEval.
@Test
public void testEval() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person()\n" + " eval( $p.getAge() == 40 )\n" + "then\n" + " insert(new Result($p.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mario", 40));
ksession.insert(new Person("Mark", 37));
ksession.insert(new Person("Edson", 35));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next().getValue());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class EvalTest method testEvalWith2Bindings.
@Test
public void testEvalWith2Bindings() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p1 : Person( name == \"Mario\" )\n" + " $p2 : Person( name == \"Mark\" )\n" + " eval( $p1.getAge() == $p2.getAge() + 2 )\n" + "then\n" + " insert(new Result($p1.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mario", 40));
ksession.insert(new Person("Mark", 38));
ksession.insert(new Person("Edson", 35));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next().getValue());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class EvalTest method testEvalWith2Declarations.
@Test
public void testEvalWith2Declarations() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p1 : Person( name == \"Mario\", $a1 : age > 0 )\n" + " $p2 : Person( name == \"Mark\", $a2 : age > 0 )\n" + " eval( $a1 == $a2 + 2 )\n" + "then\n" + " insert(new Result($p1.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mario", 40));
ksession.insert(new Person("Mark", 38));
ksession.insert(new Person("Edson", 35));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next().getValue());
}
Aggregations