Esempio n. 1
0
  public void testMultiAccess() {
    User user = new User();
    user.setUserName("user");
    user.setIdentity("user@dog");

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

    Messages m1 = Messages.newMessages(mbox);
    Messages m2 = Messages.newMessages(mbox);
    assertSame(m1, m2);
    Messages.releaseMessages(m2);
    Messages m3 = Messages.newMessages(mbox);
    assertSame(m1, m3);
    Messages.releaseMessages(m3);
    Messages.releaseMessages(m1);
    Messages m4 = Messages.newMessages(mbox);
    assertNotSame(m1, m4);
  }
Esempio n. 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);
  }