1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package net.objectlab.qalab.parser;
40
41 import junit.framework.Test;
42 import junit.framework.TestSuite;
43
44 import net.objectlab.qalab.exporter.ConsoleExporter;
45 import net.objectlab.qalab.exporter.QALabXMLExporter;
46 import net.objectlab.qalab.util.SilentLogger;
47
48 import org.xml.sax.InputSource;
49
50 import java.io.File;
51 import java.io.IOException;
52
53 import java.util.Properties;
54
55 public class PMDStatMergeTest extends BaseMerge {
56 /**
57 * Create the test case
58 *
59 * @param testName
60 * name of the test case
61 */
62 public PMDStatMergeTest(String testName) {
63 super(testName);
64 }
65
66 /**
67 * @return the suite of tests being tested
68 */
69 public static Test suite() {
70 return new TestSuite(PMDStatMergeTest.class);
71 }
72
73 /**
74 * test simple merge from empty
75 */
76 public void testMergeWithConsole() {
77 try {
78 StatMerger merger = (StatMerger) Class.forName(
79 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
80
81 merger.setQuiet(false);
82 merger.setSrcDir("src/main/java");
83 merger.setTaskLogger(new SilentLogger());
84 merger.mergeStats(new InputSource(
85 PMDStatMergeTest.class.getResourceAsStream("good-pmd.xml")),
86 new ConsoleExporter());
87 }
88 catch (IllegalAccessException e) {
89 fail(e.toString());
90 }
91 catch (ClassNotFoundException e) {
92 fail(e.toString());
93 }
94 catch (InstantiationException e) {
95 fail(e.toString());
96 }
97 }
98
99 /**
100 * test simple merge from empty
101 */
102 public void testMerge() {
103 try {
104 Properties properties = new Properties();
105
106 properties.setProperty("qalab.merge.output.resourcename",
107 "empty-stats.xml");
108 properties.setProperty("qalab.merge.output.classname",
109 "net.objectlab.qalab.parser.PMDStatMergeTest");
110
111 QALabXMLExporter exporter = new QALabXMLExporter();
112
113 exporter.setQuiet(true);
114 exporter.setTaskLogger(new SilentLogger());
115
116 StatMerger merger = (StatMerger) Class.forName(
117 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
118
119 merger.setQuiet(false);
120 merger.setSrcDir("src/main/java");
121 merger.setTaskLogger(new SilentLogger());
122
123 properties.setProperty("qalab.merge.output.timestamp",
124 merger.getMergerTimeStamp());
125 properties.setProperty("qalab.merge.type",
126 merger.getType());
127 exporter.configure(properties);
128
129 merger.mergeStats(new InputSource(
130 PMDStatMergeTest.class.getResourceAsStream("good-pmd.xml")),
131 exporter);
132
133 checkSummary(exporter.getDocument(), 1, 12, 5);
134 checkFileCount(exporter.getDocument(), 5, 12);
135 }
136 catch (IllegalAccessException e) {
137 fail(e.toString());
138 }
139 catch (ClassNotFoundException e) {
140 fail(e.toString());
141 }
142 catch (InstantiationException e) {
143 fail(e.toString());
144 }
145 }
146
147 /**
148 * test simple merge from empty
149 */
150 public void testMergeNonExistingQALab() {
151 try {
152 final String fileName = "new-stats-pmd.xml";
153 File file = new File(fileName);
154
155 if (file.exists()) {
156 assertTrue("Delete File: " + file.getAbsolutePath(),
157 file.delete());
158 }
159
160 Properties properties = new Properties();
161
162 properties.setProperty("qalab.merge.output.file", fileName);
163
164 QALabXMLExporter exporter = new QALabXMLExporter();
165
166 exporter.setQuiet(true);
167 exporter.setTaskLogger(new SilentLogger());
168
169 StatMerger merger = (StatMerger) Class.forName(
170 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
171
172 merger.setQuiet(false);
173 merger.setSrcDir("src/main/java");
174 merger.setTaskLogger(new SilentLogger());
175
176 properties.setProperty("qalab.merge.output.timestamp",
177 merger.getMergerTimeStamp());
178 properties.setProperty("qalab.merge.type",
179 merger.getType());
180 exporter.configure(properties);
181
182 merger.mergeStats(new InputSource(
183 PMDStatMergeTest.class.getResourceAsStream("good-pmd.xml")),
184 exporter);
185
186 System.out.println(streamToString(exporter.getDocument()));
187 checkDTDPresent(exporter.getDocument());
188 checkSummary(exporter.getDocument(), 1, 12, 5);
189 checkFileCount(exporter.getDocument(), 5, 12);
190
191 exporter.save();
192
193 if (file.exists()) {
194 assertTrue("Delete File at the end: " + file.getAbsolutePath(),
195 file.delete());
196 }
197 }
198 catch (IllegalAccessException e) {
199 fail(e.toString());
200 }
201 catch (ClassNotFoundException e) {
202 fail(e.toString());
203 }
204 catch (InstantiationException e) {
205 fail(e.toString());
206 }
207 catch (IOException e) {
208 fail(e.toString());
209 }
210 }
211
212 /**
213 * test simple merge with empty pmd and empty qalab.
214 */
215 public void testMergeEmptyPMDAndQALab() {
216 try {
217 Properties properties = new Properties();
218
219 properties.setProperty("qalab.merge.output.resourcename",
220 "empty-stats.xml");
221 properties.setProperty("qalab.merge.output.classname",
222 "net.objectlab.qalab.parser.PMDStatMergeTest");
223
224 QALabXMLExporter exporter = new QALabXMLExporter();
225
226 exporter.setQuiet(true);
227 exporter.setTaskLogger(new SilentLogger());
228
229 StatMerger merger = (StatMerger) Class.forName(
230 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
231
232 merger.setQuiet(false);
233 merger.setSrcDir("src/main/java");
234 merger.setTaskLogger(new SilentLogger());
235
236 properties.setProperty("qalab.merge.output.timestamp",
237 merger.getMergerTimeStamp());
238 properties.setProperty("qalab.merge.type",
239 merger.getType());
240 exporter.configure(properties);
241
242 merger.mergeStats(new InputSource(
243 PMDStatMergeTest.class.getResourceAsStream(
244 "pmd-noviolations.xml")), exporter);
245
246 checkDTDPresent(exporter.getDocument());
247 checkSummary(exporter.getDocument(), 0, 0, 0);
248 checkFileCount(exporter.getDocument(), 0, 0);
249 }
250 catch (IllegalAccessException e) {
251 fail(e.toString());
252 }
253 catch (ClassNotFoundException e) {
254 fail(e.toString());
255 }
256 catch (InstantiationException e) {
257 fail(e.toString());
258 }
259 }
260
261 /**
262 * test simple merge with empty pmd and NON-empty qalab.
263 */
264 public void testMergeEmptyPMDAndNonEmptyQALab() {
265 try {
266 Properties properties = new Properties();
267
268 properties.setProperty("qalab.merge.output.resourcename",
269 "one-set-pmd-stats.xml");
270 properties.setProperty("qalab.merge.output.classname",
271 "net.objectlab.qalab.parser.PMDStatMergeTest");
272
273 QALabXMLExporter exporter = new QALabXMLExporter();
274
275 exporter.setQuiet(true);
276 exporter.setTaskLogger(new SilentLogger());
277
278 StatMerger merger = (StatMerger) Class.forName(
279 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
280
281 merger.setQuiet(false);
282 merger.setSrcDir("src/main/java");
283 merger.setTaskLogger(new SilentLogger());
284
285 properties.setProperty("qalab.merge.output.timestamp",
286 merger.getMergerTimeStamp());
287 properties.setProperty("qalab.merge.type",
288 merger.getType());
289 exporter.configure(properties);
290
291 merger.mergeStats(new InputSource(
292 PMDStatMergeTest.class.getResourceAsStream(
293 "pmd-noviolations.xml")), exporter);
294
295 checkDTDPresent(exporter.getDocument());
296 checkSummary(exporter.getDocument(), 1, new int[] { 12 },
297 new int[] { 5 }, new String[] { "pmd" });
298 checkFileCount(exporter.getDocument(), 5, 12);
299 }
300 catch (IllegalAccessException e) {
301 fail(e.toString());
302 }
303 catch (ClassNotFoundException e) {
304 fail(e.toString());
305 }
306 catch (InstantiationException e) {
307 fail(e.toString());
308 }
309 }
310
311 /**
312 * test simple merge with 1 set pmd
313 */
314 public void testMergeOneSetPMD() {
315 try {
316 Properties properties = new Properties();
317
318 properties.setProperty("qalab.merge.output.resourcename",
319 "one-set-pmd-stats.xml");
320 properties.setProperty("qalab.merge.output.classname",
321 "net.objectlab.qalab.parser.PMDStatMergeTest");
322
323 QALabXMLExporter exporter = new QALabXMLExporter();
324
325 exporter.setQuiet(true);
326 exporter.setTaskLogger(new SilentLogger());
327
328 StatMerger merger = (StatMerger) Class.forName(
329 "net.objectlab.qalab.parser.PMDStatMerge").newInstance();
330
331 merger.setQuiet(false);
332 merger.setSrcDir("src/main/java");
333 merger.setTaskLogger(new SilentLogger());
334
335 properties.setProperty("qalab.merge.output.timestamp",
336 merger.getMergerTimeStamp());
337 properties.setProperty("qalab.merge.type",
338 merger.getType());
339 exporter.configure(properties);
340
341 merger.mergeStats(new InputSource(
342 PMDStatMergeTest.class.getResourceAsStream("good-pmd.xml")),
343 exporter);
344
345 System.out.println(streamToString(exporter.getDocument()));
346
347 checkDTDPresent(exporter.getDocument());
348 checkSummary(exporter.getDocument(), 2, new int[] { 12, 12 },
349 new int[] { 5, 5 }, new String[] { "pmd", "pmd" });
350 checkFileCount(exporter.getDocument(), 5, 24);
351 }
352 catch (IllegalAccessException e) {
353 fail(e.toString());
354 }
355 catch (ClassNotFoundException e) {
356 fail(e.toString());
357 }
358 catch (InstantiationException e) {
359 fail(e.toString());
360 }
361 catch (IOException e) {
362 fail(e.toString());
363 }
364 }
365 }
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381