@Test public void TestPurgeServiceRunLogNoLimit() { Calendar cal = Calendar.getInstance(Locale.getDefault()); cal.add(Calendar.DATE, -400); Date start1 = cal.getTime(); cal.add(Calendar.HOUR, 1); Date end1 = cal.getTime(); ServiceRunProvider.ServiceRun r1 = new ServiceRunProvider.ServiceRun(1, start1, end1, 0, 0); cal.add(Calendar.DATE, 200); Date start2 = cal.getTime(); cal.add(Calendar.HOUR, 1); Date end2 = cal.getTime(); ServiceRunProvider.ServiceRun r2 = new ServiceRunProvider.ServiceRun(2, start2, end2, 2, 1); long rid1 = ServiceRunProvider.InsertRow(myDb, r1); long rid2 = ServiceRunProvider.InsertRow(myDb, r2); // insert calls LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(rid1, null, "123", "dummy")); LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(rid2, null, "456", "dummy")); Cursor latest = ServiceRunProvider.LatestRuns(myDb, -1); assertEquals("There should be two records", 2, latest.getCount()); Cursor calls = LoggedCallProvider.LatestCalls(myDb, -1); assertEquals("There should be two records", 2, latest.getCount()); ServiceRunProvider.PurgeLog(myDb, myContext, "no limit"); latest = ServiceRunProvider.LatestRuns(myDb, -1); assertEquals("No purging", 2, latest.getCount()); assertEquals("No purging", 2, calls.getCount()); latest.close(); calls.close(); }
@Test public void LoggedCallsInsertRows() { LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(15, null, "123", "a dummy")); LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(21, null, "321", "another dummy")); Cursor c = LoggedCallProvider.LatestCalls(myDb, 5); assertEquals("There should be two records", 2, c.getCount()); }
@Test public void LoggedCallCheckTimeStamp() { LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(15, null, "123", "a dummy")); Cursor c = LoggedCallProvider.LatestCalls(myDb, 5); c.moveToFirst(); String ts = c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_TIMESTAMP)); assertNotNull("The timestamp is not null", ts); assertFalse("The timestamp is not empty", ts.isEmpty()); }
@Test public void LoggedCallsLatest() { LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(15, null, "123", "a dummy")); LoggedCallProvider.InsertRow( myDb, new LoggedCallProvider.LoggedCall(21, "dummy", "321", "another dummy")); Cursor c = LoggedCallProvider.LatestCalls(myDb, 5); // they should appear in reverse order c.moveToFirst(); assertEquals( "Check the second run id", 21, c.getInt(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_RUNID))); assertEquals( "Check the second number", "321", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_NUMBER))); assertEquals( "Check the second description", "another dummy", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_DESCRIPTION))); assertNotNull( "The second action is not null", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_ACTION))); assertEquals( "Check the second action", "dummy", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_ACTION))); c.moveToNext(); assertEquals( "Check the first run id", 15, c.getInt(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_RUNID))); assertEquals( "Check the first number", "123", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_NUMBER))); assertEquals( "Check the first description", "a dummy", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_DESCRIPTION))); assertNull( "The first action is null", c.getString(c.getColumnIndex(DbContract.LoggedCalls.COLUMN_NAME_ACTION))); }