use of org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method addAndRemoveEventListenerTypedNullType.
/**
* Test that adding a listener with a null-type is never called.
*/
public void addAndRemoveEventListenerTypedNullType() throws Exception {
// Create a listener that just adds the events to a list
TestActivitiEventListener newListener = new TestActivitiEventListener();
// Add event-listener to dispatcher
dispatcher.addEventListener(newListener, (ActivitiEventType) null);
ActivitiEntityEventImpl event1 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl event2 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_DELETED);
// Dispatch events, all should have entered the listener
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertTrue(newListener.getEventsReceived().isEmpty());
}
use of org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method addAndRemoveEventListenerTyped.
/**
* Test adding a listener and check if events are sent to it, for the types it
* was registered for. Also checks that after removal, no events are received.
*/
public void addAndRemoveEventListenerTyped() throws Exception {
// Create a listener that just adds the events to a list
TestActivitiEventListener newListener = new TestActivitiEventListener();
// Add event-listener to dispatcher
dispatcher.addEventListener(newListener, ActivitiEventType.ENTITY_CREATED, ActivitiEventType.ENTITY_DELETED);
ActivitiEntityEventImpl event1 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl event2 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_DELETED);
ActivitiEntityEventImpl event3 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_UPDATED);
// Dispatch events, only 2 out of 3 should have entered the listener
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
dispatcher.dispatchEvent(event3);
assertEquals(2, newListener.getEventsReceived().size());
assertEquals(event1, newListener.getEventsReceived().get(0));
assertEquals(event2, newListener.getEventsReceived().get(1));
// Remove listener and dispatch events again, listener should not be invoked
dispatcher.removeEventListener(newListener);
newListener.clearEventsReceived();
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertTrue(newListener.getEventsReceived().isEmpty());
}
use of org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method addAndRemoveEventListenerAllEvents.
/**
* Test adding a listener and check if events are sent to it. Also checks that
* after removal, no events are received.
*/
public void addAndRemoveEventListenerAllEvents() throws Exception {
// Create a listener that just adds the events to a list
TestActivitiEventListener newListener = new TestActivitiEventListener();
// Add event-listener to dispatcher
dispatcher.addEventListener(newListener);
ActivitiEntityEventImpl event1 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
ActivitiEntityEventImpl event2 = new ActivitiEntityEventImpl(new TaskEntity(), ActivitiEventType.ENTITY_CREATED);
// Dispatch events
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertEquals(2, newListener.getEventsReceived().size());
assertEquals(event1, newListener.getEventsReceived().get(0));
assertEquals(event2, newListener.getEventsReceived().get(1));
// Remove listener and dispatch events again, listener should not be invoked
dispatcher.removeEventListener(newListener);
newListener.clearEventsReceived();
dispatcher.dispatchEvent(event1);
dispatcher.dispatchEvent(event2);
assertTrue(newListener.getEventsReceived().isEmpty());
}
use of org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl in project Activiti by Activiti.
the class ActivitiEventDispatcherTest method baseEntityEventListener.
/**
* Test the {@link BaseEntityEventListener} shipped with Activiti.
*/
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());
}
Aggregations