use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class CompilerTest method testSimpleInsertDeleteExplicitScope.
@Test
public void testSimpleInsertDeleteExplicitScope() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( name.length == 4 )\n" + "then\n" + " Result r = new Result($p.getName());" + " drools.insert(r);\n" + " drools.delete($p);\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mark", 37));
ksession.insert(new Person("Mario", 40));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Mark", results.iterator().next().getValue());
assertEquals(1, getObjectsIntoList(ksession, Person.class).size());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class CompilerTest method testEmptyPatternWithBinding.
@Test
public void testEmptyPatternWithBinding() {
String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person() \n" + "then\n" + " insert(new Result($p.getName()));\n" + "end";
KieSession ksession = getKieSession(str);
Person mario = new Person("Mario", 40);
ksession.insert(mario);
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 CompilerTest method testSimpleInsertWithProperties.
@Test
public void testSimpleInsertWithProperties() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address.city.startsWith(\"M\"))\n" + "then\n" + " Result r = new Result($p.getName());" + " insert(r);\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("Mark", 37, new Address("London")));
ksession.insert(new Person("Luca", 32, new Address("Milan")));
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("Luca", results.iterator().next().getValue());
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class CompilerTest method testOrWithFixedLeftOperand.
@Test
public void testOrWithFixedLeftOperand() {
String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person(name == \"Mario\" || == \"Luca\" || == \"Edoardo\")\n" + "then\n" + " insert(new Result($p));\n" + "end";
KieSession ksession = getKieSession(str);
final Person mario = new Person("Mario", 40);
final Person luca = new Person("Luca", 33);
final Person edoardo = new Person("Edoardo", 31);
final Person matteo = new Person("Matteo", 36);
ksession.insert(mario);
ksession.insert(luca);
ksession.insert(edoardo);
ksession.insert(matteo);
ksession.fireAllRules();
Collection<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(3, results.size());
Assertions.assertThat(results.stream().map(r -> r.getValue())).containsExactlyInAnyOrder(mario, luca, edoardo);
}
use of org.drools.modelcompiler.domain.Result in project drools by kiegroup.
the class CompilerTest method testNullSafeDereferncing2.
@Test
@Ignore("the codegen does not support it yet")
public void testNullSafeDereferncing2() {
String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address!.city.startsWith(\"M\") )\n" + "then\n" + " Result r = new Result($p.getName());" + " insert(r);\n" + "end";
KieSession ksession = getKieSession(str);
ksession.insert(new Person("John1", 41, null));
ksession.insert(new Person("John2", 42, new Address("Milan")));
ksession.fireAllRules();
List<Result> results = getObjectsIntoList(ksession, Result.class);
assertEquals(1, results.size());
assertEquals("John2", results.get(0).getValue());
}
Aggregations