UnitTest for BPMN-workflow with an external task

Hello,

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:

image

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?

Thanks, Hans

Hi @hawala,

no, there is no special setup needed. I usually code this line without the if-statement around it and it works for me.

Could you please share the complete process model and the test class?

Hope this helps, Ingo

Hello,

as it is a customer workflow, i would not like to post those items in public.

Is there a way to have a more non-disclosed way to provide it ?

Hans

Hi @hawala,

you can try it the other way around and use this github repo (https://github.com/camunda/camunda-engine-unittest) to test your process or a simplified version of it.

Hope this helps, Ingo

Hello,

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).

wf-simplified.bpmn (7.9 KB)
SimplifiedTest.txt (4.3 KB)

Hope that helps
Hans

1 Like

Hi @hawala,

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.

Hope this helps, Ingo

1 Like

Hello,

thanks for the quick response,

yes, this helped and worked, One thing learned today…

Greetings, Hans