1 | |
package org.jbehave.core.reporters; |
2 | |
|
3 | |
import static org.jbehave.core.reporters.PrintStreamOutput.Format.HTML; |
4 | |
|
5 | |
import java.io.PrintStream; |
6 | |
import java.util.Properties; |
7 | |
|
8 | |
import org.jbehave.core.configuration.Keywords; |
9 | |
import org.jbehave.core.i18n.LocalizedKeywords; |
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class HtmlOutput extends PrintStreamOutput { |
23 | |
|
24 | |
public HtmlOutput(PrintStream output) { |
25 | 1 | this(output, new Properties()); |
26 | 1 | } |
27 | |
|
28 | |
public HtmlOutput(PrintStream output, Properties outputPatterns) { |
29 | 2 | this(output, outputPatterns, new LocalizedKeywords()); |
30 | 2 | } |
31 | |
|
32 | |
public HtmlOutput(PrintStream output, Keywords keywords) { |
33 | 3 | this(output, new Properties(), keywords); |
34 | 3 | } |
35 | |
|
36 | |
public HtmlOutput(PrintStream output, Properties outputPatterns, Keywords keywords) { |
37 | 5 | this(output, outputPatterns, keywords, false); |
38 | 5 | } |
39 | |
|
40 | |
public HtmlOutput(PrintStream output, Properties outputPatterns, |
41 | |
Keywords keywords, boolean reportFailureTrace) { |
42 | 5 | super(HTML, output, mergeWithDefault(outputPatterns), keywords, reportFailureTrace); |
43 | 5 | } |
44 | |
|
45 | |
private static Properties mergeWithDefault(Properties outputPatterns) { |
46 | 5 | Properties patterns = defaultHtmlPatterns(); |
47 | |
|
48 | 5 | patterns.putAll(outputPatterns); |
49 | 5 | return patterns; |
50 | |
} |
51 | |
|
52 | |
private static Properties defaultHtmlPatterns() { |
53 | 5 | Properties patterns = new Properties(); |
54 | 5 | patterns.setProperty("successful", "<div class=\"step successful\">{0}</div>\n"); |
55 | 5 | patterns.setProperty("ignorable", "<div class=\"step ignorable\">{0}</div>\n"); |
56 | 5 | patterns.setProperty("pending", "<div class=\"step pending\">{0} <span class=\"keyword pending\">({1})</span></div>\n"); |
57 | 5 | patterns.setProperty("notPerformed", "<div class=\"step notPerformed\">{0} <span class=\"keyword notPerformed\">({1})</span></div>\n"); |
58 | 5 | patterns.setProperty("failed", "<div class=\"step failed\">{0} <span class=\"keyword failed\">({1})</span><br/><span class=\"message failed\">{2}</span></div>\n"); |
59 | 5 | patterns.setProperty("outcomesTableStart", "<div class=\"outcomes\"><table>\n"); |
60 | 5 | patterns.setProperty("outcomesTableHeadStart", "<thead>\n<tr>\n"); |
61 | 5 | patterns.setProperty("outcomesTableHeadCell", "<th>{0}</th>"); |
62 | 5 | patterns.setProperty("outcomesTableHeadEnd", "</tr>\n</thead>\n"); |
63 | 5 | patterns.setProperty("outcomesTableBodyStart", "<tbody>\n"); |
64 | 5 | patterns.setProperty("outcomesTableRowStart", "<tr class=\"{0}\">\n"); |
65 | 5 | patterns.setProperty("outcomesTableCell", "<td>{0}</td>"); |
66 | 5 | patterns.setProperty("outcomesTableRowEnd", "</tr>\n"); |
67 | 5 | patterns.setProperty("outcomesTableBodyEnd", "</tbody>\n"); |
68 | 5 | patterns.setProperty("outcomesTableEnd", "</table></div>\n"); |
69 | 5 | patterns.setProperty("beforeStory", "<div class=\"story\">\n<h1>{0}</h1>\n<div class=\"path\">{1}</div>\n"); |
70 | 5 | patterns.setProperty("narrative", "<div class=\"narrative\"><h2>{0}</h2>\n<div class=\"element inOrderTo\"><span class=\"keyword inOrderTo\">{1}</span> {2}</div>\n<div class=\"element asA\"><span class=\"keyword asA\">{3}</span> {4}</div>\n<div class=\"element iWantTo\"><span class=\"keyword iWantTo\">{5}</span> {6}</div>\n</div>\n"); |
71 | 5 | patterns.setProperty("afterStory", "</div>\n"); |
72 | 5 | patterns.setProperty("beforeScenario", "<div class=\"scenario\">\n<h2>{0} {1}</h2>\n"); |
73 | 5 | patterns.setProperty("afterScenario", "</div>\n"); |
74 | 5 | patterns.setProperty("afterScenarioWithFailure", "<pre class=\"failure\">{0}</pre>\n</div>\n"); |
75 | 5 | patterns.setProperty("givenStories", "<div class=\"givenStories\">{0} {1}</div>\n"); |
76 | 5 | patterns.setProperty("beforeExamples", "<div class=\"examples\">\n<h3>{0}</h3>\n"); |
77 | 5 | patterns.setProperty("examplesStep", "<div class=\"step\">{0}</div>\n"); |
78 | 5 | patterns.setProperty("afterExamples", "</div>\n"); |
79 | 5 | patterns.setProperty("examplesTableStart", "<table>\n"); |
80 | 5 | patterns.setProperty("examplesTableHeadStart", "<thead>\n<tr>\n"); |
81 | 5 | patterns.setProperty("examplesTableHeadCell", "<th>{0}</th>"); |
82 | 5 | patterns.setProperty("examplesTableHeadEnd", "</tr>\n</thead>\n"); |
83 | 5 | patterns.setProperty("examplesTableBodyStart", "<tbody>\n"); |
84 | 5 | patterns.setProperty("examplesTableRowStart", "<tr>\n"); |
85 | 5 | patterns.setProperty("examplesTableCell", "<td>{0}</td>"); |
86 | 5 | patterns.setProperty("examplesTableRowEnd", "</tr>\n"); |
87 | 5 | patterns.setProperty("examplesTableBodyEnd", "</tbody>\n"); |
88 | 5 | patterns.setProperty("examplesTableEnd", "</table>\n"); |
89 | 5 | patterns.setProperty("example", "\n<h3 class=\"example\">{0} {1}</h3>\n"); |
90 | 5 | patterns.setProperty("parameterValueStart", "<span class=\"step parameter\">"); |
91 | 5 | patterns.setProperty("parameterValueEnd", "</span>"); |
92 | 5 | patterns.setProperty("parameterValueNewline", "<br/>"); |
93 | 5 | patterns.setProperty("dryRun", "<div class=\"dryRun\">{0}</div>\n"); |
94 | 5 | return patterns; |
95 | |
} |
96 | |
|
97 | |
} |