Search in sources :

Example 16 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class CallActivityAdvancedTest method testCallSimpleSubProcess.

@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcess.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallSimpleSubProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
    // one task in the subprocess should be active after starting the
    // process instance
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskBeforeSubProcess = taskQuery.singleResult();
    assertThat(taskBeforeSubProcess.getName()).isEqualTo("Task before subprocess");
    // Completing the task continues the process which leads to calling the
    // subprocess
    taskService.complete(taskBeforeSubProcess.getId());
    Task taskInSubProcess = taskQuery.singleResult();
    assertThat(taskInSubProcess.getName()).isEqualTo("Task in subprocess");
    // Completing the task in the subprocess, finishes the subprocess
    taskService.complete(taskInSubProcess.getId());
    Task taskAfterSubProcess = taskQuery.singleResult();
    assertThat(taskAfterSubProcess.getName()).isEqualTo("Task after subprocess");
    // Completing this task end the process instance
    taskService.complete(taskAfterSubProcess.getId());
    assertProcessEnded(processInstance.getId());
    // Validate subprocess history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // Subprocess should have initial activity set
        HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(taskInSubProcess.getProcessInstanceId()).singleResult();
        assertThat(historicProcess).isNotNull();
        assertThat(historicProcess.getStartActivityId()).isEqualTo("theStart");
        List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(taskInSubProcess.getProcessInstanceId()).list();
        // Should contain a start-event, the task and an end-event
        assertThat(historicInstances).hasSize(3);
        Set<String> expectedActivities = new HashSet<String>(asList("theStart", "task", "theEnd"));
        for (HistoricActivityInstance act : historicInstances) {
            expectedActivities.remove(act.getActivityId());
        }
        assertThat(expectedActivities).as("Not all expected activities were found in the history").isEmpty();
    }
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 17 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class CallActivityAdvancedTest method testCallSimpleSubProcessWithExpressions.

@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcessWithExpressions.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallSimpleSubProcessWithExpressions() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");
    // one task in the subprocess should be active after starting the
    // process
    // instance
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskBeforeSubProcess = taskQuery.singleResult();
    assertThat(taskBeforeSubProcess.getName()).isEqualTo("Task before subprocess");
    // Completing the task continues the process which leads to calling the
    // subprocess. The sub process we want to call is passed in as a
    // variable
    // into this task
    taskService.setVariable(taskBeforeSubProcess.getId(), "simpleSubProcessExpression", "simpleSubProcess");
    taskService.complete(taskBeforeSubProcess.getId());
    Task taskInSubProcess = taskQuery.singleResult();
    assertThat(taskInSubProcess.getName()).isEqualTo("Task in subprocess");
    // Completing the task in the subprocess, finishes the subprocess
    taskService.complete(taskInSubProcess.getId());
    Task taskAfterSubProcess = taskQuery.singleResult();
    assertThat(taskAfterSubProcess.getName()).isEqualTo("Task after subprocess");
    // Completing this task end the process instance
    taskService.complete(taskAfterSubProcess.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 18 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class CallActivityAdvancedTest method testTimerOnCallActivity.

@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testTimerOnCallActivity.bpmn20.xml", "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testTimerOnCallActivity() {
    Date startTime = processEngineConfiguration.getClock().getCurrentTime();
    // After process start, the task in the subprocess should be active
    ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskInSubProcess = taskQuery.singleResult();
    assertThat(taskInSubProcess.getName()).isEqualTo("Task in subprocess");
    ProcessInstance pi2 = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi1.getId()).singleResult();
    // When the timer on the subprocess is fired, the complete subprocess is destroyed
    // + 6 minutes, timer fires on 5 minutes
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + (6 * 60 * 1000)));
    waitForJobExecutorToProcessAllJobs(10000, 5000L);
    Task escalatedTask = taskQuery.singleResult();
    assertThat(escalatedTask.getName()).isEqualTo("Escalated Task");
    // Completing the task ends the complete process
    taskService.complete(escalatedTask.getId());
    assertThat(runtimeService.createExecutionQuery().list()).hasSize(0);
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        assertThat(historyService.createHistoricProcessInstanceQuery().processInstanceId(pi2.getId()).singleResult().getDeleteReason()).startsWith(DeleteReason.BOUNDARY_EVENT_INTERRUPTING);
        assertHistoricTasksDeleteReason(pi2, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "Task in subprocess");
        assertHistoricActivitiesDeleteReason(pi1, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "callSubProcess");
        assertHistoricActivitiesDeleteReason(pi2, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "task");
    }
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 19 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class TaskRuntimeHelperTest method applyUpdateTaskPayloadShouldThrowExceptionWhenAssigneeIsNotSetAndIsNotAdmin.

@Test
public void applyUpdateTaskPayloadShouldThrowExceptionWhenAssigneeIsNotSetAndIsNotAdmin() {
    // given
    TaskQuery taskQuery = mock(TaskQuery.class);
    given(taskService.createTaskQuery()).willReturn(taskQuery);
    given(taskQuery.taskCandidateOrAssigned(any(), any())).willReturn(taskQuery);
    given(taskQuery.taskId("taskId")).willReturn(taskQuery);
    Task internalTask = mock(Task.class);
    doReturn(internalTask).when(taskRuntimeHelper).getInternalTaskWithChecks("taskId");
    UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").build();
    // when
    Throwable throwable = catchThrowable(() -> taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload));
    // then
    assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("You cannot update a task where you are not the assignee");
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Test(org.junit.jupiter.api.Test)

Example 20 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.

the class TaskRuntimeHelperTest method getInternalTaskWithChecksShouldReturnMatchinTaskFromTaskQuery.

@Test
public void getInternalTaskWithChecksShouldReturnMatchinTaskFromTaskQuery() {
    // given
    List<String> groups = singletonList("doctor");
    given(securityManager.getAuthenticatedUserGroups()).willReturn(groups);
    TaskQuery taskQuery = mock(TaskQuery.class);
    given(taskQuery.taskCandidateOrAssigned(AUTHENTICATED_USER, groups)).willReturn(taskQuery);
    given(taskQuery.taskOwner(AUTHENTICATED_USER)).willReturn(taskQuery);
    given(taskQuery.or()).willReturn(taskQuery);
    given(taskQuery.endOr()).willReturn(taskQuery);
    given(taskQuery.taskId("taskId")).willReturn(taskQuery);
    Task internalTask = mock(Task.class);
    given(taskQuery.singleResult()).willReturn(internalTask);
    given(taskService.createTaskQuery()).willReturn(taskQuery);
    // when
    Task retrievedTask = taskRuntimeHelper.getInternalTaskWithChecks("taskId");
    // then
    assertThat(retrievedTask).isEqualTo(internalTask);
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) Test(org.junit.jupiter.api.Test)

Aggregations

TaskQuery (org.activiti.engine.task.TaskQuery)120 Task (org.activiti.engine.task.Task)47 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)21 ActivitiException (org.activiti.engine.ActivitiException)20 ArrayList (java.util.ArrayList)18 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)12 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 HashMap (java.util.HashMap)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)4 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 HashSet (java.util.HashSet)2 List (java.util.List)2