use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testScriptTaskFromKjarByNameNamedKbaseKsession.
@Test
public void testScriptTaskFromKjarByNameNamedKbaseKsession() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession").userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("ScriptTask", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testUserTaskFromKjarPPI.
@Test
public void testUserTaskFromKjarPPI() {
KieServices ks = KieServices.Factory.get();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
engine.getTaskService().start(taskId, "john");
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
engine.getTaskService().complete(taskId, "john", null);
manager.disposeRuntimeEngine(engine);
try {
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
fail("Should fail as process instance is already completed");
} catch (Exception e) {
}
manager.disposeRuntimeEngine(engine);
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testScriptTaskFromClasspathContainerNamedKbaseKsession.
@Test
public void testScriptTaskFromClasspathContainerNamedKbaseKsession() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newClasspathKmoduleDefaultBuilder("defaultKieBase", "defaultKieSession").userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("ScriptTask", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class MultiInstanceCallActivityRuntimeManagerTest method createEnvironment.
private RuntimeEnvironment createEnvironment() {
countDownListener = new NodeLeftCountDownProcessEventListener("timer", numberOfChildProcesses);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/Parent.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/Child.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
return environment;
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testEventSignalingBetweenProcessesWithPeristence.
@Test
public void testEventSignalingBetweenProcessesWithPeristence() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
long ksession1Id = ksession.getIdentifier();
assertNotNull(ksession);
ksession.startProcess("com.sample.bpmn.hello");
AuditService auditService = runtime.getAuditService();
List<? extends ProcessInstanceLog> throwProcessLogs = auditService.findProcessInstances("com.sample.bpmn.hello");
List<? extends ProcessInstanceLog> catchProcessLogs = auditService.findProcessInstances("com.sample.bpmn.Second");
assertNotNull(throwProcessLogs);
assertEquals(1, throwProcessLogs.size());
assertEquals(ProcessInstance.STATE_COMPLETED, throwProcessLogs.get(0).getStatus().intValue());
assertNotNull(catchProcessLogs);
assertEquals(1, catchProcessLogs.size());
assertEquals(ProcessInstance.STATE_COMPLETED, catchProcessLogs.get(0).getStatus().intValue());
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
Aggregations