How to mock CallActivity with Escalation Boundary Event and execute it in test

Hello. I want to test my main schema using junit5 and spring boot (job-executor is disabled). But I can’t to mock CallActivivty element, which execute another schema. I have this schema:

schema
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0guls9w" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.25.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
  <bpmn:process id="MainProcess" isExecutable="true">
    <bpmn:startEvent id="startProcess">
      <bpmn:outgoing>Flow_0dcb0w0</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="task1" name="Task1" camunda:asyncBefore="true" camunda:delegateExpression="${task1}">
      <bpmn:extensionElements>
        <camunda:failedJobRetryTimeCycle />
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0dcb0w0</bpmn:incoming>
      <bpmn:incoming>Flow_0hg9lrn</bpmn:incoming>
      <bpmn:outgoing>Flow_0qjg4o5</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:callActivity id="subProcessCallActivity" name="subProcess" camunda:asyncBefore="true" calledElement="subprocess">
      <bpmn:extensionElements>
        <camunda:failedJobRetryTimeCycle />
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0qjg4o5</bpmn:incoming>
    </bpmn:callActivity>
    <bpmn:endEvent id="Event_08w2bjr">
      <bpmn:incoming>Flow_1xkq4pb</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:boundaryEvent id="refundSuccessEvent" attachedToRef="subProcessCallActivity">
      <bpmn:outgoing>Flow_1xkq4pb</bpmn:outgoing>
      <bpmn:escalationEventDefinition id="EscalationEventDefinition_1afbwqf" escalationRef="Escalation_3v3o4na" />
    </bpmn:boundaryEvent>
    <bpmn:boundaryEvent id="refundFailEvent" attachedToRef="subProcessCallActivity">
      <bpmn:outgoing>Flow_0hg9lrn</bpmn:outgoing>
      <bpmn:escalationEventDefinition id="EscalationEventDefinition_0jhsiho" escalationRef="Escalation_0dl03mh" />
    </bpmn:boundaryEvent>
    <bpmn:sequenceFlow id="Flow_0dcb0w0" sourceRef="startProcess" targetRef="task1" />
    <bpmn:sequenceFlow id="Flow_0hg9lrn" sourceRef="refundFailEvent" targetRef="task1" />
    <bpmn:sequenceFlow id="Flow_0qjg4o5" sourceRef="task1" targetRef="subProcessCallActivity" />
    <bpmn:sequenceFlow id="Flow_1xkq4pb" sourceRef="refundSuccessEvent" targetRef="Event_08w2bjr" />
  </bpmn:process>
  <bpmn:escalation id="Escalation_3v3o4na" name="SUCCESS" escalationCode="success" />
  <bpmn:escalation id="Escalation_0dl03mh" name="FAIL" escalationCode="fail" />
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="MainProcess">
      <bpmndi:BPMNShape id="BPMNShape_0eyuhxl" bpmnElement="startProcess">
        <dc:Bounds x="182" y="112" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_186bj94_di" bpmnElement="task1">
        <dc:Bounds x="270" y="90" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_02j87xo_di" bpmnElement="subProcessCallActivity">
        <dc:Bounds x="620" y="80" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_08w2bjr_di" bpmnElement="Event_08w2bjr">
        <dc:Bounds x="812" y="142" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0s3p7dj_di" bpmnElement="refundSuccessEvent">
        <dc:Bounds x="702" y="142" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="699" y="308" width="41" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1pnwqom_di" bpmnElement="refundFailEvent">
        <dc:Bounds x="602" y="142" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="540" y="270" width="15" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_0dcb0w0_di" bpmnElement="Flow_0dcb0w0">
        <di:waypoint x="218" y="130" />
        <di:waypoint x="270" y="130" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0hg9lrn_di" bpmnElement="Flow_0hg9lrn">
        <di:waypoint x="620" y="178" />
        <di:waypoint x="620" y="220" />
        <di:waypoint x="320" y="220" />
        <di:waypoint x="320" y="170" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0qjg4o5_di" bpmnElement="Flow_0qjg4o5">
        <di:waypoint x="370" y="130" />
        <di:waypoint x="620" y="130" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1xkq4pb_di" bpmnElement="Flow_1xkq4pb">
        <di:waypoint x="738" y="160" />
        <di:waypoint x="812" y="160" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

How can I test case, run test before callActivivty and check if callActivity throw escalation success code end schema if fail check isWaitingAt(task1)

I have this code and it works, but brake my next test class. And I want to mock CallActivity only for this test.

@Test
fun testFailCase() {
   ProcessExpressions.registerCallActivityMock("subprocess")
       .onExecutionThrowEscalation("fail")
       .deploy(repositoryService) // in this case redeploing is taking place my second schema, and after that separated test class for that schema is failed
   
    val processInstance = runtimeService
        .createProcessInstanceByKey("MainProcess")
        .startBeforeActivity("subProcessCallActivity")
        .execute()
        .also { assertThat(it).isStarted }
   
    assertThat(processInstance).isWaitingAt("task1")
}

When I use:

@Test
fun testFailCase() {
    val mockActivity = CallActivityMock("subprocess")
       .onExecutionThrowEscalation("fail")
   Mocks.register("subProcessCallActivity", mockActivity)

   val processInstance = runtimeService
        .createProcessInstanceByKey("MainProcess")
        .startBeforeActivity("subProcessCallActivity")
        .execute()
        .also { assertThat(it).isStarted }
  
  assertThat(processInstance).isWaitingAt("subProcessCallActivity")

  // and I don't know how to execute callActivity in my test, this code does not work, especially if no subprocess deployed schema: no processes deployed with key 'subprocessRefund' and tenant-id 'null': processDefinition is null
  val job = managementService.createJobQuery().processInstanceId(processInstance.id).singleResult()
managementService.executeJob(job.id)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.