Search in sources :

Example 11 with ActivitiVariableEvent

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());
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiVariableEvent(org.activiti.engine.delegate.event.ActivitiVariableEvent)

Aggregations

ActivitiVariableEvent (org.activiti.engine.delegate.event.ActivitiVariableEvent)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)6 Deployment (org.activiti.engine.test.Deployment)6 Task (org.activiti.engine.task.Task)3 HashMap (java.util.HashMap)2 Date (java.util.Date)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 EventLogEntryEntity (org.activiti.engine.impl.persistence.entity.EventLogEntryEntity)1 Execution (org.activiti.engine.runtime.Execution)1