use of org.kie.api.KieBase in project drools by kiegroup.
the class StreamsTest method testMultipleWindows.
@Test(timeout = 10000)
public void testMultipleWindows() throws Exception {
String drl = "package org.drools.compiler\n" + "declare StockTick\n" + " @role(event)\n" + "end\n" + "rule FaultsCoincide\n" + "when\n" + " f1 : StockTick( company == \"RHT\" ) over window:length( 1 )\n" + " f2 : StockTick( company == \"JBW\" ) over window:length( 1 )\n" + "then\n" + "end";
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kconf.setOption(EventProcessingOption.STREAM);
KieBase kbase = loadKnowledgeBaseFromString(kconf, drl);
KieSession ksession = kbase.newKieSession();
AgendaEventListener ael = mock(AgendaEventListener.class);
ksession.addEventListener(ael);
StockTick st1 = new StockTick(1, "RHT", 10, 1000);
ksession.insert(st1);
StockTick st2 = new StockTick(2, "JBW", 10, 1000);
ksession.insert(st2);
ksession.fireAllRules();
ArgumentCaptor<org.kie.api.event.rule.AfterMatchFiredEvent> captor = ArgumentCaptor.forClass(org.kie.api.event.rule.AfterMatchFiredEvent.class);
verify(ael, times(1)).afterMatchFired(captor.capture());
AfterMatchFiredEvent aafe = captor.getValue();
assertThat((StockTick) aafe.getMatch().getDeclarationValue("f1"), is(st1));
assertThat((StockTick) aafe.getMatch().getDeclarationValue("f2"), is(st2));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class SubnetworkTest method testSubNetworks.
@Test
public void testSubNetworks() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_SubNetworks.drl"));
final KieSession session = createKnowledgeSession(kbase);
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class ShadowProxyTest method testShadowProxyOnCollections.
@Test
public void testShadowProxyOnCollections() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ShadowProxyOnCollections.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List results = new ArrayList();
ksession.setGlobal("results", results);
final Cheesery cheesery = new Cheesery();
ksession.insert(cheesery);
ksession.fireAllRules();
assertEquals(1, results.size());
assertEquals(1, cheesery.getCheeses().size());
assertEquals(results.get(0), cheesery.getCheeses().get(0));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class StrEvaluatorTest method testStrStartsWith.
@Test
public void testStrStartsWith() throws Exception {
KieBase kbase = readKnowledgeBase();
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
RoutingMessage m = new RoutingMessage();
m.setRoutingValue("R1:messageBody");
ksession.insert(m);
ksession.fireAllRules();
assertTrue(list.size() == 4);
assertTrue(((String) list.get(0)).equals("Message starts with R1"));
assertTrue(((String) list.get(1)).equals("Message length is not 17"));
assertTrue(((String) list.get(2)).equals("Message does not start with R2"));
assertTrue(((String) list.get(3)).equals("Message does not end with R1"));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class StrEvaluatorTest method testStrWithLogicalOr.
@Test
public void testStrWithLogicalOr() {
String drl = "package org.drools.compiler.integrationtests\n" + "import org.drools.compiler.RoutingMessage\n" + "rule R1\n" + " when\n" + " RoutingMessage( routingValue == \"R2\" || routingValue str[startsWith] \"R1\" )\n" + " then\n" + "end\n";
KieBase kbase = loadKnowledgeBaseFromString(drl);
KieSession ksession = kbase.newKieSession();
try {
for (String msgValue : new String[] { "R1something", "R2something", "R2" }) {
RoutingMessage msg = new RoutingMessage();
msg.setRoutingValue(msgValue);
ksession.insert(msg);
}
assertEquals("Wrong number of rules fired", 2, ksession.fireAllRules());
} finally {
ksession.dispose();
}
}
Aggregations