use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricTaskDeleteInProcessInstance.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testAttachmentEntityEventsOnHistoricTaskDeleteInProcessInstance() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Create link-attachment
Attachment attachment = taskService.createAttachment("test", task.getId(), processInstance.getId(), "attachment name", "description", "http://activiti.org");
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), null);
historyService.deleteHistoricProcessInstance(processInstance.getId());
assertEquals(1, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
Attachment attachmentFromEvent = (Attachment) event.getEntity();
assertEquals(attachment.getId(), attachmentFromEvent.getId());
}
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class CommentEventsTest method testCommentEntityEvents.
/**
* Test create, update and delete events of comments on a task/process.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCommentEntityEvents() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Create link-comment
Comment comment = taskService.addComment(task.getId(), task.getProcessInstanceId(), "comment");
assertEquals(2, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
Comment commentFromEvent = (Comment) event.getEntity();
assertEquals(comment.getId(), commentFromEvent.getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Finally, delete comment
taskService.deleteComment(comment.getId());
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
commentFromEvent = (Comment) event.getEntity();
assertEquals(comment.getId(), commentFromEvent.getId());
}
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class DeploymentEventsTest method testDeploymentEvents.
/**
* Test create, update and delete events of deployment entities.
*/
public void testDeploymentEvents() throws Exception {
Deployment deployment = null;
try {
listener.clearEventsReceived();
deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml").deploy();
assertNotNull(deployment);
// 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(deployment.getId(), ((Deployment) event.getEntity()).getId());
assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiEntityEvent);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(deployment.getId(), ((Deployment) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when category is updated
repositoryService.setDeploymentCategory(deployment.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(deployment.getId(), ((Deployment) event.getEntity()).getId());
assertEquals("test", ((Deployment) event.getEntity()).getCategory());
listener.clearEventsReceived();
// Check delete event when category is updated
repositoryService.deleteDeployment(deployment.getId(), true);
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(deployment.getId(), ((Deployment) event.getEntity()).getId());
listener.clearEventsReceived();
} finally {
if (deployment != null && repositoryService.createDeploymentQuery().deploymentId(deployment.getId()).count() > 0) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ExecutionEventsTest method testExecutionEvents.
/**
* Test create, update and delete events of process instances.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testExecutionEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
// Check create-event
assertEquals(3, 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(), ((Execution) event.getEntity()).getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when suspended/activated
runtimeService.suspendProcessInstanceById(processInstance.getId());
runtimeService.activateProcessInstanceById(processInstance.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when process-definition is supended (should cascade suspend/activate all process instances)
repositoryService.suspendProcessDefinitionById(processInstance.getProcessDefinitionId(), true, null);
repositoryService.activateProcessDefinitionById(processInstance.getProcessDefinitionId(), true, null);
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update-event when business-key is updated
runtimeService.updateBusinessKey(processInstance.getId(), "thekey");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), "Testing events");
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class GroupEventsTest method testGroupEntityEvents.
/**
* Test create, update and delete events of Groups.
*/
public void testGroupEntityEvents() throws Exception {
Group group = null;
try {
group = identityService.newGroup("fred");
group.setName("name");
group.setType("type");
identityService.saveGroup(group);
assertEquals(2, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Group);
Group groupFromEvent = (Group) event.getEntity();
assertEquals("fred", groupFromEvent.getId());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Update Group
group.setName("Another name");
identityService.saveGroup(group);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertTrue(event.getEntity() instanceof Group);
groupFromEvent = (Group) event.getEntity();
assertEquals("fred", groupFromEvent.getId());
assertEquals("Another name", groupFromEvent.getName());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
listener.clearEventsReceived();
// Delete Group
identityService.deleteGroup(group.getId());
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof Group);
groupFromEvent = (Group) event.getEntity();
assertEquals("fred", groupFromEvent.getId());
assertNull(event.getProcessDefinitionId());
assertNull(event.getExecutionId());
assertNull(event.getProcessInstanceId());
listener.clearEventsReceived();
} finally {
if (group != null && group.getId() != null) {
identityService.deleteGroup(group.getId());
}
}
}
Aggregations