Search in sources :

Example 1 with LongAddress

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));
}
Also used : InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) LongAddress(org.drools.compiler.LongAddress) KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 2 with LongAddress

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));
}
Also used : InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) LongAddress(org.drools.compiler.LongAddress) KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 3 with LongAddress

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();
}
Also used : KieBase(org.kie.api.KieBase) LongAddress(org.drools.compiler.LongAddress) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) Test(org.junit.Test)

Aggregations

LongAddress (org.drools.compiler.LongAddress)3 Person (org.drools.compiler.Person)3 Test (org.junit.Test)3 KieBase (org.kie.api.KieBase)3 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)2 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)2 KieHelper (org.kie.internal.utils.KieHelper)2 KieSession (org.kie.api.runtime.KieSession)1