use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableCreatedEventHandler method generateEventLogEntry.
@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
ActivitiVariableEvent variableEvent = (ActivitiVariableEvent) event;
Map<String, Object> data = createData(variableEvent);
data.put(Fields.CREATE_TIME, timeStamp);
return createEventLogEntry(variableEvent.getProcessDefinitionId(), variableEvent.getProcessInstanceId(), variableEvent.getExecutionId(), variableEvent.getTaskId(), data);
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method ActivitiEventType.
/**
* Test variable events when done within a process (eg. execution-listener)
*/
@Deployment
public void ActivitiEventType() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcess");
assertNotNull(processInstance);
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());
assertNull(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());
assertNull(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());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertNull(event.getTaskId());
assertEquals("variable", event.getVariableName());
assertEquals(456, event.getVariableValue());
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableDeletedEventHandler method generateEventLogEntry.
@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
ActivitiVariableEvent variableEvent = (ActivitiVariableEvent) event;
Map<String, Object> data = createData(variableEvent);
data.put(Fields.END_TIME, timeStamp);
return createEventLogEntry(variableEvent.getProcessDefinitionId(), variableEvent.getProcessInstanceId(), variableEvent.getExecutionId(), variableEvent.getTaskId(), data);
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableUpdatedEventHandler method generateEventLogEntry.
@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
ActivitiVariableEvent variableEvent = (ActivitiVariableEvent) event;
Map<String, Object> data = createData(variableEvent);
return createEventLogEntry(variableEvent.getProcessDefinitionId(), variableEvent.getProcessInstanceId(), variableEvent.getExecutionId(), variableEvent.getTaskId(), data);
}
use of org.activiti.engine.delegate.event.ActivitiVariableEvent in project Activiti by Activiti.
the class VariableEventsTest method testProcessInstanceVariableEvents.
/**
* Test create, update and delete variables on a process-instance, using the
* API.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceVariableEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
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);
vars.put("test2", 456);
runtimeService.setVariables(processInstance.getId(), vars);
runtimeService.setVariables(processInstance.getId(), vars);
runtimeService.removeVariables(processInstance.getId(), vars.keySet());
assertEquals(6, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.VARIABLE_CREATED, listener.getEventsReceived().get(0).getType());
assertEquals(ActivitiEventType.VARIABLE_CREATED, listener.getEventsReceived().get(1).getType());
assertEquals(ActivitiEventType.VARIABLE_UPDATED, listener.getEventsReceived().get(2).getType());
assertEquals(ActivitiEventType.VARIABLE_UPDATED, listener.getEventsReceived().get(3).getType());
assertEquals(ActivitiEventType.VARIABLE_DELETED, listener.getEventsReceived().get(4).getType());
assertEquals(ActivitiEventType.VARIABLE_DELETED, listener.getEventsReceived().get(5).getType());
listener.clearEventsReceived();
// Delete inexistent variable should not dispatch event
runtimeService.removeVariable(processInstance.getId(), "unexistingVariable");
assertTrue(listener.getEventsReceived().isEmpty());
}
Aggregations