Search in sources :

Example 1 with PerProcessInstanceRuntimeManager

use of org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager in project jbpm by kiegroup.

the class SingleRuntimeManagerWithListenersTest method testProcessStartOnManager.

private void testProcessStartOnManager(RuntimeEngine runtime) {
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    Collection<ProcessEventListener> pListeners = ksession.getProcessEventListeners();
    assertNotNull(pListeners);
    // prepare listeners class names for assertion
    List<String> listenerCLassNames = new ArrayList<String>();
    for (Object o : pListeners) {
        listenerCLassNames.add(o.getClass().getName());
    }
    // DebugProcessEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(DebugProcessEventListener.class.getName()));
    // JPAWorkingMemoryDbLogger one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(JPAWorkingMemoryDbLogger.class.getName()));
    if (((RuntimeEngineImpl) runtime).getManager() instanceof PerProcessInstanceRuntimeManager) {
        assertEquals(3, pListeners.size());
    } else {
        assertEquals(2, pListeners.size());
    }
    TaskService taskService = runtime.getTaskService();
    assertNotNull(taskService);
    List<?> listeners = ((EventService<?>) taskService).getTaskEventListeners();
    assertNotNull(listeners);
    assertEquals(3, listeners.size());
    // prepare listeners class names for assertion
    listenerCLassNames = new ArrayList<String>();
    for (Object o : listeners) {
        System.out.println("###### " + o.getClass().getName());
        listenerCLassNames.add(o.getClass().getName());
    }
    assertEquals(3, listenerCLassNames.size());
    // JPATaskLifeCycleEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(JPATaskLifeCycleEventListener.class.getName()));
    // external one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(ExternalTaskEventListener.class.getName()));
    // BAMTaskEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(BAMTaskEventListener.class.getName()));
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertNotNull(processInstance);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskService.start(tasks.get(0).getId(), "john");
    taskService.complete(tasks.get(0).getId(), "john", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : Status(org.kie.api.task.model.Status) TaskService(org.kie.api.task.TaskService) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) ArrayList(java.util.ArrayList) PerProcessInstanceRuntimeManager(org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager) EventService(org.kie.internal.task.api.EventService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PerProcessInstance(org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)

Aggregations

ArrayList (java.util.ArrayList)1 DebugProcessEventListener (org.drools.core.event.DebugProcessEventListener)1 PerProcessInstanceRuntimeManager (org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 KieSession (org.kie.api.runtime.KieSession)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 TaskService (org.kie.api.task.TaskService)1 Status (org.kie.api.task.model.Status)1 TaskSummary (org.kie.api.task.model.TaskSummary)1 PerProcessInstance (org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)1 EventService (org.kie.internal.task.api.EventService)1