Search in sources :

Example 16 with ActivitiEntityEvent

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());
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Attachment(org.activiti.engine.task.Attachment) Deployment(org.activiti.engine.test.Deployment)

Example 17 with ActivitiEntityEvent

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());
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 18 with ActivitiEntityEvent

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);
        }
    }
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

Example 19 with ActivitiEntityEvent

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();
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 20 with ActivitiEntityEvent

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());
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

Aggregations

ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)31 Deployment (org.activiti.engine.test.Deployment)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 Task (org.activiti.engine.task.Task)15 Attachment (org.activiti.engine.task.Attachment)5 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 HashMap (java.util.HashMap)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)2 ActivitiProcessStartedEvent (org.activiti.engine.delegate.event.ActivitiProcessStartedEvent)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 Comment (org.activiti.engine.task.Comment)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)1 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)1 Group (org.activiti.engine.identity.Group)1