use of org.kie.server.api.model.instance.TaskSummary in project droolsjbpm-integration by kiegroup.
the class UserTaskServiceIntegrationTest method testFailUserTask.
@Test
public void testFailUserTask() 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);
assertEquals("First task", taskSummary.getName());
// startTask and completeTask task
taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
Map<String, Object> taskOutcome = new HashMap<String, Object>();
taskOutcome.put("string_", "my custom data");
taskOutcome.put("person_", createPersonInstance(USER_MARY));
taskClient.failTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, taskOutcome);
taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertNotNull(taskList);
assertEquals(1, taskList.size());
taskSummary = taskList.get(0);
assertEquals("Second task", taskSummary.getName());
} 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 testDelegateUserTask.
/**
* Test verifying delegateTask method and its functionality.
* Also check task status changes when delegating task.
*
* @throws Exception
*/
@Test
public void testDelegateUserTask() 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);
assertEquals("First task", taskSummary.getName());
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.Reserved, USER_YODA);
// delegating Reserved task to john (delegating Reserved -> Reserved)
taskClient.delegateTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, USER_JOHN);
// user yoda has empty task list now
taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertNotNull(taskList);
assertEquals(0, taskList.size());
// delegated task stays in Reserved state and is assigned to john as actual owner
changeUser(USER_JOHN);
taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
assertNotNull(taskList);
assertEquals(1, taskList.size());
assertEquals(taskSummary.getId(), taskList.get(0).getId());
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.Reserved, USER_JOHN);
// releasing task to change its state to Ready
taskClient.releaseTask(CONTAINER_ID, taskSummary.getId(), USER_JOHN);
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.Ready, "");
// delegating task in Ready state back to yoda (delegating Ready -> Reserved)
taskClient.delegateTask(CONTAINER_ID, taskSummary.getId(), USER_JOHN, USER_YODA);
// delegated task change its state to Reserved and is assigned to yoda as actual owner
changeUser(USER_YODA);
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.Reserved, USER_YODA);
// starting task to change its status to In progress
taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.InProgress, USER_YODA);
// delegating task In progress back to john (delegating In progress -> Reserved)
taskClient.delegateTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, USER_JOHN);
// delegated task change state to Reserved and is assigned to john as actual owner
changeUser(USER_JOHN);
checkTaskStatusAndActualOwner(CONTAINER_ID, taskSummary.getId(), Status.Reserved, USER_JOHN);
// delegating task in Reserved state by a user who isn't potential owner (Code 403)
changeUser(USER_YODA);
assertClientException(() -> taskClient.delegateTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, USER_WITHOUT_PERMISSIONS), 403, "User '[UserImpl:'" + USER_YODA + "']' does not have permissions to execute operation 'Delegate' on task id " + taskSummary.getId());
} finally {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
changeUser(TestConfig.getUsername());
}
}
use of org.kie.server.api.model.instance.TaskSummary in project droolsjbpm-integration by kiegroup.
the class UserTaskServiceIntegrationTest method testSkipUserTask.
@Test
public void testSkipUserTask() 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);
assertEquals("First task", taskSummary.getName());
assertTrue(taskSummary.getSkipable().booleanValue());
taskClient.skipTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
// find all tasks with Obsolete status - should be only one
taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, Arrays.asList("Obsolete"), 0, 10);
assertNotNull(taskList);
assertEquals(1, taskList.size());
taskSummary = taskList.get(0);
checkTaskNameAndStatus(taskSummary, "First task", Status.Obsolete);
// Verify we did skip the task and process moved on
taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertNotNull(taskList);
assertEquals(1, taskList.size());
taskSummary = taskList.get(0);
checkTaskNameAndStatus(taskSummary, "Second task", Status.Reserved);
} 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 testUserTaskByIdWithDetails.
@Test
public void testUserTaskByIdWithDetails() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("stringData", "john is working on it");
parameters.put("personData", createPersonInstance(USER_JOHN));
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
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);
assertEquals("First task", taskSummary.getName());
TaskInstance taskInstance = taskClient.getTaskInstance(CONTAINER_ID, taskSummary.getId(), true, true, true);
assertNotNull(taskInstance);
assertEquals("First task", taskInstance.getName());
KieServerAssert.assertNullOrEmpty(taskInstance.getDescription());
KieServerAssert.assertNullOrEmpty(taskInstance.getSubject());
assertEquals("Reserved", taskInstance.getStatus());
assertEquals(0, taskInstance.getPriority().intValue());
assertEquals(USER_YODA, taskInstance.getActualOwner());
assertEquals(USER_YODA, taskInstance.getCreatedBy());
assertEquals(PROCESS_ID_USERTASK, taskInstance.getProcessId());
assertEquals(CONTAINER_ID, taskInstance.getContainerId());
assertEquals(taskSummary.getId(), taskInstance.getId());
assertEquals(-1, taskInstance.getParentId().longValue());
assertEquals(true, taskInstance.getSkipable());
assertEquals(processInstanceId, taskInstance.getProcessInstanceId());
assertNotNull(taskInstance.getWorkItemId());
assertTrue(taskInstance.getWorkItemId().longValue() > 0);
assertNotNull(taskInstance.getExcludedOwners());
assertEquals(0, taskInstance.getExcludedOwners().size());
assertNotNull(taskInstance.getPotentialOwners());
assertEquals(1, taskInstance.getPotentialOwners().size());
assertTrue(taskInstance.getPotentialOwners().contains(USER_YODA));
assertNotNull(taskInstance.getBusinessAdmins());
assertEquals(2, taskInstance.getBusinessAdmins().size());
assertTrue(taskInstance.getBusinessAdmins().contains(USER_ADMINISTRATOR));
assertTrue(taskInstance.getBusinessAdmins().contains("Administrators"));
assertNotNull(taskInstance.getInputData());
assertEquals(6, taskInstance.getInputData().size());
Map<String, Object> inputs = taskInstance.getInputData();
assertTrue(inputs.containsKey("ActorId"));
assertTrue(inputs.containsKey("_string"));
assertTrue(inputs.containsKey("Skippable"));
assertTrue(inputs.containsKey("_person"));
assertTrue(inputs.containsKey("NodeName"));
assertEquals(USER_YODA, inputs.get("ActorId"));
assertEquals("john is working on it", inputs.get("_string"));
assertEquals("true", inputs.get("Skippable"));
assertEquals("First task", inputs.get("NodeName"));
assertEquals(USER_JOHN, KieServerReflections.valueOf(inputs.get("_person"), "name"));
assertNotNull(taskInstance.getOutputData());
assertEquals(0, taskInstance.getOutputData().size());
} 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 testSuspendAndAutoResume.
@Test
public void testSuspendAndAutoResume() 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);
checkTaskNameAndStatus(taskSummary, "First task", Status.Reserved);
// release task
taskClient.suspendTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, Collections.singletonMap("suspendUntil", "PT3S"));
long time = 0L;
do {
taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertNotNull(taskList);
assertEquals(1, taskList.size());
taskSummary = taskList.get(0);
Thread.sleep(500L);
time += 500L;
} while (time <= 6000L && !Status.Reserved.toString().equals(taskSummary.getStatus()));
checkTaskNameAndStatus(taskSummary, "First task", Status.Reserved);
} finally {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
Aggregations