Exemplo n.º 1
0
  @Test
  public void testInsertCall() throws Exception {
    DBObject callObj = new BasicDBObject();

    assertTrue(missedCallsDAO.insertCall(callObj));
    assertTrue(callObj.containsField("arrival"));
    assertEquals("Pending", callObj.get("state"));
    verify(missedCalls, times(1)).insert(any(DBObject.class));
  }
Exemplo n.º 2
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);
    }
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
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);
    }
  }