Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-27936] When few FitNesse test results being published in a s…
…ingle job they renamed into Summary
  • Loading branch information
unknown committed Jun 12, 2015
1 parent 8fc43c9 commit fa03f4e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 62 deletions.
87 changes: 52 additions & 35 deletions src/main/java/hudson/plugins/fitnesse/FitnesseResults.java
Expand Up @@ -19,10 +19,12 @@
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;

public class FitnesseResults extends TabulatedResult implements Comparable<FitnesseResults> {
public class FitnesseResults extends TabulatedResult implements
Comparable<FitnesseResults> {
private static final String DETAILS = "Details";

//private static final Logger log = Logger.getLogger(FitnesseResults.class.getName());
// private static final Logger log =
// Logger.getLogger(FitnesseResults.class.getName());

private static final long serialVersionUID = 1L;
private transient List<FitnesseResults> failed;
Expand Down Expand Up @@ -60,7 +62,8 @@ void addChild(FitnesseResults fitnesseResults) {
}

/**
* {@link TestObject} Required to compare builds with one another e.g. show history graph
* {@link TestObject} Required to compare builds with one another e.g. show
* history graph
*/
@Override
public TestResult findCorrespondingResult(final String id) {
Expand Down Expand Up @@ -190,23 +193,26 @@ public String getResultsDate() {

public boolean isEarlierThan(FitnesseResults other) {
try {
return pageCounts.resultsDateAsDate().before(other.pageCounts.resultsDateAsDate());
return pageCounts.resultsDateAsDate().before(
other.pageCounts.resultsDateAsDate());
} catch (ParseException e) {
return false;
}
}

public boolean isLaterThan(FitnesseResults other) {
try {
return pageCounts.resultsDateAsDate().after(other.pageCounts.resultsDateAsDate());
return pageCounts.resultsDateAsDate().after(
other.pageCounts.resultsDateAsDate());
} catch (ParseException e) {
return false;
}
}

public long millisAfter(FitnesseResults other) {
try {
return pageCounts.resultsDateAsDate().getTime() - other.pageCounts.resultsDateAsDate().getTime();
return pageCounts.resultsDateAsDate().getTime()
- other.pageCounts.resultsDateAsDate().getTime();
} catch (ParseException e) {
return 0;
}
Expand All @@ -220,23 +226,24 @@ public String getHeadlineText() {
}

/**
* {@see TestObject#getTestResultAction()}
* Required to prevent looking for any old AbstractTestResultAction
* when e.g. looking for history across multiple builds
* {@see TestObject#getTestResultAction()} Required to prevent looking for
* any old AbstractTestResultAction when e.g. looking for history across
* multiple builds
*/
@Override
public FitnesseResultsAction getTestResultAction() {
return getParentAction();
}

/**
* {@see TestResult#getParentAction()}
* Required to prevent looking for any old AbstractTestResultAction
* when e.g. looking for history across multiple builds
* {@see TestResult#getParentAction()} Required to prevent looking for any
* old AbstractTestResultAction when e.g. looking for history across
* multiple builds
*/
@Override
public FitnesseResultsAction getParentAction() {
FitnesseResultsAction action = getOwner().getAction(FitnesseResultsAction.class);
FitnesseResultsAction action = getOwner().getAction(
FitnesseResultsAction.class);
return action;
}

Expand Down Expand Up @@ -286,7 +293,8 @@ public boolean include(FitnesseResults results) {
return skipped;
}

private List<FitnesseResults> filteredCopyOfDetails(ResultsFilter countsFilter) {
private List<FitnesseResults> filteredCopyOfDetails(
ResultsFilter countsFilter) {
List<FitnesseResults> filteredCopy = new ArrayList<FitnesseResults>();
for (FitnesseResults result : details) {
if (countsFilter.include(result)) {
Expand All @@ -305,43 +313,49 @@ interface ResultsFilter {
* referenced in body.jelly
*/
public String toHtml(FitnesseResults results) {
FitnesseBuildAction buildAction = getOwner().getAction(FitnesseBuildAction.class);
FitnesseBuildAction buildAction = getOwner().getAction(
FitnesseBuildAction.class);
if (buildAction == null) {
buildAction = FitnesseBuildAction.NULL_ACTION;
}
return buildAction.getLinkFor(results.getName(), Hudson.getInstance().getRootUrl());
return buildAction.getLinkFor(results.getName(), Hudson.getInstance()
.getRootUrl());
}

/**
* referenced in body.jelly. Link is apparently relative to
* This is the left column, which reads the results from file
* referenced in body.jelly. Link is apparently relative to This is the left
* column, which reads the results from file
*/
public String getDetailsLink() {
if (details == null) {
return "&nbsp;";
}

return String.format("<a href=\"%s/%s\">%s</a>", getName(), DETAILS, "Details");
return String.format("<a href=\"%s/%s\">%s</a>", getName(), DETAILS,
"Details");
}

/**
* referenced in body.jelly.
* The link points to the history of the fitnesse server. Note the history may not always be available.
* referenced in body.jelly. The link points to the history of the fitnesse
* server. Note the history may not always be available.
*/
public String getDetailRemoteLink() {
FitnesseBuildAction buildAction = getOwner().getAction(FitnesseBuildAction.class);
FitnesseBuildAction buildAction = getOwner().getAction(
FitnesseBuildAction.class);
if (buildAction == null) {
buildAction = FitnesseBuildAction.NULL_ACTION;
}
return buildAction.getLinkFor(getName() + "?pageHistory&resultDate=" + getResultsDate(), null, "Details");
return buildAction.getLinkFor(getName() + "?pageHistory&resultDate="
+ getResultsDate(), null, "Details");
}

/**
* called from links embedded in history/trend graphs
* TODO: Expose sub-suites as separate elements of the fitnesse report.
* called from links embedded in history/trend graphs TODO: Expose
* sub-suites as separate elements of the fitnesse report.
*/
@Override
public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) {
public Object getDynamic(String token, StaplerRequest req,
StaplerResponse rsp) {
TestResult result = findCorrespondingResult(token);
if (result != null) {
return result;
Expand All @@ -362,18 +376,19 @@ private <T extends TestResult> T findChildByName(String aName) {
}

/**
* Returns <code>true</code> if there are child results available.
* So far, only returns <code>true</code> if there is {@link #getHtmlContent()}
* for this result available.
* Returns <code>true</code> if there are child results available. So far,
* only returns <code>true</code> if there is {@link #getHtmlContent()} for
* this result available.
*/
@Override
public boolean hasChildren() {
return hasChildResults() || hasHtmlContent();
}

/**
* Returns the children of this result. Returns both the details and the html
* content, if available.
* Returns the children of this result. Returns both the details and the
* html content, if available.
*
* @return the details and html content results, or an empty Collection
*/
@Override
Expand All @@ -391,22 +406,24 @@ public Collection<? extends TestResult> getChildren() {
}

/**
* Returns <code>true</code> if there are children FitNesse results available
* Returns <code>true</code> if there are children FitNesse results
* available
*/
protected boolean hasChildResults() {
return !getChildResults().isEmpty();
}

/**
* Returns the children FitNesse results that were added with {@link #addChild(FitnesseResults)}
* Returns the children FitNesse results that were added with
* {@link #addChild(FitnesseResults)}
*/
protected List<FitnesseResults> getChildResults() {
return details;
}

/**
* Returns <code>true</code> if this results has html content
* that is available via {@link #getHtmlContent()}
* Returns <code>true</code> if this results has html content that is
* available via {@link #getHtmlContent()}
*/
protected boolean hasHtmlContent() {
return pageCounts != null && pageCounts.contentFile != null;
Expand Down
Expand Up @@ -21,6 +21,8 @@
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -137,9 +139,12 @@ public FitnesseResults getResults(PrintStream logger, FilePath resultsFile, File
+ resultsFile.getRemote());
resultsInputStream = resultsFile.read();

Path p = Paths.get(resultsFile.getRemote());
String resultFileName = p.getFileName().toString();

logger.println("Parsing results... ");
NativePageCountsParser pageCountsParser = new NativePageCountsParser();
NativePageCounts pageCounts = pageCountsParser.parse(resultsInputStream, logger, rootDir.getAbsolutePath()
NativePageCounts pageCounts = pageCountsParser.parse(resultsInputStream, resultFileName, logger, rootDir.getAbsolutePath()
+ System.getProperty("file.separator"));
logger.println("resultsFile: " + getFitnessePathToXmlResultsIn());

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hudson/plugins/fitnesse/NativePageCounts.java
Expand Up @@ -36,10 +36,12 @@ public class NativePageCounts extends DefaultHandler {

private final String rootDirName;
private final PrintStream logger;
private final String resultFileName;

public NativePageCounts(PrintStream logger, String rootDirName) {
public NativePageCounts(PrintStream logger, String resultFileName, String rootDirName) {
this.logger = logger;
this.rootDirName = rootDirName;
this.resultFileName = resultFileName;
logger.println("Write fitnesse results to: " + rootDirName);
}

Expand All @@ -59,7 +61,7 @@ public void startElement(String uri, String localName, String qName, Attributes
if (COUNTABLE.contains(qName)) {
String targetPage;
if (qName.equals(SUMMARY)) {
targetPage = "Summary";
targetPage = resultFileName;
} else {
String page = attributes.getValue(PAGE);
String pseudoPage = attributes.getValue(PSEUDO_PAGE);
Expand Down
Expand Up @@ -12,9 +12,9 @@

public class NativePageCountsParser {

public NativePageCounts parse(InputStream inputStream, PrintStream logger, String rootDirName)
public NativePageCounts parse(InputStream inputStream, String resultFileName, PrintStream logger, String rootDirName)
throws TransformerException, IOException {
NativePageCounts fitnessePageCounts = new NativePageCounts(logger, rootDirName);
NativePageCounts fitnessePageCounts = new NativePageCounts(logger, resultFileName, rootDirName);
SAXResult intermediateResult = new SAXResult(fitnessePageCounts);
transformRawResults(inputStream, intermediateResult);
return fitnessePageCounts;
Expand Down
Expand Up @@ -20,9 +20,11 @@ public class NativePageCountsParserTest {
private static final String TEST_RESULTS_FINAL_COUNTS = "<finalCounts><right>5</right><wrong>4</wrong><ignores>3</ignores><exceptions>2</exceptions></finalCounts>";
private static final String TEST_RESULTS_TOTAL_DURATION = "<totalRunTimeInMillis>2</totalRunTimeInMillis>";
private static final String TEST_RESULTS_TAIL = "</testResults>";
private static final String RESULTS = TEST_RESULTS_HEAD + PAGE_RESULTS_HEAD + PAGE_RESULTS_COUNTS
+ PAGE_RESULTS_DURATION + PAGE_RESULTS_CONTENT + PAGE_RESULTS_NAME + PAGE_RESULTS_HISTORY + PAGE_RESULTS_TAIL
+ TEST_RESULTS_FINAL_COUNTS + TEST_RESULTS_TOTAL_DURATION + TEST_RESULTS_TAIL;
private static final String RESULTS = TEST_RESULTS_HEAD + PAGE_RESULTS_HEAD
+ PAGE_RESULTS_COUNTS + PAGE_RESULTS_DURATION
+ PAGE_RESULTS_CONTENT + PAGE_RESULTS_NAME + PAGE_RESULTS_HISTORY
+ PAGE_RESULTS_TAIL + TEST_RESULTS_FINAL_COUNTS
+ TEST_RESULTS_TOTAL_DURATION + TEST_RESULTS_TAIL;
private final NativePageCountsParser fitnesseParser;

public NativePageCountsParserTest() throws Exception {
Expand All @@ -32,28 +34,35 @@ public NativePageCountsParserTest() throws Exception {
}

@Test
public void transformRawResultsShouldProduceSomethingUsable() throws Exception {
public void transformRawResultsShouldProduceSomethingUsable()
throws Exception {
DOMResult domResult = new DOMResult();
fitnesseParser.transformRawResults(toInputStream(RESULTS), domResult);
Assert.assertNotNull(domResult.getNode());
Assert.assertNotNull(domResult.getNode().getFirstChild());
Assert.assertEquals("hudson-fitnesse-plugin-report", domResult.getNode().getFirstChild().getNodeName());
Assert.assertEquals("hudson-fitnesse-plugin-report", domResult
.getNode().getFirstChild().getNodeName());
}

@Test
public void transformRawResultsShouldIgnoreBOM() throws Exception {
DOMResult domResult = new DOMResult();
fitnesseParser.transformRawResults(toInputStream(InputStreamDeBOMer.UTF32BE_BOM, RESULTS.getBytes()), domResult);
fitnesseParser.transformRawResults(
toInputStream(InputStreamDeBOMer.UTF32BE_BOM,
RESULTS.getBytes()), domResult);
Assert.assertNotNull(domResult.getNode());
Assert.assertNotNull(domResult.getNode().getFirstChild());
Assert.assertEquals("hudson-fitnesse-plugin-report", domResult.getNode().getFirstChild().getNodeName());
Assert.assertEquals("hudson-fitnesse-plugin-report", domResult
.getNode().getFirstChild().getNodeName());
}

@Test
public void parserShouldCollectFinalCounts() throws Exception {
NativePageCounts testResults = fitnesseParser.parse(toInputStream(RESULTS), System.out, "./target/");
NativePageCounts testResults = fitnesseParser.parse(
toInputStream(RESULTS), "testResult.xml", System.out,
"./target/");
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("Summary", testResults.getSummary().page);
Assert.assertEquals("testResult.xml", testResults.getSummary().page);
Assert.assertEquals(5, testResults.getSummary().right);
Assert.assertEquals(4, testResults.getSummary().wrong);
Assert.assertEquals(3, testResults.getSummary().ignored);
Expand All @@ -62,18 +71,22 @@ public void parserShouldCollectFinalCounts() throws Exception {

@Test
public void parserShouldCollectContents() throws Exception {
NativePageCounts testResults = fitnesseParser.parse(toInputStream(RESULTS), System.out, "./target/");
NativePageCounts testResults = fitnesseParser.parse(
toInputStream(RESULTS), "testResult.xml", System.out,
"./target/");
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("Summary", testResults.getSummary().page);
Assert.assertEquals("testResult.xml", testResults.getSummary().page);
Assert.assertEquals(1, testResults.getDetails().size());
}

@Test
public void parserShouldCollectAllCountsFromSuiteFile() throws Exception {
InputStream sampleXml = getClass().getResourceAsStream("fitnesse-suite-results.xml");
NativePageCounts testResults = fitnesseParser.parse(sampleXml, System.out, "./target/");
InputStream sampleXml = getClass().getResourceAsStream(
"fitnesse-suite-results.xml");
NativePageCounts testResults = fitnesseParser.parse(sampleXml,
"testResult.xml", System.out, "./target/");
Assert.assertEquals(15, testResults.size());
Assert.assertEquals("Summary", testResults.getSummary().page);
Assert.assertEquals("testResult.xml", testResults.getSummary().page);
Assert.assertEquals(6, testResults.getSummary().right);
Assert.assertEquals(5, testResults.getSummary().wrong);
Assert.assertEquals(1, testResults.getSummary().ignored);
Expand All @@ -82,9 +95,12 @@ public void parserShouldCollectAllCountsFromSuiteFile() throws Exception {
}

@Test
public void parserShouldCollectAllCountsFromSingleTestFile() throws Exception {
InputStream sampleXml = getClass().getResourceAsStream("fitnesse-test-results.xml");
NativePageCounts testResults = fitnesseParser.parse(sampleXml, System.out, "./target/");
public void parserShouldCollectAllCountsFromSingleTestFile()
throws Exception {
InputStream sampleXml = getClass().getResourceAsStream(
"fitnesse-test-results.xml");
NativePageCounts testResults = fitnesseParser.parse(sampleXml,
"testResult.xml", System.out, "./target/");
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("TestDecisionTable", testResults.getSummary().page);
Assert.assertEquals(16, testResults.getSummary().right);
Expand Down

0 comments on commit fa03f4e

Please sign in to comment.