use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class JobEventsTest method checkEventContext.
protected void checkEventContext(ActivitiEvent event, Job entity, boolean scopeExecutionExpected) {
assertEquals(entity.getProcessInstanceId(), event.getProcessInstanceId());
assertEquals(entity.getProcessDefinitionId(), event.getProcessDefinitionId());
if (scopeExecutionExpected) {
assertEquals(entity.getExecutionId(), event.getExecutionId());
} else {
assertEquals(entity.getProcessInstanceId(), event.getExecutionId());
}
assertTrue(event instanceof ActivitiEntityEvent);
ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
assertTrue(entityEvent.getEntity() instanceof Job);
assertEquals(entity.getId(), ((Job) entityEvent.getEntity()).getId());
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ProcessDefinitionEventsTest method testTimerStartEventDeployment.
/**
* test sequence of events for process definition with timer start event
*/
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/timer/StartTimerEventTest.testDurationStartTimerEvent.bpmn20.xml" })
public void testTimerStartEventDeployment() {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionKey("startTimerEventExample").singleResult();
ActivitiEntityEvent processDefinitionCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition);
TimerEntity timer = (TimerEntity) managementService.createJobQuery().singleResult();
ActivitiEntityEvent timerCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, timer);
assertSequence(processDefinitionCreated, timerCreated);
listener.clearEventsReceived();
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class ProcessDefinitionScopedEventListenerDefinitionTest method testProcessDefinitionListenerDefinition.
/**
* Test to verify listeners defined in the BPMN xml are added to the process
* definition and are active.
*/
@Deployment
public void testProcessDefinitionListenerDefinition() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testEventListeners");
assertNotNull(testListenerBean);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
// Check if the listener (defined as bean) received events (only creation, not other events)
assertFalse(testListenerBean.getEventsReceived().isEmpty());
for (ActivitiEvent event : testListenerBean.getEventsReceived()) {
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
}
// First event received should be creation of Process-definition
assertTrue(testListenerBean.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
ActivitiEntityEvent event = (ActivitiEntityEvent) testListenerBean.getEventsReceived().get(0);
assertTrue(event.getEntity() instanceof ProcessDefinition);
assertEquals(processInstance.getProcessDefinitionId(), ((ProcessDefinition) event.getEntity()).getId());
// First event received should be creation of Process-instance
assertTrue(testListenerBean.getEventsReceived().get(1) instanceof ActivitiEntityEvent);
event = (ActivitiEntityEvent) testListenerBean.getEventsReceived().get(1);
assertTrue(event.getEntity() instanceof ProcessInstance);
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
// Check if listener, defined by classname, received all events
List<ActivitiEvent> events = StaticTestActivitiEventListener.getEventsReceived();
assertFalse(events.isEmpty());
boolean insertFound = false;
boolean deleteFound = false;
for (ActivitiEvent e : events) {
if (ActivitiEventType.ENTITY_CREATED == e.getType()) {
insertFound = true;
} else if (ActivitiEventType.ENTITY_DELETED == e.getType()) {
deleteFound = true;
}
}
assertTrue(insertFound);
assertTrue(deleteFound);
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class TaskEventsTest method testTaskEventsInProcess.
/**
* Check create, update and delete events for a task.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskEventsInProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Check create event
assertEquals(3, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
Task taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertExecutionDetails(event, processInstance);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.TASK_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
taskFromEvent = (Task) event.getEntity();
assertEquals(task.getId(), taskFromEvent.getId());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Update duedate, owner and priority should trigger update-event
taskService.setDueDate(task.getId(), new Date());
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertExecutionDetails(event, processInstance);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
listener.clearEventsReceived();
taskService.setPriority(task.getId(), 12);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
taskService.setOwner(task.getId(), "kermit");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Updating detached task and calling saveTask should trigger a single update-event
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
task.setDueDate(new Date());
task.setOwner("john");
taskService.saveTask(task);
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
assertExecutionDetails(event, processInstance);
listener.clearEventsReceived();
// Check delete-event on complete
taskService.complete(task.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TASK_COMPLETED, event.getType());
assertExecutionDetails(event, processInstance);
TaskEntity taskEntity = (TaskEntity) event.getEntity();
assertNotNull(taskEntity.getDueDate());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertExecutionDetails(event, processInstance);
}
use of org.activiti.engine.delegate.event.ActivitiEntityEvent in project Activiti by Activiti.
the class TaskEventsTest method testEventFiringOrdering.
/**
* This method checks to ensure that the task.fireEvent(TaskListener.EVENTNAME_CREATE), fires before
* the dispatchEvent ActivitiEventType.TASK_CREATED. A ScriptTaskListener updates the priority and
* assignee before the dispatchEvent() takes place.
*/
@Deployment(resources = { "org/activiti/engine/test/api/event/TaskEventsTest.testEventFiring.bpmn20.xml" })
public void testEventFiringOrdering() {
//We need to add a special listener that copies the Task values - to record its state when the event fires,
//otherwise the in-memory task instances is changed after the event fires.
TestActivitiEntityEventTaskListener tlistener = new TestActivitiEntityEventTaskListener(Task.class);
processEngineConfiguration.getEventDispatcher().addEventListener(tlistener);
try {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testTaskLocalVars");
// Fetch first task
Task task = taskService.createTaskQuery().singleResult();
// Complete first task
Map<String, Object> taskParams = new HashMap<String, Object>();
taskService.complete(task.getId(), taskParams, true);
ActivitiEntityEvent event = (ActivitiEntityEvent) tlistener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
event = (ActivitiEntityEvent) tlistener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertTrue(event.getEntity() instanceof Task);
event = (ActivitiEntityEvent) tlistener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.TASK_CREATED, event.getType());
assertTrue(event.getEntity() instanceof Task);
Task taskFromEvent = tlistener.getTasks().get(2);
assertEquals(task.getId(), taskFromEvent.getId());
// verify script listener has done its job, on create before ActivitiEntityEvent was fired
assertEquals("The ScriptTaskListener must set this value before the dispatchEvent fires.", "scriptedAssignee", taskFromEvent.getAssignee());
assertEquals("The ScriptTaskListener must set this value before the dispatchEvent fires.", 877, taskFromEvent.getPriority());
// Fetch second task
taskService.createTaskQuery().singleResult();
} finally {
processEngineConfiguration.getEventDispatcher().removeEventListener(tlistener);
}
}
Aggregations