OSDN Git Service

00236fecafae1a8b9fb5a6a0885402ed395d5ba8
[spring-ext/ozacc-mail.git] / src / test / java / com / ozacc / mail / fetch / impl / FetchMailImplTest.java
1
2 package com.ozacc.mail.fetch.impl;
3
4 import javax.mail.Message.RecipientType;
5 import javax.mail.Session;
6 import javax.mail.internet.MimeMessage;
7
8 import junit.framework.TestCase;
9
10 import org.apache.log4j.BasicConfigurator;
11 import org.jvnet.mock_javamail.Mailbox;
12
13 import com.ozacc.mail.Mail;
14 import com.ozacc.mail.fetch.ReceivedMail;
15
16 /**
17  * FetchMailImplクラスのテストケース。
18  * 
19  * @since 1.2.3
20  * @author Iwao AVE!
21  */
22 public class FetchMailImplTest extends TestCase
23 {
24         protected void setUp() throws Exception
25         {
26                 super.setUp();
27                 BasicConfigurator.configure();
28         }
29
30         /**
31          * 受信したメールの返信を作成するテスト (#12279)
32          */
33         public void testReplyReceivedMail() throws Exception
34         {
35                 String subject = "Test subject";
36                 String recipient = "info@example.com";
37                 Session session = Session.getInstance(System.getProperties());
38                 MimeMessage msg = new MimeMessage(session);
39                 msg.setRecipients(RecipientType.TO, recipient);
40                 msg.setSubject(subject);
41                 msg.setText("Test body");
42                 msg.setHeader("Message-ID", "MSGID-123");
43                 Mailbox inbox = Mailbox.get("info@example.com");
44                 inbox.add(msg);
45
46                 FetchMailImpl fetchMail = new FetchMailImpl();
47                 fetchMail.setHost("example.com");
48                 fetchMail.setUsername("info");
49                 ReceivedMail[] mails = fetchMail.getMails();
50                 assertEquals(1, mails.length);
51                 ReceivedMail receivedMail = mails[0];
52                 Mail reply = (Mail)(receivedMail.reply());
53                 assertEquals(receivedMail.getReplySubjectPrefix() + subject, reply.getSubject());
54         }
55
56         protected void tearDown() throws Exception {
57                 super.tearDown();
58                 BasicConfigurator.resetConfiguration();
59                 Mailbox.clearAll();
60         }
61 }