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.runner;
04:
05: import java.io.InputStream;
06: import fitnesse.util.StreamReader;
07: import fitnesse.testutil.AbstractRegex;
08: import fitnesse.html.HtmlPageFactory;
09: import fit.Counts;
10:
11: public class HtmlResultFormatterTest extends AbstractRegex {
12: private HtmlResultFormatter formatter;
13:
14: public void setUp() throws Exception {
15: formatter = new HtmlResultFormatter(new HtmlPageFactory(),
16: "somehost.com:8080", "FitNesse");
17: }
18:
19: public void testIsValidHtml() throws Exception {
20: String html = getHtml().trim();
21: assertTrue(html.startsWith("<!DOCTYPE HTML"));
22: assertTrue(html.endsWith("</html>"));
23:
24: assertSubString("<base href=\"http://somehost.com:8080/\"",
25: html);
26: assertSubString(
27: "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>",
28: html);
29: assertSubString("href=\"/files/css/fitnesse_print.css\"", html);
30: assertNotSubString("href=\"/files/css/fitnesse.css\"", html);
31: assertSubString("Command Line Test Results", html);
32: assertSubString(HtmlResultFormatter.scriptContent, html);
33: assertSubString("<body onload=\"localizeInPageLinks()\"", html);
34: }
35:
36: public void testUsage() throws Exception {
37: formatter.acceptResult(new PageResult("PageOne", new Counts(1,
38: 0, 0, 0), "page one"));
39: formatter.acceptResult(new PageResult("PageTwo", new Counts(0,
40: 1, 0, 0), "page two"));
41: formatter.acceptFinalCount(new Counts(1, 1, 0, 0));
42:
43: String html = getHtml();
44:
45: assertSubString("PageOne", html);
46: assertSubString("page one", html);
47: assertSubString("pass", html);
48:
49: assertSubString("PageTwo", html);
50: assertSubString("page two", html);
51: assertSubString("fail", html);
52: }
53:
54: private String getHtml() throws Exception {
55: InputStream input = formatter.getResultStream();
56: assertNotNull(input);
57:
58: int bytes = formatter.getByteCount();
59: String html = new StreamReader(input).read(bytes);
60: return html;
61: }
62: }
|