Add global Process Application Event Listener to camunda-engine-unittest

In my appllication I use Global Process Application Event Listener and observe a problem when using them with Call Activities (when writing process variables via the listeners during process deletion). I would like to try to reproduce the problem in a simpler environment to be able to submit a qualified bug report if necessary.

I now wonder how to extend the camunda-engine-unittest test project so that it makes use of Process Application Event Listener. Is there a simple way to “register” these listeners. I did not found a simple way yet.

Hey Franz,

as an example you can see the ProcessApplicationEventListenerTest#testShouldInvokeExecutionListenerOnStartAndEndOfProcessInstance test.

I changed the camunda-engine-unittest regarding to this test case and it worked for me.
Change the SimpleTestCase into this:

public class SimpleTestCase {

  @Rule
  public ProcessEngineRule rule = new ProcessEngineRule();

  @Test
  public void shouldExecuteProcess() {
    // set up
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("startToEnd").startEvent().endEvent().done();
    Deployment deployment = rule.getRepositoryService()
      .createDeployment()
      .addModelInstance("test.bpmn20.xml", modelInstance)
      .deploy();

    final AtomicInteger processDefinitionEventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {
      public ExecutionListener getExecutionListener() {
        // this process application returns an execution listener
        return new ExecutionListener() {
          public void notify(DelegateExecution execution) throws Exception {
            if (((CoreExecution) execution).getEventSource() instanceof ProcessDefinitionEntity)
              processDefinitionEventCount.incrementAndGet();
          }
        };
      }
    };

    // register app so that it receives events
    rule.getManagementService()
        .registerProcessApplication(deployment.getId(), processApplication.getReference());

    // Start process instance.
    rule.getRuntimeService().startProcessInstanceByKey("startToEnd");

    // Start and end of the process
    assertEquals(2, processDefinitionEventCount.get());
  }
}

And replace the engine plugins in the camunda.cfg.xml with this plugin:

    <property name="processEnginePlugins">
      <list>
        <bean class="org.camunda.bpm.application.impl.event.ProcessApplicationEventListenerPlugin" />
      </list>
    </property>

Hope it helps.

Best regards,
Chris

Hi Chris,

that works, thanks. Would of course be nice if this would be made somehow easier in the camunda-engine-unittest project but afterall it is already possible. Thanks again!

Kind regards,
Franz