1 package com.ozacc.mail.mock; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import com.ozacc.mail.MailException; 10 import com.ozacc.mail.fetch.FetchMail; 11 import com.ozacc.mail.fetch.ReceivedMail; 12 13 /*** 14 * FetchMailImplクラスのMock。<br> 15 * <code>setupGetMails()</code>メソッドで<code>ReceivedMail</code>インスタンスをセットすると、<code>getMails()</code>メソッドがそのインスタンスを返します。 16 * 17 * @since 1.2 18 * @author Tomohiro Otsuka 19 * @version $Id: MockFetchMail.java,v 1.1.2.3 2005/02/05 09:25:25 otsuka Exp $ 20 */ 21 public class MockFetchMail implements FetchMail { 22 23 private static Log log = LogFactory.getLog(MockFetchMail.class); 24 25 /*** デフォルトのSMTPサーバ。「localhost」 */ 26 public static final String DEFAULT_HOST = "localhost"; 27 28 /*** デフォルトのプロトコル。「pop3」 */ 29 public static final String DEFAULT_PROTOCOL = "pop3"; 30 31 /*** 32 * デフォルトのポート。「-1」<br> 33 * -1はプロトコルに応じた適切なポートを設定する特別な値。 34 */ 35 public static final int DEFAULT_PORT = -1; 36 37 private static final String INBOX_NAME = "INBOX"; 38 39 private String host = DEFAULT_HOST; 40 41 private String protocol = DEFAULT_PROTOCOL; 42 43 private int port = DEFAULT_PORT; 44 45 private String username; 46 47 private String password; 48 49 private List receivedMails; 50 51 /*** 52 * コンストラクタ。 53 */ 54 public MockFetchMail() { 55 super(); 56 receivedMails = new ArrayList(); 57 } 58 59 /*** 60 * <code>MockFetchMail</code>の<code>getMails()</code>メソッドが返す 61 * <code>ReceivedMail</code>インスタンスをセットします。 62 * 63 * @param mail <code>getMails()</code>メソッドが返す<code>ReceivedMail</code>インスタンス 64 */ 65 public void setupGetMails(ReceivedMail mail) { 66 receivedMails.add(mail); 67 } 68 69 /*** 70 * <code>MockFetchMail</code>の<code>getMails()</code>メソッドが返す 71 * <code>ReceivedMail</code>インスタンスをセットします。 72 * 73 * @param mails <code>getMails()</code>メソッドが返す<code>ReceivedMail</code>インスタンス配列 74 */ 75 public void setupGetMails(ReceivedMail[] mails) { 76 for (int i = 0; i < mails.length; i++) { 77 ReceivedMail mail = mails[i]; 78 setupGetMails(mail); 79 } 80 } 81 82 /*** 83 * @see com.ozacc.mail.fetch.FetchMail#getMails() 84 */ 85 public ReceivedMail[] getMails() throws MailException { 86 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]に接続しるフリ。"); 87 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]に接続したフリ。"); 88 89 if (receivedMails.size() > 0) { 90 log.debug(receivedMails.size() + "通のメールを受信するフリ。"); 91 } else { 92 log.debug("受信するフリをするメールはありません。"); 93 } 94 try { 95 return (ReceivedMail[])receivedMails.toArray(new ReceivedMail[receivedMails.size()]); 96 } finally { 97 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断するフリ。"); 98 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断したフリ。"); 99 } 100 } 101 102 /*** 103 * @see com.ozacc.mail.fetch.FetchMail#getMails(boolean) 104 */ 105 public ReceivedMail[] getMails(boolean delete) throws MailException { 106 ReceivedMail[] result = getMails(); 107 if (delete) { 108 receivedMails.clear(); 109 } 110 return result; 111 } 112 113 /*** 114 * @return Returns the host. 115 */ 116 public String getHost() { 117 return host; 118 } 119 120 /*** 121 * @param host The host to set. 122 */ 123 public void setHost(String host) { 124 this.host = host; 125 } 126 127 /*** 128 * @return Returns the password. 129 */ 130 public String getPassword() { 131 return password; 132 } 133 134 /*** 135 * @param password The password to set. 136 */ 137 public void setPassword(String password) { 138 this.password = password; 139 } 140 141 /*** 142 * @return Returns the port. 143 */ 144 public int getPort() { 145 return port; 146 } 147 148 /*** 149 * @param port The port to set. 150 */ 151 public void setPort(int port) { 152 this.port = port; 153 } 154 155 /*** 156 * @return Returns the protocol. 157 */ 158 public String getProtocol() { 159 return protocol; 160 } 161 162 /*** 163 * @param protocol The protocol to set. 164 */ 165 public void setProtocol(String protocol) { 166 this.protocol = protocol; 167 } 168 169 /*** 170 * @return Returns the username. 171 */ 172 public String getUsername() { 173 return username; 174 } 175 176 /*** 177 * @param username The username to set. 178 */ 179 public void setUsername(String username) { 180 this.username = username; 181 } 182 }