Search in sources :

Example 16 with Address

use of org.drools.modelcompiler.domain.Address in project drools by kiegroup.

the class CompilerTest method testChainFieldAccessorsAndMethodCall.

@Test
public void testChainFieldAccessorsAndMethodCall() {
    String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + "  $p : Person( address.getCity().length == 5 )\n" + "then\n" + "  insert(\"matched\");\n" + "end";
    KieSession ksession = getKieSession(str);
    Person john = new Person("John", 47);
    Address a = new Address("Italy");
    john.setAddress(a);
    ksession.insert(john);
    ksession.fireAllRules();
    Collection<String> results = getObjectsIntoList(ksession, String.class);
    assertEquals(1, results.size());
}
Also used : Address(org.drools.modelcompiler.domain.Address) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.modelcompiler.domain.Person) Test(org.junit.Test)

Example 17 with Address

use of org.drools.modelcompiler.domain.Address in project drools by kiegroup.

the class CompilerTest method testChainOfMethodCallInConstraint.

@Test
public void testChainOfMethodCallInConstraint() {
    String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + "  $p : Person( getAddress().getCity().length() == 5 )\n" + "then\n" + "  insert(\"matched\");\n" + "end";
    KieSession ksession = getKieSession(str);
    Person john = new Person("John", 47);
    Address a = new Address("Italy");
    john.setAddress(a);
    ksession.insert(john);
    ksession.fireAllRules();
    Collection<String> results = getObjectsIntoList(ksession, String.class);
    assertEquals(1, results.size());
}
Also used : Address(org.drools.modelcompiler.domain.Address) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.modelcompiler.domain.Person) Test(org.junit.Test)

Aggregations

Address (org.drools.modelcompiler.domain.Address)17 Test (org.junit.Test)17 KieSession (org.kie.api.runtime.KieSession)17 ArrayList (java.util.ArrayList)10 Employee (org.drools.modelcompiler.domain.Employee)10 Employee.createEmployee (org.drools.modelcompiler.domain.Employee.createEmployee)10 InternationalAddress (org.drools.modelcompiler.domain.InternationalAddress)7 Person (org.drools.modelcompiler.domain.Person)7 Result (org.drools.modelcompiler.domain.Result)3 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Assertions (org.assertj.core.api.Assertions)1