예제 #1
0
  public void testLoadFolder() throws IOException, InterruptedException {
    Messages m = new Messages();
    m.loadFolder(m_inboxDir, m.m_inbox, true, null);
    assertEquals(0, m.getInboxCount());

    FileUtils.touch(new File(m_inboxDir, "0001-00.wav"));
    makeMd(new File(m_inboxDir, "0001-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0002-00.wav"));
    makeMd(new File(m_inboxDir, "0002-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0003-00.wav"));
    makeMd(new File(m_inboxDir, "0003-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0003-00.sta"));
    FileUtils.touch(new File(m_inboxDir, "0004-00.wav"));
    makeMd(new File(m_inboxDir, "0004-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0004-00.sta"));

    FileUtils.touch(new File(m_inboxDir, "0005-00.dog")); // .dog doesn't count
    makeMd(new File(m_inboxDir, "0006-00.xml")); // .xml with no .wav, it counts.
    FileUtils.touch(new File(m_inboxDir, "0007-00.wav")); // .wav with no .xml, doesn't count.

    makeMd(new File(m_inboxDir, "0008-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0008-00.wav"));
    FileUtils.touch(new File(m_inboxDir, "0008-00.sta"));
    makeMd(new File(m_inboxDir, "0008-01.xml"));
    FileUtils.touch(new File(m_inboxDir, "0008-01.wav"));
    FileUtils.touch(new File(m_inboxDir, "0008-FW.wav"));

    FileUtils.touch(new File(m_inboxDir, "hey there"));
    FileUtils.touch(new File(m_inboxDir, "this.is.a.file"));

    m.loadFolder(m_inboxDir, m.m_inbox, true, null);
    assertEquals(6, m.getInboxCount());
    assertEquals(3, m.getUnheardCount());

    m.loadFolder(m_inboxDir, m.m_saved, false, null);
    assertEquals(6, m.getSavedCount());
    assertEquals(3, m.getUnheardCount());
  }
예제 #2
0
  public void testSaveDeletePurge() throws IOException, InterruptedException {
    User user = new User();
    user.setUserName("user");
    user.setIdentity("user@dog");

    Mailbox mbox = new Mailbox(user, m_mailstoreDir.getPath());

    FileUtils.touch(new File(m_inboxDir, "0001-00.wav"));
    makeMd(new File(m_inboxDir, "0001-00.xml"));
    FileUtils.touch(new File(m_inboxDir, "0001-00.sta"));
    FileUtils.touch(new File(m_inboxDir, "0001-01.wav"));
    makeMd(new File(m_inboxDir, "0001-01.xml"));
    FileUtils.touch(new File(m_inboxDir, "0001-FW.wav"));
    FileUtils.touch(new File(m_inboxDir, "0002-00.wav"));
    makeMd(new File(m_inboxDir, "0002-00.xml"));

    Messages m = Messages.newMessages(mbox);
    m.loadFolder(m_inboxDir, m.m_inbox, true, null);
    m.loadFolder(m_savedDir, m.m_saved, false, null);
    m.loadFolder(m_deletedDir, m.m_deleted, false, null);

    assertEquals(2, m.getInboxCount());
    assertEquals(1, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());

    // Find 0001
    VmMessage msg = null;
    for (VmMessage msg1 : m.getInbox()) {
      if (msg1.getMessageId().equals("0001")) {
        msg = msg1;
        break;
      }
    }

    // Mark 0001 as heard
    m.markMessageHeard(msg, true);
    // Prove it
    assertEquals(2, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());
    assertFalse(new File(m_inboxDir, "0001-00.sta").exists());

    // Reload and make sure we get the same result
    Messages.releaseMessages(m);
    m = Messages.newMessages(mbox);
    m.loadFolder(m_inboxDir, m.m_inbox, true, null);
    m.loadFolder(m_savedDir, m.m_saved, false, null);
    m.loadFolder(m_deletedDir, m.m_deleted, false, null);

    assertEquals(2, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());

    // Find 0001 (again)
    msg = null;
    for (VmMessage msg1 : m.getInbox()) {
      if (msg1.getMessageId().equals("0001")) {
        msg = msg1;
        break;
      }
    }

    // Save the message
    m.saveMessage(msg);
    assertEquals(1, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(1, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());
    assertFalse(new File(m_inboxDir, "0001-00.wav").exists());
    assertFalse(new File(m_inboxDir, "0001-00.xml").exists());
    assertFalse(new File(m_inboxDir, "0001-00.sta").exists());
    assertFalse(new File(m_inboxDir, "0001-01.wav").exists());
    assertFalse(new File(m_inboxDir, "0001-01.xml").exists());
    assertFalse(new File(m_inboxDir, "0001-FW.wav").exists());

    File xml = new File(m_savedDir, "0001-00.xml");
    File wav = new File(m_savedDir, "0001-FW.wav");
    assertEquals(xml.getPath(), msg.m_descriptorFile.getPath());
    assertEquals(wav.getPath(), msg.getAudioFile().getPath());

    assertTrue(xml.exists());
    assertTrue(wav.exists());

    // Delete the message
    m.deleteMessage(msg);
    assertEquals(1, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(1, m.getDeletedCount());
    assertFalse(new File(m_savedDir, "0001-00.xml").exists());
    assertFalse(new File(m_savedDir, "0001-FW.wav").exists());

    xml = new File(m_deletedDir, "0001-00.xml");
    wav = new File(m_deletedDir, "0001-FW.wav");
    assertEquals(xml.getPath(), msg.m_descriptorFile.getPath());
    assertEquals(wav.getPath(), msg.getAudioFile().getPath());

    assertTrue(xml.exists());
    assertTrue(wav.exists());

    // Revive the message
    m.saveMessage(msg);
    assertEquals(2, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());
    assertFalse(new File(m_deletedDir, "0001-00.xml").exists());
    assertFalse(new File(m_deletedDir, "0001-FW.wav").exists());

    assertTrue(new File(m_inboxDir, "0001-00.xml").exists());
    assertTrue(new File(m_inboxDir, "0001-FW.wav").exists());

    // Delete the message
    m.deleteMessage(msg);
    // Purge the message
    m.deleteMessage(msg);
    assertEquals(1, m.getInboxCount());
    assertEquals(0, m.getUnheardCount());
    assertEquals(0, m.getSavedCount());
    assertEquals(0, m.getDeletedCount());
    assertFalse("File shouldn't exist", new File(m_deletedDir, "0001-00.xml").exists());
    assertFalse("File shouldn't exist", new File(m_deletedDir, "0001-FW.wav").exists());
    Messages.releaseMessages(m);
  }