1   /*
2    * Created on 13-Jul-2004
3    *
4    */
5   package uk.co.concise.maven.hdc.report;
6   
7   import java.io.InputStream;
8   import java.util.Date;
9   import java.util.Properties;
10  import java.util.Set;
11  
12  import junit.framework.TestCase;
13  import uk.co.concise.maven.hdc.model.Chart;
14  import uk.co.concise.maven.hdc.model.Label;
15  import uk.co.concise.maven.hdc.model.Point;
16  
17  /***
18   * @author readm
19   *  
20   */
21  public class TimeChartTest extends TestCase {
22  
23      private Properties props = new Properties();
24      
25      /***
26       * @see junit.framework.TestCase#setUp()
27       */
28      protected void setUp() throws Exception {
29          super.setUp();
30          InputStream input = this.getClass().getClassLoader()
31                  .getResourceAsStream(
32                          "uk/co/concise/maven/hdc/report/"
33                                  + "timeChartTest.properties");
34          assertNotNull("cannot find timeChartTest.properties", input);
35          props.load(input);
36      }
37  
38      /***
39       * @see junit.framework.TestCase#tearDown()
40       */
41      protected void tearDown() throws Exception {
42          // TODO Auto-generated method stub
43          super.tearDown();
44      }
45  
46      /***
47       * Check that we can instantiate with default constructor.
48       *
49       * @throws Exception for JUnit to handle.
50       */
51      public void testInstantiate() throws Exception {
52          
53          TimeChart chart = new TimeChart();
54          
55      }
56      
57      
58      /***
59       * Check that we are correctly mapping data to datasets.
60       * @throws Exception for JUnit to handle.
61       */
62      public void testMapOfChartToDataset() throws Exception {
63  
64          Chart chart = getChart();
65          TimeChart timeChart = getTimeChart();
66  //        XYDataset dataset = timeChart.createDataSet((Label) chart.getLabels().iterator().next());
67  //        assertEquals("should be one series in the dataset", 1, dataset.getSeriesCount());
68  //        assertEquals("series should be called MyLabel", "MyLabel", dataset.getSeriesName(0));
69  //        assertEquals("should be 3 items", 3, dataset.getItemCount(0));
70  //        assertEquals("first item should be value 1", 1, (int) dataset.getY(0, 0));
71  //        assertEquals("second item should be value 2", 2, (int) dataset.getY(0, 1));
72  //        assertEquals("third item should be value 3", 3, (int) dataset.getY(0, 2));
73  
74      }
75  
76      /***
77       * Check that we can get a Jpg out of the reporter.
78       * @throws Exception for JUnit to handle.
79       */
80      public void testCanCreateJpg() throws Exception {
81  
82          TimeChart timeChart = getTimeChart();
83          timeChart.run();
84  
85      }
86  
87      /***
88       * @return a test chart
89       */
90      private Chart getChart() {
91          Chart chart = new Chart();
92          chart.setHeading("MyTestChart");
93          Set labels = chart.getLabels();
94          Label label = new Label();
95          label.setText("MyLabel");
96          label.setChart(chart);
97          labels.add(label);
98          Set points = label.getPoints();
99          Point p1 = new Point();
100         p1.setTime(new Date());
101         p1.setValue(1d);
102         p1.setLabel(label);
103         points.add(p1);
104         Point p2 = new Point();
105         p2.setTime(new Date(new Date().getTime() + 3600));
106         p2.setValue(2d);
107         p2.setLabel(label);
108         points.add(p2);
109         Point p3 = new Point();
110         p3.setTime(new Date(new Date().getTime() + 7200));
111         p3.setValue(3d);
112         p3.setLabel(label);
113         points.add(p3);
114         return chart;
115     }
116 
117     /***
118      * @return a configured TimeChart
119      */
120     private TimeChart getTimeChart() {
121         TimeChart timeChart = new TimeChart(props
122                 .getProperty("hdc.hibernate.connection.driver_class"), props
123                 .getProperty("hdc.hibernate.connection.url"), props
124                 .getProperty("hdc.hibernate.connection.username"), props
125                 .getProperty("hdc.hibernate.connection.password"), props
126                 .getProperty("hdc.hibernate.dialect"), props
127                 .getProperty("test.output.dir"), 600, 600);
128         return timeChart;
129     }
130 }