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());
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations