KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailboxmanager > torque > TorqueMailboxTestCase


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.mailboxmanager.torque;
21
22 import java.util.Date JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.mail.Flags JavaDoc;
26 import javax.mail.internet.MimeMessage JavaDoc;
27
28 import org.apache.james.mailboxmanager.MessageResult;
29 import org.apache.james.mailboxmanager.TestUtil;
30 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
31 import org.apache.james.mailboxmanager.impl.MailboxListenerCollector;
32 import org.apache.james.mailboxmanager.torque.om.MailboxRow;
33 import org.apache.james.mailboxmanager.torque.om.MailboxRowPeer;
34 import org.apache.james.mailboxmanager.torque.om.MessageRow;
35 import org.apache.james.mailboxmanager.torque.om.MessageRowPeer;
36 import org.apache.james.mailboxmanager.tracking.UidChangeTracker;
37 import org.apache.torque.TorqueException;
38 import org.apache.torque.util.Criteria;
39
40 public class TorqueMailboxTestCase extends AbstractTorqueTestCase {
41
42
43     public TorqueMailboxTestCase() throws TorqueException {
44         super();
45     }
46
47     public void testAppendGetDeleteMessage() throws Exception JavaDoc {
48         MailboxRow mr = new MailboxRow("#users.tuser.INBOX", 100);
49         mr.save();
50         mr=MailboxRowPeer.retrieveByName("#users.tuser.INBOX");
51         TorqueMailbox torqueMailbox = new TorqueMailbox(mr, new UidChangeTracker(null,"#users.tuser.INBOX",100),null);
52         torqueMailbox.addListener(new MailboxListenerCollector(), MessageResult.NOTHING);
53         assertEquals(0,torqueMailbox.getMessageCount());
54         
55         long time = System.currentTimeMillis();
56         time = time - (time % 1000);
57         Date JavaDoc date = new Date JavaDoc(time);
58         MimeMessage JavaDoc mm=TestUtil.createMessage();
59         Flags JavaDoc flags=new Flags JavaDoc();
60         flags.add(Flags.Flag.ANSWERED);
61         flags.add(Flags.Flag.SEEN);
62         mm.setFlags(flags,true);
63         mm.writeTo(System.out);
64         torqueMailbox.appendMessage(mm, date, 0);
65         assertEquals(1,torqueMailbox.getMessageCount());
66         List JavaDoc l = MessageRowPeer.doSelect(new Criteria());
67         assertEquals(1, l.size());
68         MessageRow msg = (MessageRow) l.get(0);
69         assertEquals(mr.getMailboxId(), msg.getMailboxId());
70         assertEquals(1, msg.getUid());
71
72         assertEquals(date, msg.getInternalDate());
73         assertEquals(flags, msg.getMessageFlags().getFlagsObject());
74
75         mr = MailboxRowPeer.retrieveByPK(mr.getMailboxId());
76         assertEquals(1, mr.getLastUid());
77         
78         MessageResult[] messageResult=torqueMailbox.getMessages(GeneralMessageSetImpl.oneUid(1l),MessageResult.MIME_MESSAGE);
79         assertNotNull(messageResult);
80         assertEquals(1,messageResult.length);
81         messageResult[0].getMimeMessage().writeTo(System.out);
82         assertTrue(TorqueTestUtil.contentEquals(mm,messageResult[0].getMimeMessage(),true));
83         
84         Flags JavaDoc f=new Flags JavaDoc();
85         f.add(Flags.Flag.DELETED);
86         torqueMailbox.setFlags(f,true,false, GeneralMessageSetImpl.oneUid(1l), null);
87         MessageResult[] messageResults=torqueMailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.UID);
88         assertEquals(1,messageResults.length);
89         assertEquals(1l,messageResults[0].getUid());
90     }
91
92 }
93
Popular Tags