use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class AgendaRuleFlowGroupsTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession(long id, String... rules) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (String rule : rules) {
kbuilder.add(new ClassPathResource(rule), ResourceType.DRL);
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
if (id == -1) {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
} else {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
}
}
use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class RuleFlowGroupRollbackTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("ruleflowgroup_rollback.drl"), ResourceType.DRL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
}
use of org.drools.core.io.impl.ClassPathResource in project jbpm by kiegroup.
the class DroolsDeclaredTypeSequenceFlowExpressionTest method testDeclaredTypesInSequenceFlowDroolsExpression.
@Test
public void testDeclaredTypesInSequenceFlowDroolsExpression() {
// DROOLS-1327
String drl = "package org.drools.test;" + "declare TestFact \n" + "value: Integer\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
Resource drlResource = new InputStreamResource(new ByteArrayInputStream(drl.getBytes(StandardCharsets.UTF_8)));
Resource bpmn2Resource = new ClassPathResource("BPMN2-DroolsDeclaredTypeSequenceFlowExpressionTest.bpmn2");
ckbuilder.add(drlResource, ResourceType.DRL);
ckbuilder.add(bpmn2Resource, ResourceType.BPMN2);
ckbuilder.build();
// Assert that we don't have any issues in the build.
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors kbErrors = kbuilder.getErrors();
for (KnowledgeBuilderError nextError : kbErrors) {
fail(nextError.getMessage());
}
}
if (kbuilder.hasResults(ResultSeverity.WARNING)) {
KnowledgeBuilderResults kbResults = kbuilder.getResults(ResultSeverity.WARNING);
for (KnowledgeBuilderResult nextResult : kbResults) {
fail(nextResult.getMessage());
}
}
}
use of org.drools.core.io.impl.ClassPathResource in project jbpm by kiegroup.
the class PersistentStatefulSessionTest method testPersistenceWorkItems2.
@Test
public void testPersistenceWorkItems2() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
long id = ksession.getIdentifier();
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
ksession.insert("TestString");
logger.debug("Started process instance {}", processInstance.getId());
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
ut.commit();
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertEquals(1, ksession.getObjects().size());
for (Object o : ksession.getObjects()) {
logger.debug(o.toString());
}
assertNull(processInstance);
}
use of org.drools.core.io.impl.ClassPathResource in project jbpm by kiegroup.
the class PersistentStatefulSessionTest method testPersistenceSubProcess.
@Test
public void testPersistenceSubProcess() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("SuperProcess.rf"), ResourceType.DRF);
kbuilder.add(new ClassPathResource("SubProcess.rf"), ResourceType.DRF);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
long id = ksession.getIdentifier();
ProcessInstance processInstance = ksession.startProcess("com.sample.SuperProcess");
logger.debug("Started process instance {}", processInstance.getId());
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull("Process did not complete.", processInstance);
}
Aggregations