1
votes

I've configured Camunda engine with org.camunda.bpm.engine.test.mock.MockExpressionManager. At first glance it works as expected: when I do Mocks.register("myDelegate", myDelegateMock), the bpmn process invokes my mock, but not the real delegate. But when there is a task, that invoked by some timer boundary event, the mock is ignored and the real delegate becomes invoked.

I've looked at the code, and found that mocks are stored in the ThreadLocal. And if the tasks is invoked by timer, the execution happens in different thread. And that's looks like a root cause of such behavior. Probably mocks also will not work if the task is marked as asynchronous.

I've also tried the extension https://github.com/camunda/camunda-bpm-mockito but looks like internally it uses the same Mocks.register, and also doesn't work for me.

May be there are some other possibilities to mock delegate that will work for the case with timer?

1
Did u asked on the Camunda User Group? Usually they answer really quick (groups.google.com/forum/#!forum/camunda-bpm-users) - facundofarias
You are right, camunda-bpm-mockito just adds convenience methods on top of Mocks.register. I do not really get an idea how I would reproduce your problem. Could you provide some (test-)code and a bpmn snippet (camunda.org/share)? - Jan Galinski
I found similar problem discussion here groups.google.com/forum/#!searchin/camunda-bpm-users/… There is also a link to github project with example. - NullPointer

1 Answers

1
votes

Well, the this is already answered in the thread you mentioned:

Mocks.register is meant to be used in a purely single-threaded, no-job-executor, "unit test" environment. In such an environment, instead of setting the time and waiting for the job executor to process the jobs, you need to explicitly trigger the timer job in your own testing thread:

Job job = processEngineRule.getManagementService().createJobQuery().singleResult();
processEngineRule.getManagementService().executeJob(job.getId());

Then it should happily resolve the name and should work.

So the solution is: let the process run into the timer event, and then manually execute the job() so the process continues as if the timer was reached. This is a good idea even without the single-thread problem: do not simulate timers in camunda tests, just verify that the process is waiting in the correct step and control if the timer condition (due date) is equal to the one you expected.