public void baseEntityEventListener() throws Exception {
TestBaseEntityEventListener listener = new TestBaseEntityEventListener();
dispatcher.addEventListener(listener);
ActivitiEntityEventImpl createEvent = new ActivitiEntityEventImpl(new TaskEntity(),
ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl deleteEvent = new ActivitiEntityEventImpl(new TaskEntity(),
ActivitiEventType.ENTITY_DELETED);
ActivitiEntityEventImpl updateEvent = new ActivitiEntityEventImpl(new TaskEntity(),
ActivitiEventType.ENTITY_UPDATED);
ActivitiEntityEventImpl otherEvent = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.CUSTOM);
// Dispatch create event
dispatcher.dispatchEvent(createEvent);
assertTrue(listener.isCreateReceived());
assertFalse(listener.isUpdateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isInitializeReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Dispatch update event
dispatcher.dispatchEvent(updateEvent);
assertTrue(listener.isUpdateReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Dispatch delete event
dispatcher.dispatchEvent(deleteEvent);
assertTrue(listener.isDeleteReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isCustomReceived());
assertFalse(listener.isUpdateReceived());
listener.reset();
// Dispatch other event
dispatcher.dispatchEvent(otherEvent);
assertTrue(listener.isCustomReceived());
assertFalse(listener.isCreateReceived());
assertFalse(listener.isUpdateReceived());
assertFalse(listener.isDeleteReceived());
listener.reset();
// Test typed entity-listener
listener = new TestBaseEntityEventListener(Task.class);
// Dispatch event for a task, should be received
dispatcher.addEventListener(listener);
dispatcher.dispatchEvent(createEvent);
assertTrue(listener.isCreateReceived());
listener.reset();
// Dispatch event for a execution, should NOT be received
ActivitiEntityEventImpl createEventForExecution = new ActivitiEntityEventImpl(new ExecutionEntity(),
ActivitiEventType.ENTITY_CREATED);
dispatcher.dispatchEvent(createEventForExecution);
assertFalse(listener.isCreateReceived());
}