Sync up to the latest version of my source code
[funambol-citadel-connector.git] / funambol-citadel-connector / src / test / java / net / bionicmessage / funambol / citadel / store / EmailObjectStoreTest.java
bloba6e67eaf5a3a42614a2552d4fd7b376549143633
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;
16 import java.io.File;
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.*;
28 /**
29 * A test class for the EmailObjectStore
30 * @author matt
32 public class EmailObjectStoreTest {
34 Properties props = null;
36 public EmailObjectStoreTest() {
39 @BeforeClass
40 public static void setUpClass() throws Exception {
43 @AfterClass
44 public static void tearDownClass() throws Exception {
47 @Before
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);
56 @After
57 public void tearDown() {
60 @Test
61 public void syncHeaderTest() throws Exception {
62 props.setProperty(CtdlFnblConstants.PURGE_DB_OPTION, "");
63 EmailObjectStore eos = new EmailObjectStore(props);
64 eos.startSync(0);
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();
72 eos.close();
75 @Test
76 public void syncAddBodies() throws Exception {
77 EmailObjectStore eos = new EmailObjectStore(props);
78 eos.startSync(0);
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();
87 eos.close();
89 @Test
90 public void stillHaveBodies() throws Exception {
91 System.out.println("stillHaveBodies()");
92 EmailObjectStore eos = new EmailObjectStore(props);
93 props.remove(CtdlFnblConstants.PURGE_DB_OPTION);
94 eos.startSync(0);
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());
106 eos.close();
108 @Test
109 public void syncAddParts() throws Exception {
110 EmailObjectStore eos = new EmailObjectStore(props);
111 eos.startSync(0);
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");
120 eos.close();