KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 public class AddMessageFolderTest extends AbstractFolderTst {
30
31   
32     public AddMessageFolderTest(String JavaDoc arg0) {
33         super(arg0);
34     }
35     /**
36      * Constructor for CachedMHFolderTest.
37      *
38      * @param arg0
39      */

40     public AddMessageFolderTest(MailboxTstFactory factory, String JavaDoc arg0) {
41         super(factory, arg0);
42     }
43
44     /**
45      * Add a message as InputStream to MHCachedFolder.
46      * <p>
47      * Check if message in folder is identical.
48      * <p>
49      * Check if total message count of folder was incremented correctly.
50      *
51      * @throws Exception
52      */

53     public void testAddMessage() throws Exception JavaDoc {
54
55         Object JavaDoc[] uids1 = getSourceFolder().getUids();
56         assertEquals("starting with empty folder", 0, uids1.length);
57
58         IMailboxInfo info1 = getSourceFolder().getMessageFolderInfo();
59         assertEquals("starting with empty folder", 0, info1.getExists());
60
61         // add message "0.eml" as inputstream to folder
62
String JavaDoc input = FolderTstHelper.getString(0);
63         System.out.println("input=" + input);
64
65         // create stream from string
66
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
67                 .getByteArrayInputStream(input);
68
69         // add stream to folder
70
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
71
72         // get inputstream of this message from folder
73
InputStream JavaDoc outputStream = sourceFolder.getMessageSourceStream(uid);
74
75         // create string from inputstream
76
String JavaDoc output = FolderTstHelper.getStringFromInputStream(outputStream);
77
78         // compare both messages
79
assertEquals("message source should be equal", input, output);
80
81         Object JavaDoc[] uids = getSourceFolder().getUids();
82         assertEquals("one message should be in this folder", 1, uids.length);
83
84         IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
85         assertEquals("message-folderinfo exists", 1, info.getExists());
86
87         // close streams
88
inputStream.close();
89         outputStream.close();
90     }
91
92     /**
93      * Check if MailFolderInfo is properly set based on message attributes.
94      * <p>
95      */

96     public void testAddAttributesTest() throws Exception JavaDoc {
97
98         Object JavaDoc[] uids1 = getSourceFolder().getUids();
99         assertEquals("starting with empty folder", 0, uids1.length);
100
101         IMailboxInfo info1 = getSourceFolder().getMessageFolderInfo();
102         assertEquals("starting with empty folder", 0, info1.getExists());
103
104         // add message "0.eml" as inputstream to folder
105
String JavaDoc input = FolderTstHelper.getString(0);
106         System.out.println("input=" + input);
107
108         // create stream from string
109
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
110                 .getByteArrayInputStream(input);
111
112         // add stream to folder
113
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
114         // mark message as read
115
getSourceFolder().markMessage(new Object JavaDoc[] {uid}, MarkMessageCommand.MARK_AS_READ);
116
117         IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
118
119         assertEquals("message-folderinfo exists", 1, info.getExists());
120         assertEquals("Number of unseen messages in folder", 0, info.getUnseen());
121
122         // close streams
123
inputStream.close();
124     }
125 }
126
Popular Tags