From 8b606f6ced2f973f483b15d5919dd1b805c80698 Mon Sep 17 00:00:00 2001 From: Tattoo Date: Mon, 27 Feb 2023 12:37:49 +0200 Subject: [PATCH] Fixes JENKINS-69807 In RF4, suite name in output.xml might be non-existent in some cases (see more below [*]). In these cases, `RobotTestObject.getName()` returned null as well, which became problem for `RobotTestObject.getRelativePackageName()`. Handle null from `getName()` as an empty string. [*] RF uses double underscore ('__') in suite name as a separator as per https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-suite-name-and-documentation If user has named their suite so it ends with double undercore (eg. suite__.robot), suite name is of course empty. Before RF5, this meant output.xml's tag did not get name-attribute at all; hence the null. --- .../plugins/robot/model/RobotTestObject.java | 9 +++++- .../plugins/robot/model/RobotResultTest.java | 21 ++++++++++++++ .../robot/model/robot4_empty_suite_name.xml | 29 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/hudson/plugins/robot/model/robot4_empty_suite_name.xml diff --git a/src/main/java/hudson/plugins/robot/model/RobotTestObject.java b/src/main/java/hudson/plugins/robot/model/RobotTestObject.java index f0754ff..e0327f2 100644 --- a/src/main/java/hudson/plugins/robot/model/RobotTestObject.java +++ b/src/main/java/hudson/plugins/robot/model/RobotTestObject.java @@ -98,7 +98,14 @@ public boolean getHasReport() { * @return package name */ public String getRelativePackageName(RobotTestObject thisObject) { - StringBuilder sb = new StringBuilder(getName()); + /* + `name` attribute might be missing from suites, see more: https://issues.jenkins.io/browse/JENKINS-69807 + */ + String name = getName(); + if (name == null){ + name = ""; + } + StringBuilder sb = new StringBuilder(name); String parentPackage = getRelativeParent(thisObject); if (! "".equals(parentPackage)) { sb.insert(0, parentPackage); diff --git a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java index da5a1e8..f19d282 100644 --- a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java +++ b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java @@ -23,6 +23,9 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.apache.commons.lang.StringUtils; @@ -327,4 +330,22 @@ public void testShouldParseTagsFromRobot4() throws Exception { String tags = StringUtils.join(caseResult.getTags(), ","); assertEquals("fail,tag2,tag3", tags); } + + @Test + public void testSuiteNameAttributeMightBeMissingInRobot4() throws Exception { + /** + * see more: https://issues.jenkins.io/browse/JENKINS-69807 + **/ + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_empty_suite_name.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_empty_suite_name.xml").toURI()).getParentFile(), null); + + RobotSuiteResult r = result.getSuites().iterator().next(); + r = r.getChildSuites().iterator().next(); + RobotCaseResult caseResult = r.getCaseResults().iterator().next(); + + // passing null as `thisObject` should not matter, as the name resolving fails first + // due to getName() returning `null` + caseResult.getRelativePackageName(null); + + } } diff --git a/src/test/resources/hudson/plugins/robot/model/robot4_empty_suite_name.xml b/src/test/resources/hudson/plugins/robot/model/robot4_empty_suite_name.xml new file mode 100644 index 0000000..ab6f5e0 --- /dev/null +++ b/src/test/resources/hudson/plugins/robot/model/robot4_empty_suite_name.xml @@ -0,0 +1,29 @@ + + + + + + +Does absolutely nothing. + + + + + + + + + + +All Tests + + + + +Empty Suite Attribute +Empty Suite Attribute. + + + + +