KickJava   Java API By Example, From Geeks To Geeks.

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


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.MessagingException JavaDoc;
25 import javax.mail.internet.MimeMessage JavaDoc;
26
27 import org.apache.james.imapserver.ProtocolException;
28 import org.apache.james.imapserver.client.FetchCommand;
29 import org.apache.james.imapserver.client.LoginCommand;
30 import org.apache.james.imapserver.client.SelectCommand;
31 import org.apache.james.imapserver.client.fetch.FetchBody;
32 import org.apache.james.imapserver.client.fetch.FetchHeader;
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 /**
38  *
39  *
40  *
41  * TODO test one message number instead of message sets (1 instead of 1:1)
42  *
43  */

44
45 public class BodyFetchSessionTest extends AbstractSessionTest {
46     
47     String JavaDoc[] onlyInbox = {USER_MAILBOX_ROOT+".INBOX"};
48     MimeMessage JavaDoc[] msgs= null;
49     long[] uids = null;
50     
51     public void setUp() throws MailboxException, MessagingException JavaDoc, IOException JavaDoc, MailboxManagerException {
52         super.setUp();
53         msgs=MessageGenerator.generateSimpleMessages(4);
54         createFolders(onlyInbox);
55         // increase the uid
56
appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs);
57         deleteAll(USER_MAILBOX_ROOT+".INBOX");
58         uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs);
59     }
60     
61     
62     public void testFetchCompleteAndSize() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
63         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
64         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
65         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
66         
67         FetchCommand fc=new FetchCommand(msgs,1,-1);
68         fc.setFetchRfc822Size(true);
69         fc.setFetchBody(new FetchBody(true));
70         // TODO test \Seen get's not set because of peek and vice versa
71
verifyCommandOrdered(fc);
72     }
73     public void testFetchCompleteHeaderAndSize() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
74         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
75         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
76         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
77         FetchCommand fc=new FetchCommand(msgs,1,-1);
78         fc.setFetchRfc822Size(true);
79         FetchBody fetchBody=new FetchBody(true);
80         fetchBody.setFetchHeader(new FetchHeader());
81         fc.setFetchBody(fetchBody);
82         verifyCommandOrdered(fc);
83     }
84     public void testFetchSomeExistingHeaderAndSize() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
85         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
86         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
87         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
88         FetchCommand fc=new FetchCommand(msgs,1,-1);
89         fc.setFetchRfc822Size(true);
90         FetchHeader fetchHeader=new FetchHeader();
91         fetchHeader.setFields(new String JavaDoc[] {"Date","From","To"});
92         FetchBody fetchBody=new FetchBody(true);
93         fetchBody.setFetchHeader(fetchHeader);
94         fc.setFetchBody(fetchBody);
95         verifyCommandOrdered(fc);
96     }
97     public void testFetchSomeNonExistingHeaderAndSize() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
98         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
99         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
100         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
101         FetchCommand fc=new FetchCommand(msgs,1,-1);
102         fc.setFetchRfc822Size(true);
103         FetchHeader fetchHeader=new FetchHeader();
104         fetchHeader.setFields(new String JavaDoc[] {"Blob","Test","Oh"});
105         FetchBody fetchBody=new FetchBody(true);
106         fetchBody.setFetchHeader(fetchHeader);
107         fc.setFetchBody(fetchBody);
108         verifyCommandOrdered(fc);
109     }
110     public void testFetchSomeNoneAndExistingHeaderAndSize() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
111         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
112         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
113         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
114         FetchCommand fc=new FetchCommand(msgs,1,-1);
115         fc.setFetchRfc822Size(true);
116         FetchHeader fetchHeader=new FetchHeader();
117         fetchHeader.setFields(new String JavaDoc[] {"To","Message-ID","Blob","Test","Oh"});
118         FetchBody fetchBody=new FetchBody(true);
119         fetchBody.setFetchHeader(fetchHeader);
120         fc.setFetchBody(fetchBody);
121         verifyCommandOrdered(fc);
122     }
123
124     
125     public void testFetchSomeExistingHeader() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
126         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
127         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
128         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
129         
130         FetchCommand fc=new FetchCommand(msgs,1,-1);
131         FetchHeader fetchHeader=new FetchHeader();
132         fetchHeader.setFields(new String JavaDoc[] {"Date","From","To"});
133         FetchBody fetchBody=new FetchBody(true);
134         fetchBody.setFetchHeader(fetchHeader);
135         fc.setFetchBody(fetchBody);
136         verifyCommandOrdered(fc);
137     }
138
139     public void testFetchBodyNoParenthesisOneSeqNumber() throws ProtocolException, IOException JavaDoc, MessagingException JavaDoc, MailboxManagerException {
140         verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD));
141         verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")));
142         msgs=getMessages(USER_MAILBOX_ROOT+".INBOX");
143         
144         FetchCommand fc=new FetchCommand(msgs,1);
145         fc.setFetchBody(new FetchBody(true));
146         fc.setUseParenthesis(false);
147         verifyCommandOrdered(fc);
148         
149     }
150 }
151
Popular Tags