@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testSetVariableLocalOnUserTask() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess"); Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); taskService.setVariableLocal(task.getId(), "testVar", "testValue"); ExecutionEntity taskExecution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult(); assertNotNull(taskExecution); HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(1, query.count()); HistoricVariableInstance variable = query.singleResult(); assertNotNull(variable); // the variable is in the task scope assertEquals(taskExecution.getActivityInstanceId(), variable.getActivityInstanceId()); taskService.complete(task.getId()); assertProcessEnded(pi.getId()); }
@Deployment public void testSetVariableLocalOnTaskInsideParallelBranch() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("process"); Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); taskService.setVariableLocal(task.getId(), "testVar", "testValue"); ExecutionEntity taskExecution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult(); assertNotNull(taskExecution); HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); assertEquals(1, query.count()); HistoricVariableInstance variable = query.singleResult(); // the variable is in the user task scope assertEquals(taskExecution.getActivityInstanceId(), variable.getActivityInstanceId()); taskService.complete(task.getId()); assertProcessEnded(pi.getId()); }