How to test an activity call chain

Hi all,
I’d like to write an unit test for the following case:
image
I created namely a chain of steps to model the workflow creation of a new document.

I named it ‘process_create_new_document’

I’m using:
image
Unfortunately it seems not to work as I expected:

  • between the lines 43 and 53 it works all as expected and the token leaves the first activity create new document

  • between the lines 56 and 60 the token enters the subprocess enrich document and stopps just before an external task:

  • then I cannot go forward and the instruction:
    complete(externalTask(vMAXSubProcessInstance), withVariables("neuerWert", "dummyWert"));
    fails with the following exception:

This is strange to me because the ‘process_create_new_document’ did work, at least until the line 62…

The same subprocess enrich document can I succesfully test in a separated and dedicated unit test…

So I suspect my approach to test such chains of call activities is basically wrong or at least not supported by camunda-bpm-assert… :cry:

Do you have a tip about a better strategy to organize my tests? I would like to get a top down structure in oder to simplify a complex workflow by dividing it in a group of little ones…

Thank you so much in advance!
Regards
Fabio

Hi all,

I advice using the other testing api to get something like I described: really cool!

Bye
Fabio

I followed Fabio’s recommendation and refactored my test to use https://github.com/camunda-community-hub/camunda-platform-scenario and I was able to test my main process with the sub-process mocked:

import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.mock.Mocks;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.scenario.ProcessScenario;
import org.camunda.bpm.scenario.Scenario;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestCamundaConfiguration.class})
public class MyTest {

private ProcessScenario processScenario = mock(ProcessScenario.class);

@Before
public void setup() {
    when(processScenario.waitsAtMockedCallActivity("MyCallActivityIdTheOneWillCallASubProcess"))
            .thenReturn(callActivity -> callActivity.complete(Collections.singletonMap(
                    "status", "1"))); // "status" is a sub-process-outgoing parameter required for the main process
}

@After
public void resetMocks() {
    Mocks.reset();
}

private ProcessInstance startProcess() {

    final VariableMap variables = Variables.createVariables()
            .putValue("request_id", "1")
            .putValue("request_colour", "blue");

    final Scenario scenario = Scenario.run(this.processScenario)
      .withMockedProcess("SubProcessNameId") // mocking sub process
      .startByKey("MainProcessNameId", variables)
      .execute();

    return scenario.instance(this.processScenario);
}

@Test
public void happyFlow() {

    final ProcessInstance processInstance = startProcess();

    // task2 is part of the sub process that was mocked
    assertThat(processInstance).hasPassedInOrder("start_event", "task1", "call_sub_process","task3");
}

}