use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testProcessInstanceVariableEventsOnChildExecution.
/**
* Test create, update and delete variables locally on a child-execution of
* the process instance.
*/
@Deployment
public void testProcessInstanceVariableEventsOnChildExecution() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcess");
assertNotNull(processInstance);
Execution child = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(child);
runtimeService.setVariableLocal(child.getId(), "test", 1234567);
assertEquals(1, listener.getEventsReceived().size());
ActivitiVariableEvent event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.VARIABLE_CREATED, event.getType());
// Execution and process-id should differ
assertEquals(child.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class TestVariableEventListenerStore method onEvent.
@Override
public void onEvent(ActivitiEvent event) {
if (event instanceof ActivitiVariableEvent) {
eventsReceived.add(event);
EventLogEntryEntity eventLogEntry = new EventLogEntryEntity();
eventLogEntry.setProcessDefinitionId(event.getProcessDefinitionId());
eventLogEntry.setProcessInstanceId(event.getProcessInstanceId());
eventLogEntry.setExecutionId(event.getExecutionId());
eventLogEntry.setTaskId(((ActivitiVariableEvent) event).getTaskId());
eventLogEntry.setType(event.getType().name());
eventLogEntry.setTimeStamp(new Date());
CommandContext commandContext = Context.getCommandContext();
commandContext.getEventLogEntryEntityManager().insert(eventLogEntry);
}
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testProcessInstanceVariableEventsOnStart.
/**
* Test create event of variables when process is started with variables passed in.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceVariableEventsOnStart() throws Exception {
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("testVariable", "The value");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
assertNotNull(processInstance);
// Check create event
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();
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testTaskVariableEvents.
/**
* Test create, update and delete of task-local variables.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskVariableEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.setVariableLocal(task.getId(), "testVariable", "The value");
taskService.setVariableLocal(task.getId(), "testVariable", "Updated value");
taskService.removeVariableLocal(task.getId(), "testVariable");
// Check create event
assertEquals(3, 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());
assertEquals(task.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals("The value", event.getVariableValue());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.VARIABLE_UPDATED, event.getType());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(task.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
assertEquals("Updated value", event.getVariableValue());
event = (ActivitiVariableEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.VARIABLE_DELETED, event.getType());
// process definition Id is set to null
assertEquals(null, event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(task.getId(), event.getTaskId());
assertEquals("testVariable", event.getVariableName());
// deleted values are always null
assertEquals(null, event.getVariableValue());
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testTaskVariableEventsWithinProcess.
/**
* Test variable events when done within a process (eg. execution-listener)
*/
@Deployment
public void testTaskVariableEventsWithinProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
assertEquals(3, listener.getEventsReceived().size());
// Check create event
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());
assertEquals(task.getId(), event.getTaskId());
assertEquals("variable", event.getVariableName());
assertEquals(123, event.getVariableValue());
// Check udpate event
event = (ActivitiVariableEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.VARIABLE_UPDATED, event.getType());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(task.getId(), event.getTaskId());
assertEquals("variable", event.getVariableName());
assertEquals(456, event.getVariableValue());
// Check delete event
event = (ActivitiVariableEvent) listener.getEventsReceived().get(2);
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());
assertEquals(task.getId(), event.getTaskId());
assertEquals("variable", event.getVariableName());
// deleted variable value is always null
assertEquals(null, event.getVariableValue());
}
Aggregations