KickJava   Java API By Example, From Geeks To Geeks.

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


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.command;
17
18 import java.io.ByteArrayInputStream JavaDoc;
19 import java.io.InputStream JavaDoc;
20
21 import org.columba.core.command.NullWorkerStatusController;
22 import org.columba.mail.command.MailFolderCommandReference;
23 import org.columba.mail.folder.AbstractFolderTst;
24 import org.columba.mail.folder.FolderTstHelper;
25 import org.columba.mail.folder.IMailboxInfo;
26 import org.columba.mail.folder.MailboxTstFactory;
27 import org.columba.ristretto.message.Flags;
28
29 /**
30  * @author fdietz
31  *
32  */

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

42     public CopyMessageCommandTest(MailboxTstFactory factory, String JavaDoc arg0) {
43         super(factory, arg0);
44     }
45
46     /**
47      * Copy message using a {@link CopyMessageCommand}.
48      *
49      * @throws Exception
50      */

51     public void testCopyMessage() throws Exception JavaDoc {
52         // add message "0.eml" as inputstream to folder
53
String JavaDoc input = FolderTstHelper.getString(0);
54         System.out.println("input=" + input);
55         // create stream from string
56
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
57                 .getByteArrayInputStream(input);
58         // add stream to folder
59
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
60
61         // create Command reference
62
MailFolderCommandReference ref = new MailFolderCommandReference(
63                 getSourceFolder(), getDestFolder(), new Object JavaDoc[] { uid });
64
65         // create copy command
66
CopyMessageCommand command = new CopyMessageCommand(ref);
67
68         // execute command -> use mock object class as worker which does
69
// nothing
70
command.execute(NullWorkerStatusController.getInstance());
71
72         // get inputstream of this message from folder
73
InputStream JavaDoc outputStream = destFolder.getMessageSourceStream(uid);
74         // create string from inputstream
75
String JavaDoc output = FolderTstHelper.getStringFromInputStream(outputStream);
76         // compare both messages
77
assertEquals(input, output);
78         Object JavaDoc[] uids = getDestFolder().getUids();
79         assertEquals("one message should be in destination folder", 1,
80                 uids.length);
81         IMailboxInfo info = getDestFolder().getMessageFolderInfo();
82         assertEquals("one message should be in destination folder", 1, info
83                 .getExists());
84         // close streams
85
inputStream.close();
86         outputStream.close();
87     }
88
89     /**
90      * Copy message using a {@link CopyMessageCommand}and check if attributes
91      * are copied correctly.
92      *
93      * @throws Exception
94      */

95     public void testCopyMessageAttribute() throws Exception JavaDoc {
96         // add message "0.eml" as inputstream to folder
97
String JavaDoc input = FolderTstHelper.getString(0);
98         System.out.println("input=" + input);
99         // create stream from string
100
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
101                 .getByteArrayInputStream(input);
102         // add stream to folder
103
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
104         // get flags of message
105
Flags oldFlags = getSourceFolder().getFlags(uid);
106         // set flags
107
oldFlags.setSeen(false);
108         /*
109          * oldFlags.setRecent(true); oldFlags.setFlagged(true);
110          * oldFlags.setExpunged(false);
111          */

112
113         // create Command reference
114
MailFolderCommandReference ref = new MailFolderCommandReference(
115                 getSourceFolder(), getDestFolder(), new Object JavaDoc[] { uid });
116
117         // create copy command
118
CopyMessageCommand command = new CopyMessageCommand(ref);
119
120         // execute command -> use mock object class as worker which does
121
// nothing
122
command.execute(NullWorkerStatusController.getInstance());
123
124         Flags flags = getDestFolder().getFlags(uid);
125
126         assertEquals("copied message should be marked as not seen", false,
127                 flags.getSeen());
128         /*
129          * assertEquals("copied message should be marked as recent", true, flags
130          * .getRecent()); assertEquals("copied message should be marked as
131          * flagged", true, flags .getFlagged()); assertEquals("copied message
132          * should be marked as not expunged", false, flags.getExpunged());
133          */

134         // close streams
135
inputStream.close();
136
137     }
138
139 }
Popular Tags