Search in sources :

Example 11 with ActivitiEvent

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

the class ActivityEventsTest method testActivityTimeOutEventInSubProcess.

@Deployment(resources = "org/activiti/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testTimerOnNestingOfSubprocesses.bpmn20.xml")
public void testActivityTimeOutEventInSubProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnNestedSubprocesses");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Force timer to fire
    Calendar timeToFire = Calendar.getInstance();
    timeToFire.add(Calendar.HOUR, 2);
    timeToFire.add(Calendar.SECOND, 5);
    processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 200);
    // Check timeout-events have been dispatched
    assertEquals(3, listener.getEventsReceived().size());
    List<String> eventIdList = new ArrayList<String>();
    for (ActivitiEvent event : listener.getEventsReceived()) {
        assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
        assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
        eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
    }
    assertTrue(eventIdList.indexOf("innerTask1") >= 0);
    assertTrue(eventIdList.indexOf("innerTask2") >= 0);
    assertTrue(eventIdList.indexOf("innerFork") >= 0);
}
Also used : ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) 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 12 with ActivitiEvent

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

the class ActivityEventsTest method testActivityErrorEvents.

/**
	 * Test events related to error-events
	 */
@Deployment
public void testActivityErrorEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("errorProcess");
    assertNotNull(processInstance);
    // Error-handling should have ended the process
    ProcessInstance afterErrorInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNull(afterErrorInstance);
    ActivitiErrorEvent errorEvent = null;
    for (ActivitiEvent event : listener.getEventsReceived()) {
        if (event instanceof ActivitiErrorEvent) {
            if (errorEvent == null) {
                errorEvent = (ActivitiErrorEvent) event;
            } else {
                fail("Only one ActivityErrorEvent expected");
            }
        }
    }
    assertNotNull(errorEvent);
    assertEquals(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, errorEvent.getType());
    assertEquals("catchError", errorEvent.getActivityId());
    assertEquals("123", errorEvent.getErrorCode());
    assertEquals(processInstance.getId(), errorEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), errorEvent.getProcessDefinitionId());
    assertFalse(processInstance.getId().equals(errorEvent.getExecutionId()));
}
Also used : ActivitiErrorEvent(org.activiti.engine.delegate.event.ActivitiErrorEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Deployment(org.activiti.engine.test.Deployment)

Example 13 with ActivitiEvent

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

the class ActivityEventsTest method testActivityTimeOutEvent.

@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobEntityEvents.bpmn20.xml")
public void testActivityTimeOutEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Force timer to fire
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 100);
    // Check timeout has been dispatched
    assertEquals(1, listener.getEventsReceived().size());
    ActivitiEvent activitiEvent = listener.getEventsReceived().get(0);
    assertEquals("ACTIVITY_CANCELLED event expected", ActivitiEventType.ACTIVITY_CANCELLED, activitiEvent.getType());
    ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) activitiEvent;
    assertTrue("TIMER is the cause of the cancellation", cancelledEvent.getCause() instanceof TimerEntity);
}
Also used : ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) Calendar(java.util.Calendar) 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 14 with ActivitiEvent

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

the class ActivityEventsTest method testActivityTimeOutEventInCallActivity.

@Deployment
public void testActivityTimeOutEventInCallActivity() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Force timer to fire
    Calendar timeToFire = Calendar.getInstance();
    timeToFire.add(Calendar.HOUR, 2);
    timeToFire.add(Calendar.SECOND, 5);
    processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
    waitForJobExecutorToProcessAllJobs(20000, 500);
    // Check timeout-events have been dispatched
    assertEquals(4, listener.getEventsReceived().size());
    List<String> eventIdList = new ArrayList<String>();
    for (ActivitiEvent event : listener.getEventsReceived()) {
        assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
        assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
        eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
    }
    assertTrue(eventIdList.indexOf("innerTask1") >= 0);
    assertTrue(eventIdList.indexOf("innerTask2") >= 0);
    assertTrue(eventIdList.indexOf("innerFork") >= 0);
    assertTrue(eventIdList.indexOf("callActivity") >= 0);
}
Also used : ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) 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 15 with ActivitiEvent

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

the class SimpleSimulationRunTest method getTransformers.

private List<Function<ActivitiEvent, SimulationEvent>> getTransformers() {
    List<Function<ActivitiEvent, SimulationEvent>> transformers = new ArrayList<Function<ActivitiEvent, SimulationEvent>>();
    transformers.add(new DeploymentCreateTransformer(DEPLOYMENT_CREATED_EVENT_TYPE, DEPLOYMENT_RESOURCES_KEY));
    transformers.add(new ProcessInstanceCreateTransformer(PROCESS_INSTANCE_START_EVENT_TYPE, PROCESS_DEFINITION_ID_KEY, BUSINESS_KEY, VARIABLES_KEY));
    transformers.add(new UserTaskCompleteTransformer(USER_TASK_COMPLETED_EVENT_TYPE));
    return transformers;
}
Also used : Function(org.activiti.crystalball.simulator.delegate.event.Function) ProcessInstanceCreateTransformer(org.activiti.crystalball.simulator.delegate.event.impl.ProcessInstanceCreateTransformer) UserTaskCompleteTransformer(org.activiti.crystalball.simulator.delegate.event.impl.UserTaskCompleteTransformer) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) DeploymentCreateTransformer(org.activiti.crystalball.simulator.delegate.event.impl.DeploymentCreateTransformer)

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