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  
44  import net.objectlab.qalab.AbstractTestCase;
45  import net.objectlab.qalab.util.SilentLogger;
46  
47  import org.apache.xerces.parsers.DOMParser;
48  import org.w3c.dom.Document;
49  import org.w3c.dom.Element;
50  import org.w3c.dom.NamedNodeMap;
51  import org.w3c.dom.Node;
52  import org.w3c.dom.NodeList;
53  import org.w3c.dom.Text;
54  import org.xml.sax.InputSource;
55  import org.xml.sax.SAXException;
56  
57  import javax.xml.parsers.ParserConfigurationException;
58  
59  import java.io.File;
60  import java.io.FileReader;
61  import java.io.IOException;
62  import java.io.StringReader;
63  import java.io.StringWriter;
64  import java.io.Writer;
65  
66  import java.util.Calendar;
67  
68  public class BuildStatMoverHandlerTest extends AbstractTestCase {
69      /**
70       * Create the test case
71       * 
72       * @param testName
73       *            name of the test case
74       */
75      public BuildStatMoverHandlerTest(String testName) {
76          super(testName);
77      }
78  
79      /**
80       * @return the suite of tests being tested
81       */
82      public static Test suite() {
83          return new TestSuite(BuildStatMoverHandlerTest.class);
84      }
85  
86      public void testCheckstyleMovers() {
87          File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastats.xml");
88  
89          Writer testOutput = new StringWriter();
90  
91          try {
92              final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(testInput)),
93                      "checkstyle", testOutput, false, new SilentLogger(), false);
94  
95              Calendar cal = Calendar.getInstance();
96  
97              cal.set(2004, 01, 11, 0, 0, 0);
98              handler.setStartTimeWindow(cal.getTime());
99              cal.set(2004, 01, 14, 0, 0, 0);
100             handler.setEndTimeWindow(cal.getTime());
101             handler.process();
102 
103             System.out.println(testOutput.toString());
104 
105             // now parse it
106             DOMParser dom = new DOMParser();
107 
108             dom.parse(new InputSource(new StringReader(testOutput.toString())));
109 
110             Document doc = dom.getDocument();
111 
112             checkTagValue(doc, "datethreshold", "2004-02-11 00:00:00", 1);
113             checkTagValue(doc, "enddatethreshold", "2004-02-14 00:00:00", 1);
114             checkTagValue(doc, "types", "checkstyle", 1);
115 
116             // check presence of some file in the up list
117             NodeList listUp = doc.getElementsByTagName("up");
118 
119             assertEquals("size for up", 1, listUp.getLength());
120             assertEquals("number of files in up list", 5, countFileTags(listUp));
121             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listUp,
122                     toId("net/objectlab/test/MoveUpAndDown.java")));
123             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listUp,
124                     toId("net/objectlab/test/MoveUpAndUp.java")));
125             assertNotNull("List UP presence of net/objectlab/test/MoveUp.java", checkFilePresent(listUp,
126                     toId("net/objectlab/test/MoveUp.java")));
127             assertNotNull("List UP presence of net/objectlab/test/NewUp.java", checkFilePresent(listUp,
128                     toId("net/objectlab/test/NewUp.java")));
129             assertNull("List UP presence of net/objectlab/test/MoveDown.java", checkFilePresent(listUp,
130                     toId("net/objectlab/test/MoveDown.java")));
131             assertNull("List UP presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listUp,
132                     toId("net/objectlab/test/MoveDownAndDown.java")));
133             assertNull("List UP presence of net/objectlab/test/NoMove.java", checkFilePresent(listUp,
134                     toId("net/objectlab/test/NoMove.java")));
135             assertNull("List UP presence of BLA.java", checkFilePresent(listUp, "BLA.java"));
136             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listUp,
137                     toId("net/objectlab/test/MoveUpAndDownToZero.java")));
138 
139             // check presence of some file in the down list
140             NodeList listDown = doc.getElementsByTagName("down");
141 
142             assertEquals("size for down", 1, listDown.getLength());
143             assertEquals("number of files in down list", 5, countFileTags(listDown));
144             assertNotNull("List Down presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listDown,
145                     toId("net/objectlab/test/MoveUpAndDownToZero.java")));
146             checkDiff(listDown, "net/objectlab/test/MoveUpAndDownToZero.java", 1, // number
147                     // of
148                     // diff
149                     new String[] { "2004-02-11 22:00:06" }, // previousrun
150                     new String[] { "-" }, // currentrun
151                     new String[] { "checkstyle" }, // type
152                     new int[] { 2 }, // previous errors
153                     new int[] { 0 }, // current errors
154                     new int[] { -2 }); // diff
155 
156             assertNotNull("List Down presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listDown,
157                     toId("net/objectlab/test/MoveUpAndDown.java")));
158             checkDiff(listDown, "net/objectlab/test/MoveUpAndDown.java", 1, // number
159                     // of
160                     // diff
161                     new String[] { "2004-02-12 22:00:06" }, // previousrun
162                     new String[] { "2004-02-13 22:00:06" }, // currentrun
163                     new String[] { "checkstyle" }, // type
164                     new int[] { 3 }, // previous errors
165                     new int[] { 1 }, // current errors
166                     new int[] { -2 }); // diff
167 
168             assertNotNull("List Down presence of net/objectlab/test/MoveDownToZero.java", checkFilePresent(listDown,
169                     toId("net/objectlab/test/MoveDownToZero.java")));
170             checkDiff(listDown, "net/objectlab/test/MoveDownToZero.java", 1, // number
171                     // of
172                     // diff
173                     new String[] { "2004-02-11 22:00:06" }, // previousrun
174                     new String[] { "-" }, // currentrun
175                     new String[] { "checkstyle" }, // type
176                     new int[] { 2 }, // previous errors
177                     new int[] { 0 }, // current errors
178                     new int[] { -2 }); // diff
179 
180             assertNotNull("List Down presence of net/objectlab/test/MoveDown.java", checkFilePresent(listDown,
181                     toId("net/objectlab/test/MoveDown.java")));
182             checkDiff(listDown, "net/objectlab/test/MoveDown.java", 1, // number
183                     // of
184                     // diff
185                     new String[] { "2004-02-10 22:00:06" }, // previousrun
186                     // new String[] { "-" }, // previousrun
187                     new String[] { "2004-02-12 22:00:06" }, // currentrun
188                     new String[] { "checkstyle" }, // type
189                     new int[] { 2 }, // previous errors
190                     // new int[] { 0 }, // previous errors
191                     new int[] { 1 }, // current errors
192                     new int[] { -1 }); // diff
193 
194             assertNotNull("List Down presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listDown,
195                     toId("net/objectlab/test/MoveDownAndDown.java")));
196             checkDiff(listDown, "net/objectlab/test/MoveDownAndDown.java", 2, // number
197                     // of
198                     // diff
199                     new String[] { "2004-02-12 22:00:06", "2004-02-10 22:00:06" }, // previousrun
200                     new String[] { "2004-02-13 22:00:06", "2004-02-12 22:00:06" }, // currentrun
201                     new String[] { "checkstyle", "checkstyle" }, // type
202                     new int[] { 3, 4 }, // previous errors
203                     new int[] { 2, 3 }, // current errors
204                     new int[] { -1, -1 }); // diff
205 
206             assertNull("List Down presence of net/objectlab/test/MoveUp.java", checkFilePresent(listDown,
207                     toId("net/objectlab/test/MoveUp.java")));
208             assertNull("List Down presence of net/objectlab/test/NewUp.java", checkFilePresent(listDown,
209                     toId("net/objectlab/test/NewUp.java")));
210             assertNull("List Down presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listDown,
211                     toId("net/objectlab/test/MoveUpAndUp.java")));
212             assertNull("List Down presence of net/objectlab/test/NoMove.java", checkFilePresent(listDown,
213                     toId("net/objectlab/test/NoMove.java")));
214             assertNull("List Down presence of BLA.java", checkFilePresent(listDown, "BLA.java"));
215         } catch (ParserConfigurationException e) {
216             fail(e.toString());
217         } catch (SAXException e) {
218             fail(e.toString());
219         } catch (IOException e) {
220             fail(e.toString());
221         }
222     }
223 
224     private String toId(String string) {
225         return string.replace('/', '_');
226     }
227 
228     public void testPMDMovers() {
229         File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastats.xml");
230 
231         Writer testOutput = new StringWriter();
232 
233         try {
234             final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(testInput)), "pmd",
235                     testOutput, false, new SilentLogger(), false);
236 
237             Calendar cal = Calendar.getInstance();
238 
239             cal.set(2004, 01, 11, 0, 0, 0);
240             handler.setStartTimeWindow(cal.getTime());
241             cal.set(2004, 01, 14, 0, 0, 0);
242             handler.setEndTimeWindow(cal.getTime());
243             handler.process();
244 
245             System.out.println(testOutput.toString());
246 
247             // now parse it
248             DOMParser dom = new DOMParser();
249 
250             dom.parse(new InputSource(new StringReader(testOutput.toString())));
251 
252             Document doc = dom.getDocument();
253 
254             checkTagValue(doc, "datethreshold", "2004-02-11 00:00:00", 1);
255             checkTagValue(doc, "enddatethreshold", "2004-02-14 00:00:00", 1);
256             checkTagValue(doc, "types", "pmd", 1);
257 
258             // check presence of some file in the up list
259             NodeList listUp = doc.getElementsByTagName("up");
260 
261             assertEquals("size for up", 1, listUp.getLength());
262             assertEquals("number of files in up list", 2, countFileTags(listUp));
263             assertNotNull("List UP presence of net/objectlab/test/MoveUp.java", checkFilePresent(listUp,
264                     toId("net/objectlab/test/MoveUp.java")));
265             assertNull("List UP presence of net/objectlab/test/NoMovePMD.java", checkFilePresent(listUp,
266                     toId("net/objectlab/test/NoMovePMD.java")));
267             checkDiff(listUp, "net/objectlab/test/MoveUp.java", 2, // number of
268                     // diff
269                     new String[] { "2004-02-12 22:00:06", "-" }, // previousrun
270                     new String[] { "2004-02-13 22:00:06", "2004-02-12 22:00:06" }, // currentrun
271                     new String[] { "pmd", "pmd" }, // type
272                     new int[] { 1, 0 }, // previous errors
273                     new int[] { 2, 1 }, // current errors
274                     new int[] { 1, 1 }); // diff
275 
276             assertNotNull("List UP presence of net/objectlab/test/NewUp.java", checkFilePresent(listUp,
277                     toId("net/objectlab/test/NewUp.java")));
278             checkDiff(listUp, "net/objectlab/test/NewUp.java", 1, // number of
279                     // diff
280                     new String[] { "-" }, // previousrun
281                     new String[] { "2004-02-13 22:00:06" }, // currentrun
282                     new String[] { "pmd" }, // type
283                     new int[] { 0 }, // previous errors
284                     new int[] { 1 }, // current errors
285                     new int[] { 1 }); // diff
286 
287             assertNull("List UP presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listUp,
288                     toId("net/objectlab/test/MoveUpAndDownToZero.java")));
289             assertNull("List UP presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listUp,
290                     toId("net/objectlab/test/MoveUpAndDown.java")));
291             assertNull("List UP presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listUp,
292                     toId("net/objectlab/test/MoveUpAndUp.java")));
293             assertNull("List UP presence of net/objectlab/test/MoveDown.java", checkFilePresent(listUp,
294                     toId("net/objectlab/test/MoveDown.java")));
295             assertNull("List UP presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listUp,
296                     toId("net/objectlab/test/MoveDownAndDown.java")));
297             assertNull("List UP presence of net/objectlab/test/NoMove.java", checkFilePresent(listUp,
298                     toId("net/objectlab/test/NoMove.java")));
299             assertNull("List UP presence of net/objectlab/test/NoMovePMD.java", checkFilePresent(listUp,
300                     toId("net/objectlab/test/NoMovePMD.java")));
301             assertNull("List UP presence of BLA.java", checkFilePresent(listUp, "BLA.java"));
302 
303             // check presence of some file in the down list
304             NodeList listDown = doc.getElementsByTagName("down");
305 
306             assertEquals("size for down", 1, listDown.getLength());
307             assertEquals("number of files in down list", 1, countFileTags(listDown));
308             assertNotNull("List Down presence of net/objectlab/test/MoveDownPMD.java", checkFilePresent(listDown,
309                     toId("net/objectlab/test/MoveDownPMD.java")));
310             checkDiff(listDown, "net/objectlab/test/MoveDownPMD.java", 1, // number
311                     // of
312                     // diff
313                     new String[] { "2004-02-10 22:00:06" }, // previousrun
314                     new String[] { "2004-02-12 22:00:06" }, // currentrun
315                     new String[] { "pmd" }, // type
316                     new int[] { 2 }, // previous errors
317                     new int[] { 1 }, // current errors
318                     new int[] { -1 }); // diff
319 
320             assertNull("List Down presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listDown,
321                     "net/objectlab/test/MoveUpAndDownToZero.java"));
322             assertNull("List Down presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listDown,
323                     "net/objectlab/test/MoveUpAndDown.java"));
324             assertNull("List Down presence of net/objectlab/test/MoveDownToZero.java", checkFilePresent(listDown,
325                     "net/objectlab/test/MoveDownToZero.java"));
326             assertNull("List Down presence of net/objectlab/test/MoveDown.java", checkFilePresent(listDown,
327                     "net/objectlab/test/MoveDown.java"));
328             assertNull("List Down presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listDown,
329                     "net/objectlab/test/MoveDownAndDown.java"));
330             assertNull("List Down presence of net/objectlab/test/MoveUp.java", checkFilePresent(listDown,
331                     "net/objectlab/test/MoveUp.java"));
332             assertNull("List Down presence of net/objectlab/test/NewUp.java", checkFilePresent(listDown,
333                     "net/objectlab/test/NewUp.java"));
334             assertNull("List Down presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listDown,
335                     "net/objectlab/test/MoveUpAndUp.java"));
336             assertNull("List Down presence of net/objectlab/test/NoMove.java", checkFilePresent(listDown,
337                     "net/objectlab/test/NoMove.java"));
338             assertNull("List Down presence of net/objectlab/test/NoMovePMD.java", checkFilePresent(listDown,
339                     "net/objectlab/test/NoMovePMD.java"));
340             assertNull("List Down presence of BLA.java", checkFilePresent(listDown, "BLA.java"));
341         } catch (ParserConfigurationException e) {
342             fail(e.toString());
343         } catch (SAXException e) {
344             fail(e.toString());
345         } catch (IOException e) {
346             fail(e.toString());
347         }
348     }
349 
350     public void testUnknownTypeMovers() {
351         File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastats.xml");
352 
353         Writer testOutput = new StringWriter();
354 
355         try {
356             final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(testInput)), "bla",
357                     testOutput, false, new SilentLogger(), false);
358 
359             Calendar cal = Calendar.getInstance();
360 
361             cal.set(2004, 01, 11, 0, 0, 0);
362             handler.setStartTimeWindow(cal.getTime());
363             cal.set(2004, 01, 14, 0, 0, 0);
364             handler.setEndTimeWindow(cal.getTime());
365             handler.process();
366 
367             System.out.println(testOutput.toString());
368 
369             // now parse it
370             DOMParser dom = new DOMParser();
371 
372             dom.parse(new InputSource(new StringReader(testOutput.toString())));
373 
374             Document doc = dom.getDocument();
375 
376             checkTagValue(doc, "datethreshold", "2004-02-11 00:00:00", 1);
377             checkTagValue(doc, "enddatethreshold", "2004-02-14 00:00:00", 1);
378             checkTagValue(doc, "types", "bla", 1);
379 
380             // check presence of some file in the up list
381             NodeList listUp = doc.getElementsByTagName("up");
382 
383             assertEquals("size for up", 1, listUp.getLength());
384             assertEquals("number of files in up list", 0, countFileTags(listUp));
385             assertNull("List UP presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listUp,
386                     "net/objectlab/test/MoveUpAndDownToZero.java"));
387             assertNull("List UP presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listUp,
388                     "net/objectlab/test/MoveUpAndDown.java"));
389             assertNull("List UP presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listUp,
390                     "net/objectlab/test/MoveUpAndUp.java"));
391             assertNull("List UP presence of net/objectlab/test/MoveUp.java", checkFilePresent(listUp,
392                     "net/objectlab/test/MoveUp.java"));
393             assertNull("List UP presence of net/objectlab/test/NewUp.java", checkFilePresent(listUp,
394                     "net/objectlab/test/NewUp.java"));
395             assertNull("List UP presence of net/objectlab/test/MoveDown.java", checkFilePresent(listUp,
396                     "net/objectlab/test/MoveDown.java"));
397             assertNull("List UP presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listUp,
398                     "net/objectlab/test/MoveDownAndDown.java"));
399             assertNull("List UP presence of net/objectlab/test/NoMove.java", checkFilePresent(listUp,
400                     "net/objectlab/test/NoMove.java"));
401             assertNull("List UP presence of BLA.java", checkFilePresent(listUp, "BLA.java"));
402 
403             // check presence of some file in the down list
404             NodeList listDown = doc.getElementsByTagName("down");
405 
406             assertEquals("size for down", 1, listDown.getLength());
407             assertEquals("number of files in down list", 0, countFileTags(listDown));
408             assertNull("List Down presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listDown,
409                     "net/objectlab/test/MoveUpAndDownToZero.java"));
410             assertNull("List Down presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listDown,
411                     "net/objectlab/test/MoveUpAndDown.java"));
412             assertNull("List Down presence of net/objectlab/test/MoveDownToZero.java", checkFilePresent(listDown,
413                     "net/objectlab/test/MoveDownToZero.java"));
414             assertNull("List Down presence of net/objectlab/test/MoveDown.java", checkFilePresent(listDown,
415                     "net/objectlab/test/MoveDown.java"));
416             assertNull("List Down presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listDown,
417                     "net/objectlab/test/MoveDownAndDown.java"));
418             assertNull("List Down presence of net/objectlab/test/MoveUp.java", checkFilePresent(listDown,
419                     "net/objectlab/test/MoveUp.java"));
420             assertNull("List Down presence of net/objectlab/test/NewUp.java", checkFilePresent(listDown,
421                     "net/objectlab/test/NewUp.java"));
422             assertNull("List Down presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listDown,
423                     "net/objectlab/test/MoveUpAndUp.java"));
424             assertNull("List Down presence of net/objectlab/test/NoMove.java", checkFilePresent(listDown,
425                     "net/objectlab/test/NoMove.java"));
426             assertNull("List Down presence of BLA.java", checkFilePresent(listDown, "BLA.java"));
427         } catch (ParserConfigurationException e) {
428             fail(e.toString());
429         } catch (SAXException e) {
430             fail(e.toString());
431         } catch (IOException e) {
432             fail(e.toString());
433         }
434     }
435 
436     /**
437      * Movers for both Checkstyle and PMD in the same report.
438      */
439     public void testCheckstyleAndPMDMovers() {
440         File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastats.xml");
441 
442         Writer testOutput = new StringWriter();
443 
444         try {
445             final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(testInput)),
446                     "checkstyle,pmd", testOutput, false, new SilentLogger(), false);
447 
448             Calendar cal = Calendar.getInstance();
449 
450             cal.set(2004, 01, 11, 0, 0, 0);
451             handler.setStartTimeWindow(cal.getTime());
452             cal.set(2004, 01, 14, 0, 0, 0);
453             handler.setEndTimeWindow(cal.getTime());
454             handler.process();
455 
456             System.out.println(testOutput.toString());
457 
458             // now parse it
459             DOMParser dom = new DOMParser();
460 
461             dom.parse(new InputSource(new StringReader(testOutput.toString())));
462 
463             Document doc = dom.getDocument();
464 
465             checkTagValue(doc, "datethreshold", "2004-02-11 00:00:00", 1);
466             checkTagValue(doc, "enddatethreshold", "2004-02-14 00:00:00", 1);
467             checkTagValue(doc, "types", "checkstyle,pmd", 1);
468 
469             // check presence of some file in the up list
470             NodeList listUp = doc.getElementsByTagName("up");
471 
472             assertEquals("size for up", 1, listUp.getLength());
473             assertEquals("number of files in up list", 5, countFileTags(listUp));
474             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listUp,
475                     "net/objectlab/test/MoveUpAndDownToZero.java"));
476             checkDiff(listUp, "net/objectlab/test/MoveUpAndDownToZero.java", 1, // number
477                     // of
478                     // diff
479                     new String[] { "-" }, // previousrun
480                     new String[] { "2004-02-11 22:00:06" }, // currentrun
481                     new String[] { "checkstyle" }, // type
482                     new int[] { 0 }, // previous errors
483                     new int[] { 2 }, // current errors
484                     new int[] { 2 }); // diff
485 
486             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listUp,
487                     "net/objectlab/test/MoveUpAndDown.java"));
488             checkDiff(listUp, "net/objectlab/test/MoveUpAndDown.java", 2, // number
489                     // of
490                     // diff
491                     new String[] { "2004-02-11 22:00:06", "-" }, // previousrun
492                     new String[] { "2004-02-12 22:00:06", "2004-02-11 22:00:06" }, // currentrun
493                     new String[] { "checkstyle", "checkstyle" }, // type
494                     new int[] { 2, 0 }, // previous errors
495                     new int[] { 3, 2 }, // current errors
496                     new int[] { 1, 2 }); // diff
497 
498             assertNotNull("List UP presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listUp,
499                     "net/objectlab/test/MoveUpAndUp.java"));
500             checkDiff(listUp, "net/objectlab/test/MoveUpAndUp.java", 3, // number
501                     // of
502                     // diff
503                     new String[] { "2004-02-12 22:00:06", "2004-02-11 22:00:06", "-" }, // previousrun
504                     new String[] { "2004-02-13 22:00:06", "2004-02-12 22:00:06", "2004-02-11 22:00:06" }, // currentrun
505                     new String[] { "checkstyle", "checkstyle", "checkstyle" }, // type
506                     new int[] { 3, 2, 0 }, // previous errors
507                     new int[] { 4, 3, 2 }, // current errors
508                     new int[] { 1, 1, 2 }); // diff
509 
510             checkDiff(listUp, "net/objectlab/test/MoveUp.java", 4, // number of
511                     // diff
512                     new String[] { "2004-02-12 22:00:06", "-", "2004-02-11 22:00:06", "-" }, // previousrun
513                     new String[] { "2004-02-13 22:00:06", "2004-02-12 22:00:06", "2004-02-12 22:00:06", "2004-02-11 22:00:06" }, // currentrun
514                     new String[] { "pmd", "pmd", "checkstyle", "checkstyle" }, // type
515                     new int[] { 1, 0, 2, 0 }, // previous errors
516                     new int[] { 2, 1, 3, 2 }, // current errors
517                     new int[] { 1, 1, 1, 2 }); // diff
518 
519             assertNotNull("List UP presence of net/objectlab/test/NewUp.java", checkFilePresent(listUp,
520                     "net/objectlab/test/NewUp.java"));
521             checkDiff(listUp, "net/objectlab/test/NewUp.java", 2, // number of
522                     // diff
523                     new String[] { "-", "-" }, // previousrun
524                     new String[] { "2004-02-13 22:00:06", "2004-02-13 22:00:06" }, // currentrun
525                     new String[] { "checkstyle", "pmd" }, // type
526                     new int[] { 0, 0 }, // previous errors
527                     new int[] { 3, 1 }, // current errors
528                     new int[] { 3, 1 }); // diff
529 
530             assertNull("List UP presence of net/objectlab/test/MoveDown.java", checkFilePresent(listUp,
531                     "net/objectlab/test/MoveDown.java"));
532             assertNull("List UP presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listUp,
533                     "net/objectlab/test/MoveDownAndDown.java"));
534             assertNull("List UP presence of net/objectlab/test/NoMove.java", checkFilePresent(listUp,
535                     "net/objectlab/test/NoMove.java"));
536             assertNull("List UP presence of BLA.java", checkFilePresent(listUp, "BLA.java"));
537 
538             // check presence of some file in the down list
539             NodeList listDown = doc.getElementsByTagName("down");
540 
541             assertEquals("size for down", 1, listDown.getLength());
542             assertEquals("number of files in down list", 6, countFileTags(listDown));
543             assertNotNull("List Down presence of net/objectlab/test/MoveDownPMD.java", checkFilePresent(listDown,
544                     "net/objectlab/test/MoveDownPMD.java"));
545             checkDiff(listDown, "net/objectlab/test/MoveDownPMD.java", 1, // number
546                     // of
547                     // diff
548                     new String[] { "2004-02-10 22:00:06" }, // previousrun
549                     new String[] { "2004-02-12 22:00:06" }, // currentrun
550                     new String[] { "pmd" }, // type
551                     new int[] { 2 }, // previous errors
552                     new int[] { 1 }, // current errors
553                     new int[] { -1 }); // diff
554 
555             assertNotNull("List Down presence of net/objectlab/test/MoveUpAndDownToZero.java", checkFilePresent(listDown,
556                     "net/objectlab/test/MoveUpAndDownToZero.java"));
557             checkDiff(listDown, "net/objectlab/test/MoveUpAndDownToZero.java", 1, // number
558                     // of
559                     // diff
560                     new String[] { "2004-02-11 22:00:06" }, // previousrun
561                     new String[] { "-" }, // currentrun
562                     new String[] { "checkstyle" }, // type
563                     new int[] { 2 }, // previous errors
564                     new int[] { 0 }, // current errors
565                     new int[] { -2 }); // diff
566 
567             assertNotNull("List Down presence of net/objectlab/test/MoveUpAndDown.java", checkFilePresent(listDown,
568                     "net/objectlab/test/MoveUpAndDown.java"));
569             checkDiff(listDown, "net/objectlab/test/MoveUpAndDown.java", 1, // number
570                     // of
571                     // diff
572                     new String[] { "2004-02-12 22:00:06" }, // previousrun
573                     new String[] { "2004-02-13 22:00:06" }, // currentrun
574                     new String[] { "checkstyle" }, // type
575                     new int[] { 3 }, // previous errors
576                     new int[] { 1 }, // current errors
577                     new int[] { -2 }); // diff
578 
579             assertNotNull("List Down presence of net/objectlab/test/MoveDownToZero.java", checkFilePresent(listDown,
580                     "net/objectlab/test/MoveDownToZero.java"));
581             checkDiff(listDown, "net/objectlab/test/MoveDownToZero.java", 1, // number
582                     // of
583                     // diff
584                     new String[] { "2004-02-11 22:00:06" }, // previousrun
585                     new String[] { "-" }, // currentrun
586                     new String[] { "checkstyle" }, // type
587                     new int[] { 2 }, // previous errors
588                     new int[] { 0 }, // current errors
589                     new int[] { -2 }); // diff
590 
591             assertNotNull("List Down presence of net/objectlab/test/MoveDown.java", checkFilePresent(listDown,
592                     "net/objectlab/test/MoveDown.java"));
593             checkDiff(listDown, "net/objectlab/test/MoveDown.java", 1, // number
594                     // of
595                     // diff
596                     new String[] { "2004-02-10 22:00:06" }, // previousrun
597                     new String[] { "2004-02-12 22:00:06" }, // currentrun
598                     new String[] { "checkstyle" }, // type
599                     new int[] { 2 }, // previous errors
600                     new int[] { 1 }, // current errors
601                     new int[] { -1 }); // diff
602 
603             assertNotNull("List Down presence of net/objectlab/test/MoveDownAndDown.java", checkFilePresent(listDown,
604                     "net/objectlab/test/MoveDownAndDown.java"));
605             checkDiff(listDown, "net/objectlab/test/MoveDownAndDown.java", 2, // number
606                     // of
607                     // diff
608                     new String[] { "2004-02-12 22:00:06", "2004-02-10 22:00:06" }, // previousrun
609                     new String[] { "2004-02-13 22:00:06", "2004-02-12 22:00:06" }, // currentrun
610                     new String[] { "checkstyle", "checkstyle" }, // type
611                     new int[] { 3, 4 }, // previous errors
612                     new int[] { 2, 3 }, // current errors
613                     new int[] { -1, -1 }); // diff
614 
615             assertNull("List Down presence of net/objectlab/test/MoveUp.java", checkFilePresent(listDown,
616                     "net/objectlab/test/MoveUp.java"));
617             assertNull("List Down presence of net/objectlab/test/NewUp.java", checkFilePresent(listDown,
618                     "net/objectlab/test/NewUp.java"));
619             assertNull("List Down presence of net/objectlab/test/MoveUpAndUp.java", checkFilePresent(listDown,
620                     "net/objectlab/test/MoveUpAndUp.java"));
621             assertNull("List Down presence of net/objectlab/test/NoMove.java", checkFilePresent(listDown,
622                     "net/objectlab/test/NoMove.java"));
623             assertNull("List Down presence of BLA.java", checkFilePresent(listDown, "BLA.java"));
624         } catch (ParserConfigurationException e) {
625             fail(e.toString());
626         } catch (SAXException e) {
627             fail(e.toString());
628         } catch (IOException e) {
629             fail(e.toString());
630         }
631     }
632 
633     /**
634      * Runa test to check the impact of weekendAdjustment.
635      */
636     public void testWeekendAdjust() {
637         File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastats.xml");
638 
639         try {
640             {
641                 Writer testOutput = new StringWriter();
642                 final BuildStatMoverHandler handlerNoWeekendAdjustment = new BuildStatMoverHandler(new InputSource(
643                         new FileReader(testInput)), "pmd", testOutput, false, new SilentLogger(), false);
644 
645                 Calendar cal = Calendar.getInstance();
646 
647                 // set a window 25-06-2005 (a Saturday) to 04-06-2005 => should
648                 // NOT find anything!
649                 cal.set(2005, 05, 25, 0, 0, 0);
650                 handlerNoWeekendAdjustment.setStartTimeWindow(cal.getTime());
651                 cal.set(2005, 06, 04, 0, 0, 0);
652                 handlerNoWeekendAdjustment.setEndTimeWindow(cal.getTime());
653                 handlerNoWeekendAdjustment.process();
654 
655                 System.out.println(testOutput.toString());
656 
657                 // now parse it
658                 DOMParser dom = new DOMParser();
659                 dom.parse(new InputSource(new StringReader(testOutput.toString())));
660 
661                 Document doc = dom.getDocument();
662 
663                 checkTagValue(doc, "datethreshold", "2005-06-25 00:00:00", 1);
664                 checkTagValue(doc, "enddatethreshold", "2005-07-04 00:00:00", 1);
665                 checkTagValue(doc, "types", "pmd", 1);
666 
667                 // check presence of some file in the up list
668                 NodeList listUp = doc.getElementsByTagName("up");
669                 assertEquals("size for up", 1, listUp.getLength());
670                 assertEquals("number of files in up list", 0, countFileTags(listUp));
671                 NodeList listDown = doc.getElementsByTagName("down");
672                 assertEquals("size for down", 1, listDown.getLength());
673                 assertEquals("number of files in down list", 0, countFileTags(listDown));
674             }
675 
676             // NOW With WeekendAdjustment
677 
678             {
679                 Writer testOutput2 = new StringWriter();
680                 final BuildStatMoverHandler handlerWeekendAdjustment = new BuildStatMoverHandler(new InputSource(new FileReader(
681                         testInput)), "pmd", testOutput2, true, new SilentLogger(), false);
682 
683                 // set a window 25-06-2005 (a Saturday) to 04-06-2005 => should
684                 // NOT find anything!
685                 Calendar cal = Calendar.getInstance();
686                 cal.set(2005, 05, 25, 0, 0, 0);
687                 handlerWeekendAdjustment.setStartTimeWindow(cal.getTime());
688                 cal.set(2005, 06, 04, 0, 0, 0);
689                 handlerWeekendAdjustment.setEndTimeWindow(cal.getTime());
690                 handlerWeekendAdjustment.process();
691 
692                 System.out.println(testOutput2.toString());
693 
694                 // now parse it
695                 DOMParser dom2 = new DOMParser();
696                 dom2.parse(new InputSource(new StringReader(testOutput2.toString())));
697 
698                 Document doc2 = dom2.getDocument();
699 
700                 checkTagValue(doc2, "datethreshold", "2005-06-23 00:00:00", 1);
701                 checkTagValue(doc2, "enddatethreshold", "2005-07-04 00:00:00", 1);
702                 checkTagValue(doc2, "types", "pmd", 1);
703 
704                 NodeList listUp2 = doc2.getElementsByTagName("up");
705                 assertEquals("size for up", 1, listUp2.getLength());
706                 assertEquals("number of files in up list", 2, countFileTags(listUp2));
707                 assertNotNull("List UP presence of net/objectlab/test/WeekendAdjustUpAndDownToZero.java", checkFilePresent(
708                         listUp2, "net/objectlab/test/WeekendAdjustUpAndDownToZero.java"));
709                 checkDiff(listUp2, "net/objectlab/test/WeekendAdjustUpAndDownToZero.java", 1, // number
710                         // of
711                         // diff
712                         new String[] { "-" }, // previousrun
713                         new String[] { "2005-06-24 22:00:06" }, // currentrun
714                         new String[] { "pmd" }, // type
715                         new int[] { 0 }, // previous errors
716                         new int[] { 2 }, // current errors
717                         new int[] { 2 }); // diff
718 
719                 assertNotNull("List UP presence of net/objectlab/test/WeekendAdjustDown.java", checkFilePresent(listUp2,
720                         "net/objectlab/test/WeekendAdjustDown.java"));
721                 checkDiff(listUp2, "net/objectlab/test/WeekendAdjustDown.java", 1, // number
722                         // of
723                         // diff
724                         new String[] { "-" }, // previousrun
725                         new String[] { "2005-06-23 22:00:06" }, // currentrun
726                         new String[] { "pmd" }, // type
727                         new int[] { 0 }, // previous errors
728                         new int[] { 4 }, // current errors
729                         new int[] { 4 }); // diff
730 
731                 // check presence of some file in the down list
732                 NodeList listDown2 = doc2.getElementsByTagName("down");
733 
734                 assertEquals("size for down", 1, listDown2.getLength());
735                 assertEquals("number of files in down list", 2, countFileTags(listDown2));
736                 assertNotNull("List Down presence of net/objectlab/test/WeekendAdjustDown.java", checkFilePresent(listDown2,
737                         "net/objectlab/test/WeekendAdjustDown.java"));
738                 checkDiff(listDown2, "net/objectlab/test/WeekendAdjustDown.java", 2, // number
739                         // of
740                         // diff
741                         new String[] { "2005-06-24 22:00:06", "2005-06-23 22:00:06" }, // previousrun
742                         new String[] { "-", "2005-06-24 22:00:06" }, // currentrun
743                         new String[] { "pmd", "pmd" }, // type
744                         new int[] { 2, 4 }, // previous errors
745                         new int[] { 0, 2 }, // current errors
746                         new int[] { -2, -2 }); // diff
747 
748                 assertNotNull("List Down presence of net/objectlab/test/WeekendAdjustUpAndDownToZero.java", checkFilePresent(
749                         listDown2, "net/objectlab/test/WeekendAdjustUpAndDownToZero.java"));
750                 checkDiff(listDown2, "net/objectlab/test/WeekendAdjustUpAndDownToZero.java", 1, // number
751                         // of
752                         // diff
753                         new String[] { "2005-06-24 22:00:06" }, // previousrun
754                         new String[] { "-" }, // currentrun
755                         new String[] { "pmd" }, // type
756                         new int[] { 2 }, // previous errors
757                         new int[] { 0 }, // current errors
758                         new int[] { -2 }); // diff
759             }
760         } catch (ParserConfigurationException e) {
761             fail(e.toString());
762         } catch (SAXException e) {
763             fail(e.toString());
764         } catch (IOException e) {
765             fail(e.toString());
766         }
767     }
768 
769     /**
770      * Test added by Thomas Stoffer. It should be noted that if a value goes up
771      * (or down) during the interval BUT fails to appear within 24h of the end
772      * of the timw window, it should NOT appear at all as it has been deemed to
773      * have fallen to 0...
774      */
775     public void testCheckstyleMoversToZero() {
776         File testInput = new File("target/test-classes/net/objectlab/qalab/parser/qastatszero.xml");
777 
778         Writer testOutput = new StringWriter();
779 
780         try {
781             final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(testInput)),
782                     "checkstyle", testOutput, false, new SilentLogger(), false);
783             handler.setHoursOffsetForLastRun(0); // exact match.
784 
785             Calendar cal = Calendar.getInstance();
786 
787             cal.set(Calendar.MILLISECOND, 0);
788             cal.set(2006, 06, 26, 15, 14, 59);
789             handler.setStartTimeWindow(cal.getTime());
790             cal.set(2006, 06, 31, 16, 59, 53);
791             handler.setEndTimeWindow(cal.getTime());
792             handler.process();
793 
794             System.out.println(testOutput.toString());
795 
796             // now parse it
797             DOMParser dom = new DOMParser();
798 
799             dom.parse(new InputSource(new StringReader(testOutput.toString())));
800 
801             Document doc = dom.getDocument();
802 
803             checkTagValue(doc, "datethreshold", "2006-07-26 15:14:59", 1);
804             checkTagValue(doc, "enddatethreshold", "2006-07-31 16:59:53", 1);
805             checkTagValue(doc, "types", "checkstyle", 1);
806 
807             // check presence of some file in the up list
808             NodeList listUp = doc.getElementsByTagName("up");
809             assertEquals("size for up", 1, listUp.getLength());
810             assertNotNull("List UP presence of net/objectlab/test/ZeroToManyAtStartTime.java", checkFilePresent(listUp,
811                     toId("net/objectlab/test/ZeroToManyAtStartTime.java")));
812 
813             assertEquals("number of files in up list", 6, countFileTags(listUp));
814             assertNotNull("List UP presence of net/objectlab/test/ZeroToManyAfterStartTime.java", checkFilePresent(listUp,
815                     toId("net/objectlab/test/ZeroToManyAfterStartTime.java")));
816             checkDiff(listUp, "net/objectlab/test/ZeroToManyAfterStartTime.java", 1, // number
817                     // of
818                     // diff
819                     new String[] { "-" }, // previousrun
820                     new String[] { "2006-07-26 15:37:58" }, // currentrun
821                     new String[] { "checkstyle" }, // type
822                     new int[] { 0 }, // previous errors
823                     new int[] { 16 }, // current errors
824                     new int[] { 16 }); // diff
825             assertNotNull("List UP presence of net/objectlab/test/ZeroToManyAndChange.java", checkFilePresent(listUp,
826                     toId("net/objectlab/test/ZeroToManyAndChange.java")));
827             checkDiff(listUp, "net/objectlab/test/ZeroToManyAndChange.java", 1, // number
828                     // of
829                     // diff
830                     new String[] { "-" }, // previousrun
831                     new String[] { "2006-07-26 15:37:58" }, // currentrun
832                     new String[] { "checkstyle" }, // type
833                     new int[] { 0 }, // previous errors
834                     new int[] { 33 }, // current errors
835                     new int[] { 33 }); // diff
836 
837             assertNotNull("List UP presence of net/objectlab/test/ManyToZeroToMany.java", checkFilePresent(listUp,
838                     toId("net/objectlab/test/ManyToZeroToMany.java")));
839             checkDiff(listUp, "net/objectlab/test/ManyToZeroToMany.java", 1, // number
840                     // of
841                     // diff
842                     new String[] { "-" }, // previousrun
843                     new String[] { "2006-07-26 15:14:59" }, // currentrun
844                     new String[] { "checkstyle" }, // type
845                     new int[] { 0 }, // previous errors
846                     new int[] { 33 }, // current errors
847                     new int[] { 33 }); // diff
848 
849             // check presence of some file in the down list
850             NodeList listDown = doc.getElementsByTagName("down");
851 
852             assertEquals("size for down", 1, listDown.getLength());
853             assertEquals("number of files in down list", 4, countFileTags(listDown));
854             assertNotNull("List Down presence of net/objectlab/test/ZeroToManyAtStartTime.java", checkFilePresent(listDown,
855                     toId("net/objectlab/test/ZeroToManyAtStartTime.java")));
856             checkDiff(listDown, "net/objectlab/test/ZeroToManyAtStartTime.java", 1, // number
857                     // of
858                     // diff
859                     new String[] { "2006-07-26 15:14:59" }, // previousrun
860                     new String[] { "-" }, // currentrun
861                     new String[] { "checkstyle" }, // type
862                     new int[] { 16 }, // previous errors
863                     new int[] { 0 }, // current errors
864                     new int[] { -16 }); // diff
865 
866             assertNull("List Down presence of net/objectlab/test/ManyToZeroToMany", checkFilePresent(listDown,
867                     toId("net/objectlab/test/ManyToZeroToMany")));
868             // Thomas... this is not supported...
869             // checkDiff(listDown, "net/objectlab/test/ManyToZeroToMany.java",
870             // 1, // number
871             // // of
872             // // diff
873             // new String[] { "2006-07-28 09:40:10" }, // previousrun
874             // new String[] { "2006-07-28 09:59:06" }, // currentrun
875             // new String[] { "checkstyle" }, // type
876             // new int[] { 33 }, // previous errors
877             // new int[] { 0 }, // current errors
878             // new int[] { -33 }); // diff
879 
880             assertNotNull("List Down presence of net/objectlab/test/ManyToZero2Days.java", checkFilePresent(listDown,
881                     toId("net/objectlab/test/ManyToZero2Days.java")));
882             checkDiff(listDown, "net/objectlab/test/ManyToZero2Days.java", 1, // number
883                     // of
884                     // diff
885                     new String[] { "2006-07-28 18:40:47" }, // previousrun
886                     new String[] { "-" }, // currentrun
887                     new String[] { "checkstyle" }, // type
888                     new int[] { 33 }, // previous errors
889                     new int[] { 0 }, // current errors
890                     new int[] { -33 }); // diff
891 
892             // Thomas, this was the prime suspect in our differences,
893             // if you set the setHoursOffsetForLastRun to 0, (new parameter)
894             // QALab will expect an EXACT match otherwise it will decide whether
895             // it fell down
896             // to 0 or not by looking over the last 24h (and if there is no
897             // stat, it will assume that
898             // it fell to 0).
899             assertNotNull("List Down presence of net/objectlab/test/ManyToZeroLastRun.java", checkFilePresent(listDown,
900                     toId("net/objectlab/test/ManyToZeroLastRun.java")));
901             checkDiff(listDown, "net/objectlab/test/ManyToZeroLastRun.java", 1, // number
902                     // of
903                     // diff
904                     new String[] { "2006-07-31 16:43:03" }, // previousrun
905                     new String[] { "-" }, // currentrun
906                     new String[] { "checkstyle" }, // type
907                     new int[] { 33 }, // previous errors
908                     new int[] { 0 }, // current errors
909                     new int[] { -33 }); // diff
910 
911         } catch (ParserConfigurationException e) {
912             fail(e.toString());
913         } catch (SAXException e) {
914             fail(e.toString());
915         } catch (IOException e) {
916             fail(e.toString());
917         }
918     }
919 
920     private void checkDiff(NodeList list, String file, int numberDiff, String[] previousRuns, String[] currentRuns,
921             String[] types, int[] previousErrors, int[] currentErrors, int[] diffs) {
922         NodeList children = checkFilePresent(list, toId(file));
923         int countDiff = 0;
924 
925         for (int i = 0; i < children.getLength(); i++) {
926             Node diff = children.item(i);
927 
928             if ("diff".equals(diff.getLocalName())) {
929 
930                 // we cannot presume in which order the difference will be given
931                 // in the QALab movers report
932                 String previousRun = getAttribute(diff, "previousrun");
933                 int difference = Integer.parseInt(getAttribute(diff, "diff"));
934                 String currentRun = getAttribute(diff, "currentrun");
935                 String type = getAttribute(diff, "type");
936                 int previousErrorCount = Integer.parseInt(getAttribute(diff, "previouserrors"));
937                 int currentErrorCount = Integer.parseInt(getAttribute(diff, "currenterrors"));
938 
939                 boolean found = false;
940                 for (int u = 0; u < previousErrors.length && !found; u++) {
941                     found = previousRuns[u].equals(previousRun) && currentRuns[u].equals(currentRun) && types[u].equals(type)
942                             && previousErrors[u] == previousErrorCount && currentErrors[u] == currentErrorCount
943                             && diffs[u] == difference;
944                 }
945 
946                 if (!found) {
947                     fail("Could not match this set of data in mover report with test data for " + file + "\n" + "previousRun "
948                             + previousRun + "\n" + "currentRun " + currentRun + "\n" + "type " + type + "\n" + "previousErrors "
949                             + previousErrors + "\n" + "currentErrors " + currentErrors + "\n" + "diff " + diff + "\n");
950                 }
951 
952                 // // now check the attributes
953                 // assertEquals("Check value previousRun",
954                 // previousRuns[countDiff], previousRun);
955                 // assertEquals("Check value currentRun",
956                 // currentRuns[countDiff], currentRun);
957                 // assertEquals("Check value type", types[countDiff], type);
958                 // assertEquals("Check value previousErrors",
959                 // previousErrors[countDiff], previousErrorCount);
960                 // assertEquals("Check value currentErrors",
961                 // currentErrors[countDiff], currentErrorCount);
962                 // assertEquals("Check value diff", diffs[countDiff],
963                 // difference);
964 
965                 countDiff++;
966             }
967         }
968 
969         assertEquals("Number of diff tags", numberDiff, countDiff);
970     }
971 
972     private NodeList checkFilePresent(NodeList listUp, String shouldBePresent) {
973         String checkFile = toId(shouldBePresent);
974         for (int i = 0; i < listUp.getLength(); i++) {
975             Element element = (Element) listUp.item(i);
976             NodeList list = element.getChildNodes();
977 
978             for (int u = 0; u < list.getLength(); u++) {
979                 Node file = list.item(u);
980 
981                 if ("file".equals(file.getLocalName())) {
982                     String fileName = getAttribute(file, "name");
983 
984                     if (checkFile.equals(fileName)) {
985                         return file.getChildNodes();
986                     }
987                 }
988             }
989         }
990 
991         return null;
992     }
993 
994     private int countFileTags(NodeList listUp) {
995         int count = 0;
996 
997         for (int i = 0; i < listUp.getLength(); i++) {
998             Element element = (Element) listUp.item(i);
999             NodeList list = element.getChildNodes();
1000 
1001             for (int u = 0; u < list.getLength(); u++) {
1002                 Node file = list.item(u);
1003 
1004                 // System.out.println("UP...." + file.getLocalName() + " / "
1005                 // + file.getNodeName() +" v:" + file.getNodeValue());
1006                 if ("file".equals(file.getLocalName())) {
1007                     count++;
1008                 }
1009             }
1010         }
1011 
1012         return count;
1013     }
1014 
1015     private void checkTagValue(Document doc, String tagName, String value, int count) {
1016         // Get a list of all elements in the document
1017         NodeList list = doc.getElementsByTagName(tagName);
1018 
1019         assertEquals("size for " + tagName, count, list.getLength());
1020 
1021         for (int i = 0; i < list.getLength(); i++) {
1022             // Get element
1023             Element element = (Element) list.item(i);
1024 
1025             assertEquals("Value for " + tagName, value, getElementText(element));
1026         }
1027     }
1028 
1029     /**
1030      * Gets the value of the child text node.
1031      * 
1032      * @param node
1033      *            the XML element.
1034      * @return the child Text node value. If one of the nodes child elements is
1035      *         not of type Text then return null;
1036      */
1037     protected final String getElementText(final Node node) {
1038         String text = null;
1039         NodeList childNodes = node.getChildNodes();
1040 
1041         for (int i = 0; i < childNodes.getLength(); i++) {
1042             Node childNode = childNodes.item(i);
1043 
1044             if (childNode.getNodeType() == Node.TEXT_NODE) {
1045                 text = ((Text) childNode).getData();
1046 
1047                 break;
1048             }
1049         }
1050 
1051         return text;
1052     }
1053 
1054     /**
1055      * get the attribute value of a node.
1056      * 
1057      * @param node
1058      *            XML Dom Node
1059      * @param attributeName
1060      *            attribute.
1061      * @return string value of the attributeName.
1062      */
1063     private final String getAttribute(final Node node, final String attributeName) {
1064         String text = null;
1065         NamedNodeMap map = node.getAttributes();
1066 
1067         if (map != null) {
1068             Node n = map.getNamedItem(attributeName);
1069 
1070             if (n != null) {
1071                 return getElementText(n);
1072             }
1073         }
1074 
1075         return text;
1076     }
1077 }
1078 /*
1079  * ObjectLab is sponsoring QALab
1080  * 
1081  * Based in London, we are world leaders in the design and development of
1082  * bespoke applications for the securities financing markets.
1083  * 
1084  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
1085  * ___ _ _ _ _ _ / _ \| |__ (_) ___ ___| |_| | __ _| |__ | | | | '_ \| |/ _ \/
1086  * __| __| | / _` | '_ \ | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
1087  * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ |__/
1088  * 
1089  * www.ObjectLab.co.uk
1090  */