use of org.activiti.engine.delegate.event.ActivitiEvent in project Activiti by Activiti.
the class ProcessInstanceEventsTest method testProcessInstanceCancelledEvents_cancell.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceCancelledEvents_cancell() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), "delete_test");
List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
assertEquals("ActivitiEventType.PROCESS_CANCELLED was expected 1 time.", 1, processCancelledEvents.size());
ActivitiCancelledEvent processCancelledEvent = (ActivitiCancelledEvent) processCancelledEvents.get(0);
assertTrue("The cause has to be the same as deleteProcessInstance method call", ActivitiCancelledEvent.class.isAssignableFrom(processCancelledEvent.getClass()));
assertEquals("The process instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), processCancelledEvent.getProcessInstanceId());
assertEquals("The execution instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), processCancelledEvent.getExecutionId());
assertEquals("The cause has to be the same as in deleteProcessInstance method call", "delete_test", processCancelledEvent.getCause());
List<ActivitiEvent> taskCancelledEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
assertEquals("ActivitiEventType.ACTIVITY_CANCELLED was expected 1 time.", 1, taskCancelledEvents.size());
ActivitiActivityCancelledEvent activityCancelledEvent = (ActivitiActivityCancelledEvent) taskCancelledEvents.get(0);
assertTrue("The cause has to be the same as deleteProcessInstance method call", ActivitiActivityCancelledEvent.class.isAssignableFrom(activityCancelledEvent.getClass()));
assertEquals("The activity id has to be the same as processInstance activity", processInstance.getActivityId(), activityCancelledEvent.getActivityId());
assertEquals("The process instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), activityCancelledEvent.getProcessInstanceId());
assertEquals("The execution instance has to be the same as in deleteProcessInstance method call", processInstance.getId(), activityCancelledEvent.getExecutionId());
assertEquals("The cause has to be the same as in deleteProcessInstance method call", "delete_test", activityCancelledEvent.getCause());
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEvent in project Activiti by Activiti.
the class PlaybackRunTest 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;
}
use of org.activiti.engine.delegate.event.ActivitiEvent in project Activiti by Activiti.
the class StartTimerEventRepeatWithoutEndDateTest method testCycleDateStartTimerEvent.
/**
* Timer repetition
*/
public void testCycleDateStartTimerEvent() throws Exception {
Clock previousClock = processEngineConfiguration.getClock();
Clock testClock = new DefaultClockImpl();
processEngineConfiguration.setClock(testClock);
Calendar calendar = Calendar.getInstance();
calendar.set(2025, Calendar.DECEMBER, 10, 0, 0, 0);
testClock.setCurrentTime(calendar.getTime());
// deploy the process
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/event/timer/StartTimerEventRepeatWithoutEndDateTest.testCycleDateStartTimerEvent.bpmn20.xml").deploy();
assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo(1);
// AFTER DEPLOYMENT
// when the process is deployed there will be created a timerStartEvent
// job which will wait to be executed.
List<Job> jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(1);
// dueDate should be after 24 hours from the process deployment
Calendar dueDateCalendar = Calendar.getInstance();
dueDateCalendar.set(2025, Calendar.DECEMBER, 11, 0, 0, 0);
// check the due date is inside the 2 seconds range
assertThat(Math.abs(dueDateCalendar.getTime().getTime() - jobs.get(0).getDuedate().getTime()) < 2000).isEqualTo(true);
// No process instances
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
assertThat(processInstances).hasSize(0);
// No tasks
List<Task> tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(0);
// ADVANCE THE CLOCK
// advance the clock after 9 days from starting the process ->
// the system will execute the pending job and will create a new one (day by day)
moveByMinutes((9 * 60 * 24));
executeJobExecutorForTime(10000, 200);
// there must be a pending job because the endDate is not reached yet
assertThat(managementService.createTimerJobQuery().count()).isEqualTo(1);
// After time advanced 9 days there should be 9 process instance started
processInstances = runtimeService.createProcessInstanceQuery().list();
assertThat(processInstances).hasSize(9);
// 9 task to be executed (the userTask "Task A")
tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(9);
// one new job will be created (and the old one will be deleted after execution)
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(1);
// check if the last job to be executed has the dueDate set correctly
// (10'th repeat after 10 dec. => dueDate must have DueDate = 20 dec.)
dueDateCalendar = Calendar.getInstance();
dueDateCalendar.set(2025, Calendar.DECEMBER, 20, 0, 0, 0);
assertThat(Math.abs(dueDateCalendar.getTime().getTime() - jobs.get(0).getDuedate().getTime()) < 2000).isEqualTo(true);
// ADVANCE THE CLOCK SO that all 10 repeats to be executed
// (last execution)
moveByMinutes(60 * 24);
try {
waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000, 200);
} catch (Exception e) {
fail("Because the maximum number of repeats is reached no other jobs are created");
}
// After the 10nth startEvent Execution should have 10 process instances started
// (since the first one was not completed)
processInstances = runtimeService.createProcessInstanceQuery().list();
assertThat(processInstances).hasSize(10);
// the current job will be deleted after execution and a new one will
// not be created. (all 10 has already executed)
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(0);
jobs = managementService.createJobQuery().list();
assertThat(jobs).hasSize(0);
// 10 tasks to be executed (the userTask "Task A")
// one task for each process instance
tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(10);
// FINAL CHECK
// count "timer fired" events
int timerFiredCount = 0;
List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
for (ActivitiEvent eventReceived : eventsReceived) {
if (ActivitiEventType.TIMER_FIRED.equals(eventReceived.getType())) {
timerFiredCount++;
}
}
// count "entity created" events
int eventCreatedCount = 0;
for (ActivitiEvent eventReceived : eventsReceived) {
if (ActivitiEventType.ENTITY_CREATED.equals(eventReceived.getType())) {
eventCreatedCount++;
}
}
// count "entity deleted" events
int eventDeletedCount = 0;
for (ActivitiEvent eventReceived : eventsReceived) {
if (ActivitiEventType.ENTITY_DELETED.equals(eventReceived.getType())) {
eventDeletedCount++;
}
}
// 10 timers fired
assertThat(timerFiredCount).isEqualTo(10);
// 20 jobs created, 2 per timer job
assertThat(eventCreatedCount).isEqualTo(20);
// 20 jobs deleted, 2 per timer job
assertThat(eventDeletedCount).isEqualTo(20);
// complete the processes.
for (ProcessInstance processInstance : processInstances) {
tasks = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).list();
Task task = tasks.get(0);
assertThat(task.getName()).isEqualTo("Task A");
assertThat(tasks).hasSize(1);
taskService.complete(task.getId());
}
// now All the process instances should be completed
processInstances = runtimeService.createProcessInstanceQuery().list();
assertThat(processInstances).hasSize(0);
// no jobs
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(0);
jobs = managementService.createJobQuery().list();
assertThat(jobs).hasSize(0);
// no tasks
tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(0);
listener.clearEventsReceived();
processEngineConfiguration.setClock(previousClock);
repositoryService.deleteDeployment(repositoryService.createDeploymentQuery().singleResult().getId(), true);
}
use of org.activiti.engine.delegate.event.ActivitiEvent in project Activiti by Activiti.
the class Activiti6ExecutionTest method testSubProcessEvents.
@Test
@Deployment
public void testSubProcessEvents() {
SubProcessEventListener listener = new SubProcessEventListener();
processEngineConfiguration.getEventDispatcher().addEventListener(listener);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessEvents");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
Execution subProcessExecution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("subProcess").singleResult();
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
// Verify Events
List<ActivitiEvent> events = listener.getEventsReceived();
assertThat(events).hasSize(2);
ActivitiActivityEvent event = (ActivitiActivityEvent) events.get(0);
assertThat(event.getActivityType()).isEqualTo("subProcess");
assertThat(event.getExecutionId()).isEqualTo(subProcessExecution.getId());
event = (ActivitiActivityEvent) events.get(1);
assertThat(event.getActivityType()).isEqualTo("subProcess");
assertThat(event.getExecutionId()).isEqualTo(subProcessExecution.getId());
processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
}
use of org.activiti.engine.delegate.event.ActivitiEvent in project Activiti by Activiti.
the class EventListenersConfigurationTest method testEventListenerConfiguration.
public void testEventListenerConfiguration() {
// Fetch the listener to check received events
TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
assertThat(listener).isNotNull();
// Clear any events received (eg. engine initialisation)
listener.clearEventsReceived();
// Dispatch a custom event
ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
assertThat(listener.getEventsReceived()).hasSize(1);
assertThat(listener.getEventsReceived().get(0)).isEqualTo(event);
}
Aggregations