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:
11: private static final String cssSuffix2 = "2";
12:
13: private Counts pageCounts = new Counts();
14:
15: private String cssSuffix = cssSuffix1;
16:
17: private TagGroup testResultsGroup = new TagGroup();
18:
19: private HtmlTag currentOutputDiv;
20:
21: public SuiteHtmlFormatter(HtmlPage page) throws Exception {
22: super (page);
23:
24: HtmlTag outputTitle = new HtmlTag("h2", "Test Output");
25: outputTitle.addAttribute("class", "centered");
26: testResultsGroup.add(outputTitle);
27: }
28:
29: protected String testPageSummary() {
30: return "<strong>Test Pages:</strong> " + pageCounts.toString()
31: + " ";
32: }
33:
34: public void setPageAssertions(Counts pageCounts) {
35: this .pageCounts = pageCounts;
36: }
37:
38: public String acceptResults(String relativePageName, Counts counts)
39: throws Exception {
40: switchCssSuffix();
41: HtmlTag mainDiv = HtmlUtil.makeDivTag("alternating_row_"
42: + cssSuffix);
43:
44: mainDiv.add(HtmlUtil.makeSpanTag("test_summary_results "
45: + cssClassFor(counts), counts.toString()));
46:
47: HtmlTag link = HtmlUtil.makeLink("#" + relativePageName,
48: relativePageName);
49: link.addAttribute("class", "test_summary_link");
50: mainDiv.add(link);
51:
52: pageCounts.tallyPageCounts(counts);
53:
54: return mainDiv.html(2);
55: }
56:
57: public void startOutputForNewTest(String relativePageName,
58: String qualifiedPageName) throws Exception {
59: HtmlTag pageNameBar = HtmlUtil.makeDivTag("test_output_name");
60: HtmlTag anchor = HtmlUtil.makeLink(qualifiedPageName,
61: relativePageName);
62: anchor.addAttribute("id", relativePageName);
63: pageNameBar.add(anchor);
64: testResultsGroup.add(pageNameBar);
65: currentOutputDiv = HtmlUtil.makeDivTag("alternating_block_"
66: + cssSuffix);
67: testResultsGroup.add(currentOutputDiv);
68: }
69:
70: public void acceptOutput(String output) {
71: currentOutputDiv.add(output);
72: }
73:
74: public String testOutput() throws Exception {
75: return testResultsGroup.html();
76: }
77:
78: private void switchCssSuffix() {
79: if (cssSuffix1.equals(cssSuffix))
80: cssSuffix = cssSuffix2;
81: else
82: cssSuffix = cssSuffix1;
83: }
84: }
|