Search in sources :

Example 26 with ActivitiEntityEvent

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());
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) Job(org.activiti.engine.runtime.Job)

Example 27 with ActivitiEntityEvent

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();
}
Also used : TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 28 with ActivitiEntityEvent

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);
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 29 with ActivitiEntityEvent

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);
}
Also used : Task(org.activiti.engine.task.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 30 with ActivitiEntityEvent

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);
    }
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)31 Deployment (org.activiti.engine.test.Deployment)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 Task (org.activiti.engine.task.Task)15 Attachment (org.activiti.engine.task.Attachment)5 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 HashMap (java.util.HashMap)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)2 ActivitiProcessStartedEvent (org.activiti.engine.delegate.event.ActivitiProcessStartedEvent)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 Comment (org.activiti.engine.task.Comment)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)1 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)1 Group (org.activiti.engine.identity.Group)1