コード例 #1
0
 private void deleteCall(DBObject call) throws UnknownHostException {
   if (call.containsField("_id")) {
     Resources.getDatabaseActivity()
         .getCollection("MissedCalls")
         .remove(new BasicDBObject("_id", call.get("_id")));
   }
 }
コード例 #2
0
  @Test
  public void integrationTestInsertCall() throws Exception {

    missedCallsDAO = new MissedCallsDAO(Resources.getDatabaseActivity());

    DBObject testCall = new BasicDBObject("who", 9581300084L);
    try {
      assertTrue(missedCallsDAO.insertCall(testCall));
      assertTrue(testCall.containsField("arrival"));
      assertEquals("Pending", testCall.get("state"));
      assertTrue(testCall.containsField("_id"));
    } finally {
      deleteCall(testCall);
    }
  }
コード例 #3
0
  @Test
  public void integrationTestMarkCallAsBogus() throws Exception {
    missedCallsDAO = new MissedCallsDAO(Resources.getDatabaseActivity());

    DBObject bogusCall = new BasicDBObject("who", 1234567890L);
    try {
      assertTrue(missedCallsDAO.insertCall(bogusCall));
      assertEquals("Pending", bogusCall.get("state"));
      missedCallsDAO.setState(bogusCall, "Processing");
      bogusCall = refetchCall(bogusCall);
      missedCallsDAO.setState(bogusCall, "Bogus");
      assertEquals("Bogus", refetchCall(bogusCall).get("state"));
    } finally {
      deleteCall(bogusCall);
    }
  }
コード例 #4
0
  @Test
  public void integrationTestFetchNextPendingCall() throws Exception {

    missedCallsDAO = new MissedCallsDAO(Resources.getDatabaseActivity());

    DBObject testCallFirst = new BasicDBObject("who", 9581300084L);
    DBObject testCallSecond = new BasicDBObject("who", 9581300084L);

    try {
      assertTrue(missedCallsDAO.insertCall(testCallFirst));
      Thread.sleep(1000);
      assertTrue(missedCallsDAO.insertCall(testCallSecond));

      Date tsFirst = (Date) testCallFirst.get("arrival");
      Date tsSecond = (Date) testCallSecond.get("arrival");
      assertTrue(tsFirst.before(tsSecond));

      DBObject fetchedCallFirst = missedCallsDAO.fetchNextPendingCall();
      assertNotNull(fetchedCallFirst);
      assertTrue(fetchedCallFirst.containsField("who"));
      assertEquals("Processing", fetchedCallFirst.get("state"));
      assertEquals(testCallSecond.get("_id"), fetchedCallFirst.get("_id"));

      DBObject fetchedCallSecond = missedCallsDAO.fetchNextPendingCall();
      assertNotNull(fetchedCallSecond);
      assertTrue(fetchedCallSecond.containsField("who"));
      assertEquals("Processing", fetchedCallSecond.get("state"));
      assertEquals(testCallFirst.get("_id"), fetchedCallSecond.get("_id"));

      tsFirst = (Date) fetchedCallFirst.get("arrival");
      tsSecond = (Date) fetchedCallSecond.get("arrival");
      assertTrue(tsFirst.after(tsSecond));
    } finally {
      deleteCall(testCallFirst);
      deleteCall(testCallSecond);
    }
  }
コード例 #5
0
 @BeforeClass
 public static void init() throws Exception {
   Resources.init();
 }
コード例 #6
0
 private DBObject refetchCall(DBObject call) throws Exception {
   if (!call.containsField("_id")) throw new Exception("_id field is not present");
   return Resources.getDatabaseActivity()
       .getCollection("MissedCalls")
       .findOne(new BasicDBObject("_id", call.get("_id")));
 }