KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.james.imapserver.handler.session;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.mail.Flags JavaDoc;
25 import javax.mail.MessagingException JavaDoc;
26 import javax.mail.Flags.Flag;
27 import javax.mail.internet.MimeMessage JavaDoc;
28
29 import org.apache.james.imapserver.ProtocolException;
30 import org.apache.james.imapserver.client.FetchCommand;
31 import org.apache.james.imapserver.client.LoginCommand;
32 import org.apache.james.imapserver.client.SelectCommand;
33 import org.apache.james.imapserver.store.MailboxException;
34 import org.apache.james.imapserver.util.MessageGenerator;
35 import org.apache.james.mailboxmanager.MailboxManagerException;
36
37 public class UidFlagSizeFetchSessionTest extends AbstractSessionTest {
38     
39     String JavaDoc[] folders = {USER_MAILBOX_ROOT + ".INBOX",USER_MAILBOX_ROOT + ".test",USER_MAILBOX_ROOT + ".test1",USER_MAILBOX_ROOT + ".test1.test1a",USER_MAILBOX_ROOT + ".test1.test1b",USER_MAILBOX_ROOT + ".test2.test2a",USER_MAILBOX_ROOT + ".test2.test2b"};
40     String JavaDoc[] onlyInbox = {USER_MAILBOX_ROOT + ".INBOX"};
41     MimeMessage JavaDoc[] msgs= null;
42     long[] uids = null;
43     
44     public void setUp() throws MailboxException, MessagingException JavaDoc, IOException JavaDoc, MailboxManagerException {
45         super.setUp();
46         msgs=MessageGenerator.generateSimpleMessages(10);
47         createFolders(onlyInbox);
48         // increase the uid
49
appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs);
50         deleteAll(USER_MAILBOX_ROOT+".INBOX");
51         uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs);
52     }
53     
54     public void testEmptyFetchInRange() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
55         
56         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
57         verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
58         
59         verifyCommand(new FetchCommand(msgs,1,-1));
60         verifyCommand(new FetchCommand(msgs,1,5));
61         verifyCommand(new FetchCommand(msgs,5,-1));
62         verifyCommand(new FetchCommand(msgs,2,2));
63     }
64
65     public void testEmptyFetchOutOfRange() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
66         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
67         verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
68
69         verifyCommand(new FetchCommand(msgs,0,2));
70         verifyCommand(new FetchCommand(msgs,3,2));
71         verifyCommand(new FetchCommand(msgs,3,12));
72     }
73     
74     public void testFetchUids() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
75         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
76         verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
77         
78         FetchCommand fc=new FetchCommand(msgs,1,-1);
79         fc.setUids(uids);
80         verifyCommand(fc);
81
82     }
83     
84     public void testFetchUidsFlags() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
85         // Folder hast to be kept open for RECENT Flags
86
useFolder(USER_MAILBOX_ROOT+".INBOX");
87         appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",MessageGenerator.generateSimpleMessages(5));
88         setFlags(USER_MAILBOX_ROOT+".INBOX", 12, 12, new Flags JavaDoc(Flags.Flag.SEEN), true, false);
89         setFlags(USER_MAILBOX_ROOT+".INBOX", 14, 14, new Flags JavaDoc(Flags.Flag.SEEN), true, false);
90         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
91         uids=getUids(USER_MAILBOX_ROOT+".INBOX");
92         
93
94         
95         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
96         SelectCommand sc=new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"));
97         assertEquals(sc.getRecentCount(),5);
98         verifyCommand(sc);
99         
100         FetchCommand fc=new FetchCommand(msgs,1,-1);
101         fc.setUids(uids);
102         fc.setFetchFlags(true);
103         verifyCommand(fc);
104         freeFolder(USER_MAILBOX_ROOT+".INBOX");
105
106     }
107     
108     public void testRfc822Size() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
109         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
110         verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
111         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
112         FetchCommand fc=new FetchCommand(msgs,1,-1);
113         fc.setFetchRfc822Size(true);
114         verifyCommand(fc);
115     }
116     
117 }
118
Popular Tags