use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class AbstractKnowledgeTest method testEntry.
public void testEntry(KProjectTestClass testClass, String jarName) {
List<String> list = new ArrayList<String>();
StatelessKieSession stlsKsession = testClass.getKBase1KSession1();
stlsKsession.setGlobal("list", list);
stlsKsession.execute("dummy");
assertEquals(2, list.size());
assertTrue(list.contains(jarName + ".test1:rule1:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test1:rule2:1.0-SNAPSHOT"));
list.clear();
KieSession stflKsession = testClass.getKBase1KSession2();
stflKsession.setGlobal("list", list);
stflKsession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.contains(jarName + ".test1:rule1:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test1:rule2:1.0-SNAPSHOT"));
list.clear();
stflKsession = testClass.getKBase2KSession3();
stflKsession.setGlobal("list", list);
stflKsession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.contains(jarName + ".test2:rule1:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test2:rule2:1.0-SNAPSHOT"));
list.clear();
stlsKsession = testClass.getKBase3KSession4();
stlsKsession.setGlobal("list", list);
stlsKsession.execute("dummy");
assertEquals(4, list.size());
assertTrue(list.contains(jarName + ".test1:rule1:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test1:rule2:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test2:rule1:1.0-SNAPSHOT"));
assertTrue(list.contains(jarName + ".test2:rule2:1.0-SNAPSHOT"));
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class KieBuilderTest method testStatelessSessionDeclarativeChannelRegistration.
@Test
public void testStatelessSessionDeclarativeChannelRegistration() {
final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + " <kbase name=\"kbase1\">\n" + " <ksession name=\"ksession1\" default=\"true\" type=\"stateless\">\n" + " <channels>\n" + " <channel name=\"testChannel\" type=\"org.drools.compiler.integrationtests.KieBuilderTest$MockChannel\" />\n" + " </channels>\n" + " </ksession>" + " </kbase>\n" + "</kmodule>";
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final Resource r1 = ResourceFactory.newByteArrayResource(drl1.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
final KieModule km = createAndDeployJar(ks, kmodule, releaseId1, r1);
KieContainer kieContainer = ks.newKieContainer(km.getReleaseId());
StatelessKieSession statelessKieSession = kieContainer.newStatelessKieSession();
assertEquals(1, statelessKieSession.getChannels().size());
assertTrue(statelessKieSession.getChannels().keySet().contains("testChannel"));
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class KieLoggersTest method getStatelessKieSession.
private StatelessKieSession getStatelessKieSession(Resource dt) {
KieServices ks = populateKieFileSystem(dt);
// get the session
StatelessKieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newStatelessKieSession();
return ksession;
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class FireAllRulesCommandTest method zeroRulesFiredTest.
@Test
public void zeroRulesFiredTest() {
String str = "";
str += "package org.drools.compiler.integrationtests \n";
str += "import " + Cheese.class.getCanonicalName() + " \n";
str += "rule StringRule \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " then \n";
str += " System.out.println($c); \n";
str += "end \n";
StatelessKieSession ksession = getSession(str);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert("not cheese"));
commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(0, fired);
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class FireAllRulesCommandTest method fiveRulesFiredTest.
@Test
public void fiveRulesFiredTest() {
String str = "";
str += "package org.drools.compiler.integrationtests \n";
str += "import " + Cheese.class.getCanonicalName() + " \n";
str += "rule StringRule \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " then \n";
str += " System.out.println($c); \n";
str += "end \n";
StatelessKieSession ksession = getSession(str);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert(new Cheese("stilton")));
commands.add(CommandFactory.newInsert(new Cheese("gruyere")));
commands.add(CommandFactory.newInsert(new Cheese("cheddar")));
commands.add(CommandFactory.newInsert(new Cheese("stinky")));
commands.add(CommandFactory.newInsert(new Cheese("limburger")));
commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(5, fired);
}
Aggregations