in a test workflow where all tasks were implemented as “Delegate Expression”, i changed one task to have an “External” implementation and currently i am trying to adapt the (so far successful) unit tests to mock this external task. The task is defined as follows:
Having read the other forum entries for unit testing external tasks and the docs pointed at, i tried the following code-fragment to complete the external task:
if (activity.equalsIgnoreCase("ocr")) {
assertThat(pi).isWaitingAt(activity).externalTask().hasTopicName("ExternalOCR");
complete(externalTask());
continue;
}
The assertThat() fails in hasTopicName() with:
java.lang.AssertionError: Expecting assertion to be called on non-null object, but found it to be null!
at org.camunda.bpm.engine.test.assertions.bpmn.AbstractProcessAssert.getExistingCurrent(AbstractProcessAssert.java:65)
at org.camunda.bpm.engine.test.assertions.bpmn.ExternalTaskAssert.hasTopicName(ExternalTaskAssert.java:49)
...
So although the process instance waits at the “ocr”-task and this task ist defined as “external”, externalTask() seems to have a different opinion on this…
What did i miss? Is there some additional preparation needed in the unit test for handling external tasks?
it took a while to strip it down and remove irrelevant parts, but here are a bpmn process model and a unit test showing the problem (the Java unit test with extension .txt to allow upload).
thank you for the examples. I found that the external task is marked as “Asynchronous before”, which causes the issue. This is not needed, as en external task is a wait state/transaction boundary/save point.
If you remove the checkmark, your test should run (I tested with my own test).
As an alternative, you can execute the job explicitly and afterwards assert for the external task characteristics.