Can not get ProcessEngine with BpmPlatform in testing

I’m now creating a custom connecto which uses BpmPlatform.getDefaultProcessEngine() method to get process engine services from it. However, when testing the connector accroding to the testing guide, the method call always throws NPE.

Then, I tried to test the method call in test with the following two ways:

@Test
public void smokeTest1() {
    Assert.assertNotNull(BpmPlatform.getDefaultProcessEngine());
}

@Test
public void smokeTest2() {
    Assert.assertNotNull(BpmPlatform.getProcessEngineService().getProcessEngines().get(0));
}

but all of the tests were failed. And the second test case shows error message of java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0.

Meanwhile, the test for Assert.assertNotNull(processEngineRule.getProcessEngine()); is correct.

May I know whether there are other ways to access process engine services instead of call BpmPlatform.getDefaultProcessEngine() in testing please?

I finally found the solution as follows:

The method call of BpmPlatform.getDefaultProcessEngine() eventually retrieves process engine form RuntimeContainerDelegate, but however, the delegate class works with runtime container in which it is deployed. For test environment, there seems be no runtime container for it to retreive the process engine.

Therefore, the problem could be resolved with the following method call to register a test process engine to it:

RuntimeContainerDelegate.INSTANCE.get().registerProcessEngine(processEngine);
1 Like

Hello @Tonny_Tc ,

I am glad you found a solution.

Another way to retrieve a ProcessEngine statically would be

ProcessEngines.getDefaultProcessEngine()

Jonathan

Hi @jonathan.lukas ,

Thanks a lot for your reply.

I had tried to use ProcessEngines.getDefaultProcessEngine() instead of BpmPlatform.getDefaultProcessEngine(), but it seems the former method cause db recreation in the test. I got error messages such as:

[main] ERROR org.camunda.bpm.engine.persistence - ENGINE-03015 Problem during schema operation 'create' with statement '-- 
-- 
-- 
-- 
create table ACT_HI_PROCINST ( 
ID_ varchar(64) not null, 
PROC_INST_ID_ varchar(64) not null, 
BUSINESS_KEY_ varchar(255), 
PROC_DEF_KEY_ varchar(255), 
PROC_DEF_ID_ varchar(64) not null, 
START_TIME_ timestamp not null, 
END_TIME_ timestamp, 
REMOVAL_TIME_ timestamp, 
DURATION_ bigint, 
START_USER_ID_ varchar(255), 
START_ACT_ID_ varchar(255), 
END_ACT_ID_ varchar(255), 
SUPER_PROCESS_INSTANCE_ID_ varchar(64), 
ROOT_PROC_INST_ID_ varchar(64), 
SUPER_CASE_INSTANCE_ID_ varchar(64), 
CASE_INST_ID_ varchar(64), 
DELETE_REASON_ varchar(4000), 
TENANT_ID_ varchar(64), 
STATE_ varchar(255), 
primary key (ID_), 
unique (PROC_INST_ID_) 
)'. Cause: 'Table "ACT_HI_PROCINST" already exists; SQL statement:

and so on.

Using BpmPlatform.getDefaultProcessEngine() makes everything work properly.

1 Like

Hello @Tonny_Tc ,

I see. It seems that you call the method before the test extension would instantiate the process engine.

In this case, your solution is perfect.

Jonathan