use of org.drools.modelcompiler.domain.InternationalAddress in project drools by kiegroup.
the class InlineCastTest method testInlineCastForAFieldAndMixMethodCall.
@Test
public void testInlineCastForAFieldAndMixMethodCall() {
String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address#InternationalAddress.getState().length == 5 )\n" + "then\n" + " insert(\"matched\");\n" + "end";
KieSession ksession = getKieSession(str);
Person john = new Person("John", 47);
InternationalAddress a = new InternationalAddress("address", "Italy");
john.setAddress(a);
ksession.insert(john);
ksession.fireAllRules();
Collection<String> results = getObjectsIntoList(ksession, String.class);
assertEquals(1, results.size());
}
use of org.drools.modelcompiler.domain.InternationalAddress in project drools by kiegroup.
the class InlineCastTest method testInlineCastForAField.
@Test
public void testInlineCastForAField() {
String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address#InternationalAddress.state.length == 5 )\n" + "then\n" + " insert(\"matched\");\n" + "end";
KieSession ksession = getKieSession(str);
Person john = new Person("John", 47);
InternationalAddress a = new InternationalAddress("address", "Italy");
john.setAddress(a);
ksession.insert(john);
ksession.fireAllRules();
Collection<String> results = getObjectsIntoList(ksession, String.class);
assertEquals(1, results.size());
}
use of org.drools.modelcompiler.domain.InternationalAddress in project drools by kiegroup.
the class OOPathFlowTest method testOOPathCast.
@Test
public void testOOPathCast() {
Global<List> listG = globalOf(List.class, "defaultpkg", "list");
Variable<Man> manV = declarationOf(Man.class, "$man");
// Drools doc: In this way subsequent constraints can also safely access to properties declared only in that subclass
Variable<InternationalAddress> addressV = declarationOf(InternationalAddress.class, "$italy", reactiveFrom(manV, Man::getAddress));
Rule rule = rule("oopath").build(expr("exprA", addressV, c -> c.getState().equals("Italy")), on(manV, listG).execute((t, l) -> l.add(t.getName())));
Model model = new ModelImpl().addGlobal(listG).addRule(rule);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model);
KieSession ksession = kieBase.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("Bob", 40);
bob.setAddress(new InternationalAddress("Via Verdi", "Italy"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("Bob");
}
use of org.drools.modelcompiler.domain.InternationalAddress in project drools by kiegroup.
the class OOPathTest method testSimpleOOPathCast3.
@Test
public void testSimpleOOPathCast3() {
final String str = "import org.drools.modelcompiler.domain.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $italy: /address#InternationalAddress[ state == \"Italy\" ], $name : name != null )\n" + "then\n" + " list.add( $name );\n" + "end\n";
KieSession ksession = getKieSession(str);
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("Bob", 40);
bob.setAddress(new InternationalAddress("Via Verdi", "Italy"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("Bob");
}
use of org.drools.modelcompiler.domain.InternationalAddress in project drools by kiegroup.
the class OOPathTest method testSimpleOOPathCast1.
@Test
public void testSimpleOOPathCast1() {
final String str = "import org.drools.modelcompiler.domain.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " $man : Man( $italy: /address#InternationalAddress[ state == \"Italy\" ] )\n" + "then\n" + " list.add( $man.getName() );\n" + "end\n";
KieSession ksession = getKieSession(str);
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Man bob = new Man("Bob", 40);
bob.setAddress(new InternationalAddress("Via Verdi", "Italy"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("Bob");
}
Aggregations