Search in sources :

Example 1 with Interval

use of org.drools.mvel.compiler.Interval in project drools by kiegroup.

the class QueryTest method testQueryWithEval.

@Test
public void testQueryWithEval() throws IOException, ClassNotFoundException {
    // [Regression in 5.2.0.M2]: NPE during rule evaluation on MVELPredicateExpression.evaluate(MVELPredicateExpression.java:82)
    String str = "package org.drools.mvel.integrationtests\n" + "import " + DomainObject.class.getCanonicalName() + " \n" + "query queryWithEval \n" + "    $do: DomainObject()\n" + "    not DomainObject( id == $do.id, eval(interval.isAfter($do.getInterval())))\n" + "end";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    DomainObject do1 = new DomainObject();
    do1.setId(1);
    do1.setInterval(new Interval(10, 5));
    DomainObject do2 = new DomainObject();
    do2.setId(1);
    do2.setInterval(new Interval(20, 5));
    ksession.insert(do1);
    ksession.insert(do2);
    org.kie.api.runtime.rule.QueryResults results = ksession.getQueryResults("queryWithEval");
    assertEquals(1, results.size());
    assertEquals(do2, results.iterator().next().get("$do"));
    ksession.dispose();
}
Also used : QueryResults(org.kie.api.runtime.rule.QueryResults) KieBase(org.kie.api.KieBase) DomainObject(org.drools.mvel.compiler.DomainObject) KieSession(org.kie.api.runtime.KieSession) Interval(org.drools.mvel.compiler.Interval) Test(org.junit.Test)

Aggregations

DomainObject (org.drools.mvel.compiler.DomainObject)1 Interval (org.drools.mvel.compiler.Interval)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 QueryResults (org.kie.api.runtime.rule.QueryResults)1