Hi,
I am a very new user with respect to Camunda BPMN Junit testing. I have a simple spring boot based application. I am not able to write the Junit test for it.
My Test class looks like below
@Slf4j
@Deployment(resources = “ProcessV1.0.bpmn”)
public class ProcessTest {
@ClassRule
@Rule
public static ProcessEngineRule processEngineRule = new ProcessEngineRule();
@Test
@Deployment(resources = "PremiumProcessingCompletionV1.0.bpmn")
public void happyPathTest() {
RuntimeService runtimeService = processEngineRule.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceById("PremiumProcessing");
log.info("premiumProcessing Test class");
}
}
The problem is that i am facing is that my processEngineRule created as runtimeService as null. Can someone help that where i have gone wrong.
Below is my camunda.cfg.xml file placed inside src/test/resource:
<?xml version="1.0" encoding="UTF-8"?>
Thanks in advance!
I can’t see your Camunda.cfg.xml … could you share it?
Below is my camunda.cfg.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration">
</bean>
</beans>
I was not sure what all configuration to place and hence i have created this simple bean. Also, its placed in src/test/resources path. Please do let me know if you need more info from my side.
@ jangalinski
I did a silly mistake. For @Test annontation, I imported org.junit.jupitor.api.Test instead of org.junit.Test.
Now, i am stuck in another problem where I am getting below error:
org.camunda.bpm.engine.ProcessEngineException: An exception occurred in the persistence layer. Please check the server logs for a detailed message and the entire exception stack trace.
I need help in understanding if db connection details needed for test classes? If yes, then how do i go about it.
I have finally got this working.
I made couple of mistakes.
-
I have mistakenly used org.junit.jupitor.api.Test for @Test annotation instead of org.junit.Test.
-
I have not added the db details in camunda.cfg.xml. After adding these details, My test started working. Below is how my configuration file looks like:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="history" value="full" />
<property name="jdbcUrl" value="jdbc:h2:mem:camunda-spring-boot-test;DB_CLOSE_ON_EXIT=false" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="sa" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
</beans>
I was not aware of adding the db in configuration file as in the user guide https://docs.camunda.org/manual/7.15/user-guide/testing/ is not mentioned as quite straight away. But, in other pages of user guide I found it later.
Adding these details so that it might help anyone stuck with similar issue.
@aravindhrs Sorry for the delayed response! Below is the reference:
Check heading in below link: Configure Process Engine Using camunda cfg XML
https://docs.camunda.org/manual/7.15/user-guide/process-engine/process-engine-bootstrapping/