1   ////////////////////////////////////////////////////////////////////////////////
2   //
3   //                  ObjectLab is sponsoring QALab
4   // 
5   // Based in London, we are world leaders in the design and development 
6   // of bespoke applications for the Securities Financing markets.
7   // 
8   // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
9   //           ___  _     _           _   _          _
10  //          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
11  //         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
12  //         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
13  //          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
14  //                   |__/
15  //
16  //                   http://www.ObjectLab.co.uk
17  // ---------------------------------------------------------------------------
18  //
19  //QALab is released under the GNU General Public License.
20  //
21  //QALab: Collects QA Statistics from your build over time.
22  //2005+, ObjectLab Ltd
23  //
24  //This library is free software; you can redistribute it and/or
25  //modify it under the terms of the GNU General Public
26  //License as published by the Free Software Foundation; either
27  //version 2.1 of the License, or (at your option) any later version.
28  //
29  //This library is distributed in the hope that it will be useful,
30  //but WITHOUT ANY WARRANTY; without even the implied warranty of
31  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32  //General Public License for more details.
33  //
34  //You should have received a copy of the GNU General Public
35  //License along with this library; if not, write to the Free Software
36  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37  //
38  ////////////////////////////////////////////////////////////////////////////////
39  package net.objectlab.qalab.parser;
40  
41  import junit.framework.Test;
42  import junit.framework.TestSuite;
43  import net.objectlab.qalab.exporter.ConsoleExporter;
44  import net.objectlab.qalab.util.SilentLogger;
45  
46  import org.xml.sax.InputSource;
47  
48  public class CoberturaLineStatMergeTest extends BaseMerge {
49      /**
50       * Create the test case
51       *
52       * @param testName name of the test case
53       */
54      public CoberturaLineStatMergeTest(String testName) {
55          super(testName);
56      }
57  
58      /**
59       * @return the suite of tests being tested
60       */
61      public static Test suite() {
62          return new TestSuite(CoberturaLineStatMergeTest.class);
63      }
64  
65      /**
66       * test simple merge from empty
67       */
68      public void testMergeWithConsole() {
69          try {
70              StatMerger merger = (StatMerger) Class.forName(
71                      "net.objectlab.qalab.parser.CoberturaLineStatMerge")
72                                                    .newInstance();
73  
74              merger.setQuiet(false);
75              merger.setSrcDir("src/main/java");
76              merger.setTaskLogger(new SilentLogger());
77              merger.mergeStats(new InputSource(
78                      CoberturaLineStatMergeTest.class.getResourceAsStream(
79                          "good-cobertura.xml")), new ConsoleExporter());
80          }
81          catch (IllegalAccessException e) {
82              fail(e.toString());
83          }
84          catch (ClassNotFoundException e) {
85              fail(e.toString());
86          }
87          catch (InstantiationException e) {
88              fail(e.toString());
89          }
90      }
91  
92  /*    *//**
93       * test simple merge from empty
94       *//*
95      public void testMerge() {
96          try {
97              Properties properties = new Properties();
98  
99              properties.setProperty("qalab.merge.output.resourcename",
100                 "empty-stats.xml");
101             properties.setProperty("qalab.merge.output.classname",
102             "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
103 
104             QALabXMLExporter exporter = new QALabXMLExporter();
105 
106             exporter.setQuiet(true);
107             exporter.setTaskLogger(new SilentLogger());
108 
109             StatMerger merger = (StatMerger) Class.forName(
110                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
111                                                   .newInstance();
112 
113             merger.setQuiet(false);
114             merger.setSrcDir("src/main/java");
115             merger.setTaskLogger(new SilentLogger());
116 
117             properties.setProperty("qalab.merge.output.timestamp",
118                     merger.getMergerTimeStamp());
119             properties.setProperty("qalab.merge.type",
120                     merger.getType());
121             exporter.configure(properties);
122 
123             merger.mergeStats(new InputSource(
124                     CoberturaLineStatMergeTest.class.getResourceAsStream(
125                         "good-checkstyle.xml")), exporter);
126 
127             checkSummary(exporter.getDocument(), 1, 168, 25);
128             checkFileCount(exporter.getDocument(), 6, 168);
129         }
130         catch (IllegalAccessException e) {
131             fail(e.toString());
132         }
133         catch (ClassNotFoundException e) {
134             fail(e.toString());
135         }
136         catch (InstantiationException e) {
137             fail(e.toString());
138         }
139     }
140 
141     *//**
142      * test simple merge from empty
143      *//*
144     public void testMergeNonExistingQALab() {
145         try {
146             final String fileName = "new-stats.xml";
147             File file = new File(fileName);
148 
149             if (file.exists()) {
150                 file.delete();
151             }
152 
153             Properties properties = new Properties();
154 
155             properties.setProperty("qalab.merge.output.file", fileName);
156 
157             QALabXMLExporter exporter = new QALabXMLExporter();
158 
159             exporter.setQuiet(true);
160             exporter.setTaskLogger(new SilentLogger());
161 
162             StatMerger merger = (StatMerger) Class.forName(
163                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
164                                                   .newInstance();
165 
166             merger.setQuiet(false);
167             merger.setSrcDir("src/main/java");
168             merger.setTaskLogger(new SilentLogger());
169 
170             properties.setProperty("qalab.merge.output.timestamp",
171                     merger.getMergerTimeStamp());
172             properties.setProperty("qalab.merge.type",
173                     merger.getType());
174             exporter.configure(properties);
175 
176             merger.mergeStats(new InputSource(
177                     CoberturaLineStatMergeTest.class.getResourceAsStream(
178                         "good-checkstyle.xml")), exporter);
179 
180             System.out.println(streamToString(exporter.getDocument()));
181             checkDTDPresent(exporter.getDocument());
182             checkSummary(exporter.getDocument(), 1, 168, 25);
183             checkFileCount(exporter.getDocument(), 6, 168);
184 
185             exporter.save();
186 
187             if (file.exists()) {
188                 file.delete();
189             }
190         }
191         catch (IllegalAccessException e) {
192             fail(e.toString());
193         }
194         catch (ClassNotFoundException e) {
195             fail(e.toString());
196         }
197         catch (InstantiationException e) {
198             fail(e.toString());
199         }
200         catch (IOException e) {
201             fail(e.toString());
202         }
203     }
204 
205     *//**
206      * test simple merge with empty checkstyle and empty qalab.
207      *//*
208     public void testMergeEmptyCheckstyleAndQALab() {
209         try {
210             Properties properties = new Properties();
211 
212             properties.setProperty("qalab.merge.output.resourcename",
213                 "empty-stats.xml");
214             properties.setProperty("qalab.merge.output.classname",
215                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
216 
217             QALabXMLExporter exporter = new QALabXMLExporter();
218 
219             exporter.setQuiet(true);
220             exporter.setTaskLogger(new SilentLogger());
221 
222             StatMerger merger = (StatMerger) Class.forName(
223                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
224                                                   .newInstance();
225 
226             merger.setQuiet(false);
227             merger.setSrcDir("src/main/java");
228             merger.setTaskLogger(new SilentLogger());
229 
230             properties.setProperty("qalab.merge.output.timestamp",
231                     merger.getMergerTimeStamp());
232             properties.setProperty("qalab.merge.type",
233                     merger.getType());
234             exporter.configure(properties);
235 
236             merger.mergeStats(new InputSource(
237                     CoberturaLineStatMergeTest.class.getResourceAsStream(
238                         "checkstyle-noviolations.xml")), exporter);
239 
240             checkDTDPresent(exporter.getDocument());
241             checkSummary(exporter.getDocument(), 0, 0, 0);
242             checkFileCount(exporter.getDocument(), 0, 0);
243         }
244         catch (IllegalAccessException e) {
245             fail(e.toString());
246         }
247         catch (ClassNotFoundException e) {
248             fail(e.toString());
249         }
250         catch (InstantiationException e) {
251             fail(e.toString());
252         }
253     }
254 
255     *//**
256      * test simple merge with one checkstyle violation and empty qalab.
257      *//*
258     public void testMergeSingleCheckstyleViolationAndEmptyQALab() {
259         try {
260             Properties properties = new Properties();
261 
262             properties.setProperty("qalab.merge.output.resourcename",
263                 "empty-stats.xml");
264             properties.setProperty("qalab.merge.output.classname",
265                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
266 
267             QALabXMLExporter exporter = new QALabXMLExporter();
268 
269             exporter.setQuiet(true);
270             exporter.setTaskLogger(new SilentLogger());
271 
272             StatMerger merger = (StatMerger) Class.forName(
273                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
274                                                   .newInstance();
275 
276             merger.setQuiet(false);
277             merger.setSrcDir("src/main/java");
278             merger.setTaskLogger(new SilentLogger());
279 
280             properties.setProperty("qalab.merge.output.timestamp",
281                     merger.getMergerTimeStamp());
282             properties.setProperty("qalab.merge.type",
283                     merger.getType());
284             exporter.configure(properties);
285 
286             merger.mergeStats(new InputSource(
287                     CoberturaLineStatMergeTest.class.getResourceAsStream(
288                         "checkstyle-one-violation.xml")), exporter);
289 
290             checkDTDPresent(exporter.getDocument());
291             checkSummary(exporter.getDocument(), 1, 1, 25);
292             checkFileCount(exporter.getDocument(), 1, 1);
293         }
294         catch (IllegalAccessException e) {
295             fail(e.toString());
296         }
297         catch (ClassNotFoundException e) {
298             fail(e.toString());
299         }
300         catch (InstantiationException e) {
301             fail(e.toString());
302         }
303     }
304 
305     *//**
306      * test simple merge with empty checkstyle and NON-empty qalab.
307      *//*
308     public void testMergeEmptyCheckstyleAndNonEmptyQALab() {
309         try {
310             Properties properties = new Properties();
311 
312             properties.setProperty("qalab.merge.output.resourcename",
313                 "one-set-checkstyle-stats.xml");
314             properties.setProperty("qalab.merge.output.classname",
315                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
316 
317             QALabXMLExporter exporter = new QALabXMLExporter();
318 
319             exporter.setQuiet(true);
320             exporter.setTaskLogger(new SilentLogger());
321 
322             StatMerger merger = (StatMerger) Class.forName(
323                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
324                                                   .newInstance();
325 
326             merger.setQuiet(false);
327             merger.setSrcDir("src/main/java");
328             merger.setTaskLogger(new SilentLogger());
329 
330             properties.setProperty("qalab.merge.output.timestamp",
331                     merger.getMergerTimeStamp());
332             properties.setProperty("qalab.merge.type",
333                     merger.getType());
334             exporter.configure(properties);
335 
336             merger.mergeStats(new InputSource(
337                     CoberturaLineStatMergeTest.class.getResourceAsStream(
338                         "checkstyle-noviolations.xml")), exporter);
339 
340             checkDTDPresent(exporter.getDocument());
341             checkSummary(exporter.getDocument(), 1, new int[] { 168 },
342                 new int[] { 25 },
343                 new String[] { "checkstyle" });
344             checkFileCount(exporter.getDocument(), 6, 168);
345         }
346         catch (IllegalAccessException e) {
347             fail(e.toString());
348         }
349         catch (ClassNotFoundException e) {
350             fail(e.toString());
351         }
352         catch (InstantiationException e) {
353             fail(e.toString());
354         }
355     }
356 
357     *//**
358      * test simple merge with 1 set checkstyle
359      *//*
360     public void testMergeOneSetCheckstyle() {
361         try {
362             Properties properties = new Properties();
363 
364             properties.setProperty("qalab.merge.output.resourcename",
365                 "one-set-checkstyle-stats.xml");
366             properties.setProperty("qalab.merge.output.classname",
367                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
368 
369             QALabXMLExporter exporter = new QALabXMLExporter();
370 
371             exporter.setQuiet(false);
372             exporter.setTaskLogger(new ConsoleLogger());
373 
374             StatMerger merger = (StatMerger) Class.forName(
375                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
376                                                   .newInstance();
377 
378             merger.setQuiet(false);
379             merger.setSrcDir("src/main/java");
380             merger.setTaskLogger(new SilentLogger());
381 
382             properties.setProperty("qalab.merge.output.timestamp",
383                     merger.getMergerTimeStamp());
384             properties.setProperty("qalab.merge.type",
385                     merger.getType());
386             exporter.configure(properties);
387 
388             merger.mergeStats(new InputSource(
389                     CoberturaLineStatMergeTest.class.getResourceAsStream(
390                         "good-checkstyle.xml")), exporter);
391 
392             System.out.println(streamToString(exporter.getDocument()));
393 
394             checkDTDPresent(exporter.getDocument());
395             checkSummary(exporter.getDocument(), 2, new int[] { 168, 168 },
396                 new int[] { 25, 25 },
397                 new String[] { "checkstyle", "checkstyle" });
398             checkFileCount(exporter.getDocument(), 6, 336);
399         }
400         catch (IllegalAccessException e) {
401             fail(e.toString());
402         }
403         catch (ClassNotFoundException e) {
404             fail(e.toString());
405         }
406         catch (InstantiationException e) {
407             fail(e.toString());
408         }
409         catch (IOException e) {
410             fail(e.toString());
411         }
412     }
413 
414     *//**
415      * test simple merge with 1 set checkstyle with replace!
416      *//*
417     public void testMergeOneSetCheckstyleWithReplace() {
418         try {
419             Properties properties = new Properties();
420 
421             properties.setProperty("qalab.merge.output.resourcename",
422                 "one-set-checkstyle-stats.xml");
423             properties.setProperty("qalab.merge.output.classname",
424                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
425             properties.setProperty("qalab.merge.action","replace");
426             properties.setProperty("qalab.merge.timestampdateonly","true");
427 
428             QALabXMLExporter exporter = new QALabXMLExporter();
429 
430             exporter.setQuiet(false);
431             exporter.setTaskLogger(new ConsoleLogger());
432 
433             StatMerger merger = (StatMerger) Class.forName(
434                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
435                                                   .newInstance();
436 
437             merger.setQuiet(false);
438             merger.setSrcDir("src/main/java");
439             merger.setTaskLogger(new SilentLogger());
440             
441             // by chosing this date and having replace, we will replace
442             // the value in the summary! 
443             merger.setMergerTimeStamp("2004-06-09 00:00:00",true);
444 
445             properties.setProperty("qalab.merge.output.timestamp",
446                     merger.getMergerTimeStamp());
447             properties.setProperty("qalab.merge.type",
448                     merger.getType());
449             exporter.configure(properties);
450 
451             merger.mergeStats(new InputSource(
452                     CoberturaLineStatMergeTest.class.getResourceAsStream(
453                         "good-checkstyle-forreplace.xml")), exporter);
454 
455             System.out.println(streamToString(exporter.getDocument()));
456 
457             checkDTDPresent(exporter.getDocument());
458             checkSummary(exporter.getDocument(), 1, new int[] { 166 },
459                 new int[] { 24 },
460                 new String[] { "checkstyle" });
461             checkFileCount(exporter.getDocument(), 6, 166);
462         }
463         catch (IllegalAccessException e) {
464             fail(e.toString());
465         }
466         catch (ClassNotFoundException e) {
467             fail(e.toString());
468         }
469         catch (InstantiationException e) {
470             fail(e.toString());
471         }
472         catch (IOException e) {
473             fail(e.toString());
474         }
475     }
476 
477     *//**
478      * test simple merge with 1 set checkstyle giving a timestamp.
479      *//*
480     public void testMergeOneSetCheckstyleWithTimestamp() {
481         try {
482             Properties properties = new Properties();
483 
484             properties.setProperty("qalab.merge.output.resourcename",
485                 "one-set-checkstyle-stats.xml");
486             properties.setProperty("qalab.merge.output.classname",
487                 "net.objectlab.qalab.parser.CheckstyleStatMergeTest");
488 
489             QALabXMLExporter exporter = new QALabXMLExporter();
490 
491             exporter.setQuiet(true);
492             exporter.setTaskLogger(new SilentLogger());
493 
494             StatMerger merger = (StatMerger) Class.forName(
495                     "net.objectlab.qalab.parser.CheckstyleStatMerge")
496                                                   .newInstance();
497 
498             merger.setQuiet(false);
499             merger.setSrcDir("src/main/java");
500             merger.setTaskLogger(new SilentLogger());
501             try {
502                 merger.setMergerTimeStamp("incorrect stuff", true);
503                 fail("Incorrect time stamp was given");
504             } catch(IllegalArgumentException e) {
505                 assertNotNull(e);
506             }
507             
508             merger.setMergerTimeStamp("2005-07-08 15:45:30", false);
509 
510             properties.setProperty("qalab.merge.output.timestamp",
511                     merger.getMergerTimeStamp());
512             properties.setProperty("qalab.merge.type",
513                     merger.getType());
514             exporter.configure(properties);
515 
516             merger.mergeStats(new InputSource(
517                     CoberturaLineStatMergeTest.class.getResourceAsStream(
518                         "good-checkstyle.xml")), exporter);
519 
520             checkDTDPresent(exporter.getDocument());
521             checkSummary(exporter.getDocument(), 2, new int[] { 168, 168 },
522                 new int[] { 25, 25 },
523                 new String[] { "checkstyle", "checkstyle" });
524             checkFileCount(exporter.getDocument(), 6, 336);
525         }
526         catch (IllegalAccessException e) {
527             fail(e.toString());
528         }
529         catch (ClassNotFoundException e) {
530             fail(e.toString());
531         }
532         catch (InstantiationException e) {
533             fail(e.toString());
534         }
535     }
536 */}
537 /*
538  *                   ObjectLab is sponsoring QALab
539  * 
540  * Based in London, we are world leaders in the design and development 
541  * of bespoke applications for the securities financing markets.
542  * 
543  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
544  *           ___  _     _           _   _          _
545  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
546  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
547  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
548  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
549  *                   |__/
550  *
551  *                     www.ObjectLab.co.uk
552  */