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