Search in sources :

Example 21 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class IdentityLinkEventsTest method testProcessDefinitionIdentityLinkEvents.

/**
	 * Check identity links on process definitions. 
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionIdentityLinkEvents() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").singleResult();
    assertNotNull(processDefinition);
    // Add candidate user and group
    repositoryService.addCandidateStarterUser(processDefinition.getId(), "kermit");
    repositoryService.addCandidateStarterGroup(processDefinition.getId(), "sales");
    assertEquals(4, listener.getEventsReceived().size());
    ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    listener.clearEventsReceived();
    // Delete identity links
    repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "kermit");
    repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), "sales");
    assertEquals(2, listener.getEventsReceived().size());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
    assertNull(event.getProcessInstanceId());
    assertNull(event.getExecutionId());
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 22 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class IdentityLinkEventsTest method testProcessInstanceIdentityLinkEvents.

/**
	 * Check identity links on process instances. 
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceIdentityLinkEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // Add identity link
    runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "test");
    assertEquals(2, listener.getEventsReceived().size());
    ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    IdentityLink link = (IdentityLink) event.getEntity();
    assertEquals("kermit", link.getUserId());
    assertEquals("test", link.getType());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    listener.clearEventsReceived();
    // Deleting process should delete identity link
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    assertEquals(1, listener.getEventsReceived().size());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    assertTrue(event.getEntity() instanceof IdentityLink);
    link = (IdentityLink) event.getEntity();
    assertEquals("kermit", link.getUserId());
    assertEquals("test", link.getType());
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdentityLink(org.activiti.engine.task.IdentityLink) Deployment(org.activiti.engine.test.Deployment)

Example 23 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class JobEventsTest method testJobEntityEventsException.

/**
	 * Test create, update and delete events of jobs entities.
	 */
@Deployment
public void testJobEntityEventsException() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Set retries to 1, to prevent multiple chains of events being thrown
    managementService.setJobRetries(theJob.getId(), 1);
    listener.clearEventsReceived();
    // Force timer to fire
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
    try {
        managementService.executeJob(theJob.getId());
        fail("Expected exception");
    } catch (Exception e) {
    // exception expected
    }
    // Check delete-event has been dispatched
    assertEquals(5, listener.getEventsReceived().size());
    // First, the timer was fired
    ActivitiEvent event = listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.TIMER_FIRED, event.getType());
    checkEventContext(event, theJob, true);
    // Second, the job-entity was deleted, as the job was executed
    event = listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
    checkEventContext(event, theJob, true);
    // Next, a job failed event is dispatched
    event = listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.JOB_EXECUTION_FAILURE, event.getType());
    checkEventContext(event, theJob, true);
    // Finally, an update-event is received and the job count is decremented
    event = listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
    checkEventContext(event, theJob, true);
    event = listener.getEventsReceived().get(4);
    assertEquals(ActivitiEventType.JOB_RETRIES_DECREMENTED, event.getType());
    assertEquals(0, ((Job) ((ActivitiEntityEvent) event).getEntity()).getRetries());
    checkEventContext(event, theJob, true);
}
Also used : Calendar(java.util.Calendar) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 24 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class ProcessInstanceEventsTest method testProcessInstanceEvents.

/**
	 * Test create, update and delete events of process instances.
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceEvents() 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(), ((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());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    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());
    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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    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());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    listener.clearEventsReceived();
    runtimeService.deleteProcessInstance(processInstance.getId(), "Testing events");
    List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals(1, processCancelledEvents.size());
    ActivitiCancelledEvent cancelledEvent = (ActivitiCancelledEvent) processCancelledEvents.get(0);
    assertEquals(ActivitiEventType.PROCESS_CANCELLED, cancelledEvent.getType());
    assertEquals(processInstance.getId(), cancelledEvent.getProcessInstanceId());
    assertEquals(processInstance.getId(), cancelledEvent.getExecutionId());
    listener.clearEventsReceived();
}
Also used : ActivitiProcessStartedEvent(org.activiti.engine.delegate.event.ActivitiProcessStartedEvent) ActivitiCancelledEvent(org.activiti.engine.delegate.event.ActivitiCancelledEvent) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Deployment(org.activiti.engine.test.Deployment)

Example 25 with ActivitiEntityEvent

use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.

the class ProcessInstanceEventsTest method testProcessCompletedEvents_callActivityErrorEndEvent.

@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorOnCallActivity-parent.bpmn20.xml", "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testProcessCompletedEvents_callActivityErrorEndEvent() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("catchErrorOnCallActivity");
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("Task in subprocess", task.getName());
    List<ProcessInstance> subProcesses = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).list();
    assertEquals(1, subProcesses.size());
    // Completing the task will reach the end error event,
    // which is caught on the call activity boundary
    taskService.complete(task.getId());
    List<ActivitiEvent> processCompletedEvents = listener.filterEvents(ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT);
    assertEquals("There should be exactly one ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT event after the task complete.", 1, processCompletedEvents.size());
    ActivitiEntityEvent processCompletedEvent = (ActivitiEntityEvent) processCompletedEvents.get(0);
    assertEquals(subProcesses.get(0).getId(), processCompletedEvent.getExecutionId());
    task = taskService.createTaskQuery().singleResult();
    assertEquals("Escalated Task", task.getName());
    // Completing the task will end the process instance
    taskService.complete(task.getId());
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Deployment(org.activiti.engine.test.Deployment)

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