Search in sources :

Example 16 with EventService

use of org.kie.internal.task.api.EventService 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

EventService (org.kie.internal.task.api.EventService)16 Test (org.junit.Test)12 HashMap (java.util.HashMap)8 DefaultTaskEventListener (org.jbpm.services.task.events.DefaultTaskEventListener)7 TaskEvent (org.kie.api.task.TaskEvent)7 StringReader (java.io.StringReader)6 TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)6 Task (org.kie.api.task.model.Task)6 InternalTask (org.kie.internal.task.api.model.InternalTask)6 KieSession (org.kie.api.runtime.KieSession)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 TaskService (org.kie.api.task.TaskService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2 TaskExecutionException (org.jbpm.services.task.exception.TaskExecutionException)2