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 fitnesse.responders.run.ExecutionLog;
07: import fit.Counts;
08:
09: public class TestHtmlFormatter {
10: private HtmlPage page;
11:
12: public TestHtmlFormatter(HtmlPage page) throws Exception {
13: this .page = page;
14: page.main.use(HtmlPage.BreakPoint);
15: page.divide();
16: }
17:
18: public String head() throws Exception {
19: return page.preDivision + makeSummaryPlaceHolder().html();
20: }
21:
22: private HtmlTag makeSummaryPlaceHolder() {
23: HtmlTag testSummaryDiv = new HtmlTag("div", "Running Tests ...");
24: testSummaryDiv.addAttribute("id", "test-summary");
25:
26: return testSummaryDiv;
27: }
28:
29: public String testSummary(Counts counts) throws Exception {
30: String summaryContent = testPageSummary();
31: summaryContent += "<strong>Assertions:</strong> "
32: + counts.toString();
33:
34: HtmlTag script = new HtmlTag("script");
35: script
36: .add("document.getElementById(\"test-summary\").innerHTML = \""
37: + summaryContent + "\";");
38: script
39: .add("document.getElementById(\"test-summary\").className = \""
40: + cssClassFor(counts) + "\";");
41: return script.html();
42: }
43:
44: protected String testPageSummary() {
45: return "";
46: }
47:
48: protected String cssClassFor(Counts count) {
49: if (count.wrong > 0)
50: return "fail";
51: else if (count.exceptions > 0
52: || count.right + count.ignores == 0)
53: return "error";
54: else if (count.ignores > 0 && count.right == 0)
55: return "ignore";
56: else
57: return "pass";
58: }
59:
60: public String tail() {
61: return page.postDivision;
62: }
63:
64: public String messageForBlankHtml() throws Exception {
65: TagGroup html = new TagGroup();
66: HtmlTag h2 = new HtmlTag("h2");
67: h2.addAttribute("class", "centered");
68: h2
69: .add("Oops! Did you forget to add to some content to this ?");
70: html.add(h2.html());
71: html.add(HtmlUtil.HR.html());
72: return html.html();
73: }
74:
75: public String executionStatus(ExecutionLog log) throws Exception {
76: return log.executionStatusHtml();
77: }
78: }
|