KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > command > MoveMessageTest


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

17 package org.columba.mail.folder.command;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21
22 import org.columba.core.command.NullWorkerStatusController;
23 import org.columba.mail.command.MailFolderCommandReference;
24 import org.columba.mail.folder.AbstractFolderTst;
25 import org.columba.mail.folder.FolderTstHelper;
26 import org.columba.mail.folder.IMailboxInfo;
27 import org.columba.mail.folder.MailboxTstFactory;
28
29 /**
30  * @author fdietz
31  */

32 public class MoveMessageTest extends AbstractFolderTst {
33
34     public MoveMessageTest(String JavaDoc arg0) {
35         super(arg0);
36     }
37     
38     /**
39      * @param arg0
40      */

41     public MoveMessageTest(MailboxTstFactory factory, String JavaDoc arg0) {
42         super(factory, arg0);
43     }
44
45     public void testMoveMessage() throws Exception JavaDoc {
46         // add message "0.eml" as inputstream to folder
47
String JavaDoc input = FolderTstHelper.getString(0);
48         System.out.println("input=" + input);
49         // create stream from string
50
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper.getByteArrayInputStream(input);
51         // add stream to folder
52
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
53
54 // create Command reference
55
MailFolderCommandReference ref = new MailFolderCommandReference(
56                 getSourceFolder(), getDestFolder(), new Object JavaDoc[] { uid });
57
58         // create copy command
59
MoveMessageCommand command = new MoveMessageCommand(ref);
60
61         // execute command -> use mock object class as worker which does nothing
62
command.execute(NullWorkerStatusController.getInstance());
63
64         // get inputstream of this message from folder
65
InputStream JavaDoc outputStream = destFolder.getMessageSourceStream(uid);
66         // create string from inputstream
67
String JavaDoc output = FolderTstHelper.getStringFromInputStream(outputStream);
68         // compare both messages
69
assertEquals(input, output);
70         IMailboxInfo info = getDestFolder().getMessageFolderInfo();
71         assertEquals("one message should be in destination folder", 1, info.getExists());
72         info = getSourceFolder().getMessageFolderInfo();
73         // close streams
74
inputStream.close();
75         outputStream.close();
76     }
77 }
78
Popular Tags