use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testTaskVariableStandalone.
/**
* Test to check create, update an delete behavior for variables on a task not related to a process.
*/
public void testTaskVariableStandalone() throws Exception {
Task newTask = taskService.newTask();
try {
taskService.saveTask(newTask);
taskService.setVariable(newTask.getId(), "testVariable", 123);
taskService.setVariable(newTask.getId(), "testVariable", 456);
taskService.removeVariable(newTask.getId(), "testVariable");
assertEquals(3, listener.getEventsReceived().size());
ActivitiVariableEvent event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.VARIABLE_CREATED, event.getType());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
assertEquals(newTask.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals(123, event.getVariableValue());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.VARIABLE_UPDATED, event.getType());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
assertEquals(newTask.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals(456, event.getVariableValue());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.VARIABLE_DELETED, event.getType());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
assertEquals(newTask.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
// deleted variable value is always null
assertEquals(null, event.getVariableValue());
} finally {
// Cleanup task and history to ensure a clean DB after test success/failure
if (newTask.getId() != null) {
taskService.deleteTask(newTask.getId());
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
historyService.deleteHistoricTaskInstance(newTask.getId());
}
}
}
}
Aggregations