use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ProcessInstanceEventsTest method testSubProcessInstanceEvents.
/**
* Test create, update and delete events of process instances.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/nestedSubProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testSubProcessInstanceEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("nestedSimpleSubProcess");
assertNotNull(processInstance);
// Check create-event one main process the second one Scope execution, and the third one subprocess
assertEquals(8, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.PROCESS_STARTED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
assertTrue(event instanceof ActivitiProcessStartedEvent);
assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessDefinitionId());
assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessInstanceId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(3);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getParentId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(4);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getParentId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(5);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(6);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(7);
assertEquals(ActivitiEventType.PROCESS_STARTED, event.getType());
assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
assertTrue(event instanceof ActivitiProcessStartedEvent);
assertEquals(processInstance.getProcessDefinitionId(), ((ActivitiProcessStartedEvent) event).getNestedProcessDefinitionId());
assertEquals(processInstance.getId(), ((ActivitiProcessStartedEvent) event).getNestedProcessInstanceId());
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class TaskEventsTest method testTaskAssignmentEventInProcess.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskAssignmentEventInProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
listener.clearEventsReceived();
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Set assignee through API
taskService.setAssignee(task.getId(), "kermit");
assertEquals(2, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TASK_ASSIGNED, event.getType());
assertTrue(event.getEntity() instanceof Task);
Task taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertEquals("kermit", taskFromEvent.getAssignee());
assertExecutionDetails(event, processInstance);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Set assignee through updateTask
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
task.setAssignee("newAssignee");
taskService.saveTask(task);
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TASK_ASSIGNED, event.getType());
assertTrue(event.getEntity() instanceof Task);
taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertEquals("newAssignee", taskFromEvent.getAssignee());
assertExecutionDetails(event, processInstance);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Unclaim
taskService.unclaim(task.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TASK_ASSIGNED, event.getType());
assertTrue(event.getEntity() instanceof Task);
taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertEquals(null, taskFromEvent.getAssignee());
assertExecutionDetails(event, processInstance);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ModelEventsTest method testModelEvents.
/**
* Test create, update and delete events of model entities.
*/
public void testModelEvents() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("My model");
model.setKey("key");
repositoryService.saveModel(model);
// Check create event
assertEquals(2, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_CREATED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, listener.getEventsReceived().get(1).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(1)).getEntity()).getId());
listener.clearEventsReceived();
// Update model
model = repositoryService.getModel(model.getId());
model.setName("Updated");
repositoryService.saveModel(model);
assertEquals(1, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
listener.clearEventsReceived();
// Test additional update-methods (source and extra-source)
repositoryService.addModelEditorSource(model.getId(), "test".getBytes());
repositoryService.addModelEditorSourceExtra(model.getId(), "test extra".getBytes());
assertEquals(2, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(1).getType());
listener.clearEventsReceived();
// Delete model events
repositoryService.deleteModel(model.getId());
assertEquals(1, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_DELETED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
listener.clearEventsReceived();
} finally {
if (model != null && repositoryService.getModel(model.getId()) != null) {
repositoryService.deleteModel(model.getId());
}
}
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ProcessDefinitionEventsTest method testProcessDefinitionEvents.
/**
* Test create, update and delete events of process definitions.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionEvents() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").singleResult();
assertNotNull(processDefinition);
// Check create-event
assertEquals(2, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when category is updated
repositoryService.setProcessDefinitionCategory(processDefinition.getId(), "test");
assertEquals(1, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
assertEquals("test", ((ProcessDefinition) event.getEntity()).getCategory());
listener.clearEventsReceived();
// Check update event when suspended/activated
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
repositoryService.activateProcessDefinitionById(processDefinition.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
listener.clearEventsReceived();
// Check delete event when category is updated
repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);
deploymentIdFromDeploymentAnnotation = null;
assertEquals(1, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processDefinition.getId(), ((ProcessDefinition) event.getEntity()).getId());
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class AttachmentEventsTest method testAttachmentEntityEventsStandaloneTask.
/**
* Test create, update and delete events of users.
*/
public void testAttachmentEntityEventsStandaloneTask() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
Task task = null;
try {
task = taskService.newTask();
taskService.saveTask(task);
assertNotNull(task);
// Create link-attachment
Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
assertEquals(2, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
assertNull(event.getProcessDefinitionId());
Attachment attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Create binary attachment
attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", new ByteArrayInputStream("test".getBytes()));
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
assertNull(event.getProcessDefinitionId());
attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Update attachment
attachment = taskService.getAttachment(attachment.getId());
attachment.setDescription("Description");
taskService.saveAttachment(attachment);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
assertNull(event.getProcessDefinitionId());
attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
assertEquals("Description", attachmentFromEvent.getDescription());
listener.clearEventsReceived();
// Finally, delete attachment
taskService.deleteAttachment(attachment.getId());
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
assertNull(event.getProcessDefinitionId());
attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
} finally {
if (task != null && task.getId() != null) {
taskService.deleteTask(task.getId());
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
}
Aggregations