Search in sources :

Example 31 with ActivitiEntityEvent

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

the class UserEventsTest method testUserEntityEvents.

/**
	 * Test create, update and delete events of users.
	 */
public void testUserEntityEvents() throws Exception {
    User user = null;
    try {
        user = identityService.newUser("fred");
        user.setFirstName("Frederik");
        user.setLastName("Heremans");
        identityService.saveUser(user);
        assertEquals(2, listener.getEventsReceived().size());
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
        assertTrue(event.getEntity() instanceof User);
        User userFromEvent = (User) event.getEntity();
        assertEquals("fred", userFromEvent.getId());
        assertNull(event.getProcessDefinitionId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessInstanceId());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
        assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
        listener.clearEventsReceived();
        // Update user
        user.setFirstName("Anna");
        identityService.saveUser(user);
        assertEquals(1, listener.getEventsReceived().size());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
        assertTrue(event.getEntity() instanceof User);
        userFromEvent = (User) event.getEntity();
        assertEquals("fred", userFromEvent.getId());
        assertEquals("Anna", userFromEvent.getFirstName());
        assertNull(event.getProcessDefinitionId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessInstanceId());
        listener.clearEventsReceived();
        // Delete user
        identityService.deleteUser(user.getId());
        assertEquals(1, listener.getEventsReceived().size());
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertTrue(event.getEntity() instanceof User);
        userFromEvent = (User) event.getEntity();
        assertEquals("fred", userFromEvent.getId());
        assertNull(event.getProcessDefinitionId());
        assertNull(event.getExecutionId());
        assertNull(event.getProcessInstanceId());
        listener.clearEventsReceived();
    } finally {
        if (user != null && user.getId() != null) {
            identityService.deleteUser(user.getId());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

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