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 testConcatAudio() throws Exception { File first = new File(m_testDir, "first.wav"); makeWaves(first, (byte) 0, 4); File second = new File(m_testDir, "second.wav"); makeWaves(second, (byte) -1, 4); File combined = new File(m_testDir, "combined.wav"); VmMessage.concatAudio(combined, first, second); assertTrue("combined.wav doesn't exist", combined.exists()); AudioInputStream ais = AudioSystem.getAudioInputStream(combined); byte[] octets = new byte[42]; int len = ais.read(octets); assertEquals(8, len); assertEquals(0, octets[0]); assertEquals(-1, octets[4]); }
public void testGetInbox() { Messages m = new Messages(); m.m_inbox = new HashMap<String, VmMessage>(); long timestamp = System.currentTimeMillis(); String id; VmMessage m1 = VmMessage.testMessage(id = "woof", false, timestamp); m.m_inbox.put(id, m1); VmMessage m2 = VmMessage.testMessage(id = "dog", false, timestamp + 1000); m.m_inbox.put(id, m2); VmMessage m3 = VmMessage.testMessage(id = "cat", false, timestamp + 2000); m.m_inbox.put(id, m3); VmMessage m4 = VmMessage.testMessage(id = "firstHeard", false, timestamp - 1000); m.m_inbox.put(id, m4); List<VmMessage> l = m.getInbox(); assertEquals("firstHeard", l.get(0).getMessageId()); assertEquals("woof", l.get(1).getMessageId()); assertEquals("dog", l.get(2).getMessageId()); assertEquals("cat", l.get(3).getMessageId()); VmMessage m5 = VmMessage.testMessage(id = "firstUnheard", true, timestamp + 3000); m.m_inbox.put(id, m5); VmMessage m6 = VmMessage.testMessage(id = "lastUnheard", true, timestamp + 5000); m.m_inbox.put(id, m6); VmMessage m7 = VmMessage.testMessage(id = "nextUnheard", true, timestamp + 4000); m.m_inbox.put(id, m7); l = m.getInbox(); assertEquals("firstUnheard", l.get(0).getMessageId()); assertEquals("nextUnheard", l.get(1).getMessageId()); assertEquals("lastUnheard", l.get(2).getMessageId()); assertEquals("firstHeard", l.get(3).getMessageId()); assertEquals("woof", l.get(4).getMessageId()); assertEquals("dog", l.get(5).getMessageId()); assertEquals("cat", l.get(6).getMessageId()); }
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); }