Hi, I spent 2 days investigating comunda docs and videos from official channel and really got stuck.
I am trying to write simple integration test. Process is starting but mock registration is not working.
So i expect that my mocked task will be run when process is started but instead of it not mocked task is run.
I checked dependencies version compatibility and it’s ok. I am using jdk 17. It is sprinboot app running with jdk 11, but I’m trying to avoid springboottest annotation and unneccessary complexity.
Please share some knowledge on this problem.
pom dependencies:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<camunda.spring-boot.version>7.17.0</camunda.spring-boot.version>
<java.version>11</java.version>
<!-- <skipTests>true</skipTests>-->
<!-- <excludeTests>**/*IntegrationTest</excludeTests>-->
</properties>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
<version>${camunda.spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bpm-junit5</artifactId>
<version>7.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bpm-assert</artifactId>
<version>7.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<scope>test</scope>
</dependency>
import com.si.app.process.service.ProcessRepositoryService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.junit5.ProcessEngineExtension;
import org.camunda.bpm.engine.test.mock.Mocks;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.*;
@ExtendWith(ProcessEngineExtension.class)
public class PreLaunchCheckTaskTest {
@RegisterExtension
ProcessEngineExtension extension = ProcessEngineExtension.builder()
.configurationResource("camunda.cfg.xml")
.build();
@Test
@Deployment(resources = "rv-reverify-contact_ver_4.bpmn")
public void execute() {
PreLaunchCheckTask preLaunchCheckTask = new PreLaunchCheckTask();
Mocks.register("preLaunchCheckTask", preLaunchCheckTask);
ProcessRepositoryService processRepositoryService =
Mockito.mock(ProcessRepositoryService.class);
ReflectionTestUtils.setField(preLaunchCheckTask, "processRepositoryService", processRepositoryService);
// Given we create a new process instance
ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("ReverifyContact");
// etc
}
Code to be tested
@Component
public class PreLaunchCheckTask extends ReverifyBaseTask {
@Override
public void execute(DelegateExecution execution) throws Exception {
String mainProcessUUID = execution.getProcessBusinessKey();
String subProcessUUID = (String) execution.getVariable(BPMProcessConfigNames.assigneeSubJobUUID.configName());
String mainProcessInstanceID = execution.getProcessInstanceId();
String subProcessInstanceID = execution.getActivityInstanceId();
processRepositoryService.updateBpmSubProcessExecution(mainProcessUUID, mainProcessInstanceID,
subProcessUUID, subProcessInstanceID);
}
}
public abstract class ReverifyBaseTask extends CommonBPM implements JavaDelegate {
//bussiness logic
}
@Component
public class CommonBPM {
@Autowired
protected ProcessRepositoryService processRepositoryService;
//bussiness logic
}
I got NPE on updateBpmSubProcessExecution cause processRepositoryService is null. So my preLaunchTask is not registered in testing process (I see in debug that running task and mocked one are different objects and that’s why I inject via reflection in not used in test mocked object)
I hope, code is crystal clear, I ommited excessive details
java.lang.NullPointerException: Cannot invoke “com.si.app.process.service.ProcessRepositoryService.updateBpmSubProcessExecution(String, String, String, String)” because “this.processRepositoryService” is null