createCaseInstanceByKey("oneCaseTaskCase").getId();
// as long as the case task is not activated there should be no other case instance
assertCount(0, caseService.createCaseInstanceQuery().caseDefinitionKey(calledCaseId));
HistoricCaseActivityInstance historicInstance = queryHistoricActivityCaseInstance(taskId);
assertNull(historicInstance.getCalledCaseInstanceId());
// start case task manually to create case instance
CaseExecution caseTask = queryCaseExecutionByActivityId(taskId);
manualStart(caseTask.getId());
// there should exist a new case instance
CaseInstance calledCaseInstance = caseService.createCaseInstanceQuery().caseDefinitionKey(calledCaseId).singleResult();
assertNotNull(calledCaseInstance);
// check that the called case instance id was correctly set
historicInstance = queryHistoricActivityCaseInstance(taskId);
assertEquals(calledCaseInstance.getId(), historicInstance.getCalledCaseInstanceId());
// disable task to complete called case instance and close it
CaseExecution calledTask = queryCaseExecutionByActivityId(calledTaskId);
disable(calledTask.getId());
close(calledCaseInstance.getId());
// check that the called case instance id is still set
assertCount(0, caseService.createCaseInstanceQuery().caseDefinitionKey(calledCaseId));
historicInstance = queryHistoricActivityCaseInstance(taskId);
assertEquals(calledCaseInstance.getId(), historicInstance.getCalledCaseInstanceId());
}