package compbio.stat.collector; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; import java.util.List; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import compbio.stat.servlet.util.StatCollection; import compbio.stat.servlet.util.Totals; import compbio.ws.client.Services; public class StatDBTester { StatDB statdb; @BeforeClass public void init() { try { statdb = new StatDB(true); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getLocalizedMessage()); } } @Test public void testReadYearDataAndShutdown() { Calendar cal = Calendar.getInstance(); cal.roll(Calendar.YEAR, false); try { List jobs = statdb.readData( new Timestamp(cal.getTimeInMillis()), new Timestamp( new Date().getTime()), Services.MuscleWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 1294); // statdb.shutdownDBServer(); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } } @Test public void testReadOneMonthData() { Calendar fromCal = Calendar.getInstance(); fromCal.set(2011, 4, 1); Calendar toCal = Calendar.getInstance(); toCal.set(2011, 5, 1); try { List jobs = statdb.readData( new Timestamp(fromCal.getTimeInMillis()), new Timestamp(toCal.getTimeInMillis()), Services.TcoffeeWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 36); jobs = statdb.readData(new Timestamp(fromCal.getTimeInMillis()), new Timestamp(toCal.getTimeInMillis()), Services.ClustalWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 137); jobs = statdb.readData(new Timestamp(fromCal.getTimeInMillis()), new Timestamp(toCal.getTimeInMillis()), Services.MafftWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 126); jobs = statdb.readData(new Timestamp(fromCal.getTimeInMillis()), new Timestamp(toCal.getTimeInMillis()), Services.ProbconsWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 9); jobs = statdb.readData(new Timestamp(fromCal.getTimeInMillis()), new Timestamp(toCal.getTimeInMillis()), Services.MuscleWS, false); assertNotNull(jobs); assertEquals(jobs.size(), 63); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } } @Test public void testGetEarliestRecord() { try { StatDB db = new StatDB(); Date earliestRec = db.getEarliestRecord(); // System.out.println(earliestRec); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getLocalizedMessage()); } } @Test public void testVerifyJobsCount() { try { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -5); Timestamp from = new Timestamp(cal.getTimeInMillis()); cal.add(Calendar.MONTH, 1); Timestamp to = new Timestamp(cal.getTimeInMillis()); StatCollection sc = StatCollection.newStatCollecton(from, to); Totals t = Totals.sumStats(sc.getAllStat()); System.out.println(sc.getAllStat()); StatDB db = new StatDB(); assertEquals(t.getTotal(), db.getTotalJobsCount(from, to)); assertEquals(t.getAbandoned(), db.getAbandonedCount(from, to)); assertEquals(t.getCancelled(), db.getCancelledCount(from, to)); assertEquals(t.getIncomplete(), db.getIncompleteCount(from, to)); } catch (SQLException e) { e.printStackTrace(); Assert.fail(e.getLocalizedMessage()); } } }