Search in sources :

Example 1 with TestActivitiEventListener

use of org.activiti.engine.test.api.event.TestActivitiEventListener in project Activiti by Activiti.

the class ProcessDefinitionScopedEventListenerDefinitionTest method testProcessDefinitionListenerDefinitionEntities.

/**
 * Test to verify listeners defined in the BPMN xml are added to the process definition and are active, for all entity types
 */
@Deployment
public void testProcessDefinitionListenerDefinitionEntities() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testEventListeners");
    assertThat(processInstance).isNotNull();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    // Attachment entity
    TestActivitiEventListener theListener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("testAttachmentEventListener");
    assertThat(theListener).isNotNull();
    assertThat(theListener.getEventsReceived()).hasSize(0);
    taskService.createAttachment("test", task.getId(), processInstance.getId(), "test", "test", "url");
    assertThat(theListener.getEventsReceived()).hasSize(2);
    assertThat(theListener.getEventsReceived().get(0).getType()).isEqualTo(ActivitiEventType.ENTITY_CREATED);
    assertThat(theListener.getEventsReceived().get(1).getType()).isEqualTo(ActivitiEventType.ENTITY_INITIALIZED);
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) StaticTestActivitiEventListener(org.activiti.engine.test.api.event.StaticTestActivitiEventListener) TestActivitiEventListener(org.activiti.engine.test.api.event.TestActivitiEventListener) Deployment(org.activiti.engine.test.Deployment)

Example 2 with TestActivitiEventListener

use of org.activiti.engine.test.api.event.TestActivitiEventListener 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 3 with TestActivitiEventListener

use of org.activiti.engine.test.api.event.TestActivitiEventListener 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 4 with TestActivitiEventListener

use of org.activiti.engine.test.api.event.TestActivitiEventListener in project Activiti by Activiti.

the class EngineEventsTest method testEngineEventsTest.

public void testEngineEventsTest() {
    // Fetch the listener to check received events
    TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
    assertThat(listener).isNotNull();
    // Check create-event
    assertThat(listener.getEventsReceived()).hasSize(1);
    assertThat(listener.getEventsReceived().get(0).getType()).isEqualTo(ActivitiEventType.ENGINE_CREATED);
    listener.clearEventsReceived();
    // Check close-event
    processEngine.close();
    assertThat(listener.getEventsReceived()).hasSize(1);
    assertThat(listener.getEventsReceived().get(0).getType()).isEqualTo(ActivitiEventType.ENGINE_CLOSED);
}
Also used : TestActivitiEventListener(org.activiti.engine.test.api.event.TestActivitiEventListener)

Aggregations

TestActivitiEventListener (org.activiti.engine.test.api.event.TestActivitiEventListener)4 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)2 ActivitiEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEventImpl)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Task (org.activiti.engine.task.Task)1 Deployment (org.activiti.engine.test.Deployment)1 StaticTestActivitiEventListener (org.activiti.engine.test.api.event.StaticTestActivitiEventListener)1