Search in sources :

Example 1 with FlatQueryResultRow

use of org.drools.core.runtime.rule.impl.FlatQueryResultRow in project drools by kiegroup.

the class QueryTest method testQuery.

@Test
public void testQuery() throws Exception {
    KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("simple_query_test.drl"));
    KieSession session = createKieSession(kbase);
    final Cheese stilton = new Cheese("stinky", 5);
    FactHandle factHandle = session.insert(stilton);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    String queryName = "simple query";
    org.kie.api.runtime.rule.QueryResults results = getQueryResults(session, queryName);
    assertEquals(1, results.size());
    QueryResultsRow row = results.iterator().next();
    if (row instanceof FlatQueryResultRow) {
        FlatQueryResultRow flatRow = (FlatQueryResultRow) row;
        assertEquals(0, flatRow.getIdentifiers().size());
    } else if (row instanceof QueryResultsRowImpl) {
        QueryResultsRowImpl rowImpl = (QueryResultsRowImpl) row;
        assertEquals(0, rowImpl.getDeclarations().size());
    }
}
Also used : FlatQueryResultRow(org.drools.core.runtime.rule.impl.FlatQueryResultRow) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) QueryResults(org.kie.api.runtime.rule.QueryResults) QueryResultsRow(org.kie.api.runtime.rule.QueryResultsRow) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) QueryResultsRowImpl(org.drools.core.QueryResultsRowImpl) Test(org.junit.Test)

Aggregations

Cheese (org.drools.compiler.Cheese)1 QueryResultsRowImpl (org.drools.core.QueryResultsRowImpl)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 FlatQueryResultRow (org.drools.core.runtime.rule.impl.FlatQueryResultRow)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1 QueryResults (org.kie.api.runtime.rule.QueryResults)1 QueryResultsRow (org.kie.api.runtime.rule.QueryResultsRow)1