use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class QueryTest method testQueryWithCollect.
@Test
public void testQueryWithCollect() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Query.drl");
KieSession session = kbase.newKieSession();
session.fireAllRules();
QueryResults results = getQueryResults(session, "collect objects");
assertEquals(1, results.size());
final QueryResultsRow row = results.iterator().next();
final List list = (List) row.get("$list");
assertEquals(2, list.size());
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class QueryTest method testQueryWithOptionalOr.
@Test
public void testQueryWithOptionalOr() {
// DROOLS-1386
String str = "package org.test\n" + "import " + Question.class.getCanonicalName() + "\n" + "import " + QuestionVisible.class.getCanonicalName() + "\n" + "query QuestionsKnowledge\n" + " $question: Question()\n" + " $visible: QuestionVisible(question == $question) or not QuestionVisible(question == $question)\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
Question question = new Question();
ksession.insert(question);
QueryResults results = ksession.getQueryResults("QuestionsKnowledge");
assertEquals(1, results.size());
QueryResultsRow row = results.iterator().next();
assertSame(question, row.get("$question"));
QuestionVisible questionVisible = new QuestionVisible(question);
ksession.insert(questionVisible);
results = ksession.getQueryResults("QuestionsKnowledge");
assertEquals(1, results.size());
row = results.iterator().next();
assertSame(question, row.get("$question"));
assertSame(questionVisible, row.get("$visible"));
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class QueryTest method testDoubleQueryWithExists.
@Test
public void testDoubleQueryWithExists() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_DoubleQueryWithExists.drl");
KieSession session = kbase.newKieSession();
final Person p1 = new Person("p1", "stilton", 20);
p1.setStatus("europe");
final FactHandle c1FactHandle = session.insert(p1);
final Person p2 = new Person("p2", "stilton", 30);
p2.setStatus("europe");
final FactHandle c2FactHandle = session.insert(p2);
final Person p3 = new Person("p3", "stilton", 40);
p3.setStatus("europe");
final FactHandle c3FactHandle = session.insert(p3);
session.fireAllRules();
QueryResults results = session.getQueryResults("2 persons with the same status");
assertEquals(2, results.size());
// europe=[ 1, 2 ], america=[ 3 ]
p3.setStatus("america");
session.update(c3FactHandle, p3);
session.fireAllRules();
results = session.getQueryResults("2 persons with the same status");
assertEquals(1, results.size());
// europe=[ 1 ], america=[ 2, 3 ]
p2.setStatus("america");
session.update(c2FactHandle, p2);
session.fireAllRules();
results = session.getQueryResults("2 persons with the same status");
assertEquals(1, results.size());
// europe=[ ], america=[ 1, 2, 3 ]
p1.setStatus("america");
session.update(c1FactHandle, p1);
session.fireAllRules();
results = getQueryResults(session, "2 persons with the same status");
assertEquals(2, results.size());
// europe=[ 2 ], america=[ 1, 3 ]
p2.setStatus("europe");
session.update(c2FactHandle, p2);
session.fireAllRules();
results = getQueryResults(session, "2 persons with the same status");
assertEquals(1, results.size());
// europe=[ 1, 2 ], america=[ 3 ]
p1.setStatus("europe");
session.update(c1FactHandle, p1);
session.fireAllRules();
results = session.getQueryResults("2 persons with the same status");
assertEquals(1, results.size());
// europe=[ 1, 2, 3 ], america=[ ]
p3.setStatus("europe");
session.update(c3FactHandle, p3);
session.fireAllRules();
results = session.getQueryResults("2 persons with the same status");
assertEquals(2, results.size());
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class QueryCepTest method withResultTest.
@Test
public void withResultTest() {
secondEntryPoint.insert(new TestEvent("minusOne"));
clock.advanceTime(5, TimeUnit.SECONDS);
firstEntryPoint.insert(new TestEvent("zero"));
secondEntryPoint.insert(new TestEvent("one"));
clock.advanceTime(10, TimeUnit.SECONDS);
secondEntryPoint.insert(new TestEvent("two"));
clock.advanceTime(5, TimeUnit.SECONDS);
secondEntryPoint.insert(new TestEvent("three"));
QueryResults results = ksession.getQueryResults("ZeroToNineteenSeconds");
assertEquals(1, results.size());
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class QueryCepTest method withNoResultTest.
@Test
public void withNoResultTest() {
secondEntryPoint.insert(new TestEvent("minusOne"));
clock.advanceTime(5, TimeUnit.SECONDS);
firstEntryPoint.insert(new TestEvent("zero"));
secondEntryPoint.insert(new TestEvent("one"));
clock.advanceTime(10, TimeUnit.SECONDS);
secondEntryPoint.insert(new TestEvent("two"));
// the following expires event "zero" and "one", causing the query to no longer match
clock.advanceTime(10, TimeUnit.SECONDS);
secondEntryPoint.insert(new TestEvent("three"));
QueryResults results = ksession.getQueryResults("ZeroToNineteenSeconds");
assertEquals(0, results.size());
}
Aggregations