Search in sources :

Example 6 with TaskSummary

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

the class SLAComplianceIntegrationTest method testSLAonProcessViolated.

@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testSLAonProcessViolated() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA, new HashMap<>());
    assertProcessInstance(pid, STATE_ACTIVE, SLA_PENDING);
    // Yoda should have one task available without SLA
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Hello");
    List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    NodeInstance taskNode = activeNodes.get(0);
    assertNodeInstance(taskNode, "Hello", SLA_NA);
    // Let's wait for SLA violation
    KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, pid, 8_000L);
    assertProcessInstance(pid, STATE_ACTIVE, SLA_VIOLATED);
    taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 0);
    assertThat(tasks).isEmpty();
    activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).isEmpty();
    taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
    assertNodeInstance(taskNode, "Hello", SLA_NA);
    // Process should be completed, but SLA should still be violated
    assertProcessInstance(pid, STATE_COMPLETED, SLA_VIOLATED);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 7 with TaskSummary

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

the class SLAComplianceIntegrationTest method testSLAonProcessMet.

@Test
public void testSLAonProcessMet() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA, new HashMap<>());
    assertProcessInstance(pid, STATE_ACTIVE, SLA_PENDING);
    // Yoda should have one task available without SLA
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(tasks).hasSize(1);
    TaskSummary task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Hello");
    List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).hasSize(1);
    NodeInstance taskNode = activeNodes.get(0);
    assertNodeInstance(taskNode, "Hello", SLA_NA);
    // Complete task before SLA violation
    taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 0);
    assertThat(tasks).isEmpty();
    activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
    assertThat(activeNodes).isEmpty();
    taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
    assertNodeInstance(taskNode, "Hello", SLA_NA);
    // Process should be completed and SLA should be met
    assertProcessInstance(pid, STATE_COMPLETED, SLA_MET);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 8 with TaskSummary

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

the class ProcessServiceIntegrationTest method testWorkItemOperationComplete.

@Test
public void testWorkItemOperationComplete() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Completing human task so we can move in process flow to work item.
        // User task shouldn't be handled as work item because in such case it doesn't behave consistently:
        // i.e. leaving open tasks after finishing process instance.
        List<String> status = Arrays.asList(Status.Ready.toString());
        List<TaskSummary> taskList = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, status, 0, 10);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        taskClient.completeTask(CONTAINER_ID, taskSummary.getId(), USER_YODA, null);
        TaskInstance userTask = taskClient.findTaskById(taskSummary.getId());
        assertNotNull(userTask);
        assertEquals("Evaluate items?", userTask.getName());
        assertEquals(Status.Completed.toString(), userTask.getStatus());
        List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(workItems);
        assertEquals(1, workItems.size());
        WorkItemInstance workItemInstance = workItems.get(0);
        assertNotNull(workItemInstance);
        processClient.completeWorkItem(CONTAINER_ID, processInstanceId, workItemInstance.getId(), parameters);
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.getState().intValue());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        throw e;
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 9 with TaskSummary

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

the class ProcessServiceIntegrationTest method testCallActivityProcess.

@Test
public void testCallActivityProcess() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_CALL_EVALUATION, parameters);
    try {
        assertNotNull(processInstanceId);
        assertTrue(processInstanceId.longValue() > 0);
        // Process instance is running and is active.
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertEquals(1, tasks.size());
        taskClient.completeAutoProgress(CONTAINER_ID, tasks.get(0).getId(), USER_YODA, null);
        List<ProcessInstance> instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, 0, 10);
        assertEquals(1, instances.size());
        ProcessInstance childInstance = instances.get(0);
        assertNotNull(childInstance);
        assertEquals(PROCESS_ID_EVALUATION, childInstance.getProcessId());
        assertEquals(processInstanceId, childInstance.getParentId());
        List<NodeInstance> activeNodes = queryClient.findActiveNodeInstances(processInstanceId, 0, 10);
        assertEquals(1, activeNodes.size());
        NodeInstance active = activeNodes.get(0);
        assertEquals("Call Evaluation", active.getName());
        assertEquals("SubProcessNode", active.getNodeType());
        assertEquals(childInstance.getId(), active.getReferenceId());
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        // Process instance is now aborted.
        processInstance = processClient.getProcessInstance(CONTAINER_ID, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.getState().intValue());
        processInstance = processClient.getProcessInstance(CONTAINER_ID, childInstance.getId());
        assertNotNull(processInstance);
        assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.getState().intValue());
        // no more active instances
        instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, 0, 10);
        assertEquals(0, instances.size());
        instances = processClient.findProcessInstancesByParent(CONTAINER_ID, processInstanceId, Arrays.asList(3), 0, 10);
        assertEquals(1, instances.size());
    } catch (Exception e) {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) NodeInstance(org.kie.server.api.model.instance.NodeInstance) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 10 with TaskSummary

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

the class ProcessUserTaskServicesSecurityIntegrationTest method testNonAllowedUserForStartingProcessCanCompleteTask.

@Test
public void testNonAllowedUserForStartingProcessCanCompleteTask() throws Exception {
    try {
        Long processInstanceId = startProcessAsAdministrator(PROCESS_ID_USERTASK_SECURED);
        changeUser(USER_YODA);
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertThat(taskList).isNotNull().hasSize(1);
        Long taskId = taskList.get(0).getId();
        taskClient.startTask(CONTAINER_ID_SECURED, taskId, USER_YODA);
        taskClient.completeAutoProgress(CONTAINER_ID_SECURED, taskId, USER_YODA, new HashMap<String, Object>());
        ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ID_SECURED, processInstanceId);
        assertNotNull(processInstance);
        assertEquals(STATE_COMPLETED, processInstance.getState().intValue());
    } finally {
        changeUser(TestConfig.getUsername());
    }
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) 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