Search in sources :

Example 6 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance 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 7 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance 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 8 with TaskInstance

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

the class UserTaskServiceIntegrationTest method checkTaskStatusAndOwners.

private void checkTaskStatusAndOwners(String containerId, Long taskId, Status status, String actualOwner, String potentialOwner) {
    TaskInstance task = taskClient.getTaskInstance(containerId, taskId, false, false, true);
    checkTaskStatusAndActualOwner(containerId, taskId, status, actualOwner);
    assertEquals(1, task.getPotentialOwners().size());
    assertEquals(potentialOwner, task.getPotentialOwners().get(0));
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance)

Example 9 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance 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);
    }
}
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 10 with TaskInstance

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

the class QueryDataServiceIntegrationTest method testDefaultQueryJbpmHumanTasksWithAdmin.

@Test
public void testDefaultQueryJbpmHumanTasksWithAdmin() {
    QueryDefinition registeredQuery = queryClient.getQuery("jbpmHumanTasksWithAdmin");
    List<TaskInstance> tasks = queryClient.query(registeredQuery.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
    assertNotNull(tasks);
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) TaskInstance(org.kie.server.api.model.instance.TaskInstance) Test(org.junit.Test)

Aggregations

TaskInstance (org.kie.server.api.model.instance.TaskInstance)44 Test (org.junit.Test)29 TaskSummary (org.kie.server.api.model.instance.TaskSummary)27 HashMap (java.util.HashMap)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)8 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)6 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)5 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)5 ArrayList (java.util.ArrayList)4 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)3 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)3 ApiOperation (io.swagger.annotations.ApiOperation)2