ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
assertNotNull(tree);
assertEquals(1, tree.getChildActivityInstances().length);
// when
VariableInstanceQuery query1 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(tree.getId());
// then
VariableInstance processVariable = query1.singleResult();
assertNotNull(processVariable);
assertEquals("processVariable", processVariable.getName());
assertEquals("aProcessVariable", processVariable.getValue());
// when
ActivityInstance subProcessActivityInstance = tree.getChildActivityInstances()[0];
VariableInstanceQuery query2 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(subProcessActivityInstance.getId());
// then
checkVariables(query2.list());
// when setting a task local variable
Task task = taskService.createTaskQuery().singleResult();
taskService.setVariableLocal(task.getId(), "taskVariable", "taskVariableValue");
ActivityInstance taskActivityInstance = subProcessActivityInstance.getChildActivityInstances()[0];
VariableInstanceQuery query3 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(taskActivityInstance.getId());
// then
VariableInstance taskVariable = query3.singleResult();
assertNotNull(taskVariable);
assertEquals("taskVariable", taskVariable.getName());
assertEquals("taskVariableValue", taskVariable.getValue());
}