I am able to run a Spring Boot application with Camunda for workflow management. My pom.xml with Camunda related dependencies are shown below.
<dependencyManagement>
...
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>7.15.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter</artifactId>
<version>7.15.0</version>
</dependency>
<!-- REST API -->
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
<version>7.15.0</version>
</dependency>
<!-- dashboard -->
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
<version>7.15.0</version>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-plugin-spin</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.spin</groupId>
<artifactId>camunda-spin-dataformat-all</artifactId>
</dependency>
I have just one .BPMN file. My application.yml file looks like this:
spring.main.banner-mode: console
server.port: 9090
springdoc:
model-and-view-allowed: true
swagger-ui:
operationsSorter: alpha
spring.jpa:
hibernate:
ddl-auto: none
show-sql: true
properties:
hibernate:
format_sql: true
spring.datasource:
initialization-mode: always
platform: postgres
url: jdbc:postgresql://xxxx
username: xxxx
password: xxxx
spring.flyway.enabled: false
camunda.bpm:
admin-user:
id: demo
password: demo
generic-properties:
properties:
generalResourceWhitelistPattern: "[a-zA-Z0-9,'_\\$\\-\\.\\+\\!\\*\\(\\)]+|camunda-admin"
In the codes, all I have to do are just to declare the Camunda objects and I can used them without further setups:
@AutoWired
protected final RuntimeService runtimeService;
@AutoWired
protected final TaskService taskService;
@AutoWired
protected final IdentityService identityService;
Now I am trying to write unit tests. It seems that there are more than one way to set up Camunda for unit testing, but I am not able to get any of the examples I found working. By some trial and error, I managed to get the following codes to set up Camunda for unit test.
@ActiveProfiles("test")
public class EntitlementServiceTest {
private RuntimeService runtimeService;
private TaskService taskService;
private IdentityService identityService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
.setJdbcUrl("jdbc:h2:mem:database_user;DB_CLOSE_ON_EXIT=FALSE")
.setJobExecutorActivate(true)
.buildProcessEngine();
runtimeService = processEngine.getRuntimeService();
taskService = processEngine.getTaskService();
identityService = processEngine.getIdentityService();
}
...
}
But I am not sure if this is the correct way to do so, so it would be better if someone points this out. The codes don't seem to have loaded anything from the application file for unit testing, application-test.yml. Replacing the hardcoded JDBC URL with ${spring.datasource.url} does not work at all. And even though I have set the camunda.bpm.generic-properties.properties.generalResourceWhitelistPattern, application-test.yml, it is obvious that it is not being read.