1 19 20 21 package org.apache.james.imapserver.handler.session; 22 23 import java.io.IOException ; 24 import java.util.Arrays ; 25 import java.util.Collection ; 26 27 import javax.mail.Flags ; 28 import javax.mail.MessagingException ; 29 import javax.mail.internet.MimeMessage ; 30 31 import org.apache.james.imapserver.ProtocolException; 32 import org.apache.james.imapserver.client.ExpungeClientCommand; 33 import org.apache.james.imapserver.client.LoginCommand; 34 import org.apache.james.imapserver.client.SelectCommand; 35 import org.apache.james.imapserver.store.MailboxException; 36 import org.apache.james.imapserver.util.MessageGenerator; 37 import org.apache.james.mailboxmanager.MailboxManagerException; 38 import org.apache.james.mailboxmanager.TestUtil; 39 40 public class ExpungeSessionTest extends AbstractSessionTest { 41 42 String [] onlyInbox = { USER_INBOX }; 43 44 MimeMessage [] msgs = null; 45 46 long[] uids = null; 47 48 public void setUp() throws MailboxException, MessagingException , 49 IOException , MailboxManagerException { 50 super.setUp(); 51 createFolders(onlyInbox); 52 } 53 54 public void testExpungeOneMessage() throws MessagingException , 55 MailboxManagerException, ProtocolException, IOException { 56 msgs = MessageGenerator.generateSimpleMessages(1); 57 msgs[0].setFlag(Flags.Flag.DELETED, true); 58 addUIDMessagesOpen(USER_INBOX, msgs); 59 verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD)); 60 verifyCommand(new SelectCommand("INBOX", msgs, 61 getUidValidity(USER_INBOX))); 62 verifyCommandOrdered(new ExpungeClientCommand(msgs)); 63 assertEquals(0,getMessages(USER_INBOX).length); 64 } 65 66 public void testExpunge3Messages() throws MessagingException , 67 MailboxManagerException, ProtocolException, IOException { 68 msgs = MessageGenerator.generateSimpleMessages(3); 69 msgs[0].setFlag(Flags.Flag.DELETED, true); 70 msgs[1].setFlag(Flags.Flag.DELETED, true); 71 msgs[2].setFlag(Flags.Flag.DELETED, true); 72 addUIDMessagesOpen(USER_INBOX, msgs); 73 verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD)); 74 verifyCommand(new SelectCommand("INBOX", msgs, 75 getUidValidity(USER_INBOX))); 76 verifyCommandOrdered(new ExpungeClientCommand(msgs)); 77 assertEquals(0,getMessages(USER_INBOX).length); 78 } 79 80 public void testExpunge4Of6Messages() throws MessagingException , 81 MailboxManagerException, ProtocolException, IOException { 82 msgs = MessageGenerator.generateSimpleMessages(6); 83 msgs[0].setFlag(Flags.Flag.DELETED, true); 84 msgs[2].setFlag(Flags.Flag.DELETED, true); 85 msgs[3].setFlag(Flags.Flag.DELETED, true); 86 msgs[5].setFlag(Flags.Flag.DELETED, true); 87 addUIDMessagesOpen(USER_INBOX, msgs); 88 verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD)); 89 verifyCommand(new SelectCommand("INBOX", msgs, 90 getUidValidity(USER_INBOX))); 91 verifyCommandOrdered(new ExpungeClientCommand(msgs)); 92 MimeMessage [] currentMsgs=getMessages(USER_INBOX); 93 assertEquals(2,currentMsgs.length); 94 Collection existing=Arrays.asList(currentMsgs); 95 Collection expected=Arrays.asList(new MimeMessage [] {msgs[1],msgs[4]}); 96 assertTrue(TestUtil.messageSetsEqual(existing,expected)); 97 } 98 } 99 | Popular Tags |