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.command;
017:
018: import java.io.ByteArrayInputStream;
019: import java.io.ByteArrayOutputStream;
020: import java.io.IOException;
021: import java.io.InputStream;
022: import java.io.OutputStreamWriter;
023:
024: import org.columba.core.command.NullWorkerStatusController;
025: import org.columba.mail.command.MailFolderCommandReference;
026: import org.columba.mail.folder.AbstractFolderTst;
027: import org.columba.mail.folder.AbstractMessageFolder;
028: import org.columba.mail.folder.MailboxTstFactory;
029:
030: /**
031: * @author redsolo
032: */
033: public class MarkFolderAsReadCommandTest extends AbstractFolderTst {
034:
035: public MarkFolderAsReadCommandTest(String arg0) {
036: super (arg0);
037: }
038:
039: /**
040: * @param factory folder factory
041: * @param test the name of the test
042: */
043: public MarkFolderAsReadCommandTest(MailboxTstFactory factory,
044: String test) {
045: super (factory, test);
046: }
047:
048: /**
049: * Test to mark a folder as read.
050: * @throws Exception thrown by the command itself.
051: */
052: public void testExecute() throws Exception {
053: AbstractMessageFolder folder = getSourceFolder();
054:
055: Object uid1 = folder.addMessage(createMessageStream("sub1",
056: "body1"));
057: Object uid2 = folder.addMessage(createMessageStream("sub2",
058: "body2"));
059: Object uid3 = folder.addMessage(createMessageStream("sub3",
060: "body3"));
061: Object uid4 = folder.addMessage(createMessageStream("sub4",
062: "body4"));
063: Object uid5 = folder.addMessage(createMessageStream("sub5",
064: "body5"));
065:
066: assertNotNull("Msg 1's uid was null", uid1);
067: assertNotNull("Msg 2's uid was null", uid2);
068: assertNotNull("Msg 3's uid was null", uid3);
069:
070: folder.markMessage(new Object[] { uid1, uid3, uid5 },
071: MarkMessageCommand.MARK_AS_UNREAD);
072: folder.markMessage(new Object[] { uid2, uid4 },
073: MarkMessageCommand.MARK_AS_READ);
074:
075: assertNotNull("Flags for msg 1 was null", folder.getFlags(uid1));
076: assertFalse("Msg 1 is read", folder.getFlags(uid1).getSeen());
077: assertNotNull("Flags for msg 2 was null", folder.getFlags(uid2));
078: assertTrue("Msg 2 is read", folder.getFlags(uid2).getSeen());
079: assertNotNull("Flags for msg 3 was null", folder.getFlags(uid3));
080: assertFalse("Msg 3 is read", folder.getFlags(uid3).getSeen());
081:
082: MailFolderCommandReference references = new MailFolderCommandReference(
083: folder);
084: MarkFolderAsReadCommand command = new MarkFolderAsReadCommand(
085: references);
086: command.execute(NullWorkerStatusController.getInstance());
087:
088: assertEquals("Message 1 isnt read", true, folder.getFlags(uid1)
089: .getSeen());
090: assertEquals("Message 2 isnt read", true, folder.getFlags(uid2)
091: .getSeen());
092: assertEquals("Message 3 isnt read", true, folder.getFlags(uid3)
093: .getSeen());
094: assertEquals("Message 4 isnt read", true, folder.getFlags(uid4)
095: .getSeen());
096: assertEquals("Message 5 isnt read", true, folder.getFlags(uid5)
097: .getSeen());
098: }
099:
100: /**
101: * Creates a inputstream as a valid email
102: * @param subject the subject of email
103: * @param body the body
104: * @return an input stream
105: * @throws IOException thrown if there is some real strange things with the writers
106: */
107: private InputStream createMessageStream(String subject, String body)
108: throws IOException {
109: ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
110: OutputStreamWriter writer = new OutputStreamWriter(outputStream);
111:
112: writer.write("Subject: " + subject + "\n");
113: writer.write("\n");
114: writer.write(body);
115:
116: return new ByteArrayInputStream(outputStream.toByteArray());
117: }
118:
119: }
|