use of org.kie.api.KieBase in project drools by kiegroup.
the class StrEvaluatorTest method testStrNotStartsWith.
@Test
public void testStrNotStartsWith() throws Exception {
KieBase kbase = readKnowledgeBase();
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
RoutingMessage m = new RoutingMessage();
m.setRoutingValue("messageBody");
ksession.insert(m);
ksession.fireAllRules();
assertTrue(list.size() == 3);
assertTrue(((String) list.get(1)).equals("Message does not start with R2"));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class StrEvaluatorTest method testStrNotEndsWith.
@Test
public void testStrNotEndsWith() throws Exception {
KieBase kbase = readKnowledgeBase();
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
RoutingMessage m = new RoutingMessage();
m.setRoutingValue("messageBody");
ksession.insert(m);
ksession.fireAllRules();
assertTrue(list.size() == 3);
assertTrue(((String) list.get(0)).equals("Message length is not 17"));
assertTrue(((String) list.get(1)).equals("Message does not start with R2"));
assertTrue(((String) list.get(2)).equals("Message does not end with R1"));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class StrEvaluatorTest method testStrWithInlineCastOnThis.
@Test
public void testStrWithInlineCastOnThis() {
String drl = "package org.drools.compiler.integrationtests " + "rule R1 " + " when " + " Object( this#String str[startsWith] \"M\" ) " + " then " + "end ";
KieBase kbase = loadKnowledgeBaseFromString(drl);
KieSession ksession = kbase.newKieSession();
try {
ksession.insert("Mark");
assertEquals("Wrong number of rules fired", 1, ksession.fireAllRules());
} finally {
ksession.dispose();
}
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class TimerAndCalendarTest method testIntervalTimer.
@Test(timeout = 10000)
public void testIntervalTimer() throws Exception {
String str = "";
str += "package org.simple \n";
str += "global java.util.List list \n";
str += "rule xxx \n";
str += " timer (int:30s 10s) ";
str += "when \n";
str += "then \n";
str += " list.add(\"fired\"); \n";
str += "end \n";
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
KieBase kbase = loadKnowledgeBaseFromString(str);
KieSession ksession = createKnowledgeSession(kbase, conf);
List list = new ArrayList();
PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
timeService.advanceTime(new Date().getTime(), TimeUnit.MILLISECONDS);
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(0, list.size());
timeService.advanceTime(20, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(0, list.size());
timeService.advanceTime(15, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(1, list.size());
timeService.advanceTime(3, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(1, list.size());
timeService.advanceTime(2, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(2, list.size());
timeService.advanceTime(10, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(3, list.size());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class TimerAndCalendarTest method testCronTimer.
@Test(timeout = 10000)
public void testCronTimer() throws Exception {
String str = "";
str += "package org.simple \n";
str += "global java.util.List list \n";
str += "rule xxx \n";
str += " timer (cron:15 * * * * ?) ";
str += "when \n";
str += "then \n";
str += " list.add(\"fired\"); \n";
str += "end \n";
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
KieBase kbase = loadKnowledgeBaseFromString(str);
KieSession ksession = createKnowledgeSession(kbase, conf);
List list = new ArrayList();
PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = df.parse("2009-01-01T00:00:00.000-0000");
timeService.advanceTime(date.getTime(), TimeUnit.MILLISECONDS);
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(0, list.size());
timeService.advanceTime(10, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(0, list.size());
timeService.advanceTime(10, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(1, list.size());
timeService.advanceTime(30, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(1, list.size());
timeService.advanceTime(30, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(2, list.size());
}
Aggregations