Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-22406: implemented tag storing and showing in test case page …
…and in failed cases summary
  • Loading branch information
japiiron committed May 27, 2014
1 parent 874f1cc commit 806648a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/java/hudson/plugins/robot/RobotParser.java
Expand Up @@ -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")));
Expand All @@ -265,6 +268,26 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res
return caseResult;
}

private List<String> processTags(XMLStreamReader reader) throws XMLStreamException {
List<String> taglist = new ArrayList<String>();
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) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/hudson/plugins/robot/model/RobotCaseResult.java
Expand Up @@ -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;
Expand All @@ -42,6 +44,7 @@ public class RobotCaseResult extends RobotTestObject{
private String name;
private String starttime;
private String endtime;
private List<String> tags;

private RobotSuiteResult parent;
private int failedSince;
Expand Down Expand Up @@ -149,6 +152,18 @@ public boolean isCritical() {
return critical;
}

public List<String> getTags(){
if(tags == null)
return new ArrayList<String>();
return tags;
}

public void addTags(List<String> taglist){
if(tags == null)
tags = new ArrayList<String>();
tags.addAll(taglist);
}

/**
* Gives the buildnumber of the build that this case first failed in
* @return number of build
Expand Down
Expand Up @@ -34,6 +34,7 @@ limitations under the License.
Test execution took ${it.humanReadableDuration} (${it.getDurationDiff(prevcase)})
</div>
<h2 style="color:${headingColor};">${status}</h2>
<h4>| Tags: |<j:forEach var="tag" items="${it.tags}"><j:whitespace> ${tag} |</j:whitespace></j:forEach></h4>
<j:if test="${!it.isPassed()}">
<h3>Error message:</h3>
<p>${it.errorMsg}</p>
Expand Down
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<st:contentType value="text/plain"/>
<h3>| Tags: |<j:forEach var="tag" items="${it.tags}"><j:whitespace> ${tag} |</j:whitespace></j:forEach></h3>
<h3>Error message:</h3>
<pre><st:out value="${it.errorMsg}"/></pre>
</j:jelly>
7 changes: 7 additions & 0 deletions src/test/java/hudson/plugins/robot/model/RobotResultTest.java
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import junit.framework.TestCase;
import org.apache.commons.lang.StringUtils;


public class RobotResultTest extends TestCase {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/test/resources/hudson/plugins/robot/model/output.xml
Expand Up @@ -35,7 +35,10 @@
<status status="PASS" endtime="20100629 11:08:54.451" starttime="20100629 11:08:54.451">
</status>
</kw>
<tags></tags>
<tags>
<tag>tag1</tag>
<tag>tag2</tag>
</tags>
<status status="PASS" endtime="20100629 11:08:54.451" starttime="20100629 11:08:54.450">
</status>
</test>
Expand Down

0 comments on commit 806648a

Please sign in to comment.