From 806648a78ac7aa0cde7ba3a94b6bfc7067c4b026 Mon Sep 17 00:00:00 2001 From: Janne Piironen Date: Tue, 27 May 2014 10:51:19 +0300 Subject: [PATCH] JENKINS-22406: implemented tag storing and showing in test case page and in failed cases summary --- .../hudson/plugins/robot/RobotParser.java | 23 +++++++++++++++++++ .../plugins/robot/model/RobotCaseResult.java | 15 ++++++++++++ .../robot/model/RobotCaseResult/index.jelly | 1 + .../robot/model/RobotCaseResult/summary.jelly | 1 + .../plugins/robot/model/RobotResultTest.java | 7 ++++++ .../hudson/plugins/robot/model/output.xml | 5 +++- 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/robot/RobotParser.java b/src/main/java/hudson/plugins/robot/RobotParser.java index 9fbabee..814bea3 100644 --- a/src/main/java/hudson/plugins/robot/RobotParser.java +++ b/src/main/java/hudson/plugins/robot/RobotParser.java @@ -241,6 +241,9 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res //parse attributes caseResult.setName(reader.getAttributeValue(null, "name")); setCriticalityIfAvailable(reader, caseResult); + //parse test tags + ignoreUntilStarts(reader, "tags"); + caseResult.addTags(processTags(reader)); //parse test details from nested status ignoreUntilStarts(reader, "status"); caseResult.setPassed("PASS".equals(reader.getAttributeValue(null, "status"))); @@ -265,6 +268,26 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res return caseResult; } + private List processTags(XMLStreamReader reader) throws XMLStreamException { + List taglist = new ArrayList(); + while(reader.hasNext()){ + reader.next(); + if(reader.isStartElement() && "tag".equals(reader.getLocalName())){ + while(reader.hasNext()){ + reader.next(); + if(reader.getEventType() == XMLStreamReader.CHARACTERS){ + taglist.add(reader.getText()); + } else if(reader.isEndElement() && "tag".equals(reader.getLocalName())){ + break; + } + } + } else if(reader.isEndElement() && "tags".equals(reader.getLocalName())){ + break; + } + } + return taglist; + } + private static void setCriticalityIfAvailable(XMLStreamReader reader, RobotCaseResult caseResult) { String criticality = reader.getAttributeValue(null, "critical"); if (criticality != null) { diff --git a/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java b/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java index 790991b..72c0e66 100644 --- a/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java +++ b/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java @@ -24,7 +24,9 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.apache.log4j.Logger; import org.kohsuke.stapler.StaplerRequest; @@ -42,6 +44,7 @@ public class RobotCaseResult extends RobotTestObject{ private String name; private String starttime; private String endtime; + private List tags; private RobotSuiteResult parent; private int failedSince; @@ -149,6 +152,18 @@ public boolean isCritical() { return critical; } + public List getTags(){ + if(tags == null) + return new ArrayList(); + return tags; + } + + public void addTags(List taglist){ + if(tags == null) + tags = new ArrayList(); + tags.addAll(taglist); + } + /** * Gives the buildnumber of the build that this case first failed in * @return number of build diff --git a/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/index.jelly b/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/index.jelly index 4a3632f..1384a14 100644 --- a/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/index.jelly +++ b/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/index.jelly @@ -34,6 +34,7 @@ limitations under the License. Test execution took ${it.humanReadableDuration} (${it.getDurationDiff(prevcase)})

${status}

+

| Tags: | ${tag} |

Error message:

${it.errorMsg}

diff --git a/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/summary.jelly b/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/summary.jelly index e20bae7..9d37a2c 100644 --- a/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/summary.jelly +++ b/src/main/resources/hudson/plugins/robot/model/RobotCaseResult/summary.jelly @@ -16,6 +16,7 @@ limitations under the License. +

| Tags: | ${tag} |

Error message:

diff --git a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java index bc967dd..b53b49a 100644 --- a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java +++ b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java @@ -21,6 +21,7 @@ import java.util.List; import junit.framework.TestCase; +import org.apache.commons.lang.StringUtils; public class RobotResultTest extends TestCase { @@ -150,6 +151,12 @@ public void testShouldReturnCaseById(){ assertEquals("Hello3rd", caseResult.getName()); } + public void testShouldReturnCaseTags(){ + RobotCaseResult caseResult = (RobotCaseResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Hello3rd"); + String tags = StringUtils.join(caseResult.getTags(), ","); + assertEquals("tag1,tag2", tags); + } + public void testShouldParseSplittedOutput() throws Exception { RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("testfile.xml"); result = remoteOperation.invoke(new File(new RobotSuiteResultTest().getClass().getResource("testfile.xml").toURI()).getParentFile(), null); diff --git a/src/test/resources/hudson/plugins/robot/model/output.xml b/src/test/resources/hudson/plugins/robot/model/output.xml index a301733..1bd40d2 100755 --- a/src/test/resources/hudson/plugins/robot/model/output.xml +++ b/src/test/resources/hudson/plugins/robot/model/output.xml @@ -35,7 +35,10 @@ - + + tag1 + tag2 +