1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.reporting;
20
21 import net.sf.jameleon.TestCaseTag;
22 import net.sf.jameleon.result.TestCaseResult;
23 import net.sf.jameleon.util.Configurator;
24 import net.sf.jameleon.util.JameleonUtility;
25 import net.sf.jameleon.util.JameleonDefaultValues;
26
27 import java.util.Calendar;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.io.File;
31
32 /***
33 * Reports on all script results in a given test run as a summary in HTML. The current implementation reports
34 * a single result as an HTML table row.
35 */
36 public class HtmlTestRunReporter extends AbstractTestRunReporter {
37
38 public static final String DEFAULT_HEADER_TEMPLATE = "templates/results/summary/TestRunResultsHeader.html";
39 public static final String DEFAULT_FOOTER_TEMPLATE = "templates/results/summary/TestRunResultsFooter.html";
40 public static final String DEFAULT_RESULT_ROW_TEMPLATE = "templates/results/summary/TestRunRowResult.html";
41
42 private String testRunResultsHeaderTemplate = DEFAULT_HEADER_TEMPLATE;
43 private String testResultRowTemplate = DEFAULT_RESULT_ROW_TEMPLATE;
44 private String testRunResultsFooterTemplate = DEFAULT_FOOTER_TEMPLATE;
45
46 public void reportScriptResult(TestCaseTag tct, TestCaseCounter counter) {
47 Map params = new HashMap();
48 params.put("result", tct.getResults());
49 String path = tct.getResultsDir().getParent();
50 params.put("resultsFile", JameleonUtility.getEndingPath(path, tct.getResults().getTestCaseDocsFile()));
51 params.put("results_res_dir", "../..");
52 params.put("testCaseNum", counter.getTestCaseNum()+"");
53 ReporterUtils.outputToTemplate(getWriter(), testResultRowTemplate, params);
54 }
55
56 public void reportTestRunStart(Calendar startTime) {
57 Configurator config = Configurator.getInstance();
58 Map params = new HashMap();
59 params.put("organization", config.getValue("organization"));
60 params.put("environment", config.getValue("testEnvironment"));
61 params.put("startTime", startTime.getTime());
62 params.put("encoding", config.getValue("genTestCaseDocsEncoding", JameleonDefaultValues.FILE_CHARSET));
63
64 ReporterUtils.outputToTemplate(getWriter(), testRunResultsHeaderTemplate, params);
65 }
66
67 public void reportTestRunComplete(Calendar startTime, Calendar endTime, TestCaseCounter counter) {
68 int numPassed = 0, numFailed = 0;
69 if (counter != null){
70 numPassed = counter.getNumPassed();
71 numFailed = counter.getNumFailed();
72 }
73 Map params = new HashMap();
74 params.put("totalPassed", new Integer(numPassed));
75 params.put("totalFailed", new Integer(numFailed));
76 params.put("totalTime", ReporterUtils.getExecutionTime(startTime, endTime));
77 String percentagePassed = TestCaseResult.getPercentagePassed(numPassed, numFailed);
78 params.put("percentPassed", percentagePassed);
79 ReporterUtils.outputToTemplate(getWriter(), testRunResultsFooterTemplate, params);
80 }
81
82
83
84
85
86
87
88 /***
89 * Gets the test run results footer template
90 * @return The test run results footer template
91 */
92 public String getTestRunResultsFooterTemplate() {
93 return testRunResultsFooterTemplate;
94 }
95
96 /***
97 * Sets the test run results footer template
98 * @param testRunResultsFooterTemplate The test run results footer template
99 */
100 public void setTestRunResultsFooterTemplate(String testRunResultsFooterTemplate) {
101 this.testRunResultsFooterTemplate = testRunResultsFooterTemplate;
102 }
103
104 /***
105 * Gets the template for the test run results header file
106 * @return The test run results template
107 */
108 public String getTestRunResultsHeaderTemplate() {
109 return testRunResultsHeaderTemplate;
110 }
111
112 /***
113 * Sets the template for the test run results header file
114 * @param testRunResultsHeaderTemplate The test run results template
115 */
116 public void setTestRunResultsHeaderTemplate(String testRunResultsHeaderTemplate) {
117 this.testRunResultsHeaderTemplate = testRunResultsHeaderTemplate;
118 }
119
120 /***
121 * Gets the template for the invidual test script result
122 * @return The template for the invidual test script result
123 */
124 public String getTestResultRowTemplate() {
125 return testResultRowTemplate;
126 }
127
128 /***
129 * Sets the template for the invidual test script result
130 * @param testResultRowTemplate The template for the invidual test script result
131 */
132 public void setTestResultRowTemplate(String testResultRowTemplate) {
133 this.testResultRowTemplate = testResultRowTemplate;
134 }
135 }