caseService
.withCaseExecution(processTaskId)
.manualStart();
// then
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
query.caseInstanceId(caseInstanceId);
assertEquals(1, query.count());
assertEquals(1, query.list().size());
HistoricProcessInstance historicProcessInstance = query.singleResult();
assertNotNull(historicProcessInstance);
assertNull(historicProcessInstance.getEndTime());
assertEquals(caseInstanceId, historicProcessInstance.getCaseInstanceId());
// complete existing user task -> completes the process instance
String taskId = taskService
.createTaskQuery()
.caseInstanceId(caseInstanceId)
.singleResult()
.getId();
taskService.complete(taskId);
// the completed historic process instance is still associated with the
// case instance id
assertEquals(1, query.count());
assertEquals(1, query.list().size());
historicProcessInstance = query.singleResult();
assertNotNull(historicProcessInstance);
assertNotNull(historicProcessInstance.getEndTime());
assertEquals(caseInstanceId, historicProcessInstance.getCaseInstanceId());