You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/01/02 19:26:16 UTC

svn commit: r365388 [1/2] - in /james/server/trunk: ./ src/test/ src/test/org/ src/test/org/apache/ src/test/org/apache/james/ src/test/org/apache/james/core/ src/test/org/apache/james/dnsserver/ src/test/org/apache/james/services/ src/test/org/apache/...

Author: bago
Date: Mon Jan  2 10:25:59 2006
New Revision: 365388

URL: http://svn.apache.org/viewcvs?rev=365388&view=rev
Log:
Introduce Unit Testing (JAMES-427)
Thanks to Bernd Fondermann. Running tests require junit and ristretto (not committed by now)

Added:
    james/server/trunk/src/test/
    james/server/trunk/src/test/org/
    james/server/trunk/src/test/org/apache/
    james/server/trunk/src/test/org/apache/james/
    james/server/trunk/src/test/org/apache/james/JamesTest.java
    james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java
    james/server/trunk/src/test/org/apache/james/core/
    james/server/trunk/src/test/org/apache/james/core/MailImplTest.java
    james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java
    james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java
    james/server/trunk/src/test/org/apache/james/dnsserver/
    james/server/trunk/src/test/org/apache/james/dnsserver/DNSServerTest.java
    james/server/trunk/src/test/org/apache/james/services/
    james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java
    james/server/trunk/src/test/org/apache/james/smtpserver/
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
    james/server/trunk/src/test/org/apache/james/test/
    james/server/trunk/src/test/org/apache/james/test/mock/
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersRepository.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java
    james/server/trunk/src/test/org/apache/james/test/mock/javaxmail/
    james/server/trunk/src/test/org/apache/james/test/mock/javaxmail/MockMimeMessage.java
    james/server/trunk/src/test/org/apache/james/test/mock/mailet/
    james/server/trunk/src/test/org/apache/james/test/mock/mailet/MockMailContext.java
    james/server/trunk/src/test/org/apache/james/test/util/
    james/server/trunk/src/test/org/apache/james/test/util/Util.java
    james/server/trunk/src/test/org/apache/james/transport/
    james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java
Modified:
    james/server/trunk/build.xml
    james/server/trunk/default.properties

Modified: james/server/trunk/build.xml
URL: http://svn.apache.org/viewcvs/james/server/trunk/build.xml?rev=365388&r1=365387&r2=365388&view=diff
==============================================================================
--- james/server/trunk/build.xml (original)
+++ james/server/trunk/build.xml Mon Jan  2 10:25:59 2006
@@ -739,6 +739,7 @@
         <delete file="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.tar"/>
         <delete dir="${dist.dir}/MailetSDK"/>
     </target>
+
     <!--
     ===================================================================
                                   delete dist/ and build/
@@ -748,6 +749,57 @@
         <echo message ="deleting working directories ready for a clean build"/>
         <delete dir="${dist.dir}"/>
         <delete dir="${build.dir}"/>
+    </target>
+
+    <!--
+    ===================================================================
+                                  unit tests
+    ===================================================================
+    -->
+    <target name="unit-tests-classpath" depends="prepare">
+        <path id="unittest.class.path">
+          <pathelement location="tools/lib/optional.jar"/>
+          <pathelement location="tools/lib/junit.jar"/>
+          <pathelement location="tools/lib/ristretto-1.0-all.jar"/>
+          <fileset dir="${lib.dir}">
+            <include name="*.jar"/>
+          </fileset>
+        </path>
+    </target>
+        
+    <target name="compile-unit-tests" depends="unit-tests-classpath">
+      <echo message="Compiling James Unit Test Java sources"/>
+      <mkdir dir="${build.test}"/>
+      <mkdir dir="${build.test.classes}"/>
+      <javac destdir="${build.test.classes}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}">
+        <classpath refid="unittest.class.path"/>
+        <classpath refid="project.class.path"/>
+        <src path="${junitjava.dir}"/>
+        <exclude name="${constants.file}"/>
+        <exclude name="${poolconn.file}"/>
+      </javac>
+    </target>
+
+    <target name="run-unit-tests" depends="unit-tests-classpath, compile-unit-tests">
+        <echo message="Running James Unit Tests"/>
+        <mkdir dir="${build.test}"/>
+        <mkdir dir="${build.test.reports}"/>
+        <junit printsummary="yes" haltonfailure="yes"  >
+            <classpath refid="unittest.class.path"/>
+            <classpath refid="project.class.path"/>
+            <classpath>
+              <pathelement location="${build.test.classes}"/>
+            </classpath>
+        
+            <formatter type="plain"/>
+        
+            <batchtest fork="yes" todir="${build.test.reports}">
+              <fileset dir="${junitjava.dir}">
+                <include name="**/*Test.java"/>
+                <exclude name="**/AllTests.java"/>
+              </fileset>
+            </batchtest>
+        </junit>
     </target>
 
     <!--

Modified: james/server/trunk/default.properties
URL: http://svn.apache.org/viewcvs/james/server/trunk/default.properties?rev=365388&r1=365387&r2=365388&view=diff
==============================================================================
--- james/server/trunk/default.properties (original)
+++ james/server/trunk/default.properties Mon Jan  2 10:25:59 2006
@@ -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}
@@ -82,4 +86,8 @@
 #
 
 www.dir = ${james.dir}/www
+
+#
+#
+#
 

Added: james/server/trunk/src/test/org/apache/james/JamesTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/JamesTest.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/JamesTest.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,73 @@
+/***********************************************************************
+ * 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;
+
+import org.apache.james.services.MailServerTestAllImplementations;
+import org.apache.james.services.MailServer;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockStore;
+import org.apache.james.test.mock.avalon.MockContext;
+import org.apache.james.test.mock.james.MockUsersRepository;
+import org.apache.james.test.mock.james.MockUsersStore;
+
+import java.io.File;
+
+public class JamesTest extends MailServerTestAllImplementations {
+
+    public MailServer createMailServer() {
+        James james = new James();
+        james.service(setUpServiceManager());
+        MockLogger mockLogger = new MockLogger();
+        mockLogger.disableDebug();
+        james.enableLogging(mockLogger);
+        try {
+            JamesTestConfiguration conf = new JamesTestConfiguration();
+            conf.init();
+            james.configure(conf);
+            james.contextualize(new MockContext(File.createTempFile("james_test", "tmp")));
+            james.initialize();
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("James.initialize() failed");
+        }
+        return james;
+    }
+
+    private MockServiceManager setUpServiceManager() {
+        MockServiceManager serviceManager = new MockServiceManager();
+        MockUsersRepository mockUsersRepository = new MockUsersRepository();
+        serviceManager.put("org.apache.james.services.UsersRepository", mockUsersRepository);
+        serviceManager.put("org.apache.james.services.UsersStore", new MockUsersStore(mockUsersRepository));
+        serviceManager.put("org.apache.avalon.cornerstone.services.store.Store", new MockStore());
+        return serviceManager;
+    }
+
+    public boolean allowsPasswordlessUser() {
+        return false;
+    }
+
+    public boolean canTestUserExists() {
+        return true;
+    }
+
+    public boolean isUserExisting(MailServer mailServerImpl, String username) {
+        return ((James)mailServerImpl).isLocalUser(username);
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java (added)
+++ james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,49 @@
+/***********************************************************************
+ * 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;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.test.util.Util;
+
+public class JamesTestConfiguration extends DefaultConfiguration {
+    
+    public JamesTestConfiguration() {
+        super("James");
+    }
+
+    public void init() {
+
+        //setAttribute("enabled", true);
+
+        DefaultConfiguration serverNamesConfig = new DefaultConfiguration("servernames");
+        serverNamesConfig.setAttribute("autodetect", false);
+        serverNamesConfig.addChild(Util.getValuedConfiguration("servername", "localhost"));
+        addChild(serverNamesConfig);
+
+        DefaultConfiguration inboxRepositoryConfig = new DefaultConfiguration("inboxRepository");
+
+        DefaultConfiguration repositoryConfig = new DefaultConfiguration("repository");
+        repositoryConfig.setAttribute("destinationURL", "db://maildb/inbox/");
+        repositoryConfig.setAttribute("type", "MAIL");
+        inboxRepositoryConfig.addChild(repositoryConfig);
+
+        addChild(inboxRepositoryConfig);
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/core/MailImplTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MailImplTest.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MailImplTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/core/MailImplTest.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,96 @@
+/***********************************************************************
+ * 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.core;
+
+import org.apache.james.test.mock.james.MockMailServer;
+import org.apache.james.test.mock.javaxmail.MockMimeMessage;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+import java.util.ArrayList;
+
+public class MailImplTest extends MailTestAllImplementations {
+
+    protected Mail createMailImplementation() {
+        return new MailImpl();
+    }
+
+    public void testConstr1() throws MessagingException {
+        MailImpl mail = new MailImpl();
+
+        helperTestInitialState(mail);
+        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+        assertNull("no initial message", mail.getMessage());
+        assertNull("no initial sender", mail.getSender());
+        assertNull("no initial name", mail.getName());
+    }
+
+    public void testConstr2() throws MessagingException {
+        ArrayList recepients = new ArrayList();
+        String name = new MockMailServer().getId();
+        String sender = "sender@localhost";
+        MailAddress senderMailAddress = new MailAddress(sender);
+        MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
+
+        helperTestInitialState(mail); // MimeMessageWrapper default is 0
+        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+        assertNull("no initial message", mail.getMessage());
+        assertEquals("sender", sender, mail.getSender().toString());
+        assertEquals("name", name, mail.getName());
+
+        mail.setMessage(new MockMimeMessage());
+        assertNotNull("message", mail.getMessage());
+    }
+
+    public void testConstr3() throws MessagingException {
+        ArrayList recepients = new ArrayList();
+        String name = new MockMailServer().getId();
+        String sender = "sender@localhost";
+        MailAddress senderMailAddress = new MailAddress(sender);
+        MockMimeMessage mimeMessage = new MockMimeMessage();
+        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
+
+        helperTestInitialState(mail); 
+        helperTestMessageSize(mail, mimeMessage.getSize()); // MockMimeMessage default is -1 (accord. to javax.mail javadoc)
+        assertEquals("initial message", mimeMessage, mail.getMessage());
+        assertEquals("sender", sender, mail.getSender().toString());
+        assertEquals("name", name, mail.getName());
+    }
+
+    public void testDuplicate() throws MessagingException {
+        MailImpl mail = new MailImpl();
+        MailImpl duplicate = (MailImpl) mail.duplicate();
+        assertNotSame("is real duplicate", mail, duplicate);
+        helperTestInitialState(duplicate);
+        helperTestMessageSize(duplicate, 0);
+    }
+
+    public void testDuplicateNewName() throws MessagingException {
+        String newName = "aNewName";
+        
+        MailImpl mail = new MailImpl();
+        assertFalse("before + after names differ", newName.equals(mail.getName()));
+        
+        MailImpl duplicate = (MailImpl) mail.duplicate(newName);
+        assertEquals("new name set", newName, duplicate.getName());
+        helperTestInitialState(duplicate);
+        helperTestMessageSize(duplicate, 0);
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java (added)
+++ james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,69 @@
+/***********************************************************************
+ * 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.core;
+
+import junit.framework.TestCase;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+
+/**
+ * testing common behavior of Mail implementors. subclasses automatically get their Mail-behavior tested.
+ */
+public abstract class MailTestAllImplementations extends TestCase {
+
+    /** provide the concrete implementation to test */
+    protected abstract Mail createMailImplementation();
+
+    protected void helperTestInitialState(Mail mail) throws MessagingException {
+        assertFalse("no initial attributes", mail.hasAttributes());
+        assertNull("no initial error", mail.getErrorMessage());
+        assertNotNull("initial last update set", mail.getLastUpdated());
+        try {
+            assertTrue("no initial recipient", mail.getRecipients().isEmpty());
+        } catch (NullPointerException e) {
+            // current behavior. *BUT*, shouldn't this method better return with an empty list?!
+        }
+        assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr());
+        assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost());
+        assertEquals("default initial state", Mail.DEFAULT, mail.getState());
+    }
+
+    protected void helperTestMessageSize(Mail mail, int expectedMsgSize) throws MessagingException {
+        try {
+            assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize());
+        } catch (NullPointerException e) {
+            // current behavior. *BUT*, shouldn't this method return more gracefully?!
+        }
+    }
+
+    public void testAttributes() {
+        Mail mail = createMailImplementation();
+        assertFalse("no initial attributes", mail.hasAttributes());
+        assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
+        assertNull("not found on emtpy list", mail.getAttribute("test"));
+        assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
+        assertEquals("item found", "testValue", mail.getAttribute("testKey"));
+        assertTrue("has attribute", mail.hasAttributes());
+        assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
+        assertNull("item no longer found", mail.getAttribute("testKey"));
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,98 @@
+/***********************************************************************
+ * 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.core;
+
+import com.sun.mail.util.SharedByteArrayInputStream;
+
+import javax.mail.MessagingException;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the subject folding issue.
+ */
+public class MimeMessageWrapperTest extends TestCase {
+
+    MimeMessageWrapper mw = null;
+    String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain";
+    String sep = "\r\n\r\n";
+    String body = "bar\r\n.\r\n";
+
+    public MimeMessageWrapperTest(String arg0) {
+        super(arg0);
+
+        MimeMessageInputStreamSource mmis = null;
+        try {
+            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content+sep+body).getBytes()));
+        } catch (MessagingException e) {
+        }
+        mw = new MimeMessageWrapper(mmis);
+    }
+
+    /*
+     * Class under test for String getSubject()
+     */
+    public void testGetSubjectFolding() {
+        try {
+            StringBuffer res = new StringBuffer();
+            BufferedReader r = new BufferedReader(new InputStreamReader(mw.getInputStream()));
+            String line;
+            while (r.ready()) {
+                line = r.readLine();
+                res.append(line+"\r\n");
+            }
+            r.close();
+            assertEquals(body,res.toString());
+        } catch (MessagingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    /*
+     * Class under test for String getSubject()
+     */
+    public void testAddHeaderAndSave() {
+        try {
+            mw.addHeader("X-Test", "X-Value");
+            mw.saveChanges();
+
+            ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
+            mw.writeTo(rawMessage);
+            String res = rawMessage.toString();
+            
+            boolean found = res.indexOf("X-Test: X-Value") > 0;
+            assertEquals(true,found);
+
+        } catch (MessagingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/dnsserver/DNSServerTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/dnsserver/DNSServerTest.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/dnsserver/DNSServerTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/dnsserver/DNSServerTest.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,121 @@
+/***********************************************************************
+ * 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.dnsserver;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.fetchmail.ReaderInputStream;
+
+import java.io.StringReader;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class DNSServerTest extends TestCase {
+
+    /**
+     * Please note that this is an hardcoded test that works because
+     * www.pippo.com. is an alias to pippo.com and pippo.com has
+     * "pippo.com.inbound.mxlogic.net." as its mx record.
+     * This is the first domain with a record proving a previous james bug.
+     * This test will be invalidated by any change in the pippo.com dns records
+     * 
+     * @param args
+     * @throws Exception
+     */
+    public void testINARecords() throws Exception {
+        DNSServer d = new DNSServer();
+        DefaultConfigurationBuilder db = new DefaultConfigurationBuilder();
+
+        Configuration c = db
+                .build(
+                        new ReaderInputStream(
+                                new StringReader(
+                                        "<dnsserver><servers><server>192.168.0.1</server></servers><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>")),
+                        "dnsserver");
+        for (int i = 0; i < c.getAttributeNames().length; i++) {
+            System.out.println(c.getAttributeNames()[i]);
+        }
+
+        d.enableLogging(new Logger() {
+
+            public void debug(String arg0) {
+            }
+
+            public void debug(String arg0, Throwable arg1) {
+            }
+
+            public boolean isDebugEnabled() {
+                return false;
+            }
+
+            public void info(String arg0) {
+            }
+
+            public void info(String arg0, Throwable arg1) {
+            }
+
+            public boolean isInfoEnabled() {
+                return false;
+            }
+
+            public void warn(String arg0) {
+            }
+
+            public void warn(String arg0, Throwable arg1) {
+            }
+
+            public boolean isWarnEnabled() {
+                return false;
+            }
+
+            public void error(String arg0) {
+            }
+
+            public void error(String arg0, Throwable arg1) {
+            }
+
+            public boolean isErrorEnabled() {
+                return false;
+            }
+
+            public void fatalError(String arg0) {
+            }
+
+            public void fatalError(String arg0, Throwable arg1) {
+            }
+
+            public boolean isFatalErrorEnabled() {
+                return false;
+            }
+
+            public Logger getChildLogger(String arg0) {
+                return null;
+            }
+
+        });
+        d.configure(c);
+        d.initialize();
+        Collection records = d.findMXRecords("www.pippo.com.");
+        assertEquals(1, records.size());
+        assertEquals("pippo.com.inbound.mxlogic.net.", records.iterator()
+                .next());
+        d.dispose();
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java (added)
+++ james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,145 @@
+/***********************************************************************
+ * 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.services;
+
+import junit.framework.TestCase;
+
+/**
+ * tests all implementations for interface MailServer
+ */
+abstract public class MailServerTestAllImplementations extends TestCase {
+
+    abstract public MailServer createMailServer();
+    abstract public boolean allowsPasswordlessUser();
+
+    /**
+     * while addUser() is part of MailServer interface, a user cannot be tested for afterwards
+     * at the same time, James allows to do exactly this via isLocalUser(), other implementations
+     * might vary. 
+     */
+    abstract public boolean canTestUserExists();
+    abstract public boolean isUserExisting(MailServer mailServerImpl, String username);
+    
+    public void testId() {
+        MailServer mailServer = createMailServer();
+        
+        String id = mailServer.getId();
+        assertNotNull("mail id not null", id);
+        assertFalse("mail id not empty", "".equals(id));
+    }
+    
+    public void testIdIncrement() {
+        MailServer mailServer = createMailServer();
+        
+        String id1 = mailServer.getId();
+        String id2 = mailServer.getId();
+        assertFalse("next id is different", id1.equals(id2));
+    }
+    
+    public void testAddUser() {
+        
+        // addUser acts on field localUsers for class org.apache.james.James 
+        // thus, it is unrelated to getUserInbox() for the only known implementation of MailServer
+        // TODO clarify this 
+        
+        MailServer mailServer = createMailServer();
+
+        String userName = "testUserName";
+        MailRepository userInbox = null;
+
+        if (canTestUserExists())
+        {
+            assertFalse("this is a fresh user", isUserExisting(mailServer, userName));
+        }
+        
+        boolean allowsPasswordlessUser = allowsPasswordlessUser();
+        try {
+            boolean success = mailServer.addUser(userName, null);
+            if (!allowsPasswordlessUser) fail("null pwd was accepted unexpectedly");
+            if (!success) fail("null pwd was not accepted unexpectedly"); 
+        } catch (Exception e) {
+            if (allowsPasswordlessUser) fail("null pwd not accepted unexpectedly (with exception)");
+        }
+
+        userName = userName + "_next"; 
+        String password = "password";
+        
+        boolean success = mailServer.addUser(userName, password);
+        if (!success) fail("user has not been added"); 
+        
+        if (canTestUserExists())
+        {
+            assertTrue("user is present now", isUserExisting(mailServer, userName));
+        }
+        
+        boolean successAgain = mailServer.addUser(userName, password);
+        if (successAgain) fail("user has been added two times"); 
+        
+    }
+
+    public void testGetNonexisitingUserInbox() {
+
+        //
+        // TODO fix test (or James) -- test WILL FAIL
+        // 
+        
+        MailServer mailServer = createMailServer();
+
+        String userName = "testNonexisitingUserName";
+        MailRepository userInbox = null;
+        
+        try {
+            userInbox = mailServer.getUserInbox(userName);
+            assertEquals("test user does not exist", null, userInbox);
+            fail("found inbox which should be unexistent");
+        } catch (NullPointerException e) {
+            // this is what org.apache.james.James returns  
+            // is this behavior compatible with other implementations?
+            // shouldn't James behave more gracefully?
+        }
+    }
+    
+    public void testGetExisitingUserInbox() {
+        
+        //
+        // TODO fix test (or James) -- test WILL FAIL
+        // 
+        
+        MailServer mailServer = createMailServer();
+
+        String userName = "testUserName";
+        MailRepository userInbox = null;
+        
+        // getUserInbox acts on field mailboxes for class org.apache.james.James
+        // thus, it is unrelated to addUser() for the only known implementation of MailServer
+        // TODO clarify this 
+        mailServer.addUser(userName, "password"); // !! is not retrievable via getUserInbox !!
+        
+        
+        try {
+            userInbox = mailServer.getUserInbox(userName);
+            assertEquals("test user does not exist", null, userInbox);
+            fail("found inbox which should be unexistent");
+        } catch (NullPointerException e) {
+            // this is what org.apache.james.James returns  
+            // is this behavior compatible with other implementations?
+            // shouldn't James behave more gracefully?
+        }
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,335 @@
+/***********************************************************************
+ * 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.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.MockUsersRepository;
+import org.apache.james.test.mock.mailet.MockMailContext;
+import org.apache.james.test.util.Util;
+import org.apache.james.util.Base64;
+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 org.columba.ristretto.smtp.SMTPResponse;
+
+import java.io.IOException;
+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;
+    private SMTPTestConfiguration m_testConfiguration;
+    private SMTPServer m_smtpServer;
+    private MockUsersRepository m_usersRepository = new MockUsersRepository();
+
+    public SMTPServerTest() {
+        super("SMTPServerTest");
+    }
+
+    protected void setUp() throws Exception {
+        m_smtpServer = new SMTPServer();
+        m_smtpServer.enableLogging(new MockLogger());
+
+        m_smtpServer.service(setUpServiceManager());
+        m_testConfiguration = new SMTPTestConfiguration(m_smtpListenerPort);
+    }
+
+    private void finishSetUp(SMTPTestConfiguration testConfiguration) throws Exception {
+        testConfiguration.init();
+        m_smtpServer.configure(testConfiguration);
+        m_smtpServer.initialize();
+        m_mailServer.setMaxMessageSizeBytes(m_testConfiguration.getMaxMessageSize());
+    }
+
+    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", m_usersRepository);
+        serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_smtpListenerPort));
+        serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
+        return serviceManager;
+    }
+
+    public void testSimpleMailSendWithEHLO() throws Exception, SMTPException {
+        finishSetUp(m_testConfiguration);
+
+        SMTPProtocol smtpProtocol = new SMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        // no message there, yet
+        assertNull("no 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"));
+
+        smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(createMail()));
+
+        smtpProtocol.quit();
+
+        // mail was propagated by SMTPServer
+        assertNotNull("mail received by mail server", m_mailServer.getLastMail());
+    }
+
+    public void testSimpleMailSendWithHELO() throws Exception, SMTPException {
+        finishSetUp(m_testConfiguration);
+
+        SMTPProtocol smtpProtocol = new SMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        // no message there, yet
+        assertNull("no mail received by mail server", m_mailServer.getLastMail());
+
+        smtpProtocol.helo(InetAddress.getLocalHost());
+
+        smtpProtocol.mail(new Address("mail@localhost"));
+        smtpProtocol.rcpt(new Address("mail@localhost"));
+
+        smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(createMail()));
+
+        smtpProtocol.quit();
+
+        // mail was propagated by SMTPServer
+        assertNotNull("mail received by mail server", m_mailServer.getLastMail());
+    }
+
+    private LocalMimePart createMail() {
+        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"));
+        return mail;
+    }
+
+    public void testAuth() throws Exception, SMTPException {
+        m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+        m_testConfiguration.setAuthorizingAnnounce();
+        finishSetUp(m_testConfiguration);
+
+        MySMTPProtocol smtpProtocol = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        String[] capabilityStrings = smtpProtocol.ehlo(InetAddress.getLocalHost());
+        List capabilitieslist = Arrays.asList(capabilityStrings);
+        assertTrue("anouncing auth required", capabilitieslist.contains("AUTH LOGIN PLAIN"));
+        // is this required or just for compatibility? assertTrue("anouncing auth required", capabilitieslist.contains("AUTH=LOGIN PLAIN"));
+
+        String userName = "test_user_smtp";
+        String noexistUserName = "noexist_test_user_smtp";
+        
+        smtpProtocol.sendCommand("AUTH FOO", null);
+        SMTPResponse response = smtpProtocol.getResponse();
+        assertEquals("expected error: unrecognized authentication type", 504, response.getCode());
+
+        smtpProtocol.mail(new Address(userName));
+
+        try {
+            smtpProtocol.rcpt(new Address("mail@sample.com"));
+            fail("no auth required");
+        } catch (SMTPException e) {
+            assertEquals("expected 530 error", 530, e.getCode());
+        }
+
+        assertFalse("user not existing", m_usersRepository.contains(noexistUserName));
+        try {
+            smtpProtocol.auth("PLAIN", noexistUserName, "pwd".toCharArray());
+            fail("auth succeeded for non-existing user");
+        } catch (SMTPException e) {
+            assertEquals("expected error", 535, e.getCode());
+        }
+
+        m_usersRepository.addUser(userName, "pwd");
+        try {
+            smtpProtocol.auth("PLAIN", userName, "wrongpwd".toCharArray());
+            fail("auth succeeded with wrong password");
+        } catch (SMTPException e) {
+            assertEquals("expected error", 535, e.getCode());
+        }
+
+        try {
+            smtpProtocol.auth("PLAIN", userName, "pwd".toCharArray());
+        } catch (SMTPException e) {
+            e.printStackTrace(); 
+            fail("authentication failed");
+        }
+
+        smtpProtocol.sendCommand("AUTH PLAIN ", new String[]{Base64.encodeAsString("\0" + userName + "\0pwd")});
+        response = smtpProtocol.getResponse();
+        assertEquals("expected error: User has previously authenticated.", 503, response.getCode());
+
+        smtpProtocol.rcpt(new Address("mail@sample.com"));
+        smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(createMail()));
+
+        smtpProtocol.quit();
+
+        // mail was propagated by SMTPServer
+        assertNotNull("mail received by mail server", m_mailServer.getLastMail());
+    }
+
+    public void testNoRecepientSpecified() throws Exception, SMTPException {
+        finishSetUp(m_testConfiguration);
+
+        MySMTPProtocol smtpProtocol = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        smtpProtocol.ehlo(InetAddress.getLocalHost());
+
+        smtpProtocol.mail(new Address("mail@sample.com"));
+
+        // left out for test smtpProtocol.rcpt(new Address("mail@localhost"));
+
+        try {
+            smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(createMail()));
+            fail("sending succeeded without recepient");
+        } catch (Exception e) {
+            // test succeeded
+        }
+
+        smtpProtocol.quit();
+
+        // mail was propagated by SMTPServer
+        assertNull("no mail received by mail server", m_mailServer.getLastMail());
+    }
+
+    public void testRelayingDenied() throws Exception, SMTPException {
+        m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
+        finishSetUp(m_testConfiguration);
+
+        SMTPProtocol smtpProtocol = new SMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        smtpProtocol.ehlo(InetAddress.getLocalHost());
+
+        smtpProtocol.mail(new Address("mail@sample.com"));
+        try {
+            smtpProtocol.rcpt(new Address("maila@sample.com"));
+            fail("relaying allowed");
+        } catch (SMTPException e) {
+            assertEquals("expected 550 error", 550, e.getCode());
+        }
+    }
+
+    public void testHandleAnnouncedMessageSizeLimitExceeded() throws Exception, SMTPException {
+        m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
+        finishSetUp(m_testConfiguration);
+
+        MySMTPProtocol smtpProtocol = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        smtpProtocol.ehlo(InetAddress.getLocalHost());
+
+        smtpProtocol.sendCommand("MAIL FROM:<ma...@localhost> SIZE=1025", null);
+        SMTPResponse response = smtpProtocol.getResponse();
+        assertEquals("expected error: max msg size exceeded", 552, response.getCode());
+
+        smtpProtocol.rcpt(new Address("mail@localhost"));
+    }
+
+    public void testHandleMessageSizeLimitExceeded() throws Exception, SMTPException {
+        m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb 
+        finishSetUp(m_testConfiguration);
+
+        MySMTPProtocol smtpProtocol = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        smtpProtocol.ehlo(InetAddress.getLocalHost());
+
+        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"));
+
+        // create Body with more than 1kb
+        StringBuffer body = new StringBuffer();
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+        body.append("1234567810123456782012345"); // 1025 chars
+
+        mail.setBody(new CharSequenceSource(body.toString()));
+
+        try {
+            smtpProtocol.data(MimeTreeRenderer.getInstance().renderMimePart(mail));
+            fail("message size exceeded not recognized");
+        } catch (SMTPException e) {
+            assertEquals("expected 552 error", 552, e.getCode());
+        }
+
+    }
+}
+
+class MySMTPProtocol extends SMTPProtocol
+{
+
+    public MySMTPProtocol(String s, int i) {
+        super(s, i);
+    }
+
+    public MySMTPProtocol(String s) {
+        super(s);
+    }
+
+    public void sendCommand(String string, String[] strings) throws IOException {
+        super.sendCommand(string, strings);     
+    }
+
+    public SMTPResponse getResponse() throws IOException, SMTPException {
+        return super.readSingleLineResponse();
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java (added)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,109 @@
+/***********************************************************************
+ * 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.smtpserver;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.test.util.Util;
+
+public class SMTPTestConfiguration extends DefaultConfiguration {
+
+    private int m_smtpListenerPort;
+    private int m_maxMessageSize = 0;
+    private String m_authorizedAddresses = "127.0.0.0/8";
+    private String m_authorizingMode = "false";
+    private boolean m_verifyIdentity = false;
+
+    public SMTPTestConfiguration(int smtpListenerPort) {
+        super("smptserver");
+
+        m_smtpListenerPort = smtpListenerPort;
+    }
+
+    public void setMaxMessageSize(int kilobytes)
+    {
+        m_maxMessageSize = kilobytes;
+    }
+    
+    public int getMaxMessageSize() {
+        return m_maxMessageSize;
+    }
+
+    public String getAuthorizedAddresses() {
+        return m_authorizedAddresses;
+    }
+
+    public void setAuthorizedAddresses(String authorizedAddresses) {
+        m_authorizedAddresses = authorizedAddresses;
+    }
+
+    public void setAuthorizingNotRequired() {
+        m_authorizingMode = "false";
+        m_verifyIdentity = false; 
+    }
+
+    public void setAuthorizingRequired() {
+        m_authorizingMode = "true";
+        m_verifyIdentity = true; 
+    }
+
+    public void setAuthorizingAnnounce() {
+        m_authorizingMode = "announce";
+        m_verifyIdentity = true; 
+    }
+
+    public void init() {
+
+        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", m_authorizedAddresses));
+        handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "" + m_maxMessageSize));
+        handlerConfig.addChild(Util.getValuedConfiguration("authRequired", m_authorizingMode));
+        if (m_verifyIdentity) handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + m_verifyIdentity)); 
+
+        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;
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,39 @@
+/***********************************************************************
+ * 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.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+
+public class MockContext implements Context {
+    
+    private Object m_retObj;
+
+    public MockContext() {
+        ; // will always return NULL
+    }
+    
+    public MockContext(Object retObj) {
+        m_retObj = retObj;
+    }
+    
+    public Object get(Object object) throws ContextException {
+        return m_retObj;
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,92 @@
+/***********************************************************************
+ * 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 {
+    private boolean m_debugEnabled = true;
+
+    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 m_debugEnabled;
+    }
+
+    public void disableDebug() {
+        m_debugEnabled = false;
+    }
+
+    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;
+    }
+    
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java Mon Jan  2 10:25:59 2006
@@ -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
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java Mon Jan  2 10:25:59 2006
@@ -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();
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,57 @@
+/***********************************************************************
+ * 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.store.Store;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MockStore implements Store {
+
+    Map m_storedObjectMap = new HashMap();
+
+    public void add(Object key, Object obj) {
+        m_storedObjectMap.put(key, obj);
+    }
+    
+    public Object select(Object object) throws ServiceException {
+        if (object instanceof Configuration) {
+            Configuration repConf = (Configuration) object;
+            try {
+                object = repConf.getAttribute("destinationURL");
+            } catch (ConfigurationException e) {
+                throw new RuntimeException("test failed");
+            }
+        }
+        Object result = m_storedObjectMap.get(object);
+        return result;
+    }
+
+    public boolean isSelectable(Object object) {
+        return m_storedObjectMap.get(object) != null; 
+    }
+
+    public void release(Object object) {
+        //trivial implementation
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java Mon Jan  2 10:25:59 2006
@@ -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;
+        }
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,61 @@
+/***********************************************************************
+ * 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.mailet.Mail;
+
+import javax.mail.MessagingException;
+import java.util.Iterator;
+import java.util.Collection;
+
+public class MockMailRepository implements MailRepository {
+
+    public void store(Mail mc) throws MessagingException {
+        // trivial implementation
+    }
+
+    public Iterator list() throws MessagingException {
+        return null;  // trivial implementation
+    }
+
+    public Mail retrieve(String key) throws MessagingException {
+        return null;  // trivial implementation
+    }
+
+    public void remove(Mail mail) throws MessagingException {
+        // trivial implementation
+    }
+
+    public void remove(Collection mails) throws MessagingException {
+        // trivial implementation
+    }
+
+    public void remove(String key) throws MessagingException {
+        // trivial implementation
+    }
+
+    public boolean lock(String key) throws MessagingException {
+        return false;  // trivial implementation
+    }
+
+    public boolean unlock(String key) throws MessagingException {
+        return false;  // trivial implementation
+    }
+}

Added: james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,111 @@
+/***********************************************************************
+ * 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.james.smtpserver.MessageSizeException;
+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.*;
+
+public class MockMailServer implements MailServer {
+
+    private final HashMap m_users = new HashMap();
+
+    private int m_counter = 0;
+    private int m_maxMessageSizeBytes = 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 {
+        int bodySize = mail.getMessage().getSize();
+        try {
+            if (m_maxMessageSizeBytes != 0 && m_maxMessageSizeBytes < bodySize) throw new MessageSizeException();
+        } catch (MessageSizeException e) {
+            throw new MessagingException("message size exception is nested", e);
+        }
+        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 Map getRepositoryCounters() {
+        return null; // trivial implementation 
+    }
+
+    public synchronized String getId() {
+        m_counter++;
+        return "MockMailServer-ID-" + m_counter;
+    }
+
+    public boolean addUser(String userName, String password) {
+        m_users.put(userName, password);
+        return true;
+    }
+
+    public boolean isLocalServer(String serverName) {
+        return "localhost".equals(serverName);
+    }
+
+    public Object[] getLastMail()
+    {
+        if (mails.size() == 0) return null;
+        return (Object[])mails.get(mails.size()-1);
+    }
+
+    public void setMaxMessageSizeBytes(int maxMessageSizeBytes) {
+        m_maxMessageSizeBytes = maxMessageSizeBytes;
+    }
+}
+
+

Added: james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java?rev=365388&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java (added)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java Mon Jan  2 10:25:59 2006
@@ -0,0 +1,84 @@
+/***********************************************************************
+ * 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.SpoolRepository;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+public class MockSpoolRepository implements SpoolRepository {
+    public ArrayList storedMails = new ArrayList();
+
+    public Mail accept() throws InterruptedException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Mail accept(long delay) throws InterruptedException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Mail accept(AcceptFilter filter) throws InterruptedException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void store(Mail mc) throws MessagingException {
+        
+    }
+
+    public Iterator list() throws MessagingException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Mail retrieve(String key) throws MessagingException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void remove(Mail mail) throws MessagingException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void remove(Collection mails) throws MessagingException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void remove(String key) throws MessagingException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public boolean lock(String key) throws MessagingException {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public boolean unlock(String key) throws MessagingException {
+        // TODO Auto-generated method stub
+        return false;
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org