KickJava   Java API By Example, From Geeks To Geeks.

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


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.internet.MimeMessage JavaDoc;
27
28 import org.apache.james.imapserver.ProtocolException;
29 import org.apache.james.imapserver.client.LoginCommand;
30 import org.apache.james.imapserver.client.SelectCommand;
31 import org.apache.james.imapserver.client.StatusClientCommand;
32 import org.apache.james.imapserver.store.MailboxException;
33 import org.apache.james.imapserver.util.MessageGenerator;
34 import org.apache.james.mailboxmanager.MailboxManagerException;
35
36 public class StatusSessionTest extends AbstractSessionTest {
37     
38     String JavaDoc[] folders = {USER_INBOX,USER_MAILBOX_ROOT+".f2"};
39     MimeMessage JavaDoc[] f2_msgs= null;
40     MimeMessage JavaDoc[] inbox_msgs= new MimeMessage JavaDoc[0];
41     
42     boolean setup=false;
43     private long f2_uidV;
44     private long f2_uidNext;
45     
46     public void setUp() throws MailboxManagerException, MailboxException, MessagingException JavaDoc, IOException JavaDoc {
47         super.setUp();
48         f2_msgs=MessageGenerator.generateSimpleMessages(4);
49         createFolders(folders);
50         appendMessagesClosed(folders[1], new MimeMessage JavaDoc[]{f2_msgs[0]});
51         f2_msgs[1].setFlag(Flags.Flag.SEEN, true);
52         f2_msgs[2].setFlag(Flags.Flag.SEEN, true);
53         addUIDMessagesOpen(folders[1], new MimeMessage JavaDoc[]{f2_msgs[1],f2_msgs[2],f2_msgs[3]});
54         f2_uidV = getUidValidity(folders[1]);
55         f2_uidNext = getUidNext(folders[1]);
56     }
57     
58     protected void doTestStatus() throws MessagingException JavaDoc, ProtocolException, IOException JavaDoc {
59         StatusClientCommand statusCommand;
60         
61         // Empty
62
statusCommand = new StatusClientCommand(folders[1],f2_msgs,f2_uidNext,f2_uidV);
63         verifyCommand(statusCommand);
64
65         // One
66
statusCommand = new StatusClientCommand(folders[1],f2_msgs,f2_uidNext,f2_uidV);
67         statusCommand.setStatusMessages(true);
68         verifyCommand(statusCommand);
69         
70         // Some
71
statusCommand = new StatusClientCommand(folders[1],f2_msgs,f2_uidNext,f2_uidV);
72         statusCommand.setStatusMessages(true);
73         statusCommand.setStatusUidNext(true);
74         verifyCommand(statusCommand);
75         
76         // All
77
statusCommand = new StatusClientCommand(folders[1],f2_msgs,f2_uidNext,f2_uidV);
78         statusCommand.setStatusMessages(true);
79         statusCommand.setStatusRecent(true);
80         statusCommand.setStatusUidNext(true);
81         statusCommand.setStatusUidValidity(true);
82         statusCommand.setStatusUnseen(true);
83         verifyCommand(statusCommand);
84     }
85
86     
87     public void testStatusAuthState() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc {
88         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
89         doTestStatus();
90     }
91     
92     
93     public void testStatusSelectedState() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc {
94         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
95         verifyCommand(new SelectCommand("INBOX", inbox_msgs, getUidValidity(USER_INBOX)));
96         doTestStatus();
97     }
98     
99
100 }
101
Popular Tags