Skip to content

Commit

Permalink
Merge pull request #323 from camunda/backport-319-to-stable/8.0
Browse files Browse the repository at this point in the history
[Backport stable/8.0] Support sequence flow in hasPassedElement assertions
  • Loading branch information
remcowesterhoud authored Apr 14, 2022
2 parents 45d7fc9 + 8b5758d commit 326ae51
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public ProcessInstanceAssert hasPassedElement(final String elementId, final int
.withProcessInstanceKey(actual)
.withRejectionType(RejectionType.NULL_VAL)
.withElementId(elementId)
.withIntent(ProcessInstanceIntent.ELEMENT_COMPLETED)
.withIntents(
ProcessInstanceIntent.ELEMENT_COMPLETED, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN)
.stream()
.count();

Expand All @@ -239,7 +240,8 @@ public ProcessInstanceAssert hasPassedElementsInOrder(final String... elementIds
.withProcessInstanceKey(actual)
.withRejectionType(RejectionType.NULL_VAL)
.withElementIdIn(elementIds)
.withIntent(ProcessInstanceIntent.ELEMENT_COMPLETED)
.withIntents(
ProcessInstanceIntent.ELEMENT_COMPLETED, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN)
.stream()
.map(Record::getValue)
.map(ProcessInstanceRecordValue::getElementId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public ProcessInstanceRecordStreamFilter withIntent(final ProcessInstanceIntent
stream.filter(record -> record.getIntent() == intent));
}

public ProcessInstanceRecordStreamFilter withIntents(final ProcessInstanceIntent... intents) {
return new ProcessInstanceRecordStreamFilter(
stream.filter(
record -> Arrays.stream(intents).anyMatch(intent -> record.getIntent() == intent)));
}

public ProcessInstanceRecordStreamFilter withElementId(final String elementId) {
return new ProcessInstanceRecordStreamFilter(
stream.filter(record -> record.getValue().getElementId().equals(elementId)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ void testProcessInstanceHasPassedElementMultipleTimes()
// then
BpmnAssert.assertThat(instanceEvent)
.hasPassedElement(ProcessPackLoopingServiceTask.ELEMENT_ID, totalLoops);
BpmnAssert.assertThat(instanceEvent)
.hasPassedElement(ProcessPackLoopingServiceTask.LOOP_SEQUENCE_FLOW_ID, totalLoops - 1);
}

@Test
Expand All @@ -222,19 +224,24 @@ void testProcessInstanceHasPassedElementsInOrder()
// given
Utilities.deployResource(client, ProcessPackLoopingServiceTask.RESOURCE_NAME);
final Map<String, Object> variables =
Collections.singletonMap(ProcessPackLoopingServiceTask.TOTAL_LOOPS, 1);
Collections.singletonMap(ProcessPackLoopingServiceTask.TOTAL_LOOPS, 2);
final ProcessInstanceEvent instanceEvent =
Utilities.startProcessInstance(
engine, client, ProcessPackLoopingServiceTask.PROCESS_ID, variables);

// when
Utilities.completeTask(engine, client, ProcessPackLoopingServiceTask.ELEMENT_ID);
Utilities.completeTask(engine, client, ProcessPackLoopingServiceTask.ELEMENT_ID);

// then
BpmnAssert.assertThat(instanceEvent)
.hasPassedElementsInOrder(
ProcessPackLoopingServiceTask.START_EVENT_ID,
ProcessPackLoopingServiceTask.ELEMENT_ID,
ProcessPackLoopingServiceTask.GATEWAY_ELEMENT_ID,
ProcessPackLoopingServiceTask.LOOP_SEQUENCE_FLOW_ID,
ProcessPackLoopingServiceTask.ELEMENT_ID,
ProcessPackLoopingServiceTask.GATEWAY_ELEMENT_ID,
ProcessPackLoopingServiceTask.END_EVENT_ID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public static final class ProcessPackLoopingServiceTask {
public static final String TOTAL_LOOPS =
"totalLoops"; // variable name to indicate number of loops
public static final String GATEWAY_ELEMENT_ID = "Gateway_0fhwf5d";
public static final String LOOP_SEQUENCE_FLOW_ID = "loopSequenceFlow";
public static final String START_EVENT_ID = "startevent";
public static final String END_EVENT_ID = "endevent";
}
Expand Down
10 changes: 5 additions & 5 deletions qa/src/test/resources/looping-servicetask.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0vjlomv" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.1.0">
<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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0vjlomv" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0-alpha.1" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.1.0">
<bpmn:process id="looping-servicetask" name="looping servicetask" isExecutable="true">
<bpmn:startEvent id="startevent" name="Start event">
<bpmn:extensionElements>
Expand All @@ -22,22 +22,22 @@
</zeebe:ioMapping>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0gk7cr0</bpmn:incoming>
<bpmn:incoming>Flow_0wjr3ms</bpmn:incoming>
<bpmn:incoming>loopSequenceFlow</bpmn:incoming>
<bpmn:outgoing>Flow_0cw7eu9</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:exclusiveGateway id="Gateway_0fhwf5d" default="Flow_117ogjm">
<bpmn:incoming>Flow_0cw7eu9</bpmn:incoming>
<bpmn:outgoing>Flow_117ogjm</bpmn:outgoing>
<bpmn:outgoing>Flow_0wjr3ms</bpmn:outgoing>
<bpmn:outgoing>loopSequenceFlow</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_117ogjm" sourceRef="Gateway_0fhwf5d" targetRef="endevent" />
<bpmn:sequenceFlow id="Flow_0wjr3ms" sourceRef="Gateway_0fhwf5d" targetRef="servicetask">
<bpmn:sequenceFlow id="loopSequenceFlow" sourceRef="Gateway_0fhwf5d" targetRef="servicetask">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">= loopAmount != totalLoops</bpmn:conditionExpression>
</bpmn:sequenceFlow>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="looping-servicetask">
<bpmndi:BPMNEdge id="Flow_0wjr3ms_di" bpmnElement="Flow_0wjr3ms">
<bpmndi:BPMNEdge id="Flow_0wjr3ms_di" bpmnElement="loopSequenceFlow">
<di:waypoint x="410" y="142" />
<di:waypoint x="410" y="80" />
<di:waypoint x="300" y="80" />
Expand Down

0 comments on commit 326ae51

Please sign in to comment.