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 no...@apache.org on 2011/12/23 13:07:10 UTC

svn commit: r1222653 - in /james/protocols/trunk: ./ api/src/main/java/org/apache/james/protocols/api/ lmtp/ lmtp/src/test/ lmtp/src/test/java/ lmtp/src/test/java/org/ lmtp/src/test/java/org/apache/ lmtp/src/test/java/org/apache/james/ lmtp/src/test/ja...

Author: norman
Date: Fri Dec 23 12:07:09 2011
New Revision: 1222653

URL: http://svn.apache.org/viewvc?rev=1222653&view=rev
Log:
Add unit tests for LMTP. See PROTOCOLS-66

Added:
    james/protocols/trunk/lmtp/src/test/
    james/protocols/trunk/lmtp/src/test/java/
    james/protocols/trunk/lmtp/src/test/java/org/
    james/protocols/trunk/lmtp/src/test/java/org/apache/
    james/protocols/trunk/lmtp/src/test/java/org/apache/james/
    james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/
    james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/
    james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/LMTPServerTest.java
Modified:
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
    james/protocols/trunk/lmtp/pom.xml
    james/protocols/trunk/pom.xml
    james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocol.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/SMTPServerTest.java

Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java (original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java Fri Dec 23 12:07:09 2011
@@ -32,6 +32,13 @@ public interface Protocol {
      */
     ProtocolHandlerChain getProtocolChain();
 
+    /**
+     * Return the {@link ProtocolConfiguration} 
+     * 
+     * @return config
+     */
+    ProtocolConfiguration getConfiguration();
+    
     
     /**
      * Create a new {@link ProtocolSession} for the given {@link ProtocolTransport} 

Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java (original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java Fri Dec 23 12:07:09 2011
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
 public class ProtocolImpl implements Protocol{
     protected final static Logger logger = LoggerFactory.getLogger(ProtocolImpl.class);
     private final ProtocolHandlerChain chain;
-    protected final ProtocolConfiguration config;
+    private final ProtocolConfiguration config;
 
     public ProtocolImpl(ProtocolHandlerChain chain, ProtocolConfiguration config) {
         this.chain = chain;
@@ -53,4 +53,12 @@ public class ProtocolImpl implements Pro
         return new ProtocolSessionImpl(logger, transport, config);
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.Protocol#getConfiguration()
+     */
+    public ProtocolConfiguration getConfiguration() {
+        return config;
+    }
+
 }

Modified: james/protocols/trunk/lmtp/pom.xml
URL: http://svn.apache.org/viewvc/james/protocols/trunk/lmtp/pom.xml?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/lmtp/pom.xml (original)
+++ james/protocols/trunk/lmtp/pom.xml Fri Dec 23 12:07:09 2011
@@ -51,6 +51,22 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-net</groupId>
+            <artifactId>commons-net</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james.protocols</groupId>
+            <artifactId>protocols-netty</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james.protocols</groupId>
+            <artifactId>protocols-smtp</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Added: james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/LMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/LMTPServerTest.java?rev=1222653&view=auto
==============================================================================
--- james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/LMTPServerTest.java (added)
+++ james/protocols/trunk/lmtp/src/test/java/org/apache/james/protocols/lmtp/LMTPServerTest.java Fri Dec 23 12:07:09 2011
@@ -0,0 +1,352 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.protocols.lmtp;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.net.smtp.RelayPath;
+import org.apache.commons.net.smtp.SMTPClient;
+import org.apache.commons.net.smtp.SMTPReply;
+import org.apache.james.protocols.api.Protocol;
+import org.apache.james.protocols.api.handler.ProtocolHandler;
+import org.apache.james.protocols.api.handler.WiringException;
+import org.apache.james.protocols.lmtp.hook.DeliverToRecipientHook;
+import org.apache.james.protocols.netty.NettyServer;
+import org.apache.james.protocols.smtp.MailAddress;
+import org.apache.james.protocols.smtp.MailEnvelope;
+import org.apache.james.protocols.smtp.SMTPProtocol;
+import org.apache.james.protocols.smtp.SMTPServerTest;
+import org.apache.james.protocols.smtp.SMTPSession;
+import org.apache.james.protocols.smtp.TestUtils;
+import org.apache.james.protocols.smtp.hook.HookResult;
+import org.apache.james.protocols.smtp.hook.HookReturnCode;
+import org.apache.james.protocols.smtp.hook.MessageHook;
+import org.junit.Test;
+
+public class LMTPServerTest extends SMTPServerTest{
+
+    @Override
+    protected Protocol createProtocol(ProtocolHandler... handlers) throws WiringException {
+        LMTPProtocolHandlerChain chain = new LMTPProtocolHandlerChain();
+        List<ProtocolHandler> hList = new ArrayList<ProtocolHandler>();
+        
+        for (int i = 0; i < handlers.length; i++) {
+            ProtocolHandler handler = handlers[i];
+            if (handler instanceof MessageHook) {
+                handler = new MessageHookAdapter((MessageHook) handler);
+            } 
+            hList.add(handler);
+        }
+        chain.addAll(0, hList);
+        chain.wireExtensibleHandlers();
+        return new SMTPProtocol(chain, new LMTPConfigurationImpl());
+    }
+    
+    
+    @Override
+    public void testInvalidNoBracketsEnformance() throws Exception {
+        // Disable
+    }
+
+
+    @Override
+    public void testHeloEnforcement() throws Exception {
+        // Disable
+    }
+
+
+    @Override
+    public void testHeloEnforcementDisabled() throws Exception {
+        // Disable
+
+    }
+
+
+    @Override
+    public void testMailWithoutBrackets() throws Exception {
+        TestMessageHook hook = new TestMessageHook();
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
+        
+        NettyServer server = null;
+        try {
+            server = new NettyServer(createProtocol(hook));
+            server.setListenAddresses(address);
+            server.bind();
+            
+            SMTPClient client = createClient();
+            client.connect(address.getAddress().getHostAddress(), address.getPort());
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.helo("localhost");
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.mail(SENDER);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.quit();
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.disconnect();
+
+            Iterator<MailEnvelope> queued = hook.getQueued().iterator();
+            assertFalse(queued.hasNext());
+
+        } finally {
+            if (server != null) {
+                server.unbind();
+            }
+        }
+        
+    }
+
+
+    @Override
+    public void testRcptWithoutBrackets() throws Exception {
+        TestMessageHook hook = new TestMessageHook();
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
+        
+        NettyServer server = null;
+        try {
+            server = new NettyServer(createProtocol(hook));
+            server.setListenAddresses(address);
+            server.bind();
+            
+            SMTPClient client = createClient();
+            client.connect(address.getAddress().getHostAddress(), address.getPort());
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.helo("localhost");
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.setSender(SENDER);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.rcpt(RCPT1);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.quit();
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.disconnect();
+
+            Iterator<MailEnvelope> queued = hook.getQueued().iterator();
+            assertFalse(queued.hasNext());
+
+        } finally {
+            if (server != null) {
+                server.unbind();
+            }
+        }
+    }
+
+
+    @Test
+    public void testEhloNotSupported() throws Exception {
+        TestMessageHook hook = new TestMessageHook();
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
+        
+        NettyServer server = null;
+        try {
+            server = new NettyServer(createProtocol(hook));
+            server.setListenAddresses(address);
+            server.bind();
+            
+            LMTPClient client = (LMTPClient) createClient();
+            client.connect(address.getAddress().getHostAddress(), address.getPort());
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.sendCommand("HELO localhost");
+            assertTrue(SMTPReply.isNegativePermanent(client.getReplyCode()));
+            
+            client.quit();
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.disconnect();
+
+            Iterator<MailEnvelope> queued = hook.getQueued().iterator();
+            assertFalse(queued.hasNext());
+
+        } finally {
+            if (server != null) {
+                server.unbind();
+            }
+        }
+    }
+
+    @Test
+    public void testDeliveryHook() throws Exception {
+        TestDeliverHook deliverHook = new TestDeliverHook();
+        
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
+        
+        NettyServer server = null;
+        try {
+            server = new NettyServer(createProtocol(deliverHook));
+            server.setListenAddresses(address);
+            server.bind();
+            
+            LMTPClient client = (LMTPClient) createClient();
+            client.connect(address.getAddress().getHostAddress(), address.getPort());
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.helo("localhost");
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.setSender(SENDER);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.addRecipient(RCPT1);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            client.addRecipient(RCPT2);
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+
+            assertTrue(client.sendShortMessageData(MSG1));
+
+            int[] replies = client.getReplies();
+            
+            assertEquals("Expected two replies",2, replies.length);
+            
+            assertTrue(SMTPReply.isNegativePermanent(replies[0]));
+            assertTrue(SMTPReply.isPositiveCompletion(replies[1]));
+
+            client.quit();
+            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.disconnect();
+
+            Iterator<MailEnvelope> queued = deliverHook.getDelivered().iterator();
+            assertTrue(queued.hasNext());
+            
+            MailEnvelope env = queued.next();
+            checkEnvelope(env, SENDER, Arrays.asList(RCPT1, RCPT2), MSG1);
+            assertFalse(queued.hasNext());
+
+        } finally {
+            if (server != null) {
+                server.unbind();
+            }
+        }
+        
+    }
+    
+    protected SMTPClient createClient() {
+        return new LMTPClient();
+    }
+    
+    private final class LMTPClient extends SMTPClient {
+
+        private final List<Integer> replies = new ArrayList<Integer>();
+        private int rcptCount = 0;
+        
+        
+        @Override
+        public boolean addRecipient(String address) throws IOException {
+            boolean ok = super.addRecipient(address);
+            if (ok) {
+                rcptCount++;
+            }
+            return ok;
+        }
+
+        @Override
+        public boolean addRecipient(RelayPath path) throws IOException {
+            boolean ok = super.addRecipient(path);
+            if (ok) {
+                rcptCount++;
+            }
+            return ok;
+        }
+
+        /**
+         * Issue the LHLO command
+         */
+        @Override
+        public int helo(String hostname) throws IOException {
+            return sendCommand("LHLO", hostname);
+        }
+
+        public int[] getReplies() throws IOException
+        {
+            int[] codes = new int[replies.size()];
+            for (int i = 0; i < codes.length; i++) {
+                codes[i] = replies.remove(0);
+            }
+            return codes;
+        }
+        
+        @Override
+        public boolean completePendingCommand() throws IOException
+        {
+            for (int i = 0; i < rcptCount; i++) {
+                replies.add(getReply());
+            }
+            
+            for (int code: replies) {
+                if (SMTPReply.isPositiveCompletion(code)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        
+    }
+    
+    private final class MessageHookAdapter implements DeliverToRecipientHook {
+
+        private final MessageHook hook;
+        private  HookResult result;
+
+        public MessageHookAdapter(MessageHook hook) {
+            this.hook = hook;
+        }
+        
+        @Override
+        public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelope envelope) {
+            if (result == null) {
+                result = hook.onMessage(session, envelope);
+            } 
+            return result;
+        }
+        
+    }
+    
+    private final class TestDeliverHook implements DeliverToRecipientHook {
+        
+        private final List<MailEnvelope> delivered = new ArrayList<MailEnvelope>();
+        
+        @Override
+        public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelope envelope) {
+            if (RCPT1.equals(recipient.toString())) {
+                return new HookResult(HookReturnCode.DENY);
+            } else {
+                delivered.add(envelope);
+                return new HookResult(HookReturnCode.OK);
+            }
+        }
+        
+        public List<MailEnvelope> getDelivered() {
+            return delivered;
+        }
+    };
+
+}

Modified: james/protocols/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pom.xml?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/pom.xml (original)
+++ james/protocols/trunk/pom.xml Fri Dec 23 12:07:09 2011
@@ -76,6 +76,12 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.james.protocols</groupId>
+                <artifactId>protocols-smtp</artifactId>
+                <type>test-jar</type>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.james.protocols</groupId>
                 <artifactId>protocols-api</artifactId>
                 <version>${project.version}</version>
             </dependency>

Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocol.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocol.java?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocol.java (original)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocol.java Fri Dec 23 12:07:09 2011
@@ -39,7 +39,7 @@ public class SMTPProtocol extends Protoc
 
     @Override
     public ProtocolSession newSession(ProtocolTransport transport) {
-        return new SMTPSessionImpl(logger, transport, (SMTPConfiguration) config);
+        return new SMTPSessionImpl(logger, transport, (SMTPConfiguration) getConfiguration());
     }
 
 }

Modified: james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/SMTPServerTest.java?rev=1222653&r1=1222652&r2=1222653&view=diff
==============================================================================
--- james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/SMTPServerTest.java (original)
+++ james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/SMTPServerTest.java Fri Dec 23 12:07:09 2011
@@ -30,9 +30,12 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.commons.net.smtp.SMTPClient;
 import org.apache.commons.net.smtp.SMTPReply;
+import org.apache.james.protocols.api.Protocol;
 import org.apache.james.protocols.api.Response;
 import org.apache.james.protocols.api.handler.ConnectHandler;
 import org.apache.james.protocols.api.handler.DisconnectHandler;
+import org.apache.james.protocols.api.handler.ProtocolHandler;
+import org.apache.james.protocols.api.handler.WiringException;
 import org.apache.james.protocols.netty.NettyServer;
 import org.apache.james.protocols.smtp.hook.HeloHook;
 import org.apache.james.protocols.smtp.hook.HookResult;
@@ -45,10 +48,10 @@ import static org.junit.Assert.*;
 
 public class SMTPServerTest {
     
-    private final static String MSG1 = "Subject: Testmessage\r\n\r\nThis is a message";
-    private final static String SENDER = "me@sender";
-    private final static String RCPT1 ="rpct1@domain";
-    private final static String RCPT2 ="rpct2@domain";
+    protected final static String MSG1 = "Subject: Testmessage\r\n\r\nThis is a message";
+    protected final static String SENDER = "me@sender";
+    protected final static String RCPT1 ="rpct1@domain";
+    protected final static String RCPT2 ="rpct2@domain";
 
     @Test
     public void testSimpleDelivery() throws Exception {
@@ -57,11 +60,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -106,11 +109,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -139,11 +142,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -167,17 +170,17 @@ public class SMTPServerTest {
     
     
     @Test
-    public void testInvalidMailCommandSyntax() throws Exception {
+    public void testMailWithoutBrackets() throws Exception {
         TestMessageHook hook = new TestMessageHook();
         InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -216,11 +219,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -244,17 +247,17 @@ public class SMTPServerTest {
     
 
     @Test
-    public void testInvalidRcptCommandSyntax() throws Exception {
+    public void testRcptWithoutBrackets() throws Exception {
         TestMessageHook hook = new TestMessageHook();
         InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
         
         NettyServer server = null;
         try {
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), new SMTPConfigurationImpl()));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -292,13 +295,13 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            config.setUseAddressBracketsEnforcement(false);
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            Protocol protocol = createProtocol(hook);
+            ((SMTPConfigurationImpl) protocol.getConfiguration()).setUseAddressBracketsEnforcement(false);
+            server = new NettyServer(protocol);
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -336,12 +339,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -372,13 +374,13 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            config.setHeloEhloEnforcement(false);
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            Protocol protocol = createProtocol(hook);
+            ((SMTPConfigurationImpl) protocol.getConfiguration()).setHeloEhloEnforcement(false);
+            server = new NettyServer(protocol);
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -416,12 +418,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -456,12 +457,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -495,12 +495,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -537,12 +536,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -585,12 +583,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -641,12 +638,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook), config));
+            server = new NettyServer(createProtocol(hook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -695,12 +691,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook, testHook), config));
+            server = new NettyServer(createProtocol(hook, testHook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -752,12 +747,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            server = new NettyServer(new SMTPProtocol(new SMTPProtocolHandlerChain(hook, testHook), config));
+            server = new NettyServer(createProtocol(hook, testHook));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -807,16 +801,12 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            SMTPProtocolHandlerChain chain = new SMTPProtocolHandlerChain();
-            chain.add(0, connectHandler);
-            chain.wireExtensibleHandlers();
             
-            server = new NettyServer(new SMTPProtocol(chain, config));
+            server = new NettyServer(createProtocol(connectHandler));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isNegativePermanent(client.getReplyCode()));
             
@@ -847,16 +837,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            SMTPProtocolHandlerChain chain = new SMTPProtocolHandlerChain();
-            chain.add(0, connectHandler);
-            chain.wireExtensibleHandlers();
-            
-            server = new NettyServer(new SMTPProtocol(chain, config));
+            server = new NettyServer(createProtocol(connectHandler));
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isNegativeTransient(client.getReplyCode()));
             
@@ -888,16 +873,11 @@ public class SMTPServerTest {
         
         NettyServer server = null;
         try {
-            SMTPConfigurationImpl config = new SMTPConfigurationImpl();
-            SMTPProtocolHandlerChain chain = new SMTPProtocolHandlerChain();
-            chain.add(0, handler);
-            chain.wireExtensibleHandlers();
-            
-            server = new NettyServer(new SMTPProtocol(chain, config));
+            server = new NettyServer(createProtocol(handler));  
             server.setListenAddresses(address);
             server.bind();
             
-            SMTPClient client = new SMTPClient();
+            SMTPClient client = createClient();
             client.connect(address.getAddress().getHostAddress(), address.getPort());
             assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
             
@@ -915,7 +895,18 @@ public class SMTPServerTest {
         
     }
     
-    private static void checkEnvelope(MailEnvelope env, String sender, List<String> recipients, String msg) throws IOException {
+    protected SMTPClient createClient() {
+        return new SMTPClient();
+    }
+    
+    protected Protocol createProtocol(ProtocolHandler... handlers) throws WiringException {
+        SMTPProtocolHandlerChain chain = new SMTPProtocolHandlerChain();
+        chain.addAll(0, Arrays.asList(handlers));
+        chain.wireExtensibleHandlers();
+        return new SMTPProtocol(chain, new SMTPConfigurationImpl());
+    }
+    
+    protected static void checkEnvelope(MailEnvelope env, String sender, List<String> recipients, String msg) throws IOException {
         assertEquals(sender, env.getSender().toString());
 
         List<MailAddress> envRecipients = env.getRecipients();
@@ -956,7 +947,7 @@ public class SMTPServerTest {
 
     }
     
-    private final class TestMessageHook implements MessageHook {
+    public final class TestMessageHook implements MessageHook {
 
         private final List<MailEnvelope> queued = new ArrayList<MailEnvelope>();
         



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