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

fixed a bug where an errorCode is not transformed #273

Merged
merged 2 commits into from
May 16, 2023
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 @@ -35,6 +35,9 @@ protected void postCreationVisitor(DomElementVisitorContext context) {
if (expressionTransformationResult.getNewExpression().startsWith("=")) {
context.addMessage(MessageFactory.errorCodeNoExpression());
}
context.addConversion(
ErrorConvertible.class,
c -> c.setErrorCode(expressionTransformationResult.getNewExpression()));
// this can be enabled as soon as error codes can be expressions
/*
if (SemanticVersion.parse(context.getProperties().getPlatformVersion()).ordinal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,16 @@ void testExecutionListenerWithoutImpl() {
.isEqualTo(
"Listener at 'start' with implementation 'null' cannot be transformed. Execution Listeners do not exist in Zeebe.");
}

@Test
void testErrorCodeShouldPersist() {
BpmnModelInstance modelInstance = loadAndConvert("error-code.bpmn");
assertThat(
modelInstance.getDocument().getElementById("Error_16zktjx").getAttribute("errorCode"))
.isEqualTo("someCode");
BpmnConverter converter = BpmnConverterFactory.getInstance().get();
StringWriter writer = new StringWriter();
converter.printXml(modelInstance.getDocument(), true, writer);
System.out.println(writer.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public static Map<String, Object> mockVariables(int count) {
return variables;
}

public static BpmnModelInstance loadAndConvert(String bpmnFile) {
BpmnModelInstance modelInstance = loadModelInstance(bpmnFile);
BpmnConverter converter = BpmnConverterFactory.getInstance().get();
ConverterProperties properties = ConverterPropertiesFactory.getInstance().get();
converter.convert(modelInstance, false, properties);
return modelInstance;
}

public static BpmnDiagramCheckResult loadAndCheck(String bpmnFile) {
ConverterProperties properties = ConverterPropertiesFactory.getInstance().get();
return loadAndCheckAgainstVersion(bpmnFile, properties.getPlatformVersion());
Expand All @@ -23,8 +31,7 @@ public static BpmnDiagramCheckResult loadAndCheck(String bpmnFile) {
public static BpmnDiagramCheckResult loadAndCheckAgainstVersion(
String bpmnFile, String targetVersion) {
BpmnConverter converter = BpmnConverterFactory.getInstance().get();
BpmnModelInstance modelInstance =
Bpmn.readModelFromStream(TestUtil.class.getClassLoader().getResourceAsStream(bpmnFile));
BpmnModelInstance modelInstance = loadModelInstance(bpmnFile);
DefaultConverterProperties properties = new DefaultConverterProperties();
properties.setPlatformVersion(targetVersion);
BpmnDiagramCheckResult result =
Expand All @@ -35,4 +42,8 @@ public static BpmnDiagramCheckResult loadAndCheckAgainstVersion(
ConverterPropertiesFactory.getInstance().merge(properties));
return result;
}

private static BpmnModelInstance loadModelInstance(String bpmnFile) {
return Bpmn.readModelFromStream(TestUtil.class.getClassLoader().getResourceAsStream(bpmnFile));
}
}
71 changes: 71 additions & 0 deletions backend-diagram-converter/core/src/test/resources/error-code.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1gbx4qr" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
<bpmn:process id="TransactionTestProcess" name="Transaction Test" isExecutable="true">
<bpmn:startEvent id="Event_1i3htun" name="Error code conversion should be tested">
<bpmn:outgoing>Flow_0we8gbc</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0we8gbc" sourceRef="Event_1i3htun" targetRef="Activity_1h3hatw" />
<bpmn:serviceTask id="Activity_1h3hatw" name="Throw error">
<bpmn:incoming>Flow_0we8gbc</bpmn:incoming>
<bpmn:outgoing>Flow_0y3k84c</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_09a497u" name="Error code conversion done">
<bpmn:incoming>Flow_0y3k84c</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0y3k84c" sourceRef="Activity_1h3hatw" targetRef="Event_09a497u" />
<bpmn:boundaryEvent id="Event_0apc6gw" name="Error thrown" attachedToRef="Activity_1h3hatw">
<bpmn:outgoing>Flow_03nn2dd</bpmn:outgoing>
<bpmn:errorEventDefinition id="ErrorEventDefinition_1ue91kl" errorRef="Error_16zktjx" />
</bpmn:boundaryEvent>
<bpmn:endEvent id="Event_1ey9c8f" name="Error handled">
<bpmn:incoming>Flow_03nn2dd</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_03nn2dd" sourceRef="Event_0apc6gw" targetRef="Event_1ey9c8f" />
</bpmn:process>
<bpmn:error id="Error_16zktjx" name="SomeName" errorCode="someCode" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="TransactionTestProcess">
<bpmndi:BPMNShape id="Event_1i3htun_di" bpmnElement="Event_1i3htun">
<dc:Bounds x="142" y="102" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="116" y="145" width="89" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_10af0py_di" bpmnElement="Activity_1h3hatw">
<dc:Bounds x="230" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_09a497u_di" bpmnElement="Event_09a497u">
<dc:Bounds x="382" y="102" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="360" y="145" width="81" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ey9c8f_di" bpmnElement="Event_1ey9c8f">
<dc:Bounds x="362" y="222" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="347" y="265" width="67" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0k38m8v_di" bpmnElement="Event_0apc6gw">
<dc:Bounds x="272" y="142" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="260" y="185" width="61" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0we8gbc_di" bpmnElement="Flow_0we8gbc">
<di:waypoint x="178" y="120" />
<di:waypoint x="230" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0y3k84c_di" bpmnElement="Flow_0y3k84c">
<di:waypoint x="330" y="120" />
<di:waypoint x="382" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_03nn2dd_di" bpmnElement="Flow_03nn2dd">
<di:waypoint x="290" y="178" />
<di:waypoint x="290" y="240" />
<di:waypoint x="362" y="240" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>