1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.testdoc.maven.export;
17
18 import java.io.IOException;
19 import java.io.OutputStream;
20 import java.util.List;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import de.smartics.maven.util.report.MessageHelper;
26 import de.smartics.testdoc.core.doc.ScenarioTestDoc;
27 import de.smartics.testdoc.core.doc.Type;
28 import de.smartics.testdoc.core.doc.UnitTestDoc;
29 import de.smartics.testdoc.core.export.UnitTestDocExporter;
30 import de.smartics.testdoc.report.export.doc.ExternalReportReferences;
31 import de.smartics.testdoc.report.export.doc.InformationFilter;
32 import de.smartics.testdoc.report.export.doc.TestDocHelper;
33 import de.smartics.testdoc.report.junit.JUnitTestCaseManager;
34
35
36
37
38
39
40
41 public abstract class AbstractReportExporter implements UnitTestDocExporter
42 {
43
44
45
46
47
48
49
50
51
52 private final Logger log = LoggerFactory
53 .getLogger(AbstractReportExporter.class);
54
55
56
57
58
59 protected final MessageHelper messages;
60
61
62
63
64 protected final TestDocHelper testDocHelper;
65
66
67
68
69 protected final InformationFilter informationFilter;
70
71
72
73
74
75
76
77
78
79
80
81
82 protected AbstractReportExporter(final MessageHelper messages,
83 final TestDocHelper testDocHelper)
84 {
85 this.messages = messages;
86 this.testDocHelper = testDocHelper;
87 this.informationFilter = testDocHelper.getInformationFilter();
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 @Override
104 public String getFileExtension()
105 {
106 return "xml";
107 }
108
109
110
111
112
113
114
115
116 public InformationFilter getInformationFilter()
117 {
118 return testDocHelper.getInformationFilter();
119 }
120
121
122
123
124
125
126
127
128 public TestDocHelper getTestDocHelper()
129 {
130 return testDocHelper;
131 }
132
133
134
135
136
137
138
139
140
141 @Override
142 public void export(final UnitTestDoc testDoc, final OutputStream output)
143 throws IOException
144 {
145 final Type type = testDoc.getUutType();
146
147 final List<ScenarioTestDoc> scenarios =
148 testDocHelper.filterScenarios(testDoc.getScenarios());
149
150 if (scenarios.isEmpty())
151 {
152 if (log.isDebugEnabled())
153 {
154 log.debug("No stories for " + type + " passed the filter.");
155 }
156 return;
157 }
158
159 renderTestDocTypeStart(testDoc);
160 final ExternalReportReferences reports = testDocHelper.getReports();
161 renderTestDocUutReportLinks(type, reports);
162
163 final ScenarioTestDoc rep = scenarios.get(0);
164 renderTableStart(rep);
165
166 int counter = 1;
167 for (final ScenarioTestDoc scenario : scenarios)
168 {
169 renderScenario(counter, scenario);
170 counter++;
171 }
172
173 renderTableEnd(rep);
174
175 renderTestDocTypeEnd(testDoc);
176 }
177
178
179
180
181
182
183
184
185 protected void renderTableStart(final ScenarioTestDoc scenarioRepresentant)
186 throws IOException
187 {
188 }
189
190
191
192
193
194
195
196 protected abstract void renderTestDocTypeStart(UnitTestDoc testDoc)
197 throws IOException;
198
199
200
201
202
203
204 protected void renderTestDocTypeEnd(final UnitTestDoc testDoc)
205 throws IOException
206 {
207 }
208
209
210
211
212
213
214 protected abstract void renderTestDocUutReportLinks(Type type,
215 ExternalReportReferences reports) throws IOException;
216
217
218
219
220
221
222
223
224 protected void renderScenario(final int counter,
225 final ScenarioTestDoc scenario) throws IOException
226 {
227 startScenario();
228 renderRowNumber(counter);
229 renderJUnitStatus(scenario);
230 renderSentence(scenario);
231 renderCategories(scenario);
232 renderTestCase(scenario);
233 endScenario();
234 }
235
236 protected void startScenario()
237 {
238 }
239
240 protected void endScenario()
241 {
242 }
243
244 protected abstract void renderRowNumber(int counter) throws IOException;
245
246 protected abstract void renderJUnitStatus(final ScenarioTestDoc scenario)
247 throws IOException;
248
249 protected abstract void renderSentence(final ScenarioTestDoc scenario)
250 throws IOException;
251
252 protected abstract void renderCategories(final ScenarioTestDoc scenario)
253 throws IOException;
254
255 protected abstract void renderTestCase(final ScenarioTestDoc scenario)
256 throws IOException;
257
258 protected void renderTableEnd(final ScenarioTestDoc scenarioRepresentant)
259 throws IOException
260 {
261 final Type testCaseType = scenarioRepresentant.getTestCaseType();
262 final JUnitTestCaseManager junitManager = testDocHelper.getJunitManager();
263 junitManager.evict(testCaseType);
264 }
265
266
267
268 }