01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders.run;
04:
05: import fitnesse.html.*;
06: import fit.Counts;
07:
08: public class SuiteHtmlFormatter extends TestHtmlFormatter {
09: private static final String cssSuffix1 = "1";
10: private static final String cssSuffix2 = "2";
11:
12: private Counts pageCounts = new Counts();
13:
14: private String cssSuffix = cssSuffix1;
15: private TagGroup testResultsGroup = new TagGroup();
16: private HtmlTag currentOutputDiv;
17:
18: public SuiteHtmlFormatter(HtmlPage page) throws Exception {
19: super (page);
20:
21: HtmlTag outputTitle = new HtmlTag("h2", "Test Output");
22: outputTitle.addAttribute("class", "centered");
23: testResultsGroup.add(outputTitle);
24: }
25:
26: protected String testPageSummary() {
27: return "<strong>Test Pages:</strong> " + pageCounts.toString()
28: + " ";
29: }
30:
31: public void setPageAssertions(Counts pageCounts) {
32: this .pageCounts = pageCounts;
33: }
34:
35: public String acceptResults(String relativePageName, Counts counts)
36: throws Exception {
37: switchCssSuffix();
38: HtmlTag mainDiv = HtmlUtil.makeDivTag("alternating_row_"
39: + cssSuffix);
40:
41: mainDiv.add(HtmlUtil.makeSpanTag("test_summary_results "
42: + cssClassFor(counts), counts.toString()));
43:
44: HtmlTag link = HtmlUtil.makeLink("#" + relativePageName,
45: relativePageName);
46: link.addAttribute("class", "test_summary_link");
47: mainDiv.add(link);
48:
49: pageCounts.tallyPageCounts(counts);
50:
51: return mainDiv.html(2);
52: }
53:
54: public void startOutputForNewTest(String relativePageName,
55: String qualifiedPageName) throws Exception {
56: HtmlTag pageNameBar = HtmlUtil.makeDivTag("test_output_name");
57: HtmlTag anchor = HtmlUtil.makeLink(qualifiedPageName,
58: relativePageName);
59: anchor.addAttribute("id", relativePageName);
60: pageNameBar.add(anchor);
61: testResultsGroup.add(pageNameBar);
62: currentOutputDiv = HtmlUtil.makeDivTag("alternating_block_"
63: + cssSuffix);
64: testResultsGroup.add(currentOutputDiv);
65: }
66:
67: public void acceptOutput(String output) {
68: currentOutputDiv.add(output);
69: }
70:
71: public String testOutput() throws Exception {
72: return testResultsGroup.html();
73: }
74:
75: private void switchCssSuffix() {
76: if (cssSuffix1.equals(cssSuffix))
77: cssSuffix = cssSuffix2;
78: else
79: cssSuffix = cssSuffix1;
80: }
81: }
|