001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.folder;
017:
018: import java.io.ByteArrayInputStream;
019: import java.io.InputStream;
020:
021: import org.columba.mail.folder.command.MarkMessageCommand;
022: import org.columba.ristretto.message.MailboxInfo;
023:
024: /**
025: * Add message to folder testcase.
026: *
027: * @author fdietz
028: */
029: public class AddMessageFolderTest extends AbstractFolderTst {
030:
031: public AddMessageFolderTest(String arg0) {
032: super (arg0);
033: }
034:
035: /**
036: * Constructor for CachedMHFolderTest.
037: *
038: * @param arg0
039: */
040: public AddMessageFolderTest(MailboxTstFactory factory, String arg0) {
041: super (factory, arg0);
042: }
043:
044: /**
045: * Add a message as InputStream to MHCachedFolder.
046: * <p>
047: * Check if message in folder is identical.
048: * <p>
049: * Check if total message count of folder was incremented correctly.
050: *
051: * @throws Exception
052: */
053: public void testAddMessage() throws Exception {
054:
055: Object[] uids1 = getSourceFolder().getUids();
056: assertEquals("starting with empty folder", 0, uids1.length);
057:
058: IMailboxInfo info1 = getSourceFolder().getMessageFolderInfo();
059: assertEquals("starting with empty folder", 0, info1.getExists());
060:
061: // add message "0.eml" as inputstream to folder
062: String input = FolderTstHelper.getString(0);
063: System.out.println("input=" + input);
064:
065: // create stream from string
066: ByteArrayInputStream inputStream = FolderTstHelper
067: .getByteArrayInputStream(input);
068:
069: // add stream to folder
070: Object uid = getSourceFolder().addMessage(inputStream);
071:
072: // get inputstream of this message from folder
073: InputStream outputStream = sourceFolder
074: .getMessageSourceStream(uid);
075:
076: // create string from inputstream
077: String output = FolderTstHelper
078: .getStringFromInputStream(outputStream);
079:
080: // compare both messages
081: assertEquals("message source should be equal", input, output);
082:
083: Object[] uids = getSourceFolder().getUids();
084: assertEquals("one message should be in this folder", 1,
085: uids.length);
086:
087: IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
088: assertEquals("message-folderinfo exists", 1, info.getExists());
089:
090: // close streams
091: inputStream.close();
092: outputStream.close();
093: }
094:
095: /**
096: * Check if MailFolderInfo is properly set based on message attributes.
097: * <p>
098: */
099: public void testAddAttributesTest() throws Exception {
100:
101: Object[] uids1 = getSourceFolder().getUids();
102: assertEquals("starting with empty folder", 0, uids1.length);
103:
104: IMailboxInfo info1 = getSourceFolder().getMessageFolderInfo();
105: assertEquals("starting with empty folder", 0, info1.getExists());
106:
107: // add message "0.eml" as inputstream to folder
108: String input = FolderTstHelper.getString(0);
109: System.out.println("input=" + input);
110:
111: // create stream from string
112: ByteArrayInputStream inputStream = FolderTstHelper
113: .getByteArrayInputStream(input);
114:
115: // add stream to folder
116: Object uid = getSourceFolder().addMessage(inputStream);
117: // mark message as read
118: getSourceFolder().markMessage(new Object[] { uid },
119: MarkMessageCommand.MARK_AS_READ);
120:
121: IMailboxInfo info = getSourceFolder().getMessageFolderInfo();
122:
123: assertEquals("message-folderinfo exists", 1, info.getExists());
124: assertEquals("Number of unseen messages in folder", 0, info
125: .getUnseen());
126:
127: // close streams
128: inputStream.close();
129: }
130: }
|