Camunda BPMN testing with Mockito
Published On: 2019/08/12
Unit testing of a BPMN is not simple as that of a java class. Camunda mockito extension has provided a simple implementation to create unit tests for BPMN. In this article we will walk through a sample test case of customer activation BPMN in the cloudmessage platform.
Maven Configuration
<dependency>
<groupId>org.camunda.bpm.extension.mockito</groupId>
<artifactId>camunda-bpm-mockito</artifactId>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
BPMN Diagram
In the customer activation process, systems sends a message to the customer with activation link and then wait for the customer action. When the customer clicks on the link a message will be sent back to the system to resume the process.
Testcase Implementation
The full implementation of this testcase can be viewed here
First step is to create a process engine.
@Rule
public final ProcessEngineRule processEngineRule = new ProcessEngineRule(testAwareProcessEngineConfiguration().buildProcessEngine());
private static final String MESSAGE_ACTIVATION_RESULT = "Message_Activation_Result";
private static final String RECIEVE_ACTIVITY="process_activation_result";
autoMock("bpmn/customer-activation.bpmn");
assertThat(Mocks.get("startActivation")).isNotNull();
assertThat(Mocks.get("processActivationResult")).isNotNull();
assertThat(Mocks.get("completeActivation")).isNotNull();
assertThat(Mocks.get("sendActivationRequest")).isNotNull();
processEngineRule.manageDeployment(registerCallActivityMock(RECIEVE_ACTIVITY)
.onExecutionWaitForMessage(MESSAGE_ACTIVATION_RESULT)
.deploy(processEngineRule));
verifyExecutionListenerMock("startActivation").executed(); // For Listeners
verifyJavaDelegateMock("sendActivationRequest").executed(); // For Delegates
processEngineRule.getRuntimeService().correlateMessage(MESSAGE_ACTIVATION_RESULT);
Conclusion
In this article, the testing of a BPMN process using camunda and mockito is covered with a simple project setup . The source code of this project is available in the cloudmessage stream Github repository.