OSDN Git Service

テストで Dumbster を使用していた箇所を Mock JavaMail に変更(テスト時に J2SE 1.5 が必要となるが、ozacc-mail 自体は引き続き...
authorIwao AVE! <harawata@gmail.com>
Mon, 21 Nov 2011 18:10:17 +0000 (03:10 +0900)
committerIwao AVE! <harawata@gmail.com>
Mon, 21 Nov 2011 18:10:17 +0000 (03:10 +0900)
pom.xml
src/test/java/com/dumbster/smtp/SimpleSmtpServer.java [deleted file]
src/test/java/com/dumbster/smtp/SmtpActionType.java [deleted file]
src/test/java/com/dumbster/smtp/SmtpMessage.java [deleted file]
src/test/java/com/dumbster/smtp/SmtpRequest.java [deleted file]
src/test/java/com/dumbster/smtp/SmtpResponse.java [deleted file]
src/test/java/com/dumbster/smtp/SmtpState.java [deleted file]
src/test/java/com/ozacc/mail/impl/SendMailImplTest.java
src/test/java/com/ozacc/mail/mock/MockSendMailTest.java

diff --git a/pom.xml b/pom.xml
index d612b25..637aeb1 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
                        <version>2.5</version>
                        <type>jar</type>
                </dependency>
+               <dependency>
+                       <groupId>org.jvnet.mock-javamail</groupId>
+                       <artifactId>mock-javamail</artifactId>
+                       <version>1.9</version>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
        <build>
                <resources>
diff --git a/src/test/java/com/dumbster/smtp/SimpleSmtpServer.java b/src/test/java/com/dumbster/smtp/SimpleSmtpServer.java
deleted file mode 100644 (file)
index 654502c..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.InterruptedIOException;
-import java.io.PrintWriter;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Dummy SMTP server for testing purposes.
- */
-public class SimpleSmtpServer implements Runnable {
-
-       /** Stores all of the email received since this instance started up. */
-       private List receivedMail;
-
-       /** Default SMTP port is 25. */
-       public static final int DEFAULT_SMTP_PORT = 25;
-
-       /** Indicates whether this server is stopped or not. */
-       private volatile boolean stopped = true;
-
-       /** Indicates if a stop request has been sent to this server. */
-       private volatile boolean doStop = false;
-
-       /** Port the server listens on - set to the default SMTP port initially. */
-       private int port = DEFAULT_SMTP_PORT;
-
-       /**
-        * Constructor.
-        */
-       public SimpleSmtpServer(int port) {
-               receivedMail = new ArrayList();
-               this.port = port;
-       }
-
-       /**
-        * Main loop of the SMTP server.
-        */
-       public void run() {
-               stopped = false;
-               ServerSocket serverSocket = null;
-               try {
-                       serverSocket = new ServerSocket(port);
-                       serverSocket.setSoTimeout(500); // Block for maximum of 1.5 seconds
-
-                       // Server: loop until stopped
-                       while (!doStop) {
-                               Socket socket = null;
-                               try {
-                                       socket = serverSocket.accept();
-                               } catch (InterruptedIOException iioe) {
-                                       if (socket != null) {
-                                               socket.close();
-                                       }
-                                       continue; // Non-blocking socket timeout occurred: try accept() again
-                               }
-
-                               // Get the input and output streams
-                               BufferedReader input = new BufferedReader(new InputStreamReader(socket
-                                               .getInputStream()));
-                               PrintWriter out = new PrintWriter(socket.getOutputStream());
-
-                               // Initialize the state machine
-                               SmtpState smtpState = SmtpState.CONNECT;
-                               SmtpRequest smtpRequest = new SmtpRequest(SmtpActionType.CONNECT, "", smtpState);
-
-                               // Execute the connection request
-                               SmtpResponse smtpResponse = smtpRequest.execute();
-
-                               // Send initial response
-                               sendResponse(out, smtpResponse);
-                               smtpState = smtpResponse.getNextState();
-
-                               SmtpMessage msg = new SmtpMessage();
-
-                               while (smtpState != SmtpState.CONNECT) {
-                                       String line = input.readLine();
-
-                                       if (line == null) {
-                                               break;
-                                       }
-                                       // Create request from client input and current state
-                                       SmtpRequest request = SmtpRequest.createRequest(line, smtpState);
-                                       // Execute request and create response object
-                                       SmtpResponse response = request.execute();
-                                       // Move to next internal state
-                                       smtpState = response.getNextState();
-                                       // Send reponse to client
-                                       sendResponse(out, response);
-
-                                       // Store input in message
-                                       msg.store(response, request.getParams());
-                               }
-
-                               receivedMail.add(msg);
-                               socket.close();
-                       }
-               } catch (Exception e) {
-                       // e.printStackTrace();
-               } finally {
-                       if (serverSocket != null) {
-                               try {
-                                       serverSocket.close();
-                               } catch (IOException e) {
-                                       e.printStackTrace();
-                               }
-                       }
-               }
-               stopped = true;
-       }
-
-       /**
-        * Send response to client.
-        * @param out socket output stream
-        * @param smtpResponse response object
-        */
-       private void sendResponse(PrintWriter out, SmtpResponse smtpResponse) {
-               if (smtpResponse.getCode() > 0) {
-                       out.print(smtpResponse.getCode() + " " + smtpResponse.getMessage() + "\r\n");
-                       out.flush();
-               }
-       }
-
-       /**
-        * Get email received by this instance since start up.
-        * @return List of String
-        */
-       public Iterator getReceivedEmail() {
-               return receivedMail.iterator();
-       }
-
-       /**
-        * Get the number of messages received.
-        * @return size of received email list
-        */
-       public int getReceievedEmailSize() {
-               return receivedMail.size();
-       }
-
-       /**
-        * Forces the server to stop after processing the current request.
-        */
-       public void stop() {
-               doStop = true;
-               while (!isStopped()) {} // Wait for email server to stop
-       }
-
-       /**
-        * Indicates whether this server is stopped or not.
-        * @return true iff this server is stopped
-        */
-       public boolean isStopped() {
-               return stopped;
-       }
-
-       /**
-        * Creates an instance of SimpleSmtpServer and starts it. Will listen on the default port.
-        * @return a reference to the SMTP server
-        */
-       public static SimpleSmtpServer start() {
-               return start(DEFAULT_SMTP_PORT);
-       }
-
-       /**
-        * Creates an instance of SimpleSmtpServer and starts it.
-        * @param port port number the server should listen to
-        * @return a reference to the SMTP server
-        */
-       public static SimpleSmtpServer start(int port) {
-               SimpleSmtpServer server = new SimpleSmtpServer(port);
-               Thread t = new Thread(server);
-               t.start();
-               return server;
-       }
-
-}
\ No newline at end of file
diff --git a/src/test/java/com/dumbster/smtp/SmtpActionType.java b/src/test/java/com/dumbster/smtp/SmtpActionType.java
deleted file mode 100644 (file)
index 88e99f4..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-/**
- * Represents an SMTP action or command.
- */
-public class SmtpActionType {
-
-       /** Internal value for the action type. */
-       private byte value;
-
-       /** Internal representation of the CONNECT action. */
-       private static final byte CONNECT_BYTE = 1;
-
-       /** Internal representation of the EHLO action. */
-       private static final byte EHLO_BYTE = 2;
-
-       /** Internal representation of the MAIL FROM action. */
-       private static final byte MAIL_BYTE = 3;
-
-       /** Internal representation of the RCPT action. */
-       private static final byte RCPT_BYTE = 4;
-
-       /** Internal representation of the DATA action. */
-       private static final byte DATA_BYTE = 5;
-
-       /** Internal representation of the DATA END (.) action. */
-       private static final byte DATA_END_BYTE = 6;
-
-       /** Internal representation of the QUIT action. */
-       private static final byte QUIT_BYTE = 7;
-
-       /** Internal representation of an unrecognized action: body text gets this action type. */
-       private static final byte UNREC_BYTE = 8;
-
-       /** Internal representation of the blank line action: separates headers and body text. */
-       private static final byte BLANK_LINE_BYTE = 9;
-
-       /** Internal representation of the stateless RSET action. */
-       private static final byte RSET_BYTE = -1;
-
-       /** Internal representation of the stateless VRFY action. */
-       private static final byte VRFY_BYTE = -2;
-
-       /** Internal representation of the stateless EXPN action. */
-       private static final byte EXPN_BYTE = -3;
-
-       /** Internal representation of the stateless HELP action. */
-       private static final byte HELP_BYTE = -4;
-
-       /** Internal representation of the stateless NOOP action. */
-       private static final byte NOOP_BYTE = -5;
-
-       /** CONNECT action. */
-       public static final SmtpActionType CONNECT = new SmtpActionType(CONNECT_BYTE);
-
-       /** EHLO action. */
-       public static final SmtpActionType EHLO = new SmtpActionType(EHLO_BYTE);
-
-       /** MAIL action. */
-       public static final SmtpActionType MAIL = new SmtpActionType(MAIL_BYTE);
-
-       /** RCPT action. */
-       public static final SmtpActionType RCPT = new SmtpActionType(RCPT_BYTE);
-
-       /** DATA action. */
-       public static final SmtpActionType DATA = new SmtpActionType(DATA_BYTE);
-
-       /** "." action. */
-       public static final SmtpActionType DATA_END = new SmtpActionType(DATA_END_BYTE);
-
-       /** Body text action. */
-       public static final SmtpActionType UNRECOG = new SmtpActionType(UNREC_BYTE);
-
-       /** QUIT action. */
-       public static final SmtpActionType QUIT = new SmtpActionType(QUIT_BYTE);
-
-       /** Header/body separator action. */
-       public static final SmtpActionType BLANK_LINE = new SmtpActionType(BLANK_LINE_BYTE);
-
-       /** Stateless RSET action. */
-       public static final SmtpActionType RSET = new SmtpActionType(RSET_BYTE);
-
-       /** Stateless VRFY action. */
-       public static final SmtpActionType VRFY = new SmtpActionType(VRFY_BYTE);
-
-       /** Stateless EXPN action. */
-       public static final SmtpActionType EXPN = new SmtpActionType(EXPN_BYTE);
-
-       /** Stateless HELP action. */
-       public static final SmtpActionType HELP = new SmtpActionType(HELP_BYTE);
-
-       /** Stateless NOOP action. */
-       public static final SmtpActionType NOOP = new SmtpActionType(NOOP_BYTE);
-
-       /**
-        * Create a new SMTP action type. Private to ensure no invalid values.
-        * @param value one of the _BYTE values
-        */
-       private SmtpActionType(byte value) {
-               this.value = value;
-       }
-
-       /**
-        * Indicates whether the action is stateless or not.
-        * @return true iff the action is stateless
-        */
-       public boolean isStateless() {
-               return value < 0;
-       }
-
-       /**
-        * String representation of this SMTP action type.
-        * @return a String
-        */
-       public String toString() {
-               switch (value) {
-                       case CONNECT_BYTE:
-                               return "Connect";
-                       case EHLO_BYTE:
-                               return "EHLO";
-                       case MAIL_BYTE:
-                               return "MAIL";
-                       case RCPT_BYTE:
-                               return "RCPT";
-                       case DATA_BYTE:
-                               return "DATA";
-                       case DATA_END_BYTE:
-                               return ".";
-                       case QUIT_BYTE:
-                               return "QUIT";
-                       case RSET_BYTE:
-                               return "RSET";
-                       case VRFY_BYTE:
-                               return "VRFY";
-                       case EXPN_BYTE:
-                               return "EXPN";
-                       case HELP_BYTE:
-                               return "HELP";
-                       case NOOP_BYTE:
-                               return "NOOP";
-                       case UNREC_BYTE:
-                               return "Unrecognized command / data";
-                       case BLANK_LINE_BYTE:
-                               return "Blank line";
-                       default:
-                               return "Unknown";
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/test/java/com/dumbster/smtp/SmtpMessage.java b/src/test/java/com/dumbster/smtp/SmtpMessage.java
deleted file mode 100644 (file)
index a2c4bae..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Container for a complete SMTP message - headers and message body.
- */
-public class SmtpMessage {
-
-       /** Headers: Map of List of String hashed on header name. */
-       private Map headers;
-
-       /** Message body. */
-       private StringBuffer body;
-
-       /**
-        * Constructor. Initializes headers Map and body buffer.
-        */
-       public SmtpMessage() {
-               headers = new HashMap();
-               body = new StringBuffer();
-       }
-
-       /**
-        * Update the headers or body depending on the SmtpResponse object and line of input.
-        * @param response SmtpResponse object
-        * @param params remainder of input line after SMTP command has been removed
-        */
-       public void store(SmtpResponse response, String params) {
-               if (params != null) {
-                       if (SmtpState.DATA_HDR == response.getNextState()) {
-                               int headerNameEnd = params.indexOf(':');
-                               if (headerNameEnd >= 0) {
-                                       String name = params.substring(0, headerNameEnd).trim();
-                                       String value = params.substring(headerNameEnd + 1).trim();
-                                       addHeader(name, value);
-                               }
-                       } else if (SmtpState.DATA_BODY == response.getNextState()) {
-                               body.append(params);
-                       }
-               }
-       }
-
-       /**
-        * Get an Iterator over the header names.
-        * @return an Iterator over the set of header names (String)
-        */
-       public Iterator getHeaderNames() {
-               return headers.keySet().iterator();
-       }
-
-       /**
-        * Get the value(s) associated with the given header name.
-        * @param name header name
-        * @return value(s) associated with the header name
-        */
-       public String[] getHeaderValues(String name) {
-               List values = (List)headers.get(name);
-               if (values == null) {
-                       return new String[0];
-               } else {
-                       return (String[])values.toArray(new String[0]);
-               }
-       }
-
-       /**
-        * Get the first values associated with a given header name.
-        * @param name header name
-        * @return first value associated with the header name
-        */
-       public String getHeaderValue(String name) {
-               List values = (List)headers.get(name);
-               if (values == null) {
-                       return null;
-               } else {
-                       return (String)values.iterator().next();
-               }
-       }
-
-       /**
-        * Get the message body.
-        * @return message body
-        */
-       public String getBody() {
-               return body.toString();
-       }
-
-       /**
-        * Adds a header to the Map.
-        * @param name header name
-        * @param value header value
-        */
-       private void addHeader(String name, String value) {
-               List valueList = (List)headers.get(name);
-               if (valueList == null) {
-                       valueList = new ArrayList();
-                       headers.put(name, valueList);
-               }
-               valueList.add(value);
-       }
-
-       /**
-        * String representation of the SmtpMessage.
-        * @return a String
-        */
-       public String toString() {
-               StringBuffer msg = new StringBuffer();
-               for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
-                       String name = (String)i.next();
-                       List values = (List)headers.get(name);
-                       for (Iterator j = values.iterator(); j.hasNext();) {
-                               String value = (String)j.next();
-                               msg.append(name);
-                               msg.append(": ");
-                               msg.append(value);
-                               msg.append('\n');
-                       }
-               }
-               msg.append('\n');
-               msg.append(body);
-               msg.append('\n');
-               return msg.toString();
-       }
-}
\ No newline at end of file
diff --git a/src/test/java/com/dumbster/smtp/SmtpRequest.java b/src/test/java/com/dumbster/smtp/SmtpRequest.java
deleted file mode 100644 (file)
index 2a80d71..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-/**
- * Contains an SMTP client request.
- */
-public class SmtpRequest {
-
-       /** SMTP action received from client. */
-       private SmtpActionType action;
-
-       /** Current state of the SMTP state table. */
-       private SmtpState state;
-
-       /** Additional information passed from the client with the SMTP action. */
-       private String params;
-
-       /**
-        * Create a new SMTP client request.
-        * @param actionType type of action/command
-        * @param params remainder of command line once command is removed
-        * @param state current SMTP server state
-        */
-       public SmtpRequest(SmtpActionType actionType, String params, SmtpState state) {
-               this.action = actionType;
-               this.state = state;
-               this.params = params;
-       }
-
-       /**
-        * Execute the SMTP request returning a response. This method models the state transition table for the SMTP server.
-        * @return reponse to the request
-        */
-       public SmtpResponse execute() {
-               SmtpResponse response = null;
-               if (action.isStateless()) {
-                       if (SmtpActionType.EXPN == action || SmtpActionType.VRFY == action) {
-                               response = new SmtpResponse(252, "Not supported", this.state);
-                       } else if (SmtpActionType.HELP == action) {
-                               response = new SmtpResponse(211, "No help available", this.state);
-                       } else if (SmtpActionType.NOOP == action) {
-                               response = new SmtpResponse(250, "OK", this.state);
-                       } else if (SmtpActionType.VRFY == action) {
-                               response = new SmtpResponse(252, "Not supported", this.state);
-                       } else if (SmtpActionType.RSET == action) {
-                               response = new SmtpResponse(250, "OK", SmtpState.GREET);
-                       } else {
-                               response = new SmtpResponse(500, "Command not recognized", this.state);
-                       }
-               } else { // Stateful commands
-                       if (SmtpActionType.CONNECT == action) {
-                               if (SmtpState.CONNECT == state) {
-                                       response = new SmtpResponse(220, "localhost Dumbster SMTP service ready",
-                                                       SmtpState.GREET);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.EHLO == action) {
-                               if (SmtpState.GREET == state) {
-                                       response = new SmtpResponse(250, "OK", SmtpState.MAIL);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.MAIL == action) {
-                               if (SmtpState.MAIL == state) {
-                                       response = new SmtpResponse(250, "OK", SmtpState.RCPT);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.RCPT == action) {
-                               if (SmtpState.RCPT == state) {
-                                       response = new SmtpResponse(250, "OK", this.state);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.DATA == action) {
-                               if (SmtpState.RCPT == state) {
-                                       response = new SmtpResponse(354, "Start mail input; end with <CRLF>.<CRLF>",
-                                                       SmtpState.DATA_HDR);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.UNRECOG == action) {
-                               if (SmtpState.DATA_HDR == state || SmtpState.DATA_BODY == state) {
-                                       response = new SmtpResponse(-1, "", this.state);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.DATA_END == action) {
-                               if (SmtpState.DATA_HDR == state || SmtpState.DATA_BODY == state) {
-                                       response = new SmtpResponse(250, "OK", SmtpState.QUIT);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.BLANK_LINE == action) {
-                               if (SmtpState.DATA_HDR == state) {
-                                       response = new SmtpResponse(-1, "", SmtpState.DATA_BODY);
-                               } else if (SmtpState.DATA_BODY == state) {
-                                       response = new SmtpResponse(-1, "", this.state);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else if (SmtpActionType.QUIT == action) {
-                               if (SmtpState.QUIT == state) {
-                                       response = new SmtpResponse(250, "OK", SmtpState.CONNECT);
-                               } else {
-                                       response = new SmtpResponse(503, "Bad sequence of commands: " + action,
-                                                       this.state);
-                               }
-                       } else {
-                               response = new SmtpResponse(500, "Command not recognized", this.state);
-                       }
-               }
-               return response;
-       }
-
-       /**
-        * Create an SMTP request object given a line of the input stream from the client and the current internal state.
-        * @param s line of input
-        * @param state current state
-        * @return a populated SmtpRequest object
-        */
-       public static SmtpRequest createRequest(String s, SmtpState state) {
-               SmtpActionType action = null;
-               String params = null;
-
-               if (state == SmtpState.DATA_HDR) {
-                       if (s.equals(".")) {
-                               action = SmtpActionType.DATA_END;
-                       } else if (s.length() < 1) {
-                               action = SmtpActionType.BLANK_LINE;
-                       } else {
-                               action = SmtpActionType.UNRECOG;
-                               params = s;
-                       }
-               } else if (state == SmtpState.DATA_BODY) {
-                       if (s.equals(".")) {
-                               action = SmtpActionType.DATA_END;
-                       } else {
-                               action = SmtpActionType.UNRECOG;
-                               if (s.length() < 1) {
-                                       params = "\n";
-                               } else {
-                                       params = s;
-                               }
-                       }
-               } else {
-                       String su = s.toUpperCase();
-                       if (su.startsWith("EHLO ") || su.startsWith("HELO")) {
-                               action = SmtpActionType.EHLO;
-                               params = s.substring(5);
-                       } else if (su.startsWith("MAIL FROM:")) {
-                               action = SmtpActionType.MAIL;
-                               params = s.substring(10);
-                       } else if (su.startsWith("RCPT TO:")) {
-                               action = SmtpActionType.RCPT;
-                               params = s.substring(8);
-                       } else if (su.startsWith("DATA")) {
-                               action = SmtpActionType.DATA;
-                       } else if (su.startsWith("QUIT")) {
-                               action = SmtpActionType.QUIT;
-                       } else if (su.startsWith("RSET")) {
-                               action = SmtpActionType.RSET;
-                       } else if (su.startsWith("NOOP")) {
-                               action = SmtpActionType.NOOP;
-                       } else if (su.startsWith("EXPN")) {
-                               action = SmtpActionType.EXPN;
-                       } else if (su.startsWith("VRFY")) {
-                               action = SmtpActionType.VRFY;
-                       } else if (su.startsWith("HELP")) {
-                               action = SmtpActionType.HELP;
-                       }
-               }
-
-               SmtpRequest req = new SmtpRequest(action, params, state);
-               return req;
-       }
-
-       /**
-        * Get the parameters of this request (remainder of command line once the command is removed.
-        * @return parameters
-        */
-       public String getParams() {
-               return params;
-       }
-}
\ No newline at end of file
diff --git a/src/test/java/com/dumbster/smtp/SmtpResponse.java b/src/test/java/com/dumbster/smtp/SmtpResponse.java
deleted file mode 100644 (file)
index cacc6f1..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-/**
- * SMTP response container.
- */
-public class SmtpResponse {
-
-       /** Response code - see RFC-2821. */
-       private int code;
-
-       /** Response message. */
-       private String message;
-
-       /** New state of the SMTP server once the request has been executed. */
-       private SmtpState nextState;
-
-       /**
-        * Constructor.
-        * @param code response code
-        * @param message response message
-        * @param next next state of the SMTP server
-        */
-       public SmtpResponse(int code, String message, SmtpState next) {
-               this.code = code;
-               this.message = message;
-               this.nextState = next;
-       }
-
-       /**
-        * Get the response code.
-        * @return response code
-        */
-       public int getCode() {
-               return code;
-       }
-
-       /**
-        * Get the response message.
-        * @return response message
-        */
-       public String getMessage() {
-               return message;
-       }
-
-       /**
-        * Get the next SMTP server state.
-        * @return state
-        */
-       public SmtpState getNextState() {
-               return nextState;
-       }
-}
\ No newline at end of file
diff --git a/src/test/java/com/dumbster/smtp/SmtpState.java b/src/test/java/com/dumbster/smtp/SmtpState.java
deleted file mode 100644 (file)
index bff284d..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Dumbster: a dummy SMTP server.
- * Copyright (C) 2003, Jason Paul Kitchen
- * lilnottsman@yahoo.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package com.dumbster.smtp;
-
-/**
- * SMTP server state.
- */
-public class SmtpState {
-
-       /** Internal representation of the state. */
-       private byte value;
-
-       /** Internal representation of the CONNECT state. */
-       private static final byte CONNECT_BYTE = 1;
-
-       /** Internal representation of the GREET state. */
-       private static final byte GREET_BYTE = 2;
-
-       /** Internal representation of the MAIL state. */
-       private static final byte MAIL_BYTE = 3;
-
-       /** Internal representation of the RCPT state. */
-       private static final byte RCPT_BYTE = 4;
-
-       /** Internal representation of the DATA_HEADER state. */
-       private static final byte DATA_HEADER_BYTE = 5;
-
-       /** Internal representation of the DATA_BODY state. */
-       private static final byte DATA_BODY_BYTE = 6;
-
-       /** Internal representation of the QUIT state. */
-       private static final byte QUIT_BYTE = 7;
-
-       /** CONNECT state: waiting for a client connection. */
-       public static final SmtpState CONNECT = new SmtpState(CONNECT_BYTE);
-
-       /** GREET state: wating for a ELHO message. */
-       public static final SmtpState GREET = new SmtpState(GREET_BYTE);
-
-       /** MAIL state: waiting for the MAIL FROM: command. */
-       public static final SmtpState MAIL = new SmtpState(MAIL_BYTE);
-
-       /** RCPT state: waiting for a RCPT &lt;email address&gt; command. */
-       public static final SmtpState RCPT = new SmtpState(RCPT_BYTE);
-
-       /** Waiting for headers. */
-       public static final SmtpState DATA_HDR = new SmtpState(DATA_HEADER_BYTE);
-
-       /** Processing body text. */
-       public static final SmtpState DATA_BODY = new SmtpState(DATA_BODY_BYTE);
-
-       /** End of client transmission. */
-       public static final SmtpState QUIT = new SmtpState(QUIT_BYTE);
-
-       /**
-        * Create a new SmtpState object. Private to ensure that only valid states can be created.
-        * @param value one of the _BYTE values.
-        */
-       private SmtpState(byte value) {
-               this.value = value;
-       }
-
-       /**
-        * String representation of this SmtpState.
-        * @return a String
-        */
-       public String toString() {
-               switch (value) {
-                       case CONNECT_BYTE:
-                               return "CONNECT";
-                       case GREET_BYTE:
-                               return "GREET";
-                       case MAIL_BYTE:
-                               return "MAIL";
-                       case RCPT_BYTE:
-                               return "RCPT";
-                       case DATA_HEADER_BYTE:
-                               return "DATA_HDR";
-                       case DATA_BODY_BYTE:
-                               return "DATA_BODY";
-                       case QUIT_BYTE:
-                               return "QUIT";
-                       default:
-                               return "Unknown";
-               }
-       }
-}
\ No newline at end of file
index ad26413..63491d5 100644 (file)
@@ -1,23 +1,17 @@
 package com.ozacc.mail.impl;
 
-import java.io.UnsupportedEncodingException;
-import java.util.Iterator;
-
-import javax.mail.internet.MimeUtility;
+import javax.mail.Message;
 
 import junit.framework.TestCase;
 
 import org.apache.log4j.BasicConfigurator;
+import org.jvnet.mock_javamail.Mailbox;
 
-import com.dumbster.smtp.SimpleSmtpServer;
-import com.dumbster.smtp.SmtpMessage;
 import com.ozacc.mail.Mail;
 import com.ozacc.mail.MailException;
 
 /**
  * SendMailImplクラスのテストケース。
- * <p>
- * Dumbsterを使用してテストしているが、サポートされていない機能が多い。
  * 
  * @author Tomohiro Otsuka
  * @version $Id: SendMailImplTest.java,v 1.3 2004/09/14 00:06:13 otsuka Exp $
@@ -26,8 +20,6 @@ public class SendMailImplTest extends TestCase {
 
        private SendMailImpl sendMail;
 
-       private SimpleSmtpServer server;
-
        /*
         * @see TestCase#setUp()
         */
@@ -36,10 +28,8 @@ public class SendMailImplTest extends TestCase {
 
                BasicConfigurator.configure();
 
-               int port = 2525;
-               server = SimpleSmtpServer.start(port);
                sendMail = new SendMailImpl();
-               sendMail.setPort(port);
+               Mailbox.clearAll();
        }
 
        /**
@@ -49,10 +39,6 @@ public class SendMailImplTest extends TestCase {
                BasicConfigurator.resetConfiguration();
        }
 
-       private String convertJisValue(String str) throws UnsupportedEncodingException {
-               return new String(str.getBytes(), "JIS");
-       }
-
        /**
         * 単発メールのテスト。
         * 
@@ -73,18 +59,16 @@ public class SendMailImplTest extends TestCase {
 
                sendMail.send(mail);
 
-               server.stop();
+               Mailbox inbox = Mailbox.get("info@example.com");
+               assertEquals("1", 1, inbox.size());
 
-               assertEquals("1", 1, server.getReceievedEmailSize());
-               Iterator inbox = server.getReceivedEmail();
-               SmtpMessage email = (SmtpMessage)inbox.next();
+               Message email = inbox.get(0);
 
-               assertEquals("2", mail.getTo()[0].toString(), email.getHeaderValue("To"));
-               assertEquals("3", mail.getFrom().toString(), email.getHeaderValue("From"));
+               assertEquals("2", mail.getTo()[0].toString(), email.getHeader("To")[0]);
+               assertEquals("3", mail.getFrom().toString(), email.getHeader("From")[0]);
 
-               assertEquals("4", mail.getSubject(), MimeUtility
-                               .decodeText(email.getHeaderValue("Subject")));
-               assertEquals("5", mail.getText() + "\n", convertJisValue(email.getBody()));
+               assertEquals("4", mail.getSubject(), email.getSubject());
+               assertEquals("5", mail.getText() + "\n", email.getContent());
        }
 
        /**
@@ -120,23 +104,19 @@ public class SendMailImplTest extends TestCase {
                mail3.setSubject(subject);
                mail3.setText(text);
 
-               // Dumbsterのバグが直ったら、mail1, mail2, mail3 を含めてテスト
-               sendMail.send(new Mail[] { mail1 });
+               sendMail.send(new Mail[] { mail1, mail2, mail3 });
 
-               server.stop();
+               Mailbox inbox = Mailbox.get("info@example.com");
 
-               // Dumbsterのバグが直ったら、3 に。
-               assertEquals("1", 1, server.getReceievedEmailSize());
+               assertEquals("1", 3, inbox.size());
 
-               Iterator inbox = server.getReceivedEmail();
-               SmtpMessage email = (SmtpMessage)inbox.next();
+               Message email1 = inbox.get(0);
 
-               assertEquals("2", mail1.getTo()[0].toString(), email.getHeaderValue("To"));
-               assertEquals("3", mail1.getFrom().toString(), email.getHeaderValue("From"));
+               assertEquals("2", mail1.getTo()[0].toString(), email1.getHeader("To")[0]);
+               assertEquals("3", mail1.getFrom().toString(), email1.getHeader("From")[0]);
 
-               assertEquals("4", mail1.getSubject(), MimeUtility.decodeText(email
-                               .getHeaderValue("Subject")));
-               assertEquals("5", mail1.getText() + "\n", convertJisValue(email.getBody()));
+               assertEquals("4", mail1.getSubject(), email1.getSubject());
+               assertEquals("5", mail1.getText() + "\n", email1.getContent());
        }
 
        public void testSendMailWithReturnPath() throws Exception {
@@ -157,26 +137,23 @@ public class SendMailImplTest extends TestCase {
 
                sendMail.send(mail);
 
-               server.stop();
+               Mailbox inbox = Mailbox.get("info@example.com");
 
-               assertEquals(1, server.getReceievedEmailSize());
-               Iterator inbox = server.getReceivedEmail();
-               SmtpMessage email = (SmtpMessage)inbox.next();
+               assertEquals(1, inbox.size());
+               Message email = inbox.get(0);
 
                // ヘッダー出力
-               /*
-                Iterator itr = email.getHeaderNames();
-                while (itr.hasNext()) {
-                String name = (String)itr.next();
-                System.out.println(name + "='" + email.getHeaderValue(name) + "'");
-                }
-                */
-
-               // Dumbsterでは、Return-Pathヘッダを保持していない
-               //assertEquals(mail.getReturnPath().toString(), email.getHeaderValue("Return-Path"));
+               // Enumeration headers = email.getAllHeaders();
+               // while (headers.hasMoreElements()) {
+               // Header header = (Header)headers.nextElement();
+               // System.out.println(header.getName() + "='" + header.getValue() + "'");
+               // }
+
+               // Mock JavaMail では Return-Path ヘッダは付加されないようだ。
+               // assertEquals(mail.getReturnPath().toString(), email.getHeader("Return-Path"));
                // 重要度を確認
-               assertEquals(mail.getImportance(), email.getHeaderValue("Importance"));
-               assertEquals("1", email.getHeaderValue("X-Priority"));
+               assertEquals(mail.getImportance(), email.getHeader("Importance")[0]);
+               assertEquals("1", email.getHeader("X-Priority")[0]);
        }
 
        /**
index 9c3cea3..0dd85c7 100644 (file)
@@ -4,13 +4,10 @@ import junit.framework.TestCase;
 
 import org.apache.log4j.BasicConfigurator;
 
-import com.dumbster.smtp.SimpleSmtpServer;
 import com.ozacc.mail.Mail;
 
 /**
  * SendMailImplクラスのテストケース。
- * <p>
- * Dumbsterを使用してテストしているが、サポートされていない機能が多い。
  * 
  * @author Tomohiro Otsuka
  * @version $Id: MockSendMailTest.java,v 1.6.2.1 2005/01/18 07:24:47 otsuka Exp $
@@ -19,8 +16,6 @@ public class MockSendMailTest extends TestCase {
 
        private MockSendMail mockSendMail;
 
-       private SimpleSmtpServer server;
-
        /*
         * @see TestCase#setUp()
         */