1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.testdoc.maven.export.sink;
17
18 import java.io.IOException;
19 import java.util.List;
20 import java.util.Set;
21
22 import de.smartics.maven.util.report.MessageHelper;
23 import de.smartics.testdoc.core.doc.Type;
24 import de.smartics.testdoc.core.doc.UnitTestDoc;
25 import de.smartics.testdoc.report.export.doc.InformationFilter;
26 import de.smartics.testdoc.report.index.ExportIndex;
27 import de.smartics.testdoc.report.index.ExportMultiIndex;
28 import de.smartics.testdoc.report.index.Section;
29
30
31
32
33
34
35
36 class TestDocPageRenderer extends AbstractPageRenderer
37 {
38
39
40
41
42
43
44
45
46
47 protected final SinkExporter exporter;
48
49
50
51
52 private final RenderHelper helper;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 TestDocPageRenderer(final String reportName, final MessageHelper messages,
70 final SinkExporter exporter)
71 {
72 super(reportName, messages, exporter.getSink());
73 this.exporter = exporter;
74 this.helper = new RenderHelper(messages, sink);
75
76 }
77
78
79
80
81
82
83
84
85
86
87
88 void renderPage(final ExportMultiIndex index, final Set<UnitTestDoc> testDocs)
89 throws IOException
90 {
91 renderPageStart();
92 renderBody(index, testDocs);
93 renderPageEndAndFinalize();
94 }
95
96 private void renderBody(final ExportMultiIndex index,
97 final Set<UnitTestDoc> testDocs) throws IOException
98 {
99 renderBodyStart();
100
101 renderIndexes(index);
102 for (final Section<UnitTestDoc> section : index.getSection()
103 .getSubSections())
104 {
105 renderSections(section, 2);
106 }
107 renderTestDocs(testDocs);
108
109 renderBodyEnd();
110 }
111
112 private void renderIndexes(final ExportMultiIndex index)
113 {
114 renderIndexOfIndexes(index);
115
116 final Section<UnitTestDoc> section = index.getSection();
117 for (final Section<UnitTestDoc> subSection : section.getSubSections())
118 {
119 renderSectionIndex(subSection);
120 }
121 }
122
123 private void renderIndexOfIndexes(final ExportMultiIndex index)
124 {
125 final InformationFilter filter = exporter.getInformationFilter();
126 if (filter.isShowIndexOfIndices() && !index.isEmpty())
127 {
128 sink.section2();
129
130 sink.anchor("indexOfIndexes");
131 sink.anchor_();
132 sink.sectionTitle2();
133 sink.text(messages.getLabel("report.indexOfIndexes"));
134 sink.sectionTitle2_();
135
136 helper.renderIndexTableStart();
137 int counter = 1;
138 for (final ExportIndex exportIndex : index.getIndexes())
139 {
140 if (!exportIndex.isEmpty())
141 {
142 final String name = exportIndex.getSectionName();
143 final String label = messages.getLabel(name);
144 helper.renderIndexRow(counter, label);
145 counter++;
146 }
147 }
148 helper.renderIndexTableEnd();
149
150 sink.section2_();
151 }
152 }
153
154 private void renderSectionIndex(final Section<UnitTestDoc> section)
155 {
156 final List<Section<UnitTestDoc>> subSections = section.getSubSections();
157 if (!subSections.isEmpty())
158 {
159 sink.section3();
160
161 final String id = section.getName();
162 helper.renderAnchor(id);
163 sink.sectionTitle3();
164 sink.text(messages.getLabel("index." + id));
165 sink.sectionTitle3_();
166
167 helper.renderIndexTableStart();
168 int counter = 1;
169 for (final Section<UnitTestDoc> subSection : subSections)
170 {
171 final String name = subSection.getName();
172 helper.renderIndexRow(counter, name);
173 counter++;
174 }
175 helper.renderIndexTableEnd();
176
177 sink.section3_();
178 }
179 }
180
181 private void renderSections(final Section<UnitTestDoc> section,
182 final int level)
183 {
184 final String name = section.getName();
185 final String sectionLabel = messages.getLabel(name);
186 helper.renderSectionStart(level, sectionLabel);
187
188 if (!section.containsSubSections())
189 {
190 helper.renderIndexTableStart();
191 int counter = 1;
192 for (final UnitTestDoc testDoc : section.getItems())
193 {
194 final Type type = testDoc.getUutType();
195 final String label = type.getTypeName();
196 final String id = type.toString();
197 helper.renderIndexRow(counter, label, id);
198 counter++;
199 }
200 helper.renderIndexTableEnd();
201 }
202 else
203 {
204 final int nextLevel = level + 1;
205 for (final Section<UnitTestDoc> subSection : section.getSubSections())
206 {
207 renderSections(subSection, nextLevel);
208 }
209 }
210
211 helper.renderSectionEnd(level);
212 }
213
214 private void renderTestDocs(final Set<UnitTestDoc> testDocs)
215 throws IOException
216 {
217 sink.section2();
218
219 helper.renderAnchor("unitTestDoc");
220 sink.sectionTitle2();
221 sink.text(messages.getLabel("report.unitTestDoc"));
222 sink.sectionTitle2_();
223
224 for (final UnitTestDoc testDoc : testDocs)
225 {
226 exporter.export(testDoc);
227 }
228
229 sink.section2_();
230 }
231
232
233
234 }