Search in sources :

Example 1 with ActivitiEventImpl

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

the class EventListenersConfigurationTest method testEventListenerConfiguration.

public void testEventListenerConfiguration() {
    // Fetch the listener to check received events
    TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
    assertThat(listener).isNotNull();
    // Clear any events received (eg. engine initialisation)
    listener.clearEventsReceived();
    // Dispatch a custom event
    ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
    processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
    assertThat(listener.getEventsReceived()).hasSize(1);
    assertThat(listener.getEventsReceived().get(0)).isEqualTo(event);
}
Also used : ActivitiEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEventImpl) TestActivitiEventListener(org.activiti.engine.test.api.event.TestActivitiEventListener) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent)

Example 2 with ActivitiEventImpl

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

the class TypedEventListenersConfigurationTest method testEventListenerConfiguration.

public void testEventListenerConfiguration() {
    // Fetch the listener to check received events
    TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
    assertThat(listener).isNotNull();
    // Clear any events received (eg. engine initialisation)
    listener.clearEventsReceived();
    // Dispath a custom event
    ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
    processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
    assertThat(listener.getEventsReceived()).hasSize(1);
    assertThat(listener.getEventsReceived().get(0)).isEqualTo(event);
    listener.clearEventsReceived();
    // Dispatch another event the listener is registered for
    event = new ActivitiEventImpl(ActivitiEventType.ENTITY_DELETED);
    processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
    event = new ActivitiEventImpl(ActivitiEventType.ENTITY_UPDATED);
    processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
    assertThat(listener.getEventsReceived()).hasSize(2);
    assertThat(listener.getEventsReceived().get(0).getType()).isEqualTo(ActivitiEventType.ENTITY_DELETED);
    assertThat(listener.getEventsReceived().get(1).getType()).isEqualTo(ActivitiEventType.ENTITY_UPDATED);
    listener.clearEventsReceived();
    // Dispatch an event that is NOT part of the types configured
    event = new ActivitiEventImpl(ActivitiEventType.ENTITY_CREATED);
    processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
    assertThat(listener.getEventsReceived().isEmpty()).isTrue();
}
Also used : ActivitiEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEventImpl) TestActivitiEventListener(org.activiti.engine.test.api.event.TestActivitiEventListener) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent)

Example 3 with ActivitiEventImpl

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

the class ActivitiEventDispatcherTest method exceptionInListener.

/**
 * Test dispatching behavior when an exception occurs in the listener
 */
public void exceptionInListener() throws Exception {
    // Create listener that doesn't force the dispatching to fail
    TestExceptionActivitiEventListener listener = new TestExceptionActivitiEventListener(false);
    TestActivitiEventListener secondListener = new TestActivitiEventListener();
    dispatcher.addEventListener(listener);
    dispatcher.addEventListener(secondListener);
    ActivitiEventImpl event = new ActivitiEventImpl(ActivitiEventType.ENTITY_CREATED);
    try {
        dispatcher.dispatchEvent(event);
        assertThat(secondListener.getEventsReceived()).hasSize(1);
    } catch (Throwable t) {
        fail("No exception expected");
    }
    // Remove listeners
    dispatcher.removeEventListener(listener);
    dispatcher.removeEventListener(secondListener);
    // Create listener that forces the dispatching to fail
    listener = new TestExceptionActivitiEventListener(true);
    secondListener = new TestActivitiEventListener();
    dispatcher.addEventListener(listener);
    dispatcher.addEventListener(secondListener);
    assertThatExceptionOfType(ActivitiException.class).isThrownBy(() -> dispatcher.dispatchEvent(event)).withCauseInstanceOf(RuntimeException.class).satisfies(ae -> assertThat(ae.getCause()).hasMessage("Test exception"));
    // Second listener should NOT have been called
    assertThat(secondListener.getEventsReceived()).hasSize(0);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEventImpl)

Aggregations

ActivitiEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEventImpl)3 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)2 TestActivitiEventListener (org.activiti.engine.test.api.event.TestActivitiEventListener)2 ActivitiException (org.activiti.engine.ActivitiException)1