use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithEmptyContext.
@Test
public void testCreationOfSessionWithEmptyContext() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 1);
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 2);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
manager.disposeRuntimeEngine(runtime);
manager.disposeRuntimeEngine(runtime2);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testErrorThrowOfChildProcessOnParent.
@Test
public void testErrorThrowOfChildProcessOnParent() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ParentError.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ChildError.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("ParentError");
List<? extends ProcessInstanceLog> processInstanceLogs = runtime.getAuditService().findProcessInstances();
assertEquals(2, processInstanceLogs.size());
for (ProcessInstanceLog log : processInstanceLogs) {
if (log.getProcessId().equals("ParentError")) {
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
} else if (log.getProcessId().equals("ChildError")) {
assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
}
}
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionTaskServiceNotConfigured.
@Test
public void testCreationOfSessionTaskServiceNotConfigured() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
try {
runtime.getTaskService();
fail("Should fail as task service is not configured");
} catch (UnsupportedOperationException e) {
assertEquals("TaskService was not configured", e.getMessage());
}
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testExecuteReusableSubprocess.
@Test
public void testExecuteReusableSubprocess() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
ProcessInstance pi1 = ksession.startProcess("ParentProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
try {
ksession.getWorkItemManager().completeWorkItem(1, null);
fail("Invalid session was used for subprocess of (" + pi1.getId() + ") process instance");
} catch (RuntimeException e) {
}
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(2l));
ksession = runtime.getKieSession();
ksession.getWorkItemManager().completeWorkItem(1, null);
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findActiveProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
String externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
logs = logService.findProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testStartTwoProcessIntancesOnSameSession.
@Test
public void testStartTwoProcessIntancesOnSameSession() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
ProcessInstance pi1 = ksession.startProcess("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
try {
ProcessInstance pi2 = ksession.startProcess("UserTask");
fail("Invalid session was used for (" + pi2.getId() + ") process instance");
} catch (RuntimeException e) {
}
manager.close();
}
Aggregations