Skip to content

Commit

Permalink
fix: added meaningful tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas committed Dec 3, 2024
1 parent e2dcd81 commit 242bda4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DomElement> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<camunda:inputParameter name="HinweisText">
<camunda:script scriptFormat="feel">"Vorgang automatisiert durchgeführt und abgeschlossen"</camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="anotherReference">
<camunda:script scriptFormat="feel" resource="external.feel" />
</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1wn0wn6</bpmn:incoming>
Expand Down

0 comments on commit 242bda4

Please sign in to comment.