KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > CopyMessageFolderTest


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18

19 package org.columba.mail.folder;
20
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 import org.columba.ristretto.message.Attributes;
25 import org.columba.ristretto.message.Flags;
26
27 /**
28  * @author fdietz
29  */

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

39     public CopyMessageFolderTest(MailboxTstFactory factory, String JavaDoc arg0) {
40         super(factory, arg0);
41     }
42
43    
44
45     /**
46      * Copy message and check if attributes are copied correctly.
47      * <p>
48      * Use Folder.addMessage(InputStream, Attributes), instead of
49      * CopyMessageCommand.
50      *
51      * @throws Exception
52      */

53     public void testCopyMessageAttribute2() throws Exception JavaDoc {
54         // add message "0.eml" as inputstream to folder
55
String JavaDoc input = FolderTstHelper.getString(0);
56         System.out.println("input=" + input);
57         // create stream from string
58
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
59                 .getByteArrayInputStream(input);
60
61         // add stream to folder
62
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
63         // close streams
64
inputStream.close();
65         // get flags of message
66
Flags oldFlags = getSourceFolder().getFlags(uid);
67         // set flags
68
oldFlags.setSeen(false);
69         oldFlags.setRecent(false);
70         oldFlags.setFlagged(true);
71         oldFlags.setDeleted(false);
72
73         // get message source stream
74
InputStream JavaDoc is = getSourceFolder().getMessageSourceStream(uid);
75         // get message attributes
76
Attributes attributes = getSourceFolder().getAttributes(uid);
77         
78         uid = getDestFolder().addMessage(is, attributes, oldFlags);
79
80         // close inpustream
81
is.close();
82
83         Flags flags = getDestFolder().getFlags(uid);
84
85         assertEquals("copied message should be marked as not seen", false,
86                 flags.getSeen());
87         assertEquals("copied message should be marked as flagged", true, flags
88                 .getFlagged());
89         assertEquals("copied message should be marked as not expunged", false,
90                 flags.getDeleted());
91         // close streams
92
inputStream.close();
93
94     }
95 }
96
Popular Tags