Search in sources :

Example 1 with InsertedObject

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

the class QueryTest method testQuery2.

@Test
public void testQuery2() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Query.drl");
    KieSession session = kbase.newKieSession();
    session.fireAllRules();
    QueryResults results = getQueryResults(session, "assertedobjquery");
    assertEquals(1, results.size());
    assertEquals(new InsertedObject("value1"), results.iterator().next().get("assertedobj"));
}
Also used : InsertedObject(org.drools.mvel.compiler.InsertedObject) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Test(org.junit.Test)

Example 2 with InsertedObject

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

the class QueryTest method testQueryWithParams.

@Test
public void testQueryWithParams() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_QueryWithParams.drl");
    KieSession session = kbase.newKieSession();
    session.fireAllRules();
    String queryName = "assertedobjquery";
    String[] arguments = new String[] { "value1" };
    QueryResultsImpl resultsImpl = (QueryResultsImpl) session.getQueryResults(queryName, arguments);
    QueryResults results = getQueryResults(session, queryName, arguments);
    assertEquals(1, results.size());
    InsertedObject value = new InsertedObject("value1");
    assertEquals(value, results.iterator().next().get("assertedobj"));
    results = getQueryResults(session, "assertedobjquery", new String[] { "value3" });
    assertEquals(0, results.size());
    results = getQueryResults(session, "assertedobjquery2", new String[] { null, "value2" });
    assertEquals(1, results.size());
    assertEquals(new InsertedObject("value2"), results.iterator().next().get("assertedobj"));
    results = getQueryResults(session, "assertedobjquery2", new String[] { "value3", "value2" });
    assertEquals(1, results.size());
    assertEquals(new InsertedObject("value2"), results.iterator().next().get("assertedobj"));
}
Also used : QueryResultsImpl(org.drools.core.QueryResultsImpl) InsertedObject(org.drools.mvel.compiler.InsertedObject) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Test(org.junit.Test)

Aggregations

FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)2 InsertedObject (org.drools.mvel.compiler.InsertedObject)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 KieSession (org.kie.api.runtime.KieSession)2 QueryResults (org.kie.api.runtime.rule.QueryResults)2 QueryResultsImpl (org.drools.core.QueryResultsImpl)1