Search in sources :

Example 1 with ActivitiEntityEvent

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

Example 2 with ActivitiEntityEvent

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();
}
Also used : 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 3 with ActivitiEntityEvent

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

Example 4 with ActivitiEntityEvent

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

Example 5 with ActivitiEntityEvent

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());
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ByteArrayInputStream(java.io.ByteArrayInputStream) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) Attachment(org.activiti.engine.task.Attachment)

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