1   package uk.co.concise.maven;
2   
3   import junit.framework.TestCase;
4   
5   /***
6    * Tests the HistoricalDataCollector.
7    * 
8    * @author martenssonb
9    * @see uk.co.concise.maven.HistoricalDataCollector
10   */
11  public class HistoricalDataCollectorTest extends TestCase {
12  
13      private HistoricalDataCollector collector;
14      
15      /***
16       * Constructor.
17       * 
18       * @param name
19       *            testcase name.
20       */
21      public HistoricalDataCollectorTest(String name) {
22          super(name);
23          collector = new HistoricalDataCollector();
24          collector.setHeading("Test Heading");
25          collector
26                  .setDbHibernateDialect("net.sf.hibernate.dialect.MySQLDialect");
27          collector.setDbDriverClass("com.mysql.jdbc.Driver");
28          collector.setDbUrl("jdbc:mysql:"
29                  + "//localhost:3306/historical_build_results");
30          collector.setDbUser("root");
31          collector.setDbPass("");
32      }
33      
34      /***
35       * Test the run method.
36       * 
37       * @throws Exception
38       *             if something goes wrong.
39       */
40      public void testRun() throws Exception {
41          // Get the file.
42          String file = "src/test/uk/co/concise/maven/junit-report.xml";
43          collector.setBuildResultFile(file);
44          // "/doc/name/@first"
45          collector.setValuesToTrackXPath("/document/body/"
46                  + "section[@name='Package List']/table/tr/td[2]/text()");
47          collector.setLabelsToTrackXPath("/document/body/"
48                  + "section[@name='Package List']/table/tr/td[1]/a/text()");
49          collector.run();
50      }
51      
52      /***
53       * Test that we can collect data with labels specified as attributes.
54       * Also tests that labels that don't have a value are handled gracefully.
55       * I.e. it could be that in some builds a value wouldn't have a value,
56       * but would have a value at a later stage.
57       * 
58       * @throws Exception
59       *             if something goes wrong.
60       */
61      public void testAttributeRun() throws Exception {
62          // Get the file.
63          String file = "src/test/uk/co/concise/maven/dashboard.xml";
64          collector.setBuildResultFile(file);
65          // "/doc/name/@first"
66          collector.setValuesToTrackXPath("/dashboard/project/"
67                  + "aggregator/text()");
68          collector.setLabelsToTrackXPath("/dashboard/project/"
69                  + "aggregator/@name");
70          collector.run();
71      }
72   
73  }