// After starting the process, the task in the subprocess should be active
Map<String, Object> varMap = new HashMap<String, Object>();
varMap.put("test", "test");
varMap.put("helloWorld", "helloWorld");
ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcess", varMap);
Task subProcessTask = taskService.createTaskQuery()
.processInstanceId(pi.getId())
.singleResult();
runtimeService.setVariableLocal(pi.getProcessInstanceId(), "mainProcessLocalVariable", "Hello World");
assertEquals("Task in subprocess", subProcessTask.getName());
runtimeService.setVariableLocal(subProcessTask.getExecutionId(), "subProcessLocalVariable", "Hello SubProcess");
// Returns a set of local variablenames of pi
List<String> result = processEngineConfiguration.
getCommandExecutorTxRequired().
execute(new GetVariableNamesCommand(pi.getProcessInstanceId(), true));
// pi contains local the variablenames "test", "helloWorld" and "mainProcessLocalVariable" but not "subProcessLocalVariable"
assertTrue(result.contains("test"));
assertTrue(result.contains("helloWorld"));
assertTrue(result.contains("mainProcessLocalVariable"));
assertFalse(result.contains("subProcessLocalVariable"));
// Returns a set of global variablenames of pi
result = processEngineConfiguration.
getCommandExecutorTxRequired().
execute(new GetVariableNamesCommand(pi.getProcessInstanceId(), false));
// pi contains global the variablenames "test", "helloWorld" and "mainProcessLocalVariable" but not "subProcessLocalVariable"
assertTrue(result.contains("test"));
assertTrue(result.contains("mainProcessLocalVariable"));
assertTrue(result.contains("helloWorld"));
assertFalse(result.contains("subProcessLocalVariable"));
// Returns a set of local variablenames of subProcessTask execution
result = processEngineConfiguration.
getCommandExecutorTxRequired().
execute(new GetVariableNamesCommand(subProcessTask.getExecutionId(), true));
// subProcessTask execution contains local the variablenames "test", "subProcessLocalVariable" but not "helloWorld" and "mainProcessLocalVariable"
assertTrue(result.contains("test")); // the variable "test" was set locally by SetLocalVariableTask
assertTrue(result.contains("subProcessLocalVariable"));
assertFalse(result.contains("helloWorld"));
assertFalse(result.contains("mainProcessLocalVariable"));
// Returns a set of global variablenames of subProcessTask execution
result = processEngineConfiguration.
getCommandExecutorTxRequired().
execute(new GetVariableNamesCommand(subProcessTask.getExecutionId(), false));
// subProcessTask execution contains global all defined variablenames
assertTrue(result.contains("test")); // the variable "test" was set locally by SetLocalVariableTask
assertTrue(result.contains("subProcessLocalVariable"));
assertTrue(result.contains("helloWorld"));
assertTrue(result.contains("mainProcessLocalVariable"));
taskService.complete(subProcessTask.getId());
}