85bc81d740f6b294270f03db1d80b3dceaa61fe0
[proteocache.git] / testsrc / compbio / stat / collector / StatDBTester.java
1 package compbio.stat.collector;\r
2 \r
3 import static org.testng.Assert.assertEquals;\r
4 import static org.testng.Assert.assertNotNull;\r
5 \r
6 import java.sql.SQLException;\r
7 import java.sql.Timestamp;\r
8 import java.util.Calendar;\r
9 import java.util.Date;\r
10 import java.util.List;\r
11 \r
12 import org.testng.Assert;\r
13 import org.testng.annotations.BeforeClass;\r
14 import org.testng.annotations.Test;\r
15 \r
16 import compbio.stat.servlet.util.StatCollection;\r
17 import compbio.stat.servlet.util.Totals;\r
18 import compbio.ws.client.Services;\r
19 \r
20 public class StatDBTester {\r
21         StatDB statdb;\r
22         Timestamp from;\r
23         Timestamp to;\r
24         \r
25         @BeforeClass(alwaysRun=true )\r
26         public void init() {\r
27                 try {\r
28                         statdb = new StatDB(true);\r
29                         Calendar fromCal = Calendar.getInstance();\r
30                         fromCal.set(2011, 4, 1);\r
31                                                 \r
32                         Calendar toCal = Calendar.getInstance();\r
33                         toCal.set(2011, 5, 1);\r
34                         from = new Timestamp(fromCal.getTimeInMillis());\r
35                         to = new Timestamp(toCal.getTimeInMillis());\r
36                         \r
37                 } catch (SQLException e) {\r
38                         e.printStackTrace();\r
39                         Assert.fail(e.getLocalizedMessage());\r
40                 }\r
41         }\r
42 \r
43         /*\r
44          * This test fails if run with other tests. This is likely due to the fact that StatDB \r
45          * is initialised with connection to other then the test database from StatCollector class.\r
46          * TODO look at this\r
47          */\r
48         @Test(enabled = false)\r
49         public void testReadYearData() {\r
50                 Calendar cal = Calendar.getInstance();\r
51                 cal.set(2010, 4, 1);\r
52                 try {\r
53                         List<JobStat> jobs = statdb.readData(\r
54                                         new Timestamp(cal.getTimeInMillis()), to, Services.MuscleWS, false);\r
55                         assertNotNull(jobs);\r
56                         assertEquals(jobs.size(), 1294);\r
57                         // statdb.shutdownDBServer();\r
58                 } catch (SQLException e) {\r
59                         e.printStackTrace();\r
60                         Assert.fail(e.getMessage());\r
61                 }\r
62 \r
63         }\r
64 \r
65         /*\r
66          * This test fails if run with other tests. This is likely due to the fact that StatDB \r
67          * is initialised with connection to other then the test database from StatCollector class.\r
68          * TODO look at this\r
69          */\r
70         @Test(enabled =false)\r
71         public void testReadOneMonthData() {\r
72                 try {\r
73                         List<JobStat> jobs = statdb.readData(from, to, Services.TcoffeeWS, false);\r
74                         assertNotNull(jobs);\r
75                         assertEquals(jobs.size(), 36);\r
76 \r
77                         jobs = statdb.readData(from,to, Services.ClustalWS,false);\r
78 \r
79                         assertNotNull(jobs);\r
80                         assertEquals(jobs.size(), 137);\r
81 \r
82                         jobs = statdb.readData(from, to, Services.MafftWS,false);\r
83                         assertNotNull(jobs);\r
84                         assertEquals(jobs.size(), 136);\r
85 \r
86                         jobs = statdb.readData(from,to, Services.ProbconsWS,false);\r
87                         assertNotNull(jobs);\r
88                         assertEquals(jobs.size(), 9);\r
89 \r
90                         jobs = statdb.readData(from,to, Services.MuscleWS,false);\r
91                         assertNotNull(jobs);\r
92                         assertEquals(jobs.size(), 63);\r
93 \r
94                 } catch (SQLException e) {\r
95                         e.printStackTrace();\r
96                         Assert.fail(e.getMessage());\r
97                 }\r
98         }\r
99 \r
100         /*\r
101          * This test fails if run with other tests. This is likely due to the fact that StatDB \r
102          * is initialised with connection to other then the test database from StatCollector class.\r
103          * TODO look at this\r
104          */\r
105         @Test(enabled=false)\r
106         public void testGetEarliestRecord() {\r
107                 try {\r
108                         Date earliestRec = statdb.getEarliestRecord();\r
109                         \r
110                         assertEquals(1278543600000L, earliestRec.getTime());\r
111                 } catch (SQLException e) {\r
112                         e.printStackTrace();\r
113                         Assert.fail(e.getLocalizedMessage());\r
114                 }\r
115 \r
116         }\r
117 \r
118         @Test(sequential=true)\r
119         public void testVerifyJobsCount() {\r
120 \r
121                 try {\r
122                         Calendar cal = Calendar.getInstance();\r
123                         cal.add(Calendar.MONTH, -5);\r
124                         Timestamp from = new Timestamp(cal.getTimeInMillis());\r
125                         cal.add(Calendar.MONTH, 1);\r
126                         Timestamp to = new Timestamp(cal.getTimeInMillis());\r
127                         StatCollection sc = StatCollection.newStatCollecton(from, to);\r
128                         Totals t = Totals.sumStats(sc.getAllStat());\r
129 \r
130                         //System.out.println(sc.getAllStat());\r
131                         \r
132                         assertEquals(t.getTotal(), statdb.getTotalJobsCount(from, to));\r
133                         assertEquals(t.getAbandoned(), statdb.getAbandonedCount(from, to));\r
134                         assertEquals(t.getCancelled(), statdb.getCancelledCount(from, to));\r
135                         assertEquals(t.getIncomplete(), statdb.getIncompleteCount(from, to));\r
136 \r
137                 } catch (SQLException e) {\r
138                         e.printStackTrace();\r
139                         Assert.fail(e.getLocalizedMessage());\r
140                 }\r
141 \r
142         }\r
143 }\r