##### Coverage Report - org.jbehave.core.reporters.XmlOutput

Classes in this File | Line Coverage | Branch Coverage | Complexity
XmlOutput |
100% | 68/68
N/A | N/A
| 1.0;1

1 |  |
     package org.jbehave.core.reporters;
2 |  |
3 |  |
     import java.io.PrintStream;
4 |  |
     import java.util.Properties;
5 |  |
6 |  |
     import org.jbehave.core.configuration.Keywords;
7 |  |
     import org.jbehave.core.i18n.LocalizedKeywords;
8 |  |
9 |  |
     import static org.jbehave.core.reporters.PrintStreamOutput.Format.XML;
10 |  |
11 |  |
     /**
12 |  |
      * <p>
13 |  |
      * Story reporter that outputs to a PrintStream, as XML. It extends
14 |  |
      * {@link PrintStreamOutput}, providing XML-based default output
15 |  |
      * patterns, which can be overridden via the {@link
16 |  |
      * XmlOutput (PrintStream,Properties)} constructor.
17 |  |
      * </p>
18 |  |
      *
19 |  |
      * @author Mauro Talevi
20 |  |
      */
21 |  |
     public class XmlOutput extends PrintStreamOutput {
22 |  |
23 |  |
         public XmlOutput(PrintStream output) {
24 | 2 |
             this(output, new Properties());
25 | 2 |
         }
26 |  |
27 |  |
         public XmlOutput(PrintStream output, Properties outputPatterns) {
28 | 2 |
             this(output, outputPatterns, new LocalizedKeywords());
29 | 2 |
         }
30 |  |
31 |  |
             public XmlOutput(PrintStream output, Keywords keywords) {
32 | 6 |
                     this(output, new Properties(), keywords);
33 | 6 |
             }
34 |  |
35 |  |
             public XmlOutput(PrintStream output, Properties outputPatterns, Keywords keywords) {
36 | 8 |
                     this(output, outputPatterns, keywords, false);
37 | 8 |
             }
38 |  |
39 |  |
         public XmlOutput(PrintStream output, Properties outputPatterns,
40 |  |
                 Keywords keywords, boolean reportFailureTrace) {
41 | 8 |
             this(output, mergeWithDefault(outputPatterns), keywords, reportFailureTrace, false);
42 | 8 |
         }
43 |  |
44 |  |
         public XmlOutput(PrintStream output, Properties outputPatterns,
45 |  |
                 Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace) {
46 | 8 |
             super(XML, output, mergeWithDefault(outputPatterns), keywords, reportFailureTrace, compressFailureTrace);
47 | 8 |
         }
48 |  |
49 |  |
         private static Properties mergeWithDefault(Properties outputPatterns) {
50 | 16 |
             Properties patterns = defaultHtmlPatterns();
51 |  |
             // override any default pattern
52 | 16 |
             patterns.putAll(outputPatterns);
53 | 16 |
             return patterns;
54 |  |
         }
55 |  |
56 |  |
         private static Properties defaultHtmlPatterns() {
57 | 16 |
             Properties patterns = new Properties();
58 | 16 |
             patterns.setProperty("dryRun", "<dryRun>{0}</dryRun>\n");
59 | 16 |
             patterns.setProperty("beforeStory", "<story path=\"{1}\" title=\"{0}\">\n");
60 | 16 |
             patterns.setProperty("storyCancelled", "<cancelled keyword=\"{0}\" durationKeyword=\"{1}\" durationInSecs=\"{2}\"/>\n");
61 | 16 |
             patterns.setProperty("afterStory", "</story>\n");
62 | 16 |
             patterns.setProperty("pendingMethod", "<pendingMethod>{0}</pendingMethod>\n");
63 | 16 |
             patterns.setProperty("metaStart", "<meta>\n");
64 | 16 |
             patterns.setProperty("metaProperty", "<property keyword=\"{0}\" name=\"{1}\" value=\"{2}\"/>\n");
65 | 16 |
             patterns.setProperty("metaEnd", "</meta>\n");
66 | 16 |
             patterns.setProperty("filter", "<filter>{0}</filter>\n");
67 | 16 |
             patterns.setProperty("narrative", "<narrative keyword=\"{0}\">\n  <inOrderTo keyword=\"{1}\">{2}</inOrderTo>\n  <asA keyword=\"{3}\">{4}</asA>\n  <iWantTo keyword=\"{5}\">{6}</iWantTo>\n</narrative>\n");
68 | 16 |
             patterns.setProperty("beforeScenario", "<scenario keyword=\"{0}\" title=\"{1}\">\n");
69 | 16 |
             patterns.setProperty("scenarioNotAllowed", "<notAllowed pattern=\"{0}\"/>\n");
70 | 16 |
             patterns.setProperty("afterScenario", "</scenario>\n");
71 | 16 |
             patterns.setProperty("afterScenarioWithFailure", "<failure>{0}</failure>\n</scenario>\n");
72 | 16 |
             patterns.setProperty("givenStories", "<givenStories keyword=\"{0}\" paths=\"{1}\"/>\n");
73 | 16 |
             patterns.setProperty("givenStoriesStart", "<givenStories keyword=\"{0}\">\n");
74 | 16 |
             patterns.setProperty("givenStory", "<givenStory parameters=\"{1}\">{0}</givenStory>\n");
75 | 16 |
             patterns.setProperty("givenStoriesEnd", "</givenStories>\n");
76 | 16 |
             patterns.setProperty("successful", "<step outcome=\"successful\">{0}</step>\n");
77 | 16 |
             patterns.setProperty("ignorable", "<step outcome=\"ignorable\">{0}</step>\n");
78 | 16 |
             patterns.setProperty("pending", "<step outcome=\"pending\" keyword=\"{1}\">{0}</step>\n");
79 | 16 |
             patterns.setProperty("notPerformed", "<step outcome=\"notPerformed\" keyword=\"{1}\">{0}</step>\n");
80 | 16 |
             patterns.setProperty("failed", "<step outcome=\"failed\" keyword=\"{1}\">{0}<failure>{2}</failure></step>\n");
81 | 16 |
             patterns.setProperty("restarted", "<step outcome=\"restarted\">{0}<reason>{1}</reason></step>\n");
82 | 16 |
             patterns.setProperty("outcomesTableStart", "<outcomes>\n");
83 | 16 |
             patterns.setProperty("outcomesTableHeadStart", "<fields>");
84 | 16 |
             patterns.setProperty("outcomesTableHeadCell", "<field>{0}</field>");
85 | 16 |
             patterns.setProperty("outcomesTableHeadEnd", "</fields>\n");
86 | 16 |
             patterns.setProperty("outcomesTableBodyStart", "");
87 | 16 |
             patterns.setProperty("outcomesTableRowStart", "<outcome>");
88 | 16 |
             patterns.setProperty("outcomesTableCell", "<value>{0}</value>");
89 | 16 |
             patterns.setProperty("outcomesTableRowEnd", "</outcome>\n");
90 | 16 |
             patterns.setProperty("outcomesTableBodyEnd", "");
91 | 16 |
             patterns.setProperty("outcomesTableEnd", "</outcomes>\n");
92 | 16 |
             patterns.setProperty("beforeExamples", "<examples keyword=\"{0}\">\n");
93 | 16 |
             patterns.setProperty("examplesStep", "<step>{0}</step>\n");
94 | 16 |
             patterns.setProperty("afterExamples", "</examples>\n");
95 | 16 |
             patterns.setProperty("examplesTableStart", "<parameters>\n");
96 | 16 |
             patterns.setProperty("examplesTableHeadStart", "<names>");
97 | 16 |
             patterns.setProperty("examplesTableHeadCell", "<name>{0}</name>");
98 | 16 |
             patterns.setProperty("examplesTableHeadEnd", "</names>\n");
99 | 16 |
             patterns.setProperty("examplesTableBodyStart", "");
100 | 16 |
             patterns.setProperty("examplesTableRowStart", "<values>");
101 | 16 |
             patterns.setProperty("examplesTableCell", "<value>{0}</value>");
102 | 16 |
             patterns.setProperty("examplesTableRowEnd", "</values>\n");
103 | 16 |
             patterns.setProperty("examplesTableBodyEnd", "");
104 | 16 |
             patterns.setProperty("examplesTableEnd", "</parameters>\n");
105 | 16 |
             patterns.setProperty("example", "\n<example keyword=\"{0}\">{1}</example>\n");
106 | 16 |
             patterns.setProperty("parameterValueStart", "<parameter>");
107 | 16 |
             patterns.setProperty("parameterValueEnd", "</parameter>");
108 | 16 |
             patterns.setProperty("parameterValueNewline", "\n");
109 | 16 |
             return patterns;
110 |  |
         }
111 |  |
112 |  |
     }