KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailboxmanager > AbstractMailboxManagerSelfTestCase


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.mailboxmanager;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
27 import org.apache.james.mailboxmanager.manager.MailboxManager;
28 import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
29
30 import junit.framework.TestCase;
31
32 public abstract class AbstractMailboxManagerSelfTestCase extends TestCase {
33     
34     protected MailboxManager mailboxManager;
35     protected MailboxManagerProvider mailboxManagerProvider;
36     
37     public void testCreateList() throws MailboxManagerException {
38         ListResult[] listResult;
39         listResult=mailboxManager.list("","*",false);
40         assertNotNull(listResult);
41         assertEquals(0,mailboxManager.list("","*",false).length);
42         Set JavaDoc boxes=new HashSet JavaDoc();
43         boxes.add("#users.joachim.INBOX");
44         boxes.add("#users.joachim.INBOX.Drafts");
45         boxes.add("#users.joachim2.INBOX");
46         for (Iterator JavaDoc iter = boxes.iterator(); iter.hasNext();) {
47             String JavaDoc box = (String JavaDoc) iter.next();
48             mailboxManager.createMailbox(box);
49         }
50         listResult=mailboxManager.list("","*",false);
51         assertEquals(3,listResult.length);
52         for (int i = 0; i < listResult.length; i++) {
53             assertTrue(boxes.contains(listResult[i].getName()));
54         }
55     }
56     
57     public void testGetSessionMailboxLife() throws MailboxManagerException {
58         final String JavaDoc folder="#users.joachim3.INBOX";
59         assertEquals(0, mailboxManagerProvider.getOpenMailboxSessionCountMap().size());
60         mailboxManager.createMailbox(folder);
61         GeneralMailboxSession sessionMailbox=mailboxManager.getGeneralMailboxSession(folder);
62         assertNotNull(sessionMailbox);
63         assertEquals(1, mailboxManagerProvider.getOpenMailboxSessionCountMap().size());
64         assertEquals(new Integer JavaDoc(1), mailboxManagerProvider.getOpenMailboxSessionCountMap().get(folder));
65         sessionMailbox.close();
66         assertEquals(0, mailboxManagerProvider.getOpenMailboxSessionCountMap().size());
67     }
68     
69     public void testListOne() throws MailboxManagerException {
70         mailboxManager.createMailbox("test1");
71         mailboxManager.createMailbox("INBOX");
72         mailboxManager.createMailbox("INBOX2");
73         
74         ListResult[] listResult=mailboxManager.list("","INBOX",false);
75         assertNotNull(listResult);
76         assertEquals(1, listResult.length);
77         assertEquals("INBOX", listResult[0].getName());
78     }
79
80 }
81
Popular Tags