1 19 20 package org.apache.james.mailboxmanager.torque; 21 22 import java.util.Date ; 23 import java.util.List ; 24 25 import javax.mail.Flags ; 26 import javax.mail.internet.MimeMessage ; 27 28 import org.apache.james.mailboxmanager.MessageResult; 29 import org.apache.james.mailboxmanager.TestUtil; 30 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl; 31 import org.apache.james.mailboxmanager.impl.MailboxListenerCollector; 32 import org.apache.james.mailboxmanager.torque.om.MailboxRow; 33 import org.apache.james.mailboxmanager.torque.om.MailboxRowPeer; 34 import org.apache.james.mailboxmanager.torque.om.MessageRow; 35 import org.apache.james.mailboxmanager.torque.om.MessageRowPeer; 36 import org.apache.james.mailboxmanager.tracking.UidChangeTracker; 37 import org.apache.torque.TorqueException; 38 import org.apache.torque.util.Criteria; 39 40 public class TorqueMailboxTestCase extends AbstractTorqueTestCase { 41 42 43 public TorqueMailboxTestCase() throws TorqueException { 44 super(); 45 } 46 47 public void testAppendGetDeleteMessage() throws Exception { 48 MailboxRow mr = new MailboxRow("#users.tuser.INBOX", 100); 49 mr.save(); 50 mr=MailboxRowPeer.retrieveByName("#users.tuser.INBOX"); 51 TorqueMailbox torqueMailbox = new TorqueMailbox(mr, new UidChangeTracker(null,"#users.tuser.INBOX",100),null); 52 torqueMailbox.addListener(new MailboxListenerCollector(), MessageResult.NOTHING); 53 assertEquals(0,torqueMailbox.getMessageCount()); 54 55 long time = System.currentTimeMillis(); 56 time = time - (time % 1000); 57 Date date = new Date (time); 58 MimeMessage mm=TestUtil.createMessage(); 59 Flags flags=new Flags (); 60 flags.add(Flags.Flag.ANSWERED); 61 flags.add(Flags.Flag.SEEN); 62 mm.setFlags(flags,true); 63 mm.writeTo(System.out); 64 torqueMailbox.appendMessage(mm, date, 0); 65 assertEquals(1,torqueMailbox.getMessageCount()); 66 List l = MessageRowPeer.doSelect(new Criteria()); 67 assertEquals(1, l.size()); 68 MessageRow msg = (MessageRow) l.get(0); 69 assertEquals(mr.getMailboxId(), msg.getMailboxId()); 70 assertEquals(1, msg.getUid()); 71 72 assertEquals(date, msg.getInternalDate()); 73 assertEquals(flags, msg.getMessageFlags().getFlagsObject()); 74 75 mr = MailboxRowPeer.retrieveByPK(mr.getMailboxId()); 76 assertEquals(1, mr.getLastUid()); 77 78 MessageResult[] messageResult=torqueMailbox.getMessages(GeneralMessageSetImpl.oneUid(1l),MessageResult.MIME_MESSAGE); 79 assertNotNull(messageResult); 80 assertEquals(1,messageResult.length); 81 messageResult[0].getMimeMessage().writeTo(System.out); 82 assertTrue(TorqueTestUtil.contentEquals(mm,messageResult[0].getMimeMessage(),true)); 83 84 Flags f=new Flags (); 85 f.add(Flags.Flag.DELETED); 86 torqueMailbox.setFlags(f,true,false, GeneralMessageSetImpl.oneUid(1l), null); 87 MessageResult[] messageResults=torqueMailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.UID); 88 assertEquals(1,messageResults.length); 89 assertEquals(1l,messageResults[0].getUid()); 90 } 91 92 } 93 | Popular Tags |