use of org.drools.compiler.LongAddress in project drools by kiegroup.
the class RuleUnitTest method testTwoPartsOOPath.
@Test
public void testTwoPartsOOPath() throws Exception {
// DROOLS-1539
String drl1 = "package org.drools.compiler.integrationtests\n" + "unit " + getCanonicalSimpleName(AdultUnit.class) + "\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + LongAddress.class.getCanonicalName() + "\n" + "rule Adult when\n" + " $a: /persons[ age > 18 ]/addresses#LongAddress[ country == \"it\" ]\n" + "then\n" + " System.out.println($a.getCountry());\n" + "end";
KieBase kbase = new KieHelper(PropertySpecificOption.ALWAYS).addContent(drl1, ResourceType.DRL).build();
RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
Person mario = new Person("Mario", 43);
mario.setAddresses(asList(new LongAddress("street", "suburb", "zipCode", "it")));
Person mark = new Person("Mark", 40);
mark.setAddresses(asList(new LongAddress("street", "suburb", "zipCode", "uk")));
DataSource<Person> persons = executor.newDataSource("persons", mario, mark);
assertEquals(1, executor.run(AdultUnit.class));
}
use of org.drools.compiler.LongAddress in project drools by kiegroup.
the class RuleUnitTest method testNestedOOPath.
@Test
public void testNestedOOPath() throws Exception {
// DROOLS-1539
String drl1 = "package org.drools.compiler.integrationtests\n" + "unit " + getCanonicalSimpleName(AdultUnit.class) + "\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + LongAddress.class.getCanonicalName() + "\n" + "rule Adult when\n" + " $p: /persons[ age > 18, $a: /addresses#LongAddress[ country == \"it\" ] ]\n" + "then\n" + " System.out.println($p.getName() + \" is in \" + $a.getCountry());\n" + "end";
KieBase kbase = new KieHelper(PropertySpecificOption.ALWAYS).addContent(drl1, ResourceType.DRL).build();
RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
Person mario = new Person("Mario", 43);
mario.setAddresses(asList(new LongAddress("street", "suburb", "zipCode", "it")));
Person mark = new Person("Mark", 40);
mark.setAddresses(asList(new LongAddress("street", "suburb", "zipCode", "uk")));
DataSource<Person> persons = executor.newDataSource("persons", mario, mark);
assertEquals(1, executor.run(AdultUnit.class));
}
use of org.drools.compiler.LongAddress in project drools by kiegroup.
the class InstanceOfTest method testInstanceof.
@Test
public void testInstanceof() throws Exception {
// JBRULES-3591
final String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + " Person( address instanceof LongAddress )\n" + "then\n" + "end\n";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = kbase.newKieSession();
final Person mark = new Person("mark");
mark.setAddress(new LongAddress("uk"));
ksession.insert(mark);
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
}
Aggregations