Search in sources :

Example 6 with TaskEventInstance

use of org.kie.server.api.model.instance.TaskEventInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskServiceIntegrationTest method testFindTaskEventsSortedBy.

@Test
public void testFindTaskEventsSortedBy() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        taskClient.stopTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        List<TaskEventInstance> events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, true);
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), events.get(0).getType());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), events.get(1).getType());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), events.get(2).getType());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), events.get(3).getType());
        try {
            events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 2, 3, SORT_BY_TASK_EVENTS_TYPE, true);
            KieServerAssert.assertNullOrEmpty("Task events list is not empty.", events);
        } catch (KieServicesException ee) {
            if (configuration.isRest()) {
                KieServerAssert.assertResultContainsString(ee.getMessage(), "Could not find task instance with id " + taskInstance.getId());
                KieServicesHttpException httpEx = (KieServicesHttpException) ee;
                assertEquals(Integer.valueOf(404), httpEx.getHttpCode());
            } else {
                assertTrue(ee.getMessage().contains("No task found with id " + taskInstance.getId()));
            }
        }
        events = taskClient.findTaskEvents(CONTAINER_ID, taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, false);
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), events.get(0).getType());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), events.get(1).getType());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), events.get(2).getType());
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), events.get(3).getType());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Aggregations

TaskEventInstance (org.kie.server.api.model.instance.TaskEventInstance)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 TaskSummary (org.kie.server.api.model.instance.TaskSummary)5 KieServicesException (org.kie.server.api.exception.KieServicesException)2 KieServicesHttpException (org.kie.server.api.exception.KieServicesHttpException)2 TaskEvent (org.kie.internal.task.api.model.TaskEvent)1 TaskEventInstanceList (org.kie.server.api.model.instance.TaskEventInstanceList)1