01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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.mbox;
18:
19: import java.io.ByteArrayInputStream;
20:
21: import junit.framework.TestCase;
22:
23: import org.columba.mail.folder.MHFolderFactory;
24: import org.columba.ristretto.io.Source;
25:
26: public class MboxDataStorageTest extends TestCase {
27:
28: private static final String mail1 = "From: alice1@columba-mail.org\r\nTo: bob@columba-mail.org\r\n\r\ntest 1 mail";
29: private static final String mail2 = "From: alice2@columba-mail.org\r\nTo: bob@columba-mail.org\r\n\r\ntest 2 mail";
30: private static final String mail3 = "From: alice3@columba-mail.org\r\nTo: bob@columba-mail.org\r\n\r\ntest 3 mail";
31:
32: public void testSaveMessage() throws Exception {
33: MboxDataStorage storage = new MboxDataStorage(
34: new MHFolderFactory().createFolder(100));
35:
36: storage.saveMessage(new Integer(1), new ByteArrayInputStream(
37: mail1.getBytes("US-ASCII")));
38:
39: Source source = storage.getMessageSource(new Integer(1));
40:
41: assertEquals(mail1, source.toString());
42:
43: storage.removeMessage(new Integer(1));
44:
45: assertFalse(storage.exists(new Integer(1)));
46: assertEquals(storage.getMessageCount(), 0);
47: }
48:
49: public void testSaveMultipleMessages() throws Exception {
50: MboxDataStorage storage = new MboxDataStorage(
51: new MHFolderFactory().createFolder(100));
52:
53: storage.saveMessage(new Integer(1), new ByteArrayInputStream(
54: mail1.getBytes("US-ASCII")));
55: storage.saveMessage(new Integer(2), new ByteArrayInputStream(
56: mail2.getBytes("US-ASCII")));
57:
58: Source source = storage.getMessageSource(new Integer(1));
59: assertEquals(mail1, source.toString());
60: source = null;
61:
62: storage.saveMessage(new Integer(3), new ByteArrayInputStream(
63: mail3.getBytes("US-ASCII")));
64:
65: storage.removeMessage(new Integer(1));
66: storage.removeMessage(new Integer(3));
67:
68: source = storage.getMessageSource(new Integer(2));
69: assertEquals(mail2, source.toString());
70: }
71:
72: public void testLoadSave() throws Exception {
73: MboxDataStorage storage = new MboxDataStorage(
74: new MHFolderFactory().createFolder(100));
75:
76: storage.saveMessage(new Integer(1), new ByteArrayInputStream(
77: mail1.getBytes("US-ASCII")));
78: storage.saveMessage(new Integer(2), new ByteArrayInputStream(
79: mail2.getBytes("US-ASCII")));
80:
81: storage.save();
82:
83: storage.load();
84: Source source = storage.getMessageSource(new Integer(1));
85: assertEquals(mail1, source.toString());
86:
87: }
88:
89: }
|