1 /* This program is free software: you can redistribute it and/or modify
2 * it under the terms of the GNU Affero General Public License as
3 * published by the Free Software Foundation, either version 3 of the
4 * License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU Affero General Public License for more details.
11 * You should have received a copy of the GNU Affero General Public License
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 package net
.bionicmessage
.funambol
.citadel
.store
;
17 import java
.io
.FileInputStream
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
20 import java
.util
.Properties
;
21 import org
.junit
.After
;
22 import org
.junit
.AfterClass
;
23 import org
.junit
.Before
;
24 import org
.junit
.BeforeClass
;
25 import org
.junit
.Test
;
26 import static org
.junit
.Assert
.*;
29 * A test class for the EmailObjectStore
32 public class EmailObjectStoreTest
{
34 Properties props
= null;
36 public EmailObjectStoreTest() {
40 public static void setUpClass() throws Exception
{
44 public static void tearDownClass() throws Exception
{
48 public void setUp() throws Exception
{
49 props
= new Properties();
50 /* Set up your config here */
51 File configFile
= new File("/home/matt/.emailobjectstore/eosprops");
52 FileInputStream confStream
= new FileInputStream(configFile
);
53 props
.load(confStream
);
57 public void tearDown() {
61 public void syncHeaderTest() throws Exception
{
62 props
.setProperty(CtdlFnblConstants
.PURGE_DB_OPTION
, "");
63 EmailObjectStore eos
= new EmailObjectStore(props
);
65 List
<String
> msgsInMail
= eos
.listMessagesInRoom("Mail");
66 Iterator
<String
> it
= msgsInMail
.iterator();
67 while (it
.hasNext()) {
68 String key
= it
.next();
69 CitadelMailObject cmo
= eos
.getMessageByPointer(key
);
70 System
.out
.format("Message %s, From: %s\n", key
, cmo
.getFrom()).flush();
76 public void syncAddBodies() throws Exception
{
77 EmailObjectStore eos
= new EmailObjectStore(props
);
79 List
<String
> msgsInMail
= eos
.listMessagesInRoom("Mail");
80 Iterator
<String
> it
= msgsInMail
.iterator();
81 while (it
.hasNext()) {
82 String key
= it
.next();
83 CitadelMailObject cmo
= eos
.getFilledMessageByPointer(key
);
84 System
.out
.format("Message %s, From: %s\n", key
, cmo
.getFrom()).flush();
85 System
.out
.format("Message body size: %d\n", cmo
.getData().length()).flush();
90 public void stillHaveBodies() throws Exception
{
91 System
.out
.println("stillHaveBodies()");
92 EmailObjectStore eos
= new EmailObjectStore(props
);
93 props
.remove(CtdlFnblConstants
.PURGE_DB_OPTION
);
95 List
<String
> msgsInMail
= eos
.listMessagesInRoom("Mail");
96 Iterator
<String
> it
= msgsInMail
.iterator();
97 while (it
.hasNext()) {
98 String key
= it
.next();
99 CitadelMailObject cmo
= eos
.getFilledMessageByPointer(key
);
100 System
.out
.println("Current key:"+key
);
101 if (!cmo
.hasData()) {
102 eos
.close(); // Keep the db intact
104 assertTrue(cmo
.hasData());
109 public void syncAddParts() throws Exception
{
110 EmailObjectStore eos
= new EmailObjectStore(props
);
112 List
<String
> msgsInMail
= eos
.listMessagesInRoom("Mail");
113 Iterator
<String
> it
= msgsInMail
.iterator();
114 while (it
.hasNext()) {
115 String key
= it
.next();
116 CitadelMailObject cmo
= eos
.getFilledMessageByPointer(key
);
117 eos
.fillPartsForMessage(cmo
);
118 System
.out
.println("Object "+key
+ " has "+cmo
.getAttachedParts().size() + " attached parts");