Search in sources :

Example 31 with Address

use of org.drools.compiler.Address in project drools by kiegroup.

the class FieldAccessTest method testGenericsOption.

@Test
public void testGenericsOption() throws Exception {
    // JBRULES-3579
    final String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   $c : Cheese( $type: type )\n" + "   $p : Person( $name : name, addressOption.get.street == $type )\n" + "then\n" + "end\n";
    final KieBase kbase = loadKnowledgeBaseFromString(str);
    final KieSession ksession = kbase.newKieSession();
    final Person p = new Person("x");
    p.setAddress(new Address("x", "x", "x"));
    ksession.insert(p);
    ksession.insert(new Cheese("x"));
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}
Also used : Address(org.drools.compiler.Address) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 32 with Address

use of org.drools.compiler.Address in project drools by kiegroup.

the class UpdateTest method testModifyBlockWithFrom.

@Test
public void testModifyBlockWithFrom() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ModifyBlockWithFrom.drl"));
    final KieSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    final Person bob = new Person("Bob");
    final Address addr = new Address("abc");
    bob.addAddress(addr);
    ksession.insert(bob);
    ksession.insert(addr);
    ksession.fireAllRules();
    // modify worked
    assertEquals("12345", addr.getZipCode());
    // chaining worked
    assertEquals(1, results.size());
    assertEquals(addr, results.get(0));
}
Also used : Address(org.drools.compiler.Address) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Person(org.drools.compiler.Person) Test(org.junit.Test)

Aggregations

Address (org.drools.compiler.Address)32 Person (org.drools.compiler.Person)30 Test (org.junit.Test)30 KieSession (org.kie.api.runtime.KieSession)30 KieBase (org.kie.api.KieBase)22 ArrayList (java.util.ArrayList)16 List (java.util.List)12 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)7 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)7 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)7 MVELObjectClassFieldReader (org.drools.core.base.extractors.MVELObjectClassFieldReader)4 AlphaNode (org.drools.core.reteoo.AlphaNode)4 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)4 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4 Cheese (org.drools.compiler.Cheese)3 KieHelper (org.kie.internal.utils.KieHelper)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 KiePackage (org.kie.api.definition.KiePackage)2 InputStreamReader (java.io.InputStreamReader)1