Search in sources :

Example 16 with ActivitiEvent

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

the class AbstractPlaybackTest method getTransformers.

protected List<Function<ActivitiEvent, SimulationEvent>> getTransformers() {
    List<Function<ActivitiEvent, SimulationEvent>> transformers = new ArrayList<Function<ActivitiEvent, SimulationEvent>>();
    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) ArrayList(java.util.ArrayList) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent)

Example 17 with ActivitiEvent

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

the class ReplayRunTest method getTransformers.

private static List<Function<ActivitiEvent, SimulationEvent>> getTransformers() {
    List<Function<ActivitiEvent, SimulationEvent>> transformers = new ArrayList<Function<ActivitiEvent, SimulationEvent>>();
    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) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent)

Example 18 with ActivitiEvent

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

the class HistoricActivityEventsTest method testHistoricActivityEventDispatched.

/**
   * Test added to assert the historic activity instance event
   */
@Deployment
public void testHistoricActivityEventDispatched() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestActivityEvents");
        assertNotNull(processInstance);
        for (int i = 0; i < 2; i++) {
            taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId());
        }
        List<ActivitiEvent> events = listener.getEventsReceived();
        // Process instance start
        assertEquals(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, events.get(0).getType());
        // main start
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(1).getType());
        assertEquals("mainStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(1)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(2).getType());
        assertEquals("mainStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(2)).getEntity()).getActivityId()));
        assertNotNull("mainStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(2)).getEntity()).getEndTime()));
        // Subprocess start
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(3).getType());
        assertEquals("subProcess", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(3)).getEntity()).getActivityId()));
        // subProcessStart
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(4).getType());
        assertEquals("subProcessStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(4)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(5).getType());
        assertEquals("subProcessStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(5)).getEntity()).getActivityId()));
        assertNotNull("subProcessStart", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(5)).getEntity()).getEndTime()));
        // Task a
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(6).getType());
        assertEquals("a", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(6)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(7).getType());
        assertEquals("a", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(7)).getEntity()).getActivityId()));
        assertNotNull("a", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(7)).getEntity()).getEndTime()));
        // Task b
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(8).getType());
        assertEquals("b", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(8)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(9).getType());
        assertEquals("b", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(9)).getEntity()).getActivityId()));
        assertNotNull("b", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(9)).getEntity()).getEndTime()));
        // subProcessEnd
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(10).getType());
        assertEquals("subprocessEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(10)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(11).getType());
        assertEquals("subprocessEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(11)).getEntity()).getActivityId()));
        assertNotNull("subprocessEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(11)).getEntity()).getEndTime()));
        // subProcess end
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(12).getType());
        assertEquals("subProcess", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(12)).getEntity()).getActivityId()));
        assertNotNull("subProcess", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(12)).getEntity()).getEndTime()));
        // main end
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, events.get(13).getType());
        assertEquals("mainEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(13)).getEntity()).getActivityId()));
        assertEquals(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, events.get(14).getType());
        assertEquals("mainEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(14)).getEntity()).getActivityId()));
        assertNotNull("mainEnd", (((HistoricActivityInstance) ((ActivitiEntityEvent) events.get(14)).getEntity()).getEndTime()));
        // Process instance end
        assertEquals(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, events.get(15).getType());
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 19 with ActivitiEvent

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

the class JobEventsTest method checkEventCount.

private void checkEventCount(int expectedCount, ActivitiEventType eventType) {
    // count timer cancelled events
    int timerCancelledCount = 0;
    List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
    for (ActivitiEvent eventReceived : eventsReceived) {
        if (eventType.equals(eventReceived.getType())) {
            timerCancelledCount++;
        }
    }
    assertEquals(eventType.name() + " event was expected " + expectedCount + " times.", expectedCount, timerCancelledCount);
}
Also used : ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent)

Example 20 with ActivitiEvent

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

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