Search in sources :

Example 1 with InsertedObject

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

the class QueryTest method testQueryWithParams.

@Test
public void testQueryWithParams() throws Exception {
    KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_QueryWithParams.drl"));
    KieSession session = createKieSession(kbase);
    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, ((InternalFactHandle) results.iterator().next().getFactHandle("assertedobj")).getObject());
    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"), ((InternalFactHandle) results.iterator().next().getFactHandle("assertedobj")).getObject());
    results = getQueryResults(session, "assertedobjquery2", new String[] { "value3", "value2" });
    assertEquals(1, results.size());
    assertEquals(new InsertedObject("value2"), ((InternalFactHandle) results.iterator().next().getFactHandle("assertedobj")).getObject());
}
Also used : QueryResultsImpl(org.drools.core.QueryResultsImpl) InsertedObject(org.drools.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.compiler.InsertedObject in project drools by kiegroup.

the class QueryTest method testQuery2.

@Test
public void testQuery2() throws Exception {
    KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_Query.drl"));
    KieSession session = createKieSession(kbase);
    session.fireAllRules();
    QueryResults results = getQueryResults(session, "assertedobjquery");
    assertEquals(1, results.size());
    assertEquals(new InsertedObject("value1"), ((InternalFactHandle) results.iterator().next().getFactHandle("assertedobj")).getObject());
}
Also used : InsertedObject(org.drools.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

InsertedObject (org.drools.compiler.InsertedObject)2 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)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