String taskId2 = "PI_HumanTask_2";
String oneTaskCaseId = createCaseInstanceByKey("oneTaskCase").getId();
String twoTaskCaseId = createCaseInstanceByKey("twoTaskCase").getId();
CaseExecution task1 = caseService.createCaseExecutionQuery().caseInstanceId(oneTaskCaseId).activityId(taskId1).singleResult();
CaseExecution task2 = caseService.createCaseExecutionQuery().caseInstanceId(twoTaskCaseId).activityId(taskId1).singleResult();
CaseExecution task3 = caseService.createCaseExecutionQuery().caseInstanceId(twoTaskCaseId).activityId(taskId2).singleResult();
// sort by historic case activity instance ids
assertQuerySorting("id", historicQuery().orderByHistoricCaseActivityInstanceId(),
task1.getId(), task2.getId(), task3.getId());
// sort by case instance ids
assertQuerySorting("caseInstanceId", historicQuery().orderByCaseInstanceId(),
oneTaskCaseId, twoTaskCaseId, twoTaskCaseId);
// sort by case execution ids
assertQuerySorting("caseExecutionId", historicQuery().orderByCaseExecutionId(),
task1.getId(), task2.getId(), task3.getId());
// sort by case activity ids
assertQuerySorting("caseActivityId", historicQuery().orderByCaseActivityId(),
taskId1, taskId1, taskId2);
// sort by case activity names
assertQuerySorting("caseActivityName", historicQuery().orderByCaseActivityName(),
"A HumanTask", "A HumanTask", "Another HumanTask");
// sort by case definition ids
assertQuerySorting("caseDefinitionId", historicQuery().orderByCaseDefinitionId(),
task1.getCaseDefinitionId(), task2.getCaseDefinitionId(), task3.getCaseDefinitionId());
// manually start tasks to be able to complete them
manualStart(task1.getId());
manualStart(task2.getId());
manualStart(task3.getId());
// complete tasks to set end time and duration
for (Task task : taskService.createTaskQuery().list()) {
taskService.complete(task.getId());
}