Skip to content

Commit

Permalink
Merge pull request #22 from antoine-aumjaud/features/FITNESSE-PLUGIN-…
Browse files Browse the repository at this point in the history
…FixGetDetailOnTestPage

Fix JENKINS-26387: can't run a test page only
  • Loading branch information
antoine-aumjaud committed Mar 3, 2015
2 parents 19b7421 + f819b5b commit cf0644c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
target
work
/bin
/target/
36 changes: 7 additions & 29 deletions src/main/java/hudson/plugins/fitnesse/FitnesseResults.java
Expand Up @@ -22,12 +22,12 @@
public class FitnesseResults extends TabulatedResult implements Comparable<FitnesseResults>{
private static final String DETAILS = "Details";

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

private static final long serialVersionUID = 1L;
private transient List<FitnesseResults> failed = null;
private transient List<FitnesseResults> skipped = null;
private transient List<FitnesseResults> passed = null;
private transient List<FitnesseResults> failed;
private transient List<FitnesseResults> skipped;
private transient List<FitnesseResults> passed;

private Counts pageCounts;
private TestObject parent;
Expand Down Expand Up @@ -334,14 +334,6 @@ public String getDetailRemoteLink() {
return buildAction.getLinkFor(getName() + "?pageHistory&resultDate="+getResultsDate(), null, "Details");
}

@Override
public String getErrorDetails() {
if (pageCounts.content != null) {
return pageCounts.content;
}
return "";
}


/**
* called from links embedded in history/trend graphs
Expand All @@ -356,6 +348,7 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
return findChildByName(token);
}

@SuppressWarnings("unchecked")
private <T extends TestResult> T findChildByName(String aName) {
Collection<? extends TestResult> children = getChildren();
for (TestResult child : children) {
Expand Down Expand Up @@ -415,24 +408,9 @@ protected List<FitnesseResults> getChildResults() {
* that is available via {@link #getHtmlContent()}
*/
protected boolean hasHtmlContent() {
return pageCounts != null && pageCounts.content != null;
return pageCounts != null && pageCounts.contentFile != null;
}

/**
* Returns the html content of this result.
*/
protected String getHtmlContent() {
if (hasHtmlContent()) {
return pageCounts.content;
}
return "";
}

@Override
public String getStdout() {
return getHtmlContent();
}


/**
* Make page counts accessible to ResultsDetails
*/
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/hudson/plugins/fitnesse/NativePageCounts.java
Expand Up @@ -57,11 +57,16 @@ public NativePageCounts(PrintStream logger, String rootDirName) {
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) {
if (COUNTABLE.contains(qName)) {
String page = attributes.getValue(PAGE);
String pseudoPage = attributes.getValue(PSEUDO_PAGE);
String targetPage = page == null || page.equals("") ? pseudoPage : page;

if (COUNTABLE.contains(qName)) {
String targetPage;
if (qName.equals(SUMMARY)) {
targetPage = "Summary";
} else {
String page = attributes.getValue(PAGE);
String pseudoPage = attributes.getValue(PSEUDO_PAGE);
targetPage = page == null || page.equals("") ? pseudoPage : page;
}
Counts counts = new Counts(
targetPage,
qName.equals(SUMMARY) ? "" : resultsDateOf(attributes.getValue(APPROX_RESULT_DATE)),
Expand All @@ -73,9 +78,11 @@ public void startElement(String uri, String localName, String qName,
writeFitnesseResultFiles(targetPage, attributes.getValue(CONTENT))
);

if (qName.equals(SUMMARY))
summary = counts;
allCounts.put(counts.page, counts);

if (qName.equals(SUMMARY)) {
summary = counts;
}
}
}

Expand All @@ -101,16 +108,6 @@ public Counts getSummary() {
return summary;
}

public List<String> getDetailsContents() {
ArrayList<String> contents = new ArrayList<String>();
for (String key : allCounts.keySet()) {
Counts counts = allCounts.get(key);
if (counts != summary)
contents.add(counts.content);
}
return contents;
}

public Collection<Counts> getAllCounts() {
return allCounts.values();
}
Expand All @@ -126,7 +123,6 @@ public List<Counts> getDetails() {
}

static final class Counts {
private static final long serialVersionUID = 1L;
static final SimpleDateFormat RESULTS_DATE_FORMAT = new SimpleDateFormat(
"yyyyMMddHHmmss");

Expand All @@ -138,7 +134,7 @@ static final class Counts {
public final int exceptions;
public final int duration;

public String content; // TODO remove this useless field, use contentFile in tests
public String content; // not used, keep for backward compatibility

// stores the file-path where to find the actual fitnesse result (html)
public final String contentFile;
Expand All @@ -153,9 +149,6 @@ public Counts(String page, String resultsDate, int right, int wrong, int ignored
this.exceptions = exceptions;
this.duration = duration;
this.contentFile = contentFile;
if (contentFile != null) {
content = "";
}
}

public Date resultsDateAsDate() throws ParseException {
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void parserShouldCollectFinalCounts() throws Exception {
NativePageCounts testResults = fitnesseParser.parse(toInputStream(RESULTS), System.out,
"./target/");
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("SuiteBlah", testResults.getSummary().page);
Assert.assertEquals("Summary", testResults.getSummary().page);
Assert.assertEquals(5, testResults.getSummary().right);
Assert.assertEquals(4, testResults.getSummary().wrong);
Assert.assertEquals(3, testResults.getSummary().ignored);
Expand All @@ -78,16 +78,16 @@ public void parserShouldCollectContents() throws Exception {
NativePageCounts testResults = fitnesseParser.parse(toInputStream(RESULTS), System.out,
"./target/");
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("SuiteBlah", testResults.getSummary().page);
Assert.assertEquals(1, testResults.getDetailsContents().size());
Assert.assertEquals("Summary", 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/");
Assert.assertEquals(15, testResults.size());
Assert.assertEquals("SuiteBranchMain", testResults.getSummary().page);
Assert.assertEquals("Summary", testResults.getSummary().page);
Assert.assertEquals(6, testResults.getSummary().right);
Assert.assertEquals(5, testResults.getSummary().wrong);
Assert.assertEquals(1, testResults.getSummary().ignored);
Expand All @@ -99,7 +99,7 @@ public void parserShouldCollectAllCountsFromSuiteFile() throws Exception {
public void parserShouldCollectAllCountsFromSingleTestFile() throws Exception {
InputStream sampleXml = getClass().getResourceAsStream("fitnesse-test-results.xml");
NativePageCounts testResults = fitnesseParser.parse(sampleXml, System.out, "./target/");
Assert.assertEquals(1, testResults.size());
Assert.assertEquals(2, testResults.size());
Assert.assertEquals("TestDecisionTable", testResults.getSummary().page);
Assert.assertEquals(16, testResults.getSummary().right);
Assert.assertEquals(2, testResults.getSummary().wrong);
Expand Down
Expand Up @@ -58,7 +58,7 @@ public void resultsShouldCollectSummaryFromAttributes() {
Assert.assertEquals(1, results.size());
Assert.assertNotNull(results.getSummary());
Assert.assertEquals(0, results.getDetails().size());
Assert.assertEquals("pseudo-name", results.getSummary().page);
Assert.assertEquals("Summary", results.getSummary().page);
Assert.assertEquals("", results.getSummary().resultsDate);
Assert.assertEquals(1, results.getSummary().right);
Assert.assertEquals(2, results.getSummary().wrong);
Expand Down

0 comments on commit cf0644c

Please sign in to comment.