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());
}
}
}
Aggregations