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.InputStream;
020:
021: import org.columba.core.command.NullWorkerStatusController;
022: import org.columba.mail.command.MailFolderCommandReference;
023: import org.columba.mail.folder.AbstractFolderTst;
024: import org.columba.mail.folder.FolderTstHelper;
025: import org.columba.mail.folder.IMailboxInfo;
026: import org.columba.mail.folder.MailboxTstFactory;
027: import org.columba.ristretto.message.Flags;
028:
029: /**
030: * @author fdietz
031: *
032: */
033: public class CopyMessageCommandTest extends AbstractFolderTst {
034:
035: public CopyMessageCommandTest(String arg0) {
036: super (arg0);
037: }
038:
039: /**
040: * @param arg0
041: */
042: public CopyMessageCommandTest(MailboxTstFactory factory, String arg0) {
043: super (factory, arg0);
044: }
045:
046: /**
047: * Copy message using a {@link CopyMessageCommand}.
048: *
049: * @throws Exception
050: */
051: public void testCopyMessage() throws Exception {
052: // add message "0.eml" as inputstream to folder
053: String input = FolderTstHelper.getString(0);
054: System.out.println("input=" + input);
055: // create stream from string
056: ByteArrayInputStream inputStream = FolderTstHelper
057: .getByteArrayInputStream(input);
058: // add stream to folder
059: Object uid = getSourceFolder().addMessage(inputStream);
060:
061: // create Command reference
062: MailFolderCommandReference ref = new MailFolderCommandReference(
063: getSourceFolder(), getDestFolder(),
064: new Object[] { uid });
065:
066: // create copy command
067: CopyMessageCommand command = new CopyMessageCommand(ref);
068:
069: // execute command -> use mock object class as worker which does
070: // nothing
071: command.execute(NullWorkerStatusController.getInstance());
072:
073: // get inputstream of this message from folder
074: InputStream outputStream = destFolder
075: .getMessageSourceStream(uid);
076: // create string from inputstream
077: String output = FolderTstHelper
078: .getStringFromInputStream(outputStream);
079: // compare both messages
080: assertEquals(input, output);
081: Object[] uids = getDestFolder().getUids();
082: assertEquals("one message should be in destination folder", 1,
083: uids.length);
084: IMailboxInfo info = getDestFolder().getMessageFolderInfo();
085: assertEquals("one message should be in destination folder", 1,
086: info.getExists());
087: // close streams
088: inputStream.close();
089: outputStream.close();
090: }
091:
092: /**
093: * Copy message using a {@link CopyMessageCommand}and check if attributes
094: * are copied correctly.
095: *
096: * @throws Exception
097: */
098: public void testCopyMessageAttribute() throws Exception {
099: // add message "0.eml" as inputstream to folder
100: String input = FolderTstHelper.getString(0);
101: System.out.println("input=" + input);
102: // create stream from string
103: ByteArrayInputStream inputStream = FolderTstHelper
104: .getByteArrayInputStream(input);
105: // add stream to folder
106: Object uid = getSourceFolder().addMessage(inputStream);
107: // get flags of message
108: Flags oldFlags = getSourceFolder().getFlags(uid);
109: // set flags
110: oldFlags.setSeen(false);
111: /*
112: * oldFlags.setRecent(true); oldFlags.setFlagged(true);
113: * oldFlags.setExpunged(false);
114: */
115:
116: // create Command reference
117: MailFolderCommandReference ref = new MailFolderCommandReference(
118: getSourceFolder(), getDestFolder(),
119: new Object[] { uid });
120:
121: // create copy command
122: CopyMessageCommand command = new CopyMessageCommand(ref);
123:
124: // execute command -> use mock object class as worker which does
125: // nothing
126: command.execute(NullWorkerStatusController.getInstance());
127:
128: Flags flags = getDestFolder().getFlags(uid);
129:
130: assertEquals("copied message should be marked as not seen",
131: false, flags.getSeen());
132: /*
133: * assertEquals("copied message should be marked as recent", true, flags
134: * .getRecent()); assertEquals("copied message should be marked as
135: * flagged", true, flags .getFlagged()); assertEquals("copied message
136: * should be marked as not expunged", false, flags.getExpunged());
137: */
138: // close streams
139: inputStream.close();
140:
141: }
142:
143: }
|