Search in sources :

Example 21 with ActivitiEvent

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

the class JobEventsTest method testRepetitionJobEntityEvents.

/**
   * Timer repetition
   */
@Deployment
public void testRepetitionJobEntityEvents() throws Exception {
    Clock previousClock = processEngineConfiguration.getClock();
    Clock testClock = new DefaultClockImpl();
    processEngineConfiguration.setClock(testClock);
    Date now = new Date();
    testClock.setCurrentTime(now);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testRepetitionJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Check if create-event has been dispatched
    assertEquals(2, listener.getEventsReceived().size());
    ActivitiEvent event = listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    checkEventContext(event, theJob, false);
    event = listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    checkEventContext(event, theJob, false);
    listener.clearEventsReceived();
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
        fail("a new job must be prepared because there are 2 repeats");
    } catch (Exception ex) {
    //expected exception because a new job is prepared
    }
    testClock.setCurrentTime(new Date(now.getTime() + 10000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
        fail("a new job must be prepared because there are 2 repeats");
    } catch (Exception ex) {
    //expected exception because a new job is prepared
    }
    testClock.setCurrentTime(new Date(now.getTime() + 20000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
    } catch (Exception ex) {
        fail("There must be no jobs remaining");
    }
    testClock.setCurrentTime(new Date(now.getTime() + 30000L));
    try {
        waitForJobExecutorToProcessAllJobs(2000, 100);
    } catch (Exception ex) {
        fail("There must be no jobs remaining");
    }
    // count timer fired events
    int timerFiredCount = 0;
    List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
    for (ActivitiEvent eventReceived : eventsReceived) {
        if (ActivitiEventType.TIMER_FIRED.equals(eventReceived.getType())) {
            timerFiredCount++;
        }
    }
    listener.clearEventsReceived();
    processEngineConfiguration.setClock(previousClock);
    assertEquals(2, timerFiredCount);
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Clock(org.activiti.engine.runtime.Clock) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 22 with ActivitiEvent

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

the class ProcessInstanceEventsTest method testProcessInstanceTerminatedEvents.

@Deployment(resources = "org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.testProcessTerminate.bpmn")
public void testProcessInstanceTerminatedEvents() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");
    long executionEntities = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).count();
    assertEquals(3, executionEntities);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preTerminateTask").singleResult();
    taskService.complete(task.getId());
    List<ActivitiEvent> processTerminatedEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals("There should be exactly one ActivitiEventType.PROCESS_CANCELLED event after the task complete.", 1, processTerminatedEvents.size());
    ActivitiProcessCancelledEventImpl activitiEvent = (ActivitiProcessCancelledEventImpl) processTerminatedEvents.get(0);
    assertThat(activitiEvent.getProcessInstanceId(), is(pi.getProcessInstanceId()));
    assertThat(((ActivityImpl) activitiEvent.getCause()).getId(), is("EndEvent_2"));
    List<ActivitiEvent> activityTerminatedEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat("There should be exactly two ActivitiEventType.ACTIVITY_CANCELLED event after the task complete.", activityTerminatedEvents.size(), is(2));
    ActivitiActivityCancelledEventImpl activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(0);
    assertThat("The user task must be terminated", activityEvent.getActivityId(), is("preNormalTerminateTask"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_2"));
    activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(1);
    assertThat("The gateway must be terminated", activityEvent.getActivityId(), is("ParallelGateway_1"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_2"));
}
Also used : Task(org.activiti.engine.task.Task) ActivitiActivityCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiActivityCancelledEventImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) ActivitiProcessCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl) Deployment(org.activiti.engine.test.Deployment)

Example 23 with ActivitiEvent

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

the class ProcessInstanceEventsTest method testProcessInstanceCancelledEvents_complete.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceCancelledEvents_complete() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processInstance);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals("There should be no ActivitiEventType.PROCESS_CANCELLED event after process complete.", 0, processCancelledEvents.size());
    List<ActivitiEvent> taskCancelledEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
    assertEquals("There should be no ActivitiEventType.ACTIVITY_CANCELLED event.", 0, taskCancelledEvents.size());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Deployment(org.activiti.engine.test.Deployment)

Example 24 with ActivitiEvent

use of org.activiti.engine.delegate.event.ActivitiEvent 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 ActivitiEvent

use of org.activiti.engine.delegate.event.ActivitiEvent 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

ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)31 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)23 Deployment (org.activiti.engine.test.Deployment)19 Task (org.activiti.engine.task.Task)11 Job (org.activiti.engine.runtime.Job)10 Calendar (java.util.Calendar)9 ActivitiActivityCancelledEvent (org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent)5 DefaultClockImpl (org.activiti.engine.impl.util.DefaultClockImpl)5 Clock (org.activiti.engine.runtime.Clock)5 ArrayList (java.util.ArrayList)4 Function (org.activiti.crystalball.simulator.delegate.event.Function)4 ProcessInstanceCreateTransformer (org.activiti.crystalball.simulator.delegate.event.impl.ProcessInstanceCreateTransformer)4 UserTaskCompleteTransformer (org.activiti.crystalball.simulator.delegate.event.impl.UserTaskCompleteTransformer)4 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)4 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)3 ActivitiProcessCancelledEventImpl (org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl)3 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)3 DeploymentCreateTransformer (org.activiti.crystalball.simulator.delegate.event.impl.DeploymentCreateTransformer)2 ActivitiErrorEvent (org.activiti.engine.delegate.event.ActivitiErrorEvent)2 ActivitiActivityCancelledEventImpl (org.activiti.engine.delegate.event.impl.ActivitiActivityCancelledEventImpl)2