KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > ExpungeFolderTest


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21
22 import org.columba.mail.folder.command.MarkMessageCommand;
23 import org.columba.ristretto.message.Flags;
24
25 /**
26  * @author fdietz
27  *
28  */

29 public class ExpungeFolderTest extends AbstractFolderTst {
30
31     public ExpungeFolderTest(String JavaDoc arg0) {
32         super(arg0);
33     }
34     
35     /**
36      * @param arg0
37      */

38     public ExpungeFolderTest(MailboxTstFactory factory, String JavaDoc arg0) {
39         super(factory, arg0);
40
41     }
42
43     /**
44      * Expunge folder, message is *not* marked as expunged
45      *
46      * @throws Exception
47      */

48     public void testExpungeMessage() throws Exception JavaDoc {
49         // add message "0.eml" as inputstream to folder
50
String JavaDoc input = FolderTstHelper.getString(0);
51         System.out.println("input=" + input);
52         // create stream from string
53
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
54                 .getByteArrayInputStream(input);
55         // add stream to folder
56
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
57         // get flags of message
58
Flags oldFlags = getSourceFolder().getFlags(uid);
59         // set flags
60
oldFlags.setSeen(false);
61         oldFlags.setRecent(true);
62         oldFlags.setFlagged(true);
63         oldFlags.setDeleted(false);
64
65         getSourceFolder().expungeFolder();
66
67         Object JavaDoc[] uids = getSourceFolder().getUids();
68         assertEquals("one message should be in source folder", 1, uids.length);
69         IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
70         assertEquals("one message should be in source folder", 1, info
71                 .getExists());
72         // close streams
73
inputStream.close();
74     }
75
76     /**
77      * Expunge folder, one message is marked as expunged
78      *
79      * @throws Exception
80      */

81     public void testExpungeMessage2() throws Exception JavaDoc {
82         // add message "0.eml" as inputstream to folder
83
String JavaDoc input = FolderTstHelper.getString(0);
84         System.out.println("input=" + input);
85         // create stream from string
86
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
87                 .getByteArrayInputStream(input);
88         // add stream to folder
89
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
90
91         getSourceFolder().markMessage(new Object JavaDoc[] {uid}, MarkMessageCommand.MARK_AS_EXPUNGED);
92         
93         getSourceFolder().expungeFolder();
94
95         Object JavaDoc[] uids = getSourceFolder().getUids();
96         assertEquals("null message should be in source folder", 0, uids.length);
97         IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
98         assertEquals("null message should be in source folder", 0, info
99                 .getExists());
100         // close streams
101
inputStream.close();
102     }
103 }
104
Popular Tags