assertNotNull(processInstance);
// Check create event
runtimeService.setVariable(processInstance.getId(), "testVariable", "The value");
assertEquals(1, listener.getEventsReceived().size());
ActivitiVariableEvent event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.VARIABLE_CREATED, event.getType());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertNull(event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals("The value", event.getVariableValue());
listener.clearEventsReceived();
// Update variable
runtimeService.setVariable(processInstance.getId(), "testVariable", "Updated value");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.VARIABLE_UPDATED, event.getType());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertNull(event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals("Updated value", event.getVariableValue());
listener.clearEventsReceived();
// Delete variable
runtimeService.removeVariable(processInstance.getId(), "testVariable");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.VARIABLE_DELETED, event.getType());
// process definition Id can't be recognized in DB flush
assertEquals(null, event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertNull(event.getTaskId());
assertEquals("testVariable", event.getVariableName());
// deleted variable value is always null
assertEquals(null, event.getVariableValue());
listener.clearEventsReceived();
// Create, update and delete multiple variables
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("test", 123);