Index: default.properties
===================================================================
--- default.properties (revision 327257)
+++ default.properties (working copy)
@@ -50,6 +50,9 @@
build.lib = ${build.dir}/lib
build.src = ${build.dir}/src
build.classes = ${build.dir}/classes
+build.test = ${build.dir}/test
+build.test.classes = ${build.test}/classes
+build.test.reports = ${build.test}/reports
build.javadocs = ${build.docs}/javadocs
build.docs = ${build.dir}/docs
build.mailetdocs = ${build.dir}/mailetdocs
@@ -62,6 +65,7 @@
src.dir=${james.dir}/src
java.dir=${src.dir}/java
+junitjava.dir=${src.dir}/test
conf.dir=${src.dir}/conf
xdocs.dir=${src.dir}/xdocs
docs.src=${xdocs.dir}
@@ -83,3 +87,7 @@
www.dir = ${james.dir}/www
+#
+#
+#
+
Index: tools/lib/junit.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: tools/lib/junit.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: tools/lib/ristretto-1.0-all.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: tools/lib/ristretto-1.0-all.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: tools/lib/LICENSE.ristretto.txt
===================================================================
--- tools/lib/LICENSE.ristretto.txt (revision 0)
+++ tools/lib/LICENSE.ristretto.txt (revision 0)
@@ -0,0 +1,35 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Ristretto Mail API.
+ *
+ * The Initial Developers of the Original Code are
+ * Timo Stich and Frederik Dietz.
+ * Portions created by the Initial Developers are Copyright (C) 2004
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
\ No newline at end of file
Index: src/test/org/apache/james/test/mock/james/MockMailServer.java
===================================================================
--- src/test/org/apache/james/test/mock/james/MockMailServer.java (revision 0)
+++ src/test/org/apache/james/test/mock/james/MockMailServer.java (revision 0)
@@ -0,0 +1,98 @@
+/***********************************************************************
+ * Copyright (c) 2000-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.james;
+
+import org.apache.james.services.MailRepository;
+import org.apache.james.services.MailServer;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+
+public class MockMailServer implements MailServer {
+
+ private final HashMap users = new HashMap();
+
+ private int counter = 0;
+
+ private final ArrayList mails = new ArrayList();
+
+ public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException {
+ Object[] mailObjects = new Object[]{sender, recipients, msg};
+ mails.add(mailObjects);
+ }
+
+ public void sendMail(MailAddress sender, Collection recipients, InputStream msg) throws MessagingException {
+ Object[] mailObjects = new Object[]{sender, recipients, msg};
+ mails.add(mailObjects);
+ }
+
+ public void sendMail(Mail mail) throws MessagingException {
+ sendMail(mail.getSender(), mail.getRecipients(), mail.getMessage());
+ }
+
+ public void sendMail(MimeMessage message) throws MessagingException {
+ // taken from class org.apache.james.James
+ MailAddress sender = new MailAddress((InternetAddress)message.getFrom()[0]);
+ Collection recipients = new HashSet();
+ Address addresses[] = message.getAllRecipients();
+ if (addresses != null) {
+ for (int i = 0; i < addresses.length; i++) {
+ // Javamail treats the "newsgroups:" header field as a
+ // recipient, so we want to filter those out.
+ if ( addresses[i] instanceof InternetAddress ) {
+ recipients.add(new MailAddress((InternetAddress)addresses[i]));
+ }
+ }
+ }
+ sendMail(sender, recipients, message);
+ }
+
+ public MailRepository getUserInbox(String userName) {
+ return null; // trivial implementation
+ }
+
+ public synchronized String getId() {
+ counter++;
+ return "MockMailServer-ID-" + counter;
+ }
+
+ public boolean addUser(String userName, String password) {
+ users.put(userName, password);
+ return true;
+ }
+
+ public boolean isLocalServer(String serverName) {
+ return false; // trivial implementation
+ }
+
+ public Object[] getLastMail()
+ {
+ if (mails.size() == 0) return null;
+ return (Object[])mails.get(mails.size()-1);
+ }
+}
+
+
Index: src/test/org/apache/james/test/mock/james/MockUserRepository.java
===================================================================
--- src/test/org/apache/james/test/mock/james/MockUserRepository.java (revision 0)
+++ src/test/org/apache/james/test/mock/james/MockUserRepository.java (revision 0)
@@ -0,0 +1,81 @@
+/***********************************************************************
+ * Copyright (c) 2000-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.james;
+
+import org.apache.james.services.UsersRepository;
+import org.apache.james.services.User;
+
+import java.util.Iterator;
+
+public class MockUserRepository implements UsersRepository {
+
+ public boolean addUser(User user) {
+ return false; // trivial implementation
+ }
+
+ public void addUser(String name, Object attributes) {
+ // trivial implementation
+ }
+
+ public Object getAttributes(String name) {
+ return null; // trivial implementation
+ }
+
+ public User getUserByName(String name) {
+ return null; // trivial implementation
+ }
+
+ public User getUserByNameCaseInsensitive(String name) {
+ return null; // trivial implementation
+ }
+
+ public String getRealName(String name) {
+ return null; // trivial implementation
+ }
+
+ public boolean updateUser(User user) {
+ return false; // trivial implementation
+ }
+
+ public void removeUser(String name) {
+ // trivial implementation
+ }
+
+ public boolean contains(String name) {
+ return false; // trivial implementation
+ }
+
+ public boolean containsCaseInsensitive(String name) {
+ return false; // trivial implementation
+ }
+
+ public boolean test(String name, Object attributes) {
+ return false; // trivial implementation
+ }
+
+ public boolean test(String name, String password) {
+ return false; // trivial implementation
+ }
+
+ public int countUsers() {
+ return 0; // trivial implementation
+ }
+
+ public Iterator list() {
+ return null; // trivial implementation
+ }
+}
Index: src/test/org/apache/james/test/mock/avalon/MockServiceManager.java
===================================================================
--- src/test/org/apache/james/test/mock/avalon/MockServiceManager.java (revision 0)
+++ src/test/org/apache/james/test/mock/avalon/MockServiceManager.java (revision 0)
@@ -0,0 +1,42 @@
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.avalon;
+
+import org.apache.avalon.framework.service.ServiceException;
+
+import java.util.HashMap;
+
+public class MockServiceManager implements org.apache.avalon.framework.service.ServiceManager {
+
+ private HashMap m_serviceMap = new HashMap();
+
+ public Object lookup(String serviceName) throws ServiceException {
+ return m_serviceMap.get(serviceName);
+ }
+
+ public boolean hasService(String serviceName) {
+ return m_serviceMap.get(serviceName) != null;
+ }
+
+ public void put(String name, Object service) {
+ m_serviceMap.put(name, service);
+ }
+
+ public void release(Object object) {
+ // trivial implementation
+ }
+}
Index: src/test/org/apache/james/test/mock/avalon/MockLogger.java
===================================================================
--- src/test/org/apache/james/test/mock/avalon/MockLogger.java (revision 0)
+++ src/test/org/apache/james/test/mock/avalon/MockLogger.java (revision 0)
@@ -0,0 +1,87 @@
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.avalon;
+
+import org.apache.avalon.framework.logger.Logger;
+
+public class MockLogger implements Logger {
+
+ public void debug(java.lang.String string) {
+ System.out.println(string);
+ }
+
+ public void debug(java.lang.String string, java.lang.Throwable throwable) {
+ System.out.println(string + throwable.toString());
+ }
+
+ public boolean isDebugEnabled() {
+ return true;
+ }
+
+ public void info(java.lang.String string) {
+ System.out.println(string);
+ }
+
+ public void info(java.lang.String string, java.lang.Throwable throwable) {
+ System.out.println(string + throwable.toString());
+ }
+
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ public void warn(java.lang.String string) {
+ System.out.println(string);
+ }
+
+ public void warn(java.lang.String string, java.lang.Throwable throwable) {
+ System.out.println(string + throwable.toString());
+ }
+
+ public boolean isWarnEnabled() {
+ return true;
+ }
+
+ public void error(java.lang.String string) {
+ System.out.println(string);
+ }
+
+ public void error(java.lang.String string, java.lang.Throwable throwable) {
+ System.out.println(string + throwable.toString());
+ }
+
+ public boolean isErrorEnabled() {
+ return true;
+ }
+
+ public void fatalError(java.lang.String string) {
+ System.out.println(string);
+ }
+
+ public void fatalError(java.lang.String string, java.lang.Throwable throwable) {
+ System.out.println(string + throwable.toString());
+ }
+
+ public boolean isFatalErrorEnabled() {
+ return true;
+ }
+
+ public org.apache.avalon.framework.logger.Logger getChildLogger(java.lang.String string) {
+ return this;
+ }
+
+}
Index: src/test/org/apache/james/test/mock/avalon/MockThreadManager.java
===================================================================
--- src/test/org/apache/james/test/mock/avalon/MockThreadManager.java (revision 0)
+++ src/test/org/apache/james/test/mock/avalon/MockThreadManager.java (revision 0)
@@ -0,0 +1,38 @@
+/***********************************************************************
+ * Copyright (c) 2000-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.avalon;
+
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+import org.apache.avalon.excalibur.thread.impl.DefaultThreadPool;
+import org.apache.excalibur.thread.ThreadPool;
+
+public class MockThreadManager implements ThreadManager {
+ public ThreadPool getThreadPool(String string) throws IllegalArgumentException {
+ return getDefaultThreadPool();
+ }
+
+ public ThreadPool getDefaultThreadPool() {
+ try {
+ DefaultThreadPool defaultThreadPool = new DefaultThreadPool(1);
+ defaultThreadPool.enableLogging(new MockLogger());
+ return defaultThreadPool;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}
Index: src/test/org/apache/james/test/mock/avalon/MockSocketManager.java
===================================================================
--- src/test/org/apache/james/test/mock/avalon/MockSocketManager.java (revision 0)
+++ src/test/org/apache/james/test/mock/avalon/MockSocketManager.java (revision 0)
@@ -0,0 +1,40 @@
+/***********************************************************************
+ * Copyright (c) 2000-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.avalon;
+
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
+import org.apache.avalon.cornerstone.services.sockets.SocketFactory;
+import org.apache.avalon.cornerstone.blocks.sockets.DefaultServerSocketFactory;
+import org.apache.avalon.cornerstone.blocks.sockets.DefaultSocketFactory;
+
+public class MockSocketManager implements SocketManager {
+ private int m_port;
+
+ public MockSocketManager(int port)
+ {
+ m_port = port;
+ }
+
+ public ServerSocketFactory getServerSocketFactory(String string) throws Exception {
+ return new DefaultServerSocketFactory();
+ }
+
+ public SocketFactory getSocketFactory(String string) throws Exception {
+ return new DefaultSocketFactory();
+ }
+}
Index: src/test/org/apache/james/test/mock/mailet/MockMailContext.java
===================================================================
--- src/test/org/apache/james/test/mock/mailet/MockMailContext.java (revision 0)
+++ src/test/org/apache/james/test/mock/mailet/MockMailContext.java (revision 0)
@@ -0,0 +1,113 @@
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.mock.mailet;
+
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import java.util.Collection;
+import java.util.Iterator;
+
+public class MockMailContext implements MailetContext {
+
+ public void bounce(Mail mail, String message) throws MessagingException {
+ // trivial implementation
+ }
+
+ public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
+ // trivial implementation
+ }
+
+ public Collection getMailServers(String host) {
+ return null; // trivial implementation
+ }
+
+ public MailAddress getPostmaster() {
+ return null; // trivial implementation
+ }
+
+ public Object getAttribute(String name) {
+ return null; // trivial implementation
+ }
+
+ public Iterator getAttributeNames() {
+ return null; // trivial implementation
+ }
+
+ public int getMajorVersion() {
+ return 0; // trivial implementation
+ }
+
+ public int getMinorVersion() {
+ return 0; // trivial implementation
+ }
+
+ public String getServerInfo() {
+ return null; // trivial implementation
+ }
+
+ public boolean isLocalServer(String serverName) {
+ return false; // trivial implementation
+ }
+
+ public boolean isLocalUser(String userAccount) {
+ return false; // trivial implementation
+ }
+
+ public void log(String message) {
+ // trivial implementation
+ }
+
+ public void log(String message, Throwable t) {
+ // trivial implementation
+ }
+
+ public void removeAttribute(String name) {
+ // trivial implementation
+ }
+
+ public void sendMail(MimeMessage msg) throws MessagingException {
+ // trivial implementation
+ }
+
+ public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException {
+ // trivial implementation
+ }
+
+ public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException {
+ // trivial implementation
+ }
+
+ public void sendMail(Mail mail) throws MessagingException {
+ // trivial implementation
+ }
+
+ public void setAttribute(String name, Object object) {
+ // trivial implementation
+ }
+
+ public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
+ // trivial implementation
+ }
+
+ public Iterator getSMTPHostAddresses(String domainName) {
+ return null; // trivial implementation
+ }
+}
Index: src/test/org/apache/james/test/util/Util.java
===================================================================
--- src/test/org/apache/james/test/util/Util.java (revision 0)
+++ src/test/org/apache/james/test/util/Util.java (revision 0)
@@ -0,0 +1,33 @@
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.test.util;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+
+public class Util {
+
+ public static int getRandomNonPrivilegedPort() {
+ return ((int)( Math.random() * 1000) + 3000);
+ }
+
+ public static Configuration getValuedConfiguration(String name, String value) {
+ DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);
+ defaultConfiguration.setValue(value);
+ return defaultConfiguration;
+ }
+}
Index: src/test/org/apache/james/smtpserver/SMTPServerTest.java
===================================================================
--- src/test/org/apache/james/smtpserver/SMTPServerTest.java (revision 0)
+++ src/test/org/apache/james/smtpserver/SMTPServerTest.java (revision 0)
@@ -0,0 +1,164 @@
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+package org.apache.james.smtpserver;
+
+import junit.framework.TestCase;
+import org.apache.avalon.cornerstone.services.sockets.SocketManager;
+import org.apache.avalon.cornerstone.services.threads.ThreadManager;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.services.JamesConnectionManager;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockSocketManager;
+import org.apache.james.test.mock.avalon.MockThreadManager;
+import org.apache.james.test.mock.james.MockMailServer;
+import org.apache.james.test.mock.james.MockUserRepository;
+import org.apache.james.test.mock.mailet.MockMailContext;
+import org.apache.james.test.util.Util;
+import org.apache.james.util.connection.SimpleConnectionManager;
+import org.columba.ristretto.composer.MimeTreeRenderer;
+import org.columba.ristretto.io.CharSequenceSource;
+import org.columba.ristretto.message.*;
+import org.columba.ristretto.smtp.SMTPException;
+import org.columba.ristretto.smtp.SMTPProtocol;
+
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests the org.apache.james.smtpserver.SMTPServer unit
+ */
+public class SMTPServerTest extends TestCase {
+ private int m_smtpListenerPort = Util.getRandomNonPrivilegedPort();
+ private MockMailServer m_mailServer;
+
+ public SMTPServerTest() {
+ super("SMTPServerTest");
+ }
+
+ private SMTPServer _smtpServer;
+
+
+ protected void setUp() throws Exception {
+ _smtpServer = new SMTPServer();
+ _smtpServer.enableLogging(new MockLogger());
+
+ _smtpServer.service(setUpServiceManager());
+ _smtpServer.configure(new DefaultSMTPConfiguration(m_smtpListenerPort));
+ _smtpServer.initialize();
+ }
+
+ private MockServiceManager setUpServiceManager() {
+ MockServiceManager serviceManager = new MockServiceManager();
+ SimpleConnectionManager connectionManager = new SimpleConnectionManager();
+ connectionManager.enableLogging(new MockLogger());
+ serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
+ serviceManager.put("org.apache.mailet.MailetContext", new MockMailContext());
+ m_mailServer = new MockMailServer();
+ serviceManager.put("org.apache.james.services.MailServer", m_mailServer);
+ serviceManager.put("org.apache.james.services.UsersRepository", new MockUserRepository());
+ serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_smtpListenerPort));
+ serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
+ return serviceManager;
+ }
+
+ public void testSimpleMailSend() throws Exception, SMTPException {
+ SMTPProtocol smtpProtocol = new SMTPProtocol("127.0.0.1", m_smtpListenerPort);
+
+ smtpProtocol.openPort();
+
+ // no message there, yet
+ assertNull("mail received by mail server", m_mailServer.getLastMail());
+
+ String[] capabilityStrings = smtpProtocol.ehlo(InetAddress.getLocalHost());
+ assertEquals("capabilities", 3, capabilityStrings.length);
+ List capabilitieslist = Arrays.asList(capabilityStrings);
+ assertTrue("capabilities present PIPELINING", capabilitieslist.contains("PIPELINING"));
+ assertTrue("capabilities present ENHANCEDSTATUSCODES", capabilitieslist.contains("ENHANCEDSTATUSCODES"));
+ assertTrue("capabilities present 8BITMIME", capabilitieslist.contains("8BITMIME"));
+
+ smtpProtocol.mail(new Address("mail@localhost"));
+ smtpProtocol.rcpt(new Address("mail@localhost"));
+
+ MimeHeader mimeHeader = new MimeHeader(new Header());
+ mimeHeader.set("Mime-Version", "1.0");
+ LocalMimePart mail = new LocalMimePart(mimeHeader);
+ MimeHeader header = mail.getHeader();
+ header.setMimeType(new MimeType("text", "plain"));
+
+ mail.setBody(new CharSequenceSource("James Unit Test Body"));
+
+ smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(mail));
+
+ smtpProtocol.quit();
+
+ // mail was propagated by SMTPServer
+ assertNotNull("mail received by mail server", m_mailServer.getLastMail());
+ }
+
+}
+
+class DefaultSMTPConfiguration extends DefaultConfiguration {
+
+ private int m_smtpListenerPort;
+
+ public DefaultSMTPConfiguration(int smtpListenerPort) {
+ super("smptserver");
+
+ init(smtpListenerPort);
+ }
+
+ private void init(int smtpListenerPort) {
+ m_smtpListenerPort = smtpListenerPort;
+
+ setAttribute("enabled", true);
+
+ addChild(Util.getValuedConfiguration("port", "" + m_smtpListenerPort));
+
+ DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
+ handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer"));
+ handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000"));
+ handlerConfig.addChild(Util.getValuedConfiguration("authorizedAddresses", "127.0.0.0/8"));
+ handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "0"));
+
+ DefaultConfiguration handlerChainConfig = new DefaultConfiguration("handlerchain");
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("HELO", HeloCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("EHLO", EhloCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("AUTH", AuthCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("VRFY", VrfyCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("EXPN", ExpnCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("MAIL", MailCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("RCPT", RcptCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("DATA", DataCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("RSET", RsetCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("HELP", HelpCmdHandler.class));
+ handlerChainConfig.addChild(createCommandHandlerConfiguration("QUIT", QuitCmdHandler.class));
+
+ handlerConfig.addChild(handlerChainConfig);
+ addChild(handlerConfig);
+ }
+
+ private DefaultConfiguration createCommandHandlerConfiguration(String command, Class commandClass) {
+ DefaultConfiguration cmdHandlerConfig = new DefaultConfiguration("handler");
+ cmdHandlerConfig.setAttribute("command", command);
+ String classname = commandClass.getName();
+ cmdHandlerConfig.setAttribute("class", classname);
+ return cmdHandlerConfig;
+ }
+
+}
Index: build.xml
===================================================================
--- build.xml (revision 327257)
+++ build.xml (working copy)
@@ -740,6 +740,7 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+