Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sequence flow in hasPassedElement assertions #319

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/abstracts/src/main/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