Unit Testing: How to get Call Activity's called process instance from runtime?

During Unit testing for Script Based unit testing with Coverage Reporting (Spock Framework), I have noticed that it does not seem possible? (or not obvious) on how to get the process instance that was created from a Call Activity execution?

I had to use the HistoryService:

  HistoricActivityInstance callActInstance = historyService().createHistoricActivityInstanceQuery()
                                                              .processInstanceId(callActivityCoverage1ProcessInstance.getProcessInstanceId())
                                                              .activityId('Task_1gdn63n')
                                                              .singleResult()

    ProcessInstance callActivityCoverage2ProcessInstance = calledProcessInstance(processInstanceQuery().processInstanceId(callActInstance.getCalledProcessInstanceId()))

The calledProcessInstance helper in BPMN Assert seems to only work to return a process instance based on a generic query of “give me all process instances that have a Super of my current process instance”; This logic seems really problematic for the following scenario:

The second we have a single process instance that could call the same sub-process through Call Activities, then the calledProcessInstance() helper in BPMN assert seems to fall apart.

I’m i missing a helper or a route to accessing the specific process instance of the called activity?

Re: @felix-mueller related to Coverage experiences with more than 1 BPMN definition and Pools · Issue #35 · camunda-community-hub/camunda-bpm-process-test-coverage · GitHub

reference: New assertion: process instance calledProcessInstance() · Issue #28 · camunda/camunda-bpm-assert · GitHub @BerndRuecker

Thanks!

1 Like