1 package compbio.stat.collector;
\r
3 import static org.testng.Assert.assertEquals;
\r
4 import static org.testng.Assert.assertNotNull;
\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
12 import org.testng.Assert;
\r
13 import org.testng.annotations.BeforeClass;
\r
14 import org.testng.annotations.Test;
\r
16 import compbio.stat.servlet.util.StatCollection;
\r
17 import compbio.stat.servlet.util.Totals;
\r
18 import compbio.ws.client.Services;
\r
20 public class StatDBTester {
\r
25 @BeforeClass(alwaysRun=true )
\r
26 public void init() {
\r
28 statdb = new StatDB(true);
\r
29 Calendar fromCal = Calendar.getInstance();
\r
30 fromCal.set(2011, 4, 1);
\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
37 } catch (SQLException e) {
\r
38 e.printStackTrace();
\r
39 Assert.fail(e.getLocalizedMessage());
\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
48 @Test(enabled = false)
\r
49 public void testReadYearData() {
\r
50 Calendar cal = Calendar.getInstance();
\r
51 cal.set(2010, 4, 1);
\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
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
70 @Test(enabled =false)
\r
71 public void testReadOneMonthData() {
\r
73 List<JobStat> jobs = statdb.readData(from, to, Services.TcoffeeWS, false);
\r
74 assertNotNull(jobs);
\r
75 assertEquals(jobs.size(), 36);
\r
77 jobs = statdb.readData(from,to, Services.ClustalWS,false);
\r
79 assertNotNull(jobs);
\r
80 assertEquals(jobs.size(), 137);
\r
82 jobs = statdb.readData(from, to, Services.MafftWS,false);
\r
83 assertNotNull(jobs);
\r
84 assertEquals(jobs.size(), 136);
\r
86 jobs = statdb.readData(from,to, Services.ProbconsWS,false);
\r
87 assertNotNull(jobs);
\r
88 assertEquals(jobs.size(), 9);
\r
90 jobs = statdb.readData(from,to, Services.MuscleWS,false);
\r
91 assertNotNull(jobs);
\r
92 assertEquals(jobs.size(), 63);
\r
94 } catch (SQLException e) {
\r
95 e.printStackTrace();
\r
96 Assert.fail(e.getMessage());
\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
105 @Test(enabled=false)
\r
106 public void testGetEarliestRecord() {
\r
108 Date earliestRec = statdb.getEarliestRecord();
\r
110 assertEquals(1278543600000L, earliestRec.getTime());
\r
111 } catch (SQLException e) {
\r
112 e.printStackTrace();
\r
113 Assert.fail(e.getLocalizedMessage());
\r
118 @Test(sequential=true)
\r
119 public void testVerifyJobsCount() {
\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
130 //System.out.println(sc.getAllStat());
\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
137 } catch (SQLException e) {
\r
138 e.printStackTrace();
\r
139 Assert.fail(e.getLocalizedMessage());
\r