*/
@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();
// fire timer for the first time
testClock.setCurrentTime(new Date(now.getTime() + 10000L));
waitForJobExecutorToProcessAllJobs(20000, 100);
// fire timer for the second time
testClock.setCurrentTime(new Date(now.getTime() + 20000L));
waitForJobExecutorToProcessAllJobs(20000, 100);
// do not fire timer
testClock.setCurrentTime(new Date(now.getTime() + 30000L));
waitForJobExecutorToProcessAllJobs(20000, 100);
// count timer fired events
int timerFiredCount = 0;
List<ActivitiEvent> eventsReceived = listener.getEventsReceived();