Java Code Examples for org.activiti.engine.delegate.event.ActivitiEventType#CUSTOM

The following examples show how to use org.activiti.engine.delegate.event.ActivitiEventType#CUSTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventListenersConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testEventListenerConfiguration() {
  // Fetch the listener to check received events
  TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
  assertNotNull(listener);

  // Clear any events received (eg. engine initialisation)
  listener.clearEventsReceived();

  // Dispatch a custom event
  ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
  processEngineConfiguration.getEventDispatcher().dispatchEvent(event);

  assertEquals(1, listener.getEventsReceived().size());
  assertEquals(event, listener.getEventsReceived().get(0));
}
 
Example 2
Source File: TypedEventListenersConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testEventListenerConfiguration() {
  // Fetch the listener to check received events
  TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
  assertNotNull(listener);

  // Clear any events received (eg. engine initialisation)
  listener.clearEventsReceived();

  // Dispath a custom event
  ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
  processEngineConfiguration.getEventDispatcher().dispatchEvent(event);

  assertEquals(1, listener.getEventsReceived().size());
  assertEquals(event, listener.getEventsReceived().get(0));
  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);

  assertEquals(2, listener.getEventsReceived().size());
  assertEquals(ActivitiEventType.ENTITY_DELETED, listener.getEventsReceived().get(0).getType());
  assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(1).getType());
  listener.clearEventsReceived();

  // Dispatch an event that is NOT part of the types configured
  event = new ActivitiEventImpl(ActivitiEventType.ENTITY_CREATED);
  processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
  assertTrue(listener.getEventsReceived().isEmpty());
}
 
Example 3
Source File: EventListenersConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testEventListenerConfiguration() {
	// Fetch the listener to check received events
	TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
	assertNotNull(listener);
	
	// Clear any events received (eg. engine initialisation)
  listener.clearEventsReceived();
	
	// Dispath a custom event
	ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
	processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
	
	assertEquals(1, listener.getEventsReceived().size());
	assertEquals(event, listener.getEventsReceived().get(0));
}
 
Example 4
Source File: TypedEventListenersConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testEventListenerConfiguration() {
	// Fetch the listener to check received events
	TestActivitiEventListener listener = (TestActivitiEventListener) processEngineConfiguration.getBeans().get("eventListener");
	assertNotNull(listener);
	
	// Clear any events received (eg. engine initialisation)
	listener.clearEventsReceived();
	
	// Dispath a custom event
	ActivitiEvent event = new ActivitiEventImpl(ActivitiEventType.CUSTOM);
	processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
	
	assertEquals(1, listener.getEventsReceived().size());
	assertEquals(event, listener.getEventsReceived().get(0));
	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);
 	
 	assertEquals(2, listener.getEventsReceived().size());
 	assertEquals(ActivitiEventType.ENTITY_DELETED, listener.getEventsReceived().get(0).getType());
 	assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(1).getType());
 	listener.clearEventsReceived();
	
	// Dispatch an event that is NOT part of the types configured
	event = new ActivitiEventImpl(ActivitiEventType.ENTITY_CREATED);
	processEngineConfiguration.getEventDispatcher().dispatchEvent(event);
	assertTrue(listener.getEventsReceived().isEmpty());
}
 
Example 5
Source File: ActivitiEventDispatcherTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test the {@link BaseEntityEventListener} shipped with Activiti.
 */
public void baseEntityEventListener() throws Exception {
  TestBaseEntityEventListener listener = new TestBaseEntityEventListener();

  dispatcher.addEventListener(listener);

  ActivitiEntityEventImpl createEvent = new ActivitiEntityEventImpl(processEngineConfiguration.getTaskEntityManager().create(), ActivitiEventType.ENTITY_CREATED);
  ActivitiEntityEventImpl deleteEvent = new ActivitiEntityEventImpl(processEngineConfiguration.getTaskEntityManager().create(), ActivitiEventType.ENTITY_DELETED);
  ActivitiEntityEventImpl updateEvent = new ActivitiEntityEventImpl(processEngineConfiguration.getTaskEntityManager().create(), ActivitiEventType.ENTITY_UPDATED);
  ActivitiEntityEventImpl otherEvent = new ActivitiEntityEventImpl(processEngineConfiguration.getTaskEntityManager().create(), 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 ExecutionEntityImpl(), ActivitiEventType.ENTITY_CREATED);

  dispatcher.dispatchEvent(createEventForExecution);
  assertFalse(listener.isCreateReceived());
}
 
Example 6
Source File: ActivitiEventDispatcherTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
}