use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testLocalTransactionPerStatement.
@Test
public void testLocalTransactionPerStatement() {
String str = "";
str += "package org.kie.test\n";
str += "global java.util.List list\n";
str += "rule rule1\n";
str += "when\n";
str += " Integer(intValue > 0)\n";
str += "then\n";
str += " list.add( 1 );\n";
str += "end\n";
str += "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
KieSession ksession = ks.getStoreServices().newKieSession(kbase, null, env);
List<?> list = new ArrayList<Object>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert(2);
ksession.insert(3);
ksession.fireAllRules();
assertEquals(3, list.size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testGetFactHandles.
@Test
public void testGetFactHandles() {
// DROOLS-1270
String str = "package org.kie.test\n" + "rule rule1 when\n" + " String(this == \"A\")\n" + "then\n" + " insertLogical( \"B\" );\n" + "end\n" + "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
KieSession ksession = ks.getStoreServices().newKieSession(kbase, null, env);
ksession.insert("A");
ksession.fireAllRules();
assertEquals(2, ksession.getFactCount());
for (FactHandle fh : ksession.getFactHandles()) {
System.out.println(fh);
if (fh.toString().contains("String:A")) {
ksession.delete(fh);
}
}
ksession.fireAllRules();
assertEquals(0, ksession.getFactCount());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testMergeConfig.
@Test
public void testMergeConfig() {
// JBRULES-3155
String str = "";
str += "package org.kie.test\n";
str += "global java.util.List list\n";
str += "rule rule1\n";
str += "when\n";
str += " $i : Integer(intValue > 0)\n";
str += "then\n";
str += " list.add( $i );\n";
str += "end\n";
str += "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "com.example.CustomJPAProcessInstanceManagerFactory");
KieSessionConfiguration config = ks.newKieSessionConfiguration(properties);
KieSession ksession = ks.getStoreServices().newKieSession(kbase, config, env);
SessionConfiguration sessionConfig = (SessionConfiguration) ksession.getSessionConfiguration();
assertEquals("com.example.CustomJPAProcessInstanceManagerFactory", sessionConfig.getProcessInstanceManagerFactory());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testGetCount.
@Test
public void testGetCount() {
// BZ-1022374
String str = "";
str += "package org.kie.test\n";
str += "rule rule1\n";
str += "when\n";
str += "then\n";
str += " insertLogical( new String(\"a\") );\n";
str += "end\n";
str += "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
KieSession ksession = ks.getStoreServices().newKieSession(kbase, null, env);
assertEquals(1, ksession.fireAllRules());
assertEquals(1, ksession.getFactCount());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class DroolsAbstractPMMLTest method readKnowledgeBase.
private static KieBase readKnowledgeBase(List<InputStream> theory) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (int j = 0; j < theory.size(); j++) {
Resource res = ks.getResources().newInputStreamResource(theory.get(j));
kfs.write(RESOURCE_PATH + "source_" + j + ".drl", res);
}
KieModuleModel model = ks.newKieModuleModel();
KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
kfs.writeKModuleXML(model.toXML());
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
return kContainer.getKieBase();
}
Aggregations