KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > handler > session > ExpungeSessionTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20
21 package org.apache.james.imapserver.handler.session;
22
23 import java.io.IOException JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import javax.mail.Flags JavaDoc;
28 import javax.mail.MessagingException JavaDoc;
29 import javax.mail.internet.MimeMessage JavaDoc;
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 JavaDoc[] onlyInbox = { USER_INBOX };
43
44     MimeMessage JavaDoc[] msgs = null;
45
46     long[] uids = null;
47
48     public void setUp() throws MailboxException, MessagingException JavaDoc,
49             IOException JavaDoc, MailboxManagerException {
50         super.setUp();
51         createFolders(onlyInbox);
52     }
53
54     public void testExpungeOneMessage() throws MessagingException JavaDoc,
55             MailboxManagerException, ProtocolException, IOException JavaDoc {
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 JavaDoc,
67             MailboxManagerException, ProtocolException, IOException JavaDoc {
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 JavaDoc,
81             MailboxManagerException, ProtocolException, IOException JavaDoc {
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 JavaDoc[] currentMsgs=getMessages(USER_INBOX);
93         assertEquals(2,currentMsgs.length);
94         Collection JavaDoc existing=Arrays.asList(currentMsgs);
95         Collection JavaDoc expected=Arrays.asList(new MimeMessage JavaDoc[] {msgs[1],msgs[4]});
96         assertTrue(TestUtil.messageSetsEqual(existing,expected));
97     }
98 }
99
Popular Tags