From 242bda41a2c19f18b014171d2384ae52e6795133 Mon Sep 17 00:00:00 2001 From: Jonathan Lukas Date: Tue, 26 Nov 2024 12:01:07 +0100 Subject: [PATCH] fix: added meaningful tests --- .../element/InputOutputParameterVisitor.java | 20 +++++----- .../resources/message-templates.properties | 2 +- .../converter/BpmnConverterTest.java | 39 +++++++++++++++++++ .../resources/feel_expr_not_tranformed.bpmn | 3 ++ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/InputOutputParameterVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/InputOutputParameterVisitor.java index 56c3c584..d751e188 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/InputOutputParameterVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/InputOutputParameterVisitor.java @@ -1,5 +1,7 @@ package org.camunda.community.migration.converter.visitor.impl.element; +import static org.camunda.community.migration.converter.NamespaceUri.*; + import org.camunda.bpm.model.xml.instance.DomElement; import org.camunda.community.migration.converter.DomElementVisitorContext; import org.camunda.community.migration.converter.convertible.AbstractDataMapperConvertible; @@ -24,6 +26,10 @@ protected Message visitCamundaElement(DomElementVisitorContext context) { DomElement element = context.getElement(); String name = element.getAttribute("name"); MappingDirection direction = findMappingDirection(element); + if (isScript(element)) { + // Scripts are handled in ScriptVisitor + return MessageFactory.inputOutputScript(); + } if (isNotStringOrExpression(element)) { return MessageFactory.inputOutputParameterIsNoExpression(localName(), name); } @@ -61,6 +67,11 @@ protected Message visitCamundaElement(DomElementVisitorContext context) { return resultMessage; } + private boolean isScript(DomElement element) { + return element.getChildElements().stream() + .anyMatch(e -> e.getNamespaceURI().equals(CAMUNDA) && e.getLocalName().equals("script")); + } + private MappingDirection findMappingDirection(DomElement element) { if (isInputParameter(element.getLocalName())) { return MappingDirection.INPUT; @@ -75,15 +86,6 @@ private boolean isNotStringOrExpression(DomElement element) { return !element.getChildElements().isEmpty(); } - private boolean isFeelScript(DomElement element) { - if (element.getChildElements().isEmpty()) { - return false; - } - DomElement script = element.getChildElements().get(0); - String scriptFormat = script.getAttribute("scriptFormat"); - return "feel".equalsIgnoreCase(scriptFormat); - } - private boolean isInputParameter(String localName) { return INPUT_PARAMETER.equals(localName); } diff --git a/backend-diagram-converter/core/src/main/resources/message-templates.properties b/backend-diagram-converter/core/src/main/resources/message-templates.properties index 9d1cbb6c..7afd12e1 100644 --- a/backend-diagram-converter/core/src/main/resources/message-templates.properties +++ b/backend-diagram-converter/core/src/main/resources/message-templates.properties @@ -163,7 +163,7 @@ called-element-ref-binding.severity=INFO input-output-parameter-feel-script.message={{ templates.element-transformed-prefix }} Parameter '{{ parameterName }}': '{{ feelScript }}' has been mapped. input-output-parameter-feel-script.severity=INFO # -input-output-parameter-is-no-expression.message={{ templates.element-not-transformable-prefix }} Parameter '{{ parameterName }}': Only String, Expression or Feel script is supported as Input/Output. +input-output-parameter-is-no-expression.message={{ templates.element-not-transformable-prefix }} Parameter '{{ parameterName }}': Only String, Expression or inline FEEL script is supported as Input/Output. input-output-parameter-is-no-expression.severity=WARNING # input-output-parameter.message={{ templates.element-transformed-prefix }} Parameter '{{ parameterName }}': {{ templates.expression-transformation-result }} diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java index bf6ffba6..3591e5e4 100644 --- a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java @@ -9,6 +9,7 @@ import java.io.StringWriter; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; @@ -796,6 +797,44 @@ void testCalledElementRefDeploymentBindingConversion() { .isEqualTo("deployment"); } + @Test + void testFeelScriptInputShouldBeTransformed() { + BpmnModelInstance modelInstance = loadAndConvert("feel_expr_not_tranformed.bpmn"); + DomElement serviceTask = modelInstance.getDocument().getElementById("Activity_1s02kf9"); + assertThat(serviceTask).isNotNull(); + DomElement extensionElements = + serviceTask.getChildElementsByNameNs(BPMN, "extensionElements").get(0); + assertThat(extensionElements).isNotNull(); + DomElement ioMapping = extensionElements.getChildElementsByNameNs(ZEEBE, "ioMapping").get(0); + assertThat(ioMapping).isNotNull(); + DomElement input = + ioMapping.getChildElementsByNameNs(ZEEBE, "input").stream() + .filter(e -> e.getAttribute(ZEEBE, "target").equals("HinweisText")) + .findFirst() + .get(); + assertThat(input).isNotNull(); + assertThat(input.getAttribute(ZEEBE, "target")).isEqualTo("HinweisText"); + assertThat(input.getAttribute(ZEEBE, "source")) + .isEqualTo("=\"Vorgang automatisiert durchgeführt und abgeschlossen\""); + } + + @Test + void testNonFeelScriptInputShouldNotBeTransformed() { + BpmnModelInstance modelInstance = loadAndConvert("feel_expr_not_tranformed.bpmn"); + DomElement serviceTask = modelInstance.getDocument().getElementById("Activity_1s02kf9"); + assertThat(serviceTask).isNotNull(); + DomElement extensionElements = + serviceTask.getChildElementsByNameNs(BPMN, "extensionElements").get(0); + assertThat(extensionElements).isNotNull(); + DomElement ioMapping = extensionElements.getChildElementsByNameNs(ZEEBE, "ioMapping").get(0); + assertThat(ioMapping).isNotNull(); + Optional input = + ioMapping.getChildElementsByNameNs(ZEEBE, "input").stream() + .filter(e -> e.getAttribute(ZEEBE, "target").equals("anotherReference")) + .findFirst(); + assertThat(input).isEmpty(); + } + @Test void testDefaultResultVariable() { BpmnModelInstance modelInstance = loadAndConvert("default-result-variable.bpmn"); diff --git a/backend-diagram-converter/core/src/test/resources/feel_expr_not_tranformed.bpmn b/backend-diagram-converter/core/src/test/resources/feel_expr_not_tranformed.bpmn index 553872cc..a4d2f5ba 100644 --- a/backend-diagram-converter/core/src/test/resources/feel_expr_not_tranformed.bpmn +++ b/backend-diagram-converter/core/src/test/resources/feel_expr_not_tranformed.bpmn @@ -11,6 +11,9 @@ "Vorgang automatisiert durchgeführt und abgeschlossen" + + + Flow_1wn0wn6