Task subProcessTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertEquals("Task in subprocess", subProcessTask.getName());
// now we have 4 levels in the activityInstance:
// pd
ActivityInstance rootActivityInstance = runtimeService.getActivityInstance(pi.getProcessInstanceId());
assertEquals(pi.getProcessDefinitionId(), rootActivityInstance.getActivityId());
//subprocess1
assertEquals(1, rootActivityInstance.getChildActivityInstances().length);
ActivityInstance subProcessInstance1 = rootActivityInstance.getChildActivityInstances()[0];
assertEquals("outerSubProcess", subProcessInstance1.getActivityId());
//subprocess2
assertEquals(1, rootActivityInstance.getChildActivityInstances().length);
ActivityInstance subProcessInstance2 = subProcessInstance1.getChildActivityInstances()[0];
assertEquals("innerSubProcess", subProcessInstance2.getActivityId());
// usertask
assertEquals(1, subProcessInstance2.getChildActivityInstances().length);
ActivityInstance userTaskInstance = subProcessInstance2.getChildActivityInstances()[0];
assertEquals("innerSubProcessTask", userTaskInstance.getActivityId());
// Setting the clock forward 1 hour 1 second (timer fires in 1 hour) and fire up the job executor
ClockUtil.setCurrentTime(new Date(startTime.getTime() + ( 60 * 60 * 1000 ) + 1000));
waitForJobExecutorToProcessAllJobs(5000L);
// The inner subprocess should be destoyed, and the escalated task should be active
Task escalationTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertEquals("Escalated task", escalationTask.getName());
// now we have 3 levels in the activityInstance:
// pd
rootActivityInstance = runtimeService.getActivityInstance(pi.getProcessInstanceId());
assertEquals(pi.getProcessDefinitionId(), rootActivityInstance.getActivityId());
//subprocess1
assertEquals(1, rootActivityInstance.getChildActivityInstances().length);
subProcessInstance1 = rootActivityInstance.getChildActivityInstances()[0];
assertEquals("outerSubProcess", subProcessInstance1.getActivityId());
//subprocess2
assertEquals(1, rootActivityInstance.getChildActivityInstances().length);
ActivityInstance escalationTaskInst = subProcessInstance1.getChildActivityInstances()[0];
assertEquals("escalationTask", escalationTaskInst.getActivityId());
// Completing the escalated task, destroys the outer scope and activates the task after the subprocess
taskService.complete(escalationTask.getId());
Task taskAfterSubProcess = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertEquals("Task after subprocesses", taskAfterSubProcess.getName());