cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a BPMN Parser

jatz
Champ in-the-making
Champ in-the-making
We have a unit test where a service task needs to be mocked as it calls an external web service.

To get around this we have added a handler to the ProcessEngineConfiguration as below:


processEngineConfiguration.getBpmnParser().getBpmnParserHandlers().addHandler(new ExternalCheckMockHandler("mock"));
processEngineConfiguration.buildProcessEngine();


This looks to work fine, except that when we encounter a listener (as shown below). This ends up getting called twice instead of once:


<serviceTask id="testServiceTask" name="Test Service Task" activiti:expression="#{testService.updateStatus(execution.getProcessBusinessKey())}">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{testService.runListener(execution.getProcessBusinessKey())}"></activiti:executionListener>
      </extensionElements>
    </serviceTask>


The testService.runListener runs two times instead of once at the end of the service task.

Could someone please guide me on if the way this handler has been added is the correct way to go?
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
If you want to mock out behaviours, I recommend using an custom org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory to acchieve this. An instance of this class can be set into the processEngineConfiguration. Instead of returning REAL service-task, you can return a mocked one OR replace the execution-listeners added by the default DefaultActivityBehaviorFactory and replace them by the listener you like to see called…

OR take a look at http://forums.activiti.org/content/activiti-mock-support we have some experimantal OOTB mock support which uses the approach described above. You can at least use this as a source of inspiration