public void testCopyMessage() throws IOException { User user = new User(); user.setUserName("user"); user.setIdentity("user@dog"); Mailbox mbox = new Mailbox(user, m_mailstoreDir.getPath()); File tempFile = new File(m_testDir, "temp.wav"); makeWaves(tempFile, (byte) 0, 4); Message m = Message.newMessage(mbox, tempFile, "woof@dog", Priority.NORMAL, null); m.storeInInbox(); assertFalse("temp file was not deleted", tempFile.exists()); VmMessage vm = m.getVmMessage(); VmMessage vm2 = vm.copy(mbox); assertFalse("Message ID didn't change", vm.getMessageId().equals(vm2.getMessageId())); assertTrue("vmMessage wasn't created", vm2 != null); assertTrue("Audio File not created", vm2.m_audioFile.exists()); assertTrue("Descriptor File not created", vm2.m_descriptorFile.exists()); assertTrue("Status File not created", vm2.m_statusFile.exists()); assertFalse( "Subject didn't change", vm.m_messageDescriptor.getSubject().equals(vm2.m_messageDescriptor.getSubject())); }
public void testForwardMessage() throws IOException { User user = new User(); user.setUserName("user"); user.setIdentity("user@dog"); Mailbox mbox = new Mailbox(user, m_mailstoreDir.getPath()); File tempFile = new File(m_testDir, "temp.wav"); makeWaves(tempFile, (byte) 0, 42); Message m = Message.newMessage(mbox, tempFile, "woof@dog", Priority.NORMAL, null); m.storeInInbox(); assertFalse("temp file was not deleted", tempFile.exists()); VmMessage vm = m.getVmMessage(); File fwdWavFile = new File(m_testDir, "fwd.wav"); makeWaves(fwdWavFile, (byte) -1, 42); Message m2 = Message.newMessage(mbox, fwdWavFile, "knight@dog", Priority.NORMAL, null); VmMessage vm2 = vm.forward(mbox, m2); assertFalse("Message ID didn't change", vm.getMessageId().equals(vm2.getMessageId())); assertTrue("vmMessage wasn't created", vm2 != null); assertTrue("comments Audio File not created", vm2.m_audioFile.exists()); assertTrue("Descriptor File not created", vm2.m_descriptorFile.exists()); assertTrue("Status File not created", vm2.m_statusFile.exists()); assertTrue("Orig Descriptor File not created", vm2.m_originalDescriptorFile.exists()); assertTrue("Orig Audio File not created", vm2.m_originalAudioFile.exists()); assertTrue("Combined audio File not created", vm2.m_combinedAudioFile.exists()); assertFalse( "Subject didn't change", vm.m_messageDescriptor.getSubject().equals(vm2.m_messageDescriptor.getSubject())); File comment = new File(m_testDir, "comment.wav"); makeWaves(comment, (byte) -1, 42); Message m3 = Message.newMessage(mbox, comment, "knight@dog", Priority.NORMAL, null); VmMessage vm3 = vm.forward(mbox, m3); assertTrue("Combined audio File not created", vm3.m_combinedAudioFile.exists()); }
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); }