Signaling an event from unit test
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2014 10:22 PM
I'm trying to write a unit test for a stupid flow. Its xml definition is:
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
<?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?
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2014 10:54 PM
One more thing. I've just found that <java>activityQuery.activityId("provisioningEndEvent").unfinished().singleResult();</java> is also returning null. I would expect to see "provisioningEndEvent" in here. Or maybe not?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2014 01:48 AM
Hi,
Have a look on similar test from activiti sources:
Regards
Martin
Have a look on similar test from activiti sources:
org.activiti.engine.test.api.runtime.RuntimeServiceTest#testSignalEventReceived
Regards
Martin
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2014 07:27 AM
Hi Martin. Looking at the example test you directed me to, I used this code in my test:
<java>List<Execution> page = runtimeService.createExecutionQuery().signalEventSubscriptionName("Provisioning is Done").listPage(0, 1);</java>
But, returned list is empty and test is still failing.
<java>List<Execution> page = runtimeService.createExecutionQuery().signalEventSubscriptionName("Provisioning is Done").listPage(0, 1);</java>
But, returned list is empty and test is still failing.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2014 08:38 AM
It seems that parallel gateway was causing problems. I removed it and it worked. Out of curiosity, can someone explain why is it not working with the parallel gateway?