vars.put("superVariable", "Hello from the super process.");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", vars);
// one task in the subprocess should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskBeforeSubProcess = taskQuery.singleResult();
assertEquals("Task in subprocess", taskBeforeSubProcess.getName());
assertEquals("Hello from the super process.", runtimeService.getVariable(taskBeforeSubProcess.getProcessInstanceId(), "subVariable"));
assertEquals("Hello from the super process.", taskService.getVariable(taskBeforeSubProcess.getId(), "subVariable"));
runtimeService.setVariable(taskBeforeSubProcess.getProcessInstanceId(), "subVariable", "Hello from sub process.");
// super variable is unchanged
assertEquals("Hello from the super process.", runtimeService.getVariable(processInstance.getId(), "superVariable"));
// Completing this task ends the subprocess which leads to a task in the super process
taskService.complete(taskBeforeSubProcess.getId());
// one task in the subprocess should be active after starting the process instance
Task taskAfterSubProcess = taskQuery.singleResult();
assertEquals("Task in super process", taskAfterSubProcess.getName());
assertEquals("Hello from sub process.", runtimeService.getVariable(processInstance.getId(), "superVariable"));
assertEquals("Hello from sub process.", taskService.getVariable(taskAfterSubProcess.getId(), "superVariable"));
vars.clear();
vars.put("x", 5l);
// Completing this task ends the super process which leads to a task in the super process
taskService.complete(taskAfterSubProcess.getId(), vars);
// now we are the second time in the sub process but passed variables via expressions
Task taskInSecondSubProcess = taskQuery.singleResult();
assertEquals("Task in subprocess", taskInSecondSubProcess.getName());
assertEquals(10l, runtimeService.getVariable(taskInSecondSubProcess.getProcessInstanceId(), "y"));
assertEquals(10l, taskService.getVariable(taskInSecondSubProcess.getId(), "y"));
// Completing this task ends the subprocess which leads to a task in the super process
taskService.complete(taskInSecondSubProcess.getId());
// one task in the subprocess should be active after starting the process instance
Task taskAfterSecondSubProcess = taskQuery.singleResult();
assertEquals("Task in super process", taskAfterSecondSubProcess.getName());
assertEquals(15l, runtimeService.getVariable(taskAfterSecondSubProcess.getProcessInstanceId(), "z"));
assertEquals(15l, taskService.getVariable(taskAfterSecondSubProcess.getId(), "z"));
// and end last task in Super process