AnsweredAssumed Answered

Signaling an event from unit test

Question asked by rmilovic on Dec 23, 2014
Latest reply on Dec 23, 2014 by rmilovic
I'm trying to write a unit test for a stupid flow. Its xml definition is:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <signal id="provisioningIsDone" name="Provisioning is Done"></signal>
  <process id="provisioningProcess" name="Provisioning Process" isExecutable="true">
    <startEvent id="provisioningStartEvent" name="Start"></startEvent>
    <parallelGateway id="provisioningIsDoneGateway" name="Provisioning is Done"></parallelGateway>
    <intermediateCatchEvent id="provisioningIsDoneEvent" name="Provisioning Is Done">
      <signalEventDefinition signalRef="provisioningIsDone"></signalEventDefinition>
    </intermediateCatchEvent>
    <endEvent id="provisioningEndEvent" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="provisioningStartEvent" targetRef="provisioningIsDoneGateway"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="provisioningIsDoneGateway" targetRef="provisioningEndEvent"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="provisioningIsDoneEvent" targetRef="provisioningIsDoneGateway"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_provisioningProcess">
    <bpmndi:BPMNPlane bpmnElement="provisioningProcess" id="BPMNPlane_provisioningProcess">
      <bpmndi:BPMNShape bpmnElement="provisioningEndEvent" id="BPMNShape_provisioningEndEvent">
        <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="320.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="provisioningIsDoneEvent" id="BPMNShape_provisioningIsDoneEvent">
        <omgdc:Bounds height="35.0" width="35.0" x="374.0" y="223.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="provisioningStartEvent" id="BPMNShape_provisioningStartEvent">
        <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="120.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="provisioningIsDoneGateway" id="BPMNShape_provisioningIsDoneGateway">
        <omgdc:Bounds height="40.0" width="40.0" x="227.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="247.0" y="155.0"></omgdi:waypoint>
        <omgdi:waypoint x="247.0" y="220.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="247.0" y="260.0"></omgdi:waypoint>
        <omgdi:waypoint x="247.0" y="320.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="374.0" y="240.0"></omgdi:waypoint>
        <omgdi:waypoint x="267.0" y="240.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

And this is the unit test for it:

[java]
@Test
@Deployment(resources = { "ProvisioningSubProcess.bpmn" })
public void startProcess() throws Exception {
   RuntimeService runtimeService = activitiRule.getRuntimeService();
   HistoryService historyService = activitiRule.getHistoryService();

   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("provisioningProcess");
   assertNotNull(processInstance.getId()); // process is started
      
   HistoricActivityInstanceQuery activityQuery = historyService.createHistoricActivityInstanceQuery();
      
   HistoricActivityInstance result1 = activityQuery.activityId("provisioningStartEvent").finished().singleResult();
   assertNotNull(result1.getActivityId());
      
   runtimeService.signalEventReceived("Provisioning is Done");
      
   HistoricActivityInstance result2 = activityQuery.activityId("provisioningIsDoneGateway").finished().singleResult();
   assertNotNull(result2.getActivityId());
      
   HistoricActivityInstance result3 = activityQuery.activityId("provisioningEndEvent").finished().singleResult();
   assertNotNull(result3.getActivityId());
      
   HistoricProcessInstanceQuery processQuery = historyService.createHistoricProcessInstanceQuery();
      
   HistoricProcessInstance result4 = processQuery.processDefinitionKey("provisioningProcess").finished().singleResult();
   assertNotNull(result4.getId());
}
[/java]

The problem is that
runtimeService.signalEventReceived("Provisioning is Done");
doesn't trigger the event in the process and next step that is checking whether "provisioningEndEvent" is finished fails. Am I missing something?

Outcomes