Search in sources :

Example 21 with TaskSummary

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

the class UserTaskEscalationIntegrationTest method testEscalation.

@Test
@Category(Unstable.class)
public void testEscalation() throws InterruptedException, MessagingException, Exception {
    // Unstable on slow DBs where completing of the task overlaps with escalation causing race conditions in Hibernate.
    // Could be stabilized using specific transaction isolation.
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_ESCALATION, params);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        assertEquals("User Task", taskSummary.getName());
        Long taskId = taskSummary.getId();
        TaskInstance taskInstance = taskClient.findTaskById(taskId);
        assertNotNull(taskInstance);
        assertEquals(USER_YODA, taskInstance.getActualOwner());
        changeUser(USER_JOHN);
        waitForAssign(taskId, USER_JOHN);
        taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        taskId = taskList.get(0).getId();
        taskInstance = taskClient.findTaskById(taskId);
        assertNotNull(taskInstance);
        taskClient.startTask(CONTAINER_ID, taskId, USER_JOHN);
        taskInstance = taskClient.findTaskById(taskId);
        assertNotNull(taskInstance);
        assertEquals(USER_JOHN, taskInstance.getActualOwner());
        waitForEmailsReceive(wiser);
        taskClient.completeTask(CONTAINER_ID, taskId, USER_JOHN, new HashMap<String, Object>());
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
        assertTotalOfEmails(1);
        assertEmails("Escalation", ESCALATION_TEXT, USER_JOHN, 1);
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        throw e;
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) TimeoutException(java.util.concurrent.TimeoutException) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 22 with TaskSummary

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

the class UserTaskServiceAdditionalIntegrationTest method testNotAllowedUserTaskUpdateOutputVariable.

@Test
public void testNotAllowedUserTaskUpdateOutputVariable() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID_USERTASK, PROCESS_ID_USERTASK_DIFF_POTUSERS);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        changeUser(USER_JOHN);
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID_USERTASK, taskSummary.getId(), USER_JOHN);
        Map<String, Object> taskOutcomeComplete = new HashMap<>();
        taskClient.completeTask(CONTAINER_ID_USERTASK, taskSummary.getId(), USER_JOHN, taskOutcomeComplete);
        changeUser(USER_YODA);
        taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary task2 = taskList.get(0);
        taskClient.startTask(CONTAINER_ID_USERTASK, task2.getId(), USER_YODA);
        changeUser(USER_JOHN);
        assertClientException(() -> taskClient.saveTaskContent(CONTAINER_ID_USERTASK, task2.getId(), taskOutcomeComplete), 403, "User '[UserImpl:'" + USER_JOHN + "']' does not have permissions to execute operation 'Modify' on task id " + task2.getId());
    } finally {
        changeUser(TestConfig.getUsername());
        processClient.abortProcessInstance(CONTAINER_ID_USERTASK, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 23 with TaskSummary

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

the class UserTaskServiceIntegrationTest method testAllowedUserTaskUpdateOutputVariable.

@Test
public void testAllowedUserTaskUpdateOutputVariable() {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        Map<String, Object> outputData = new HashMap<>();
        outputData.put("string_", "my custom data");
        outputData.put("person_", createPersonInstance(USER_MARY));
        taskClient.saveTaskContent(CONTAINER_ID, taskSummary.getId(), outputData);
        // retrieve started task
        TaskInstance taskInstance = taskClient.getTaskInstance(CONTAINER_ID, taskSummary.getId(), true, true, false);
        Object personVar = taskInstance.getOutputData().get("person_");
        assertNotNull(personVar);
        assertEquals(USER_MARY, KieServerReflections.valueOf(personVar, "name"));
        String stringVar = (String) taskInstance.getOutputData().get("string_");
        assertNotNull(personVar);
        assertEquals("my custom data", stringVar);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 24 with TaskSummary

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

the class UserTaskServiceIntegrationTest method testUserTaskAttachmentsAsByteArray.

@Test
public void testUserTaskAttachmentsAsByteArray() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        // Adding attachments to user task.
        byte[] attachmentContent = new String("This is first attachment.").getBytes();
        Long attachmentId = taskClient.addTaskAttachment(CONTAINER_ID, taskSummary.getId(), USER_YODA, "my attachment", attachmentContent);
        // start task
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        // Verifying attachment returned by getTaskAttachmentById().
        Object taskAttachmentContent = taskClient.getTaskAttachmentContentById(CONTAINER_ID, taskSummary.getId(), attachmentId);
        assertArrayEquals(attachmentContent, (byte[]) taskAttachmentContent);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 25 with TaskSummary

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

the class UserTaskServiceIntegrationTest method testUserTaskComments.

@Test
public void testUserTaskComments() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        // Adding comment to user task as yoda.
        String firstComment = "First comment.";
        Calendar firstCommentTime = Calendar.getInstance();
        Long firstCommentId = taskClient.addTaskComment(CONTAINER_ID, taskSummary.getId(), firstComment, USER_YODA, firstCommentTime.getTime());
        // Adding second comment to user task as john.
        String secondComment = "Second comment.";
        Calendar secondCommentTime = Calendar.getInstance();
        secondCommentTime.add(Calendar.MINUTE, 5);
        Long secondCommentId = taskClient.addTaskComment(CONTAINER_ID, taskSummary.getId(), secondComment, USER_JOHN, secondCommentTime.getTime());
        // start task
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        // Verifying first comment returned by getTaskCommentById().
        TaskComment firstTaskComment = taskClient.getTaskCommentById(CONTAINER_ID, taskSummary.getId(), firstCommentId);
        assertNotNull(firstTaskComment.getAddedAt());
        assertEquals(USER_YODA, firstTaskComment.getAddedBy());
        assertEquals(firstCommentId, firstTaskComment.getId());
        assertEquals(firstComment, firstTaskComment.getText());
        // Verifying second comment returned by getTaskCommentsByTaskId().
        List<TaskComment> taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ID, taskSummary.getId());
        assertEquals(2, taskComments.size());
        TaskComment secondTaskComment = null;
        if (secondCommentId.equals(taskComments.get(0).getId())) {
            secondTaskComment = taskComments.get(0);
        } else {
            secondTaskComment = taskComments.get(1);
        }
        assertNotNull(secondTaskComment.getAddedAt());
        assertEquals(USER_JOHN, secondTaskComment.getAddedBy());
        assertEquals(secondCommentId, secondTaskComment.getId());
        assertEquals(secondComment, secondTaskComment.getText());
        // Delete task comment.
        taskClient.deleteTaskComment(CONTAINER_ID, taskSummary.getId(), secondCommentId);
        // Now there is just one comment left.
        taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ID, taskSummary.getId());
        assertEquals(1, taskComments.size());
        assertEquals(firstCommentId, taskComments.get(0).getId());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskComment(org.kie.server.api.model.instance.TaskComment) Calendar(java.util.Calendar) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.server.api.model.instance.TaskSummary)142 Test (org.junit.Test)131 HashMap (java.util.HashMap)79 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)39 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)31 TaskInstance (org.kie.server.api.model.instance.TaskInstance)28 ArrayList (java.util.ArrayList)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)21 KieServicesException (org.kie.server.api.exception.KieServicesException)14 Category (org.junit.experimental.categories.Category)7 NodeInstance (org.kie.server.api.model.instance.NodeInstance)7 Date (java.util.Date)6 CaseInstance (org.kie.server.api.model.cases.CaseInstance)6 TaskEventInstance (org.kie.server.api.model.instance.TaskEventInstance)6 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)6 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)5 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)5 UserTaskServicesClient (org.kie.server.client.UserTaskServicesClient)5 Calendar (java.util.Calendar)4 List (java.util.List)3