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