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 2009/08/18 17:42:13 UTC

svn commit: r805459 [7/7] - in /james/server/trunk: avalon-socket-library/src/main/java/org/apache/james/socket/ avalon-socket-library/src/main/java/org/apache/james/util/ core-library/src/main/java/org/apache/james/core/ phoenix-deployment-refactor/sr...

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -24,7 +24,6 @@
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.smtpserver.core.SetMimeHeaderHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.mailet.base.test.MailUtil;
 import org.apache.mailet.Mail;
 
 import javax.mail.MessagingException;
@@ -60,16 +59,12 @@
     }
 
     private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = MailUtil.createMimeMessage(headerName, headerValue);
+        mockedMimeMessage = Util.createMimeMessage(headerName, headerValue);
     }
 
     private void setupMockedSMTPSession() {
         mockedSMTPSession = new AbstractSMTPSession() {
 
-            public Mail getMail() {
-                return mockedMail;
-            }
-
             public int getRcptCount() {
                 return 0;
             }
@@ -83,7 +78,7 @@
         setHeaderValue(HEADER_VALUE);
 
         setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
+        mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
@@ -91,9 +86,9 @@
 
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
-        header.onMessage(mockedSMTPSession);
+        header.onMessage(mockedSMTPSession, mockedMail);
 
-        assertEquals(HEADER_VALUE, mockedSMTPSession.getMail().getMessage()
+        assertEquals(HEADER_VALUE, mockedMail.getMessage()
                 .getHeader(HEADER_NAME)[0]);
     }
 
@@ -103,7 +98,7 @@
         setHeaderValue(headerValue);
 
         setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
+        mockedMail = Util.createMockMail2Recipients(mockedMimeMessage);
 
         SetMimeHeaderHandler header = new SetMimeHeaderHandler();
 
@@ -111,9 +106,9 @@
 
         header.setHeaderName(HEADER_NAME);
         header.setHeaderValue(HEADER_VALUE);
-        header.onMessage(mockedSMTPSession);
+        header.onMessage(mockedSMTPSession, mockedMail);
 
-        assertEquals(HEADER_VALUE, mockedSMTPSession.getMail().getMessage()
+        assertEquals(HEADER_VALUE, mockedMail.getMessage()
                 .getHeader(HEADER_NAME)[0]);
     }
 

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -31,9 +31,11 @@
 
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.smtpserver.core.filter.fastfail.SpamAssassinHandler;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.HookReturnCode;
+import org.apache.james.test.mock.MockMimeMessage;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.mailet.base.test.FakeMimeMessage;
-import org.apache.mailet.base.test.FakeMail;
+import org.apache.james.test.mock.mailet.MockMail;
 import org.apache.james.test.mock.util.MockSpamd;
 import org.apache.james.test.util.Util;
 import org.apache.james.util.scanner.SpamAssassinInvoker;
@@ -42,16 +44,12 @@
 public class SpamAssassinHandlerTest extends TestCase {
     private SMTPSession mockedSMTPSession;
 
-    private String response = null;
-    
+    private Mail mockedMail;
+ 
     public final static String SPAMD_HOST = "localhost";
 
-    public void setUp() {
-        // reset reponse
-        response = null;
-    }
-
     private SMTPSession setupMockedSMTPSession(final Mail mail) {
+        mockedMail = mail;
         mockedSMTPSession = new AbstractSMTPSession() {
 
             private HashMap state = new HashMap();
@@ -62,13 +60,6 @@
 
             private boolean relayingAllowed;
 
-            public void abortMessage() {
-            }
-
-            public Mail getMail() {
-                return mail;
-            }
-
             public String getRemoteHost() {
                 return host;
             }
@@ -89,29 +80,21 @@
             public void setRelayingAllowed(boolean relayingAllowed) {
                 this.relayingAllowed = relayingAllowed;
             }
-
-            public void writeResponse(String respString) {
-                response = respString;
-            }
         };
 
         return mockedSMTPSession;
 
     }
 
-    private String getResponse() {
-        return response;
-    }
-
     private Mail setupMockedMail(MimeMessage message) {
-        FakeMail mail = new FakeMail();
+        MockMail mail = new MockMail();
         mail.setMessage(message);
         return mail;
     }
 
     public MimeMessage setupMockedMimeMessage(String text)
             throws MessagingException {
-        MimeMessage message = new MimeMessage(new FakeMimeMessage());
+        MimeMessage message = new MimeMessage(new MockMimeMessage());
         message.setText(text);
         message.saveChanges();
 
@@ -132,12 +115,12 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertNull("Email was not rejected", getResponse());
-        assertEquals("email was not spam", session.getMail().getAttribute(
+        assertEquals("Email was not rejected", response.getResult(), HookReturnCode.DECLINED);
+        assertEquals("email was not spam", mockedMail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "NO");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mockedMail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
 
     }
@@ -155,12 +138,12 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(2000.0);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertNull("Email was not rejected", getResponse());
-        assertEquals("email was spam", session.getMail().getAttribute(
+        assertEquals("Email was not rejected", response.getResult(), HookReturnCode.DECLINED);
+        assertEquals("email was spam", mockedMail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mockedMail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
     }
 
@@ -177,12 +160,12 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertNotNull("Email was rejected", getResponse());
-        assertEquals("email was spam", session.getMail().getAttribute(
+        assertEquals("Email was rejected", response.getResult(), HookReturnCode.DENY);
+        assertEquals("email was spam", mockedMail.getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
-        assertNotNull("spam hits", session.getMail().getAttribute(
+        assertNotNull("spam hits", mockedMail.getAttribute(
                 SpamAssassinInvoker.STATUS_MAIL_ATTRIBUTE_NAME));
     }
 

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamTrapHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamTrapHandlerTest.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamTrapHandlerTest.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamTrapHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import java.util.ArrayList;
+
+import javax.mail.internet.ParseException;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.smtpserver.core.filter.fastfail.SpamTrapHandler;
+import org.apache.james.smtpserver.hook.HookReturnCode;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.mailet.MailAddress;
+
+import junit.framework.TestCase;
+
+public class SpamTrapHandlerTest extends TestCase {
+    private static final String SPAM_TRAP_RECIP1 = "spamtrap1@localhost";
+    private static final String RECIP1 = "recip@localhost";
+    
+    private SMTPSession setUpSMTPSession(final String ip) {
+        return new AbstractSMTPSession() {
+            public String getRemoteIPAddress() {
+                return ip;
+            }
+        
+        };
+    }
+    
+    public void testSpamTrap() throws ParseException {
+        String ip = "192.168.100.1";
+        String ip2 = "192.168.100.2";
+        long blockTime = 2000;
+    
+        ArrayList rcpts = new ArrayList();
+        rcpts.add(SPAM_TRAP_RECIP1);
+    
+        SpamTrapHandler handler = new SpamTrapHandler();
+        ContainerUtil.enableLogging(handler, new MockLogger());
+    
+        handler.setBlockTime(blockTime);
+        handler.setSpamTrapRecipients(rcpts);
+    
+        int result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(SPAM_TRAP_RECIP1)).getResult();
+    
+        assertEquals("Blocked on first connect",HookReturnCode.DENY,result);
+    
+
+        result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(RECIP1)).getResult();
+    
+        assertEquals("Blocked on second connect", HookReturnCode.DENY,result);
+    
+        
+        result = handler.doRcpt(setUpSMTPSession(ip2),null,new MailAddress(RECIP1)).getResult();
+    
+        assertEquals("Not Blocked", HookReturnCode.DECLINED,result);
+    
+        try {
+            // Wait for the blockTime to exceed
+            Thread.sleep(blockTime);
+        } catch (InterruptedException e) {
+            fail("Failed to sleep for " + blockTime +" ms");
+        }
+    
+        result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(RECIP1)).getResult();
+    
+        assertEquals("Not blocked. BlockTime exceeded", HookReturnCode.DECLINED,result); 
+    }
+}

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -18,9 +18,12 @@
  ****************************************************************/
 package org.apache.james.smtpserver;
 
+import javax.mail.internet.ParseException;
+
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.smtpserver.core.filter.fastfail.TarpitHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.mailet.MailAddress;
 
 import junit.framework.TestCase;
 
@@ -34,13 +37,18 @@
             public int getRcptCount() {
                 return rcptCount;
             }
+            
+            public void sleep(long ms) {
+                // use the real code 
+                (new SMTPHandler()).sleep(ms);
+            }
 
         };
 
         return session;
     }
 
-    public void testTarpit() {
+    public void testTarpit() throws ParseException {
         long tarpitTime = 1000;
         long tarpitTolerance = 100;
         long startTime;
@@ -53,13 +61,13 @@
 
         // no tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(0));
+        handler.doRcpt(setupMockedSession(0),null,new MailAddress("test@test"));
         assertTrue("No tarpit",
                 (System.currentTimeMillis() - startTime) < tarpitTime - tarpitTolerance);
 
         // tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(3));
+        handler.doRcpt(setupMockedSession(3),null,new MailAddress("test@test"));
         assertTrue("tarpit",
                 (System.currentTimeMillis() - startTime) >= tarpitTime - tarpitTolerance);
     }

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -42,11 +42,11 @@
 import org.apache.james.api.dnsservice.AbstractDNSServer;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.smtpserver.core.filter.fastfail.URIRBLHandler;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.HookReturnCode;
+import org.apache.james.test.mock.MockMimeMessage;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.mailet.base.test.FakeMimeMessage;
-import org.apache.mailet.base.test.FakeMail;
+import org.apache.james.test.mock.mailet.MockMail;
 import org.apache.mailet.Mail;
 
 public class URIRBLHandlerTest extends TestCase {
@@ -55,15 +55,10 @@
     private static final String GOOD_DOMAIN = "good.apache.org";
     private static final String URISERVER = "multi.surbl.org.";
     private SMTPSession mockedSMTPSession;
-
-    private String response = null;
-    
-    public void setUp() {
-        // reset reponse
-        response = null;
-    }
+    private Mail mockedMail;
 
     private SMTPSession setupMockedSMTPSession(final Mail mail) {
+        mockedMail = mail;
         mockedSMTPSession = new AbstractSMTPSession() {
 
             private HashMap state = new HashMap();
@@ -74,15 +69,6 @@
 
             private boolean relayingAllowed;
 
-            private boolean processing;
-            
-            public void abortMessage() {
-            }
-
-            public Mail getMail() {
-                return mail;
-            }
-
             public String getRemoteHost() {
                 return host;
             }
@@ -103,37 +89,21 @@
             public void setRelayingAllowed(boolean relayingAllowed) {
                 this.relayingAllowed = relayingAllowed;
             }
-
-            public void writeResponse(String respString) {
-                response = respString;
-            }
-            
-            public void setStopHandlerProcessing(boolean processing) {
-                this.processing = processing;
-            }
-            
-            public boolean getStopHandlerProcessing() {
-                return processing;
-            }
         };
 
         return mockedSMTPSession;
 
     }
 
-    private String getResponse() {
-        return response;
-    }
-
     private Mail setupMockedMail(MimeMessage message) {
-        FakeMail mail = new FakeMail();
+        MockMail mail = new MockMail();
         mail.setMessage(message);
         return mail;
     }
 
     public MimeMessage setupMockedMimeMessage(String text)
             throws MessagingException {
-        MimeMessage message = new MimeMessage(new FakeMimeMessage());
+        MimeMessage message = new MimeMessage(new MockMimeMessage());
         message.setText(text);
         message.saveChanges();
 
@@ -141,12 +111,12 @@
     }
     
     public MimeMessage setupMockedMimeMessageMP(String text) throws MessagingException {
-        MimeMessage message = new MimeMessage(new FakeMimeMessage());
+        MimeMessage message = new MimeMessage(new MockMimeMessage());
         
-//      Create the message part 
+        // Create the message part 
         BodyPart messageBodyPart = new MimeBodyPart();
 
-//         Fill the message
+        // Fill the message
         messageBodyPart.setText(text);
 
         Multipart multipart = new MimeMultipart();
@@ -163,7 +133,7 @@
      *
      */
     private DNSService setupMockedDnsServer() {
-        DNSService mockedDnsServer = new AbstractDNSServer() {
+    	DNSService mockedDnsServer = new AbstractDNSServer() {
 
             public Collection findTXTRecords(String hostname) {
                 List res = new ArrayList();
@@ -203,12 +173,11 @@
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
-        handler.setDnsServer(setupMockedDnsServer());
+        handler.setDNSService(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertFalse("Not Stop handler processing", session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
+        assertEquals("Email was not rejected", response.getResult(),HookReturnCode.DECLINED);
     }
     
     public void testBlocked() throws IOException, MessagingException {
@@ -221,12 +190,11 @@
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
-        handler.setDnsServer(setupMockedDnsServer());
+        handler.setDNSService(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertTrue("Stop handler processing", session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
+        assertEquals("Email was rejected", response.getResult(), HookReturnCode.DENY);
     }
     
     public void testBlockedMultiPart() throws IOException, MessagingException {
@@ -239,14 +207,14 @@
         URIRBLHandler handler = new URIRBLHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
-        handler.setDnsServer(setupMockedDnsServer());
+        handler.setDNSService(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertTrue("Stop handler processing", session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
+        assertEquals("Email was rejected", response.getResult(), HookReturnCode.DENY);
     }
-    
+
+    /*
     public void testAddJunkScore() throws IOException, MessagingException {
         
         ArrayList servers = new ArrayList();
@@ -262,10 +230,10 @@
         handler.setUriRblServer(servers);
         handler.setAction("junkScore");
         handler.setScore(20);
-        handler.onMessage(session);
+        HookResult response = handler.onMessage(session, mockedMail);
 
-        assertFalse("Not stop handler processing", session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
         assertEquals("JunkScore added", ((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("UriRBLCheck"), 20.0, 0d);
     }
+    */
 }

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/Util.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/Util.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/Util.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/Util.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,141 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Random;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.test.mock.MockMimeMessage;
+import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.mailet.MailAddress;
+
+/**
+ * some utilities for James unit testing
+ */
+public class Util {
+
+    private static final int PORT_RANGE_START =  8000; // the lowest possible port number assigned for testing
+    private static final int PORT_RANGE_END   = 11000; // the highest possible port number assigned for testing
+    private static int PORT_LAST_USED = PORT_RANGE_START;
+    private static final Random RANDOM = new Random();
+    /**
+     * assigns a port from the range of test ports
+     * @return port number
+     */
+    public static int getNonPrivilegedPort() {
+        return getNextNonPrivilegedPort(); // uses sequential assignment of ports
+    }
+
+    /**
+     * assigns a random port from the range of test ports
+     * @return port number
+     */
+    protected static int getRandomNonPrivilegedPortInt() {
+        return ((int)( Math.random() * (PORT_RANGE_END - PORT_RANGE_START) + PORT_RANGE_START));
+    }
+
+    /**
+     * assigns ports sequentially from the range of test ports
+     * @return port number
+     */
+    protected synchronized static int getNextNonPrivilegedPort() {
+        // Hack to increase probability that the port is bindable
+        int nextPortCandidate = PORT_LAST_USED;
+        while (true) {
+            try {
+                nextPortCandidate++;
+                if (PORT_LAST_USED == nextPortCandidate) throw new RuntimeException("no free port found");
+                if (nextPortCandidate > PORT_RANGE_END) nextPortCandidate = PORT_RANGE_START; // start over
+
+                // test, port is available
+                ServerSocket ss;
+                ss = new ServerSocket(nextPortCandidate);
+                ss.setReuseAddress(true);
+                ss.close();
+                break;
+            } catch (IOException e) {
+                e.printStackTrace();
+                continue; // try next port
+            }
+        }
+        PORT_LAST_USED = nextPortCandidate;
+        return PORT_LAST_USED;
+    }
+
+    public static Configuration getValuedConfiguration(String name, String value) {
+        DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);
+        defaultConfiguration.setValue(value);
+        return defaultConfiguration;
+    }
+
+    public static DefaultConfiguration createRemoteManagerHandlerChainConfiguration() {
+        DefaultConfiguration handlerChainConfig = new DefaultConfiguration("test");
+        return handlerChainConfig;
+    }
+
+    public static MockMail createMockMail2Recipients(MimeMessage m) throws ParseException {
+        MockMail mockedMail = new MockMail();
+        mockedMail.setName("ID="+RANDOM.nextLong());
+        mockedMail.setMessage(m);
+        mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
+                new MailAddress("test@james.apache.org"),
+                new MailAddress("test2@james.apache.org") }));
+        return mockedMail;
+    }
+
+    public static MockMimeMessage createMimeMessage() throws MessagingException {
+        return createMimeMessage(null, null);
+    }
+    
+    public static MockMimeMessage createMimeMessageWithSubject(String subject) throws MessagingException {
+        return createMimeMessage(null, null, subject, 0);
+    }
+    
+    public static MockMimeMessage createMimeMessage(String subject, int number) throws MessagingException {
+        return createMimeMessage(null, null, subject, number);
+    }
+    
+    public static MockMimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException {
+        return createMimeMessage(headerName, headerValue, "testmail", 0);
+    }
+    
+    public static MockMimeMessage createMimeMessage(String headerName, String headerValue, String subject, int number) throws MessagingException {
+        String sender = "test@james.apache.org";
+        String rcpt = "test2@james.apache.org";
+
+        MockMimeMessage mockedMimeMessage = new MockMimeMessage(number);
+        mockedMimeMessage.setFrom(new InternetAddress(sender));
+        mockedMimeMessage.setRecipients(MimeMessage.RecipientType.TO, rcpt);
+        if (headerName != null) mockedMimeMessage.setHeader(headerName, headerValue);
+        if (subject != null) mockedMimeMessage.setSubject(subject);
+        mockedMimeMessage.setText("testtext");
+        mockedMimeMessage.saveChanges();
+        return mockedMimeMessage;
+    }
+}

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -27,46 +27,33 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import junit.framework.TestCase;
+
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.api.vut.ErrorMappingException;
 import org.apache.james.api.vut.VirtualUserTable;
 import org.apache.james.services.MailServer;
 import org.apache.james.smtpserver.core.filter.fastfail.ValidRcptHandler;
+import org.apache.james.smtpserver.hook.HookReturnCode;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.james.test.mock.avalon.MockServiceManager;
 import org.apache.james.userrepository.MockUsersRepository;
 import org.apache.mailet.MailAddress;
 import org.apache.oro.text.regex.MalformedPatternException;
 
-import junit.framework.TestCase;
-
 public class ValidRcptHandlerTest extends TestCase {
     
     private final static String VALID_USER = "postmaster";
     private final static String INVALID_USER = "invalid";
     private final static String USER1 = "user1";
     private final static String USER2 = "user2";
-    private String response = null;
     private MockServiceManager serviceMan;
     
-    public void setUp() {
-        response = null;
-    }
-    
-    private SMTPSession setupMockedSMTPSession(final SMTPHandlerConfigurationData conf, final MailAddress rcpt, final boolean relayingAllowed, final boolean authRequired, final String username) {
+    private SMTPSession setupMockedSMTPSession(final SMTPHandlerConfigurationData conf, final MailAddress rcpt, final boolean relayingAllowed) {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
-            boolean stop = false;
-        
-            public boolean isAuthRequired() {
-                return authRequired;
-            }
-        
-            public String getUser() {
-                return username;
-            }
-        
+
             public boolean isRelayingAllowed() {
                 return relayingAllowed;
             }
@@ -76,22 +63,8 @@
             }
         
             public Map getState() {
-                state.put(SMTPSession.CURRENT_RECIPIENT,rcpt);
-
                 return state;
             }
-        
-            public void writeResponse(String resp) {
-                response = resp;
-            }
-        
-            public void setStopHandlerProcessing(boolean stop) {
-                this.stop = stop;
-            }
-        
-            public boolean getStopHandlerProcessing() {
-                return stop;
-            }
         };
     
         return session;
@@ -111,7 +84,7 @@
                 if (user.equals(USER1)) {
                     mappings.add("address@localhost");
                 } else if (user.equals(USER2)) {
-                    throw new ErrorMappingException("BOUNCE!");
+                    throw new ErrorMappingException("554 BOUNCE");
                 }
                 return mappings;
             }
@@ -148,22 +121,10 @@
                 return user;
             }
 
-            public boolean isAuthRequired(String remoteIP) {
-                throw new UnsupportedOperationException("Unimplemented Stub Method");
-            }
-
-            public boolean isAuthRequired() {
-                throw new UnsupportedOperationException("Unimplemented Stub Method");
-            }
-
             public boolean isRelayingAllowed(String remoteIP) {
                 throw new UnsupportedOperationException("Unimplemented Stub Method");
             }
 
-            public boolean isVerifyIdentity() {
-                throw new UnsupportedOperationException("Unimplemented Stub Method");
-            }
-
             public boolean useHeloEhloEnforcement() {
                 throw new UnsupportedOperationException("Unimplemented Stub Method");
             }
@@ -171,6 +132,18 @@
             public boolean useAddressBracketsEnforcement() {
                 return  true;
             }
+
+			public boolean isAuthRequired(String remoteIP) {
+                throw new UnsupportedOperationException("Unimplemented Stub Method");
+			}
+
+			public boolean isAuthRequired() {
+				return false;
+			}
+
+			public boolean isVerifyIdentity() {
+				return false;
+			}
         
         };
     
@@ -180,64 +153,52 @@
     public void testRejectInvalidUser() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER + "@localhost"),false,false,null);
-        ContainerUtil.enableLogging(handler,new MockLogger());
-    
-        handler.onCommand(session);
-    
-        assertTrue("Rejected",session.getStopHandlerProcessing());
-        assertNotNull("Rejected",response);
-    }
-    
-    public void testNotRejectInvalidUserAuth() throws Exception {
-        ValidRcptHandler handler = new ValidRcptHandler();
-        ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER + "@localhost"),false,true,"authedUser");
+        MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
     
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+        assertEquals("Rejected",rCode,HookReturnCode.DENY);
     }
     
     public void testNotRejectInvalidUserRelay() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(INVALID_USER + "@localhost"),true,false,null);
+        MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,true);
         ContainerUtil.enableLogging(handler,new MockLogger());
-    
-        handler.onCommand(session);
-    
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
+        
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testNotRejectValidUser() throws Exception {
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(VALID_USER + "@localhost"),false,false,null);
+        MailAddress mailAddress = new MailAddress(VALID_USER + "@localhost");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.onCommand(session);
-    
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
+        
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testNotRejectValidUserRecipient() throws Exception {
         String recipient = "recip@domain";
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        MailAddress mailAddress = new MailAddress(recipient);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidRecipients(recipient);
-        handler.onCommand(session);
+
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
         
-    
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testNotRejectValidUserDomain() throws Exception {
@@ -246,15 +207,15 @@
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        MailAddress mailAddress = new MailAddress(recipient);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidDomains(domain);
-        handler.onCommand(session);
+
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
         
-    
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testNotRejectValidUserRegex() throws Exception {
@@ -263,15 +224,15 @@
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(recipient),false,false,null);
+        MailAddress mailAddress = new MailAddress(recipient);
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
     
         handler.setValidRegex("reci.*");
-        handler.onCommand(session);
+
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
         
-    
-        assertFalse("Not rejected",session.getStopHandlerProcessing());
-        assertNull("Not rejected",response);
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testInvalidRegex() throws Exception{
@@ -290,27 +251,29 @@
     }
     
     public void testHasAddressMapping() throws Exception {
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(USER1 + "@localhost"),false,false,null);
+        MailAddress mailAddress = new MailAddress(USER1 + "@localhost");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
     
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
         ContainerUtil.enableLogging(handler,new MockLogger());
-        handler.onCommand(session);
-    
-        assertNull("No reject",response);
-        assertFalse("Not stop processing",session.getStopHandlerProcessing());
+
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
+        
+        assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
     }
     
     public void testHasErrorMapping() throws Exception {
-        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),new MailAddress(USER2 + "@localhost"),false,false,null);
+        MailAddress mailAddress = new MailAddress(USER2 + "@localhost");
+        SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
 
         ValidRcptHandler handler = new ValidRcptHandler();
         ContainerUtil.service(handler, setUpServiceManager());
         ContainerUtil.enableLogging(handler,new MockLogger());
-        handler.onCommand(session);
-     
-       assertNull("Valid Error mapping",session.getState().get("VALID_USER"));
-       assertNotNull("Error mapping",response);
-       assertTrue("Stop processing",session.getStopHandlerProcessing());
+
+        int rCode = handler.doRcpt(session, null,mailAddress).getResult();
+    
+        assertNull("Valid Error mapping",session.getState().get("VALID_USER"));
+        assertEquals("Error mapping",rCode, HookReturnCode.DENY);
     }
 }

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java Tue Aug 18 15:42:09 2009
@@ -32,15 +32,13 @@
 import org.apache.james.api.dnsservice.AbstractDNSServer;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.smtpserver.core.filter.fastfail.ValidRcptMX;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
+import org.apache.james.smtpserver.hook.HookReturnCode;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.mailet.MailAddress;
 
 import junit.framework.TestCase;
 
 public class ValidRcptMXTest extends TestCase {
-    private String response = null;
 
     private final static String INVALID_HOST = "invalid.host.de";
 
@@ -48,40 +46,24 @@
 
     private final static String LOOPBACK = "127.0.0.1";
 
-    protected void setUp() throws Exception {
-        response = null;
-
-        super.setUp();
-    }
-
     private SMTPSession setupMockedSMTPSession(final MailAddress rcpt) {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
-            boolean stopProcessing = false;
-
+            
             public Map getState() {
-                state.put(SMTPSession.CURRENT_RECIPIENT, rcpt);
                 return state;
             }
-
-            public void writeResponse(String resp) {
-                response = resp;
-            }
             
             public String getRemoteIPAddress() {
                 return "127.0.0.1";
             }
-            
-            public void setStopHandlerProcessing(boolean stopProcessing) {
-                this.stopProcessing = stopProcessing;
-            }
 
         };
         return session;
     }
 
     private DNSService setupMockedDNSServer() {
-        DNSService dns = new AbstractDNSServer() {
+    	DNSService dns = new AbstractDNSServer() {
 
             public Collection findMXRecords(String hostname) {
                 Collection mx = new ArrayList();
@@ -111,37 +93,17 @@
         bNetworks.add("127.0.0.1");
         
         DNSService dns = setupMockedDNSServer();
+        MailAddress mailAddress = new MailAddress("test@" + INVALID_HOST);
+        SMTPSession session = setupMockedSMTPSession(mailAddress);
         ValidRcptMX handler = new ValidRcptMX();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
 
-        handler.setDNSServer(dns);
+        handler.setDNSService(dns);
         handler.setBannedNetworks(bNetworks, dns);
-        handler.onCommand(setupMockedSMTPSession(new MailAddress("test@" + INVALID_HOST)));
+        int rCode = handler.doRcpt(session, null, mailAddress).getResult();
 
-        assertNotNull("Reject", response);
+        assertEquals("Reject", rCode, HookReturnCode.DENY);
     }
     
-
-    public void testAddJunkScoreLoopbackMX() throws ParseException {
-        Collection bNetworks = new ArrayList();
-        bNetworks.add("127.0.0.1");
-        
-        SMTPSession session = setupMockedSMTPSession(new MailAddress("test@" + INVALID_HOST));
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-        
-        DNSService dns = setupMockedDNSServer();
-        ValidRcptMX handler = new ValidRcptMX();
-        handler.setScore(20);
-        handler.setAction("junkScore");
-
-        ContainerUtil.enableLogging(handler, new MockLogger());
-
-        handler.setDNSServer(dns);
-        handler.setBannedNetworks(bNetworks, dns);
-        handler.onCommand(session);
-
-        assertNull("Not Reject", response);
-        assertEquals("JunkScore added",((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("ValidRcptMXCheck"),20.0, 0d);
-    }
 }

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java?rev=805459&r1=805458&r2=805459&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java Tue Aug 18 15:42:09 2009
@@ -26,27 +26,20 @@
 
 import javax.mail.internet.ParseException;
 
+import junit.framework.TestCase;
+
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.api.dnsservice.AbstractDNSServer;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.smtpserver.core.filter.fastfail.ValidSenderDomainHandler;
-import org.apache.james.smtpserver.junkscore.JunkScore;
-import org.apache.james.smtpserver.junkscore.JunkScoreImpl;
+import org.apache.james.smtpserver.hook.HookReturnCode;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.mailet.MailAddress;
 
-import junit.framework.TestCase;
-
 public class ValidSenderDomainHandlerTest extends TestCase {
     
-    private String response = null;
-
-    public void setUp() {
-        response = null;
-    }
-    
     private DNSService setupDNSServer() {
-        DNSService dns = new AbstractDNSServer(){
+    	DNSService dns = new AbstractDNSServer(){
 
             public Collection findMXRecords(String hostname) {
                 Collection mx = new ArrayList();
@@ -63,8 +56,7 @@
     private SMTPSession setupMockedSession(final MailAddress sender) {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
-            boolean processing = false;
-            
+
             public Map getState() {
 
                 state.put(SMTPSession.SENDER, sender);
@@ -75,59 +67,31 @@
             public boolean isRelayingAllowed() {
                 return false;
             }
-            
-            public void writeResponse(String resp) {
-                response = resp;
-            }
-            
-            public void setStopHandlerProcessing(boolean processing) {
-                this.processing = processing;
-            }
-            
-            public boolean getStopHandlerProcessing() {
-                return processing;
-            }
+
             
         };
         return session;
     }
     
-    private String getResponse() {
-        return response;
-    }
     
     // Test for JAMES-580
     public void testNullSenderNotReject() {
         ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
         ContainerUtil.enableLogging(handler, new MockLogger());
         
-        handler.setDnsServer(setupDNSServer());
-        handler.onCommand(setupMockedSession(null));
-        
-        assertNull("Not blocked cause its a nullsender",getResponse());
-    }
-    
-    public void testInvalidSenderDomainAddJunkScore() throws ParseException {
-        ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
-        SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
-        ContainerUtil.enableLogging(handler, new MockLogger());
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-        handler.setAction("JunkScore");
-        handler.setScore(20);
-        handler.setDnsServer(setupDNSServer());
-        handler.onCommand(session);
+        handler.setDNSService(setupDNSServer());
+        int response = handler.doMail(setupMockedSession(null),null).getResult();
         
-        assertNull("Not blocked cause we use JunkScore",getResponse());
-        assertEquals("JunkScore is stored",((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("ValidSenderDomainCheck"),20.0,0d);
+        assertEquals("Not blocked cause its a nullsender",response,HookReturnCode.DECLINED);
     }
-    
+
     public void testInvalidSenderDomainReject() throws ParseException {
         ValidSenderDomainHandler handler = new ValidSenderDomainHandler();
         SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
         ContainerUtil.enableLogging(handler, new MockLogger());
-        handler.setDnsServer(setupDNSServer());
-        handler.onCommand(session);
+        handler.setDNSService(setupDNSServer());
+        int response = handler.doMail(session,(MailAddress) session.getState().get(SMTPSession.SENDER)).getResult();
         
-        assertNotNull("Blocked cause we use reject action",getResponse());
+        assertEquals("Blocked cause we use reject action", response,HookReturnCode.DENY);
     }
 }

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/MockMimeMessage.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/MockMimeMessage.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/MockMimeMessage.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/MockMimeMessage.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,486 @@
+/****************************************************************
+ * 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.test.mock;
+
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.InternetAddress;
+import javax.mail.*;
+import javax.mail.search.SearchTerm;
+import javax.activation.DataHandler;
+import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+public class MockMimeMessage extends MimeMessage {
+
+    private final List m_fromAddresses = new ArrayList();
+    private Address m_senderAddress;
+    private final List m_toRecepients = new ArrayList();
+    private final List m_ccRecepients = new ArrayList();
+    private final List m_bccRecepients = new ArrayList();
+    private final List m_replyToAddresses = new ArrayList();
+    private String m_subject;
+    private int m_iMessageNumber;
+    private boolean m_bIsExpunged;
+    private Object m_content;
+    private Date m_sentDate;
+    private String[] m_contentLanguage;
+    private String m_fileName;
+    private DataHandler m_dataHandler;
+    private HashMap m_contentHeaders = new HashMap();
+    private Flags m_setFlags = new Flags();
+    private boolean m_doMatch;
+
+    public MockMimeMessage() throws MessagingException {
+        super((Session)null);
+    }
+
+    public MockMimeMessage(int messageNumber) throws MessagingException {
+        super((Session)null);
+        m_iMessageNumber = messageNumber;
+    }
+
+    public MockMimeMessage(MimeMessage mimeMessage) throws MessagingException {
+        super(mimeMessage); // trivial implementation
+    }
+
+    public Address[] getFrom() throws MessagingException {
+        return (Address[])m_fromAddresses.toArray();
+    }
+
+    public void setFrom(Address address) throws MessagingException {
+        m_fromAddresses.clear();
+        m_fromAddresses.add(address);
+    }
+
+    public void setFrom() throws MessagingException {
+        m_fromAddresses.clear();
+        m_fromAddresses.add(InternetAddress.getLocalAddress(null));
+    }
+
+    public void addFrom(Address[] addresses) throws MessagingException {
+        m_fromAddresses.add(addresses);
+    }
+
+    public Address getSender() throws MessagingException {
+        return m_senderAddress;
+    }
+
+    public void setSender(Address address) throws MessagingException {
+        m_senderAddress = address;
+    }
+
+    public Address[] getRecipients(Message.RecipientType recipientType) throws MessagingException {
+        List recipientsList = getRecipientsList(recipientType);
+        List recipientAddresses = new ArrayList();
+        for (Iterator iterator = recipientsList.iterator(); iterator.hasNext();) {
+            String recipient = (String) iterator.next();
+            recipientAddresses.add(new InternetAddress(recipient));
+        }
+        return (Address[]) (recipientAddresses.toArray(new Address[]{}));
+    }
+
+    private List getRecipientsList(Message.RecipientType recipientType) {
+        if (Message.RecipientType.TO.equals(recipientType)) return m_toRecepients; 
+        if (Message.RecipientType.CC.equals(recipientType)) return m_ccRecepients; 
+        if (Message.RecipientType.BCC.equals(recipientType)) return m_bccRecepients;
+        return null;
+    }
+    
+    public Address[] getAllRecipients() throws MessagingException {
+        List allRecipients = new ArrayList();
+        allRecipients.addAll(m_toRecepients);
+        allRecipients.addAll(m_ccRecepients);
+        allRecipients.addAll(m_bccRecepients);
+        return (Address[]) allRecipients.toArray();
+    }
+
+    public void setRecipients(Message.RecipientType recipientType, Address[] addresses) throws MessagingException {
+        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
+    }
+
+    public void setRecipients(Message.RecipientType recipientType, String recipient) throws MessagingException {
+        getRecipientsList(recipientType).add(recipient);
+    }
+
+    public void addRecipients(Message.RecipientType recipientType, Address[] addresses) throws MessagingException {
+        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
+    }
+
+    public void addRecipients(Message.RecipientType recipientType, String recipient) throws MessagingException {
+        getRecipientsList(recipientType).add(recipient);
+    }
+
+    public Address[] getReplyTo() throws MessagingException {
+        return (Address[]) m_replyToAddresses.toArray();
+    }
+
+    public void setReplyTo(Address[] addresses) throws MessagingException {
+        m_replyToAddresses.addAll(Arrays.asList(addresses));
+    }
+
+    public String getSubject() throws MessagingException {
+        return m_subject;
+    }
+
+    public void setSubject(String subject) throws MessagingException {
+        m_subject = subject;
+    }
+
+    public void setSubject(String subject, String charset) throws MessagingException {
+        if (subject == null)
+        {
+            m_subject = null;
+            return;
+        }
+        try {
+            m_subject = new String(subject.getBytes(charset));
+        } catch (UnsupportedEncodingException e) {
+            throw new MessagingException("setting subject failed", e);
+        }
+    }
+
+    public Date getSentDate() throws MessagingException {
+        return m_sentDate;
+    }
+
+    public void setSentDate(Date date) throws MessagingException {
+        m_sentDate = date;
+    }
+
+    public Date getReceivedDate() throws MessagingException {
+        return null; // trivial implementation
+    }
+
+    public int getSize() throws MessagingException {
+        return -1; // trivial implementation
+    }
+
+    public int getLineCount() throws MessagingException {
+        return -1; // trivial implementation
+    }
+
+    public String getContentType() throws MessagingException {
+        return getHeader("Content-Type", null);
+    }
+
+    public boolean isMimeType(String mimeType) throws MessagingException {
+        return mimeType.startsWith(getContentType());
+    }
+
+    public String getDisposition() throws MessagingException {
+        return getHeader("Content-Disposition", null);
+    }
+
+    public void setDisposition(String disposition) throws MessagingException {
+        setHeader("Content-Disposition", disposition);
+    }
+
+    public String getEncoding() throws MessagingException {
+        return getHeader("Content-Transfer-Encoding", null);
+    }
+
+    public String getContentID() throws MessagingException {
+        return getHeader("Content-ID", null);
+    }
+
+    public void setContentID(String contentID) throws MessagingException {
+        setHeader("Content-ID", contentID);
+    }
+
+    public String getContentMD5() throws MessagingException {
+        return getHeader("Content-MD5", null);
+    }
+
+    public void setContentMD5(String value) throws MessagingException {
+        setHeader("Content-MD5", value);
+    }
+
+    public String getDescription() throws MessagingException {
+        return getHeader("Content-Description", null);
+    }
+
+    public void setDescription(String description) throws MessagingException { 
+        setHeader("Content-Description", description);
+    }
+
+    public void setDescription(String description, String charset) throws MessagingException {
+        try {
+            setDescription(new String(description.getBytes(charset)));
+        } catch (UnsupportedEncodingException e) {
+            throw new MessagingException("setting description failed", e);
+        }
+    }
+
+    public String[] getContentLanguage() throws MessagingException {
+        return m_contentLanguage;
+    }
+
+    public void setContentLanguage(String[] contentLanguage) throws MessagingException {
+        m_contentLanguage = contentLanguage;
+    }
+
+    public String getMessageID() throws MessagingException {
+        return "ID-" + m_iMessageNumber; // trivial implementation
+    }
+
+    public String getFileName() throws MessagingException {
+        return m_fileName;
+    }
+
+    public void setFileName(String fileName) throws MessagingException {
+        m_fileName = fileName;
+    }
+
+    public InputStream getInputStream() throws IOException, MessagingException {
+        return null; // trivial implementation
+    }
+
+    protected InputStream getContentStream() throws MessagingException {
+        return null; // trivial implementation
+    }
+
+    public InputStream getRawInputStream() throws MessagingException {
+        if (m_content instanceof String) {
+            return new ByteArrayInputStream(m_content.toString().getBytes());
+        }
+        throw new UnsupportedOperationException("Unimplementated method");
+    }
+
+    public synchronized DataHandler getDataHandler() throws MessagingException {
+        return m_dataHandler;
+    }
+
+    public synchronized void setDataHandler(DataHandler dataHandler) throws MessagingException {
+        m_dataHandler = dataHandler;
+    }
+
+    public Object getContent() throws IOException, MessagingException {
+        return m_content;
+    }
+
+    public void setContent(Object object, String mimeType) throws MessagingException {
+        m_content = object;  // trivial implementation
+    }
+
+    public void setText(String string) throws MessagingException {
+        setContent(string, "text/plain");
+    }
+
+    public void setText(String string, String charset) throws MessagingException {
+        try {
+            setContent(new String(string.getBytes(charset)) , "text/plain");
+        } catch (UnsupportedEncodingException e) {
+            throw new MessagingException("setting text content failed", e);
+        }
+    }
+
+    public void setContent(Multipart multipart) throws MessagingException {
+        m_content = multipart;
+    }
+
+    public Message reply(boolean b) throws MessagingException {
+        return new MockMimeMessage(this); // trivial implementation
+    }
+
+    public void writeTo(OutputStream outputStream) throws IOException, MessagingException {
+        ; // trivial implementation
+    }
+
+    public void writeTo(OutputStream outputStream, String[] strings) throws IOException, MessagingException {
+        ; // trivial implementation
+    }
+
+    public String[] getHeader(String name) throws MessagingException {
+        String value = (String) m_contentHeaders.get(name);
+        if (value == null) return null;
+        return new String[] {value};
+    }
+
+    public String getHeader(String name, String delimiter) throws MessagingException {
+        String[] header = getHeader(name);
+        if (header == null || header.length == 0) return null;
+        return header[0];
+    }
+
+    public void setHeader(String name, String value) throws MessagingException {
+        addHeader(name, value);
+    }
+
+    public void addHeader(String name, String value) throws MessagingException {
+        m_contentHeaders.put(name, value);
+    }
+
+    public void removeHeader(String name) throws MessagingException {
+        m_contentHeaders.remove(name);
+    }
+
+    public Enumeration getAllHeaders() throws MessagingException {
+        return Collections.enumeration(m_contentHeaders.values());
+    }
+
+    public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
+        ArrayList matchingHeaders = new ArrayList();
+        for (int i = 0; i < names.length; i++) {
+            String name = names[i];
+            String value = getHeader(name, null);
+            if (value == null) continue;
+            matchingHeaders.add(value);
+        }
+        return Collections.enumeration(matchingHeaders); 
+    }
+
+    public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
+        List existingHeaders = Arrays.asList(names);
+
+        ArrayList nonMatchingHeaders = new ArrayList();
+        
+        Iterator iterator = m_contentHeaders.keySet().iterator();
+        while (iterator.hasNext()) {
+            String name = (String) iterator.next();
+            if (existingHeaders.contains(name)) continue;
+            String value = getHeader(name, null);
+            if (value == null) continue;
+            nonMatchingHeaders.add(value);
+        }
+        return Collections.enumeration(nonMatchingHeaders); 
+    }
+
+    public void addHeaderLine(String headerLine) throws MessagingException {
+        int separatorIndex = headerLine.indexOf(":");
+        if (separatorIndex < 0) throw new MessagingException("header line does not conform to standard");
+        
+        addHeader(headerLine.substring(0,separatorIndex), headerLine.substring(separatorIndex,headerLine.length()));
+    }
+
+    public Enumeration getAllHeaderLines() throws MessagingException {
+        return Collections.enumeration(getHeadersAsStrings(m_contentHeaders));
+    }
+
+    private ArrayList getHeadersAsStrings(HashMap contentHeaders) {
+        ArrayList headerLines = new ArrayList();
+        Iterator iterator = contentHeaders.keySet().iterator();
+        while (iterator.hasNext()) {
+            String key = (String) iterator.next();
+            String value = (String) contentHeaders.get(key);
+            headerLines.add(key + ":" + value);
+        }
+        return headerLines;
+    }
+
+    public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
+        ArrayList matchingHeaders = new ArrayList();
+        for (int i = 0; i < names.length; i++) {
+            String name = names[i];
+            String value = getHeader(name, null);
+            if (value == null) continue;
+            matchingHeaders.add(name + ":" + value);
+        }
+        return Collections.enumeration(matchingHeaders); 
+    }
+
+    public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
+        List existingHeaders = names != null ? Arrays.asList(names) : null;
+
+        ArrayList nonMatchingHeaders = new ArrayList();
+        
+        Iterator iterator = m_contentHeaders.keySet().iterator();
+        while (iterator.hasNext()) {
+            String name = (String) iterator.next();
+            if (existingHeaders!=null && existingHeaders.contains(name)) continue;
+            String value = getHeader(name, null);
+            if (value == null) continue;
+            nonMatchingHeaders.add(name + ":" + value);
+        }
+        return Collections.enumeration(nonMatchingHeaders); 
+    }
+
+    public synchronized Flags getFlags() throws MessagingException {
+        return new Flags(m_setFlags);
+    }
+
+    public synchronized boolean isSet(Flags.Flag flag) throws MessagingException {
+        return m_setFlags.contains(flag);
+    }
+
+    public synchronized void setFlags(Flags flags, boolean set) throws MessagingException {
+        if (set) m_setFlags.add(flags);
+        else m_setFlags.remove(flags);
+    }
+
+    public void saveChanges() throws MessagingException {
+        ; // trivial implementation
+    }
+
+    protected void updateHeaders() throws MessagingException {
+        ; // trivial implementation 
+    }
+
+    protected InternetHeaders createInternetHeaders(InputStream inputStream) throws MessagingException {
+        return new InternetHeaders();
+    }
+
+    public void setRecipient(Message.RecipientType recipientType, Address address) throws MessagingException {
+        setRecipients(recipientType, new Address[]{address});
+    }
+
+    public void addRecipient(Message.RecipientType recipientType, Address address) throws MessagingException {
+        setRecipients(recipientType, new Address[]{address});
+    }
+
+    public void setFlag(Flags.Flag flag, boolean set) throws MessagingException {
+        if (set) m_setFlags.add(flag);
+        else m_setFlags.remove(flag);
+    }
+
+    public int getMessageNumber() {
+        return m_iMessageNumber;
+    }
+
+    protected void setMessageNumber(int i) {
+        m_iMessageNumber = i;
+    }
+
+    public Folder getFolder() {
+        return null;
+    }
+
+    public boolean isExpunged() {
+        return m_bIsExpunged;
+    }
+
+    protected void setExpunged(boolean b) {
+        m_bIsExpunged = b;
+    }
+
+    public void setShouldMatch(boolean doMatch) {
+        m_doMatch = doMatch;
+    }
+    
+    public boolean match(SearchTerm searchTerm) throws MessagingException {
+        return m_doMatch; 
+    }
+}

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMail.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMail.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMail.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMail.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,157 @@
+/****************************************************************
+ * 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.test.mock.mailet;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+public class MockMail implements Mail {
+
+    private MimeMessage msg = null;
+
+    private Collection recipients = new ArrayList();
+
+    private String name = null;
+
+    private MailAddress sender = null;
+
+    private String state = null;
+
+    private String errorMessage;
+
+    private Date lastUpdated;
+
+    private HashMap attributes = new HashMap();
+
+    private static final long serialVersionUID = 1L;
+
+    private long size = 0;
+    
+    private String remoteAddr ="127.0.0.1";
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String newName) {
+        this.name = newName;
+    }
+
+    public MimeMessage getMessage() throws MessagingException {
+        return msg;
+    }
+
+    public Collection getRecipients() {
+        return recipients;
+    }
+
+    public void setRecipients(Collection recipients) {
+        this.recipients = recipients;
+    }
+
+    public MailAddress getSender() {
+        return sender;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public String getRemoteHost() {
+        return "111.222.333.444";
+    }
+
+    public String getRemoteAddr() {
+        return remoteAddr;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String msg) {
+        this.errorMessage = msg;
+    }
+
+    public void setMessage(MimeMessage message) {
+        this.msg = message;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public Serializable getAttribute(String name) {
+        return (Serializable) attributes.get(name);
+    }
+
+    public Iterator getAttributeNames() {
+        return attributes.keySet().iterator();
+    }
+
+    public boolean hasAttributes() {
+        return !attributes.isEmpty();
+    }
+
+    public Serializable removeAttribute(String name) {
+        return (Serializable) attributes.remove(name);
+
+    }
+
+    public void removeAllAttributes() {
+        attributes.clear();
+    }
+
+    public Serializable setAttribute(String name, Serializable object) {
+
+        return (Serializable) attributes.put(name, object);
+    }
+
+    public long getMessageSize() throws MessagingException {
+        return size;
+    }
+
+    public Date getLastUpdated() {
+        return lastUpdated;
+    }
+
+    public void setLastUpdated(Date lastUpdated) {
+        this.lastUpdated = lastUpdated;
+    }
+    
+    public void setMessageSize(long size) {
+        this.size = size;
+    }
+
+    public void setRemoteAddr(String remoteAddr) {
+        this.remoteAddr = remoteAddr;
+    }
+}

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,124 @@
+/****************************************************************
+ * 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.test.mock.mailet;
+
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+public class MockMailContext implements MailetContext {
+    
+    HashMap attributes = new HashMap();
+
+    public void bounce(Mail mail, String message) throws MessagingException {
+        // trivial implementation
+    }
+
+    public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
+        // trivial implementation
+    }
+
+    public Collection getMailServers(String host) {
+        return null;  // trivial implementation
+    }
+
+    public MailAddress getPostmaster() {
+        return null;  // trivial implementation
+    }
+
+    public Object getAttribute(String name) {
+        return attributes.get(name);
+    }
+
+    public Iterator getAttributeNames() {
+        return attributes.keySet().iterator();
+    }
+
+    public int getMajorVersion() {
+        return 0;  // trivial implementation
+    }
+
+    public int getMinorVersion() {
+        return 0;  // trivial implementation
+    }
+
+    public String getServerInfo() {
+        return "Mock Server";
+    }
+
+    public boolean isLocalServer(String serverName) {
+        return false;  // trivial implementation
+    }
+
+    public boolean isLocalUser(String userAccount) {
+        return false;  // trivial implementation
+    }
+
+    public boolean isLocalEmail(MailAddress mailAddress) {
+        return false;  // trivial implementation
+    }
+
+    public void log(String message) {
+        System.out.println(message);
+    }
+
+    public void log(String message, Throwable t) {
+        System.out.println(message);
+        t.printStackTrace(System.out);
+    }
+
+    public void removeAttribute(String name) {
+        // trivial implementation
+    }
+
+    public void sendMail(MimeMessage msg) throws MessagingException {
+        throw new UnsupportedOperationException("MOCKed method");
+    }
+
+    public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException {
+        throw new UnsupportedOperationException("MOCKed method");
+    }
+
+    public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException {
+        throw new UnsupportedOperationException("MOCKed method");
+    }
+
+    public void sendMail(Mail mail) throws MessagingException {
+        throw new UnsupportedOperationException("MOCKed method");
+    }
+
+    public void setAttribute(String name, Object object) {
+        attributes.put(name,object);
+    }
+
+    public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
+        // trivial implementation
+    }
+
+    public Iterator getSMTPHostAddresses(String domainName) {
+        return null;  // trivial implementation
+    }
+}

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.test.mock.mailet;
+
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.MailetContext;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * MailetConfig over Properties
+ */
+public class MockMailetConfig extends Properties implements MailetConfig {
+
+    private String mailetName;
+    private MailetContext mc;
+
+    
+    public MockMailetConfig(String mailetName, MailetContext mc) {
+        super();
+        this.mailetName = mailetName;
+        this.mc = mc;
+    }
+
+    public MockMailetConfig(String mailetName, MailetContext mc, Properties arg0) {
+        super(arg0);
+        this.mailetName = mailetName;
+        this.mc = mc;
+    }
+
+    public String getInitParameter(String name) {
+        return getProperty(name);
+    }
+
+    public Iterator getInitParameterNames() {
+        return keySet().iterator();
+    }
+
+    public MailetContext getMailetContext() {
+        return mc;
+    }
+
+    public String getMailetName() {
+        return mailetName;
+    }
+
+    // Override setProperty to work like it should in this MockMailetConfig
+    public Object setProperty(String key, String value) {
+        String oldValue = getProperty(key);
+        String newValue = value;
+
+        if (oldValue != null) {
+            newValue = oldValue + "," + value;
+        }
+        return super.setProperty(key, newValue);
+    }
+}

Added: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java?rev=805459&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java (added)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java Tue Aug 18 15:42:09 2009
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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.test.mock.mailet;
+
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.MatcherConfig;
+
+/**
+ * MatcherConfig
+ */
+public class MockMatcherConfig implements MatcherConfig {
+
+    private String matcherName;
+
+    private MailetContext mc;
+
+    public MockMatcherConfig(String matcherName, MailetContext mc) {
+        super();
+        this.matcherName = matcherName;
+        this.mc = mc;
+    }
+
+    public String getCondition() {
+        if (matcherName.indexOf("=") >= 0) {
+            return matcherName.substring(getMatcherName().length() + 1);
+        } else {
+            return null;
+        }
+    }
+
+    public MailetContext getMailetContext() {
+        return mc;
+    }
+
+    public String getMatcherName() {
+        if (matcherName.indexOf("=") >= 0) {
+            return matcherName.split("=")[0];
+        } else {
+            return matcherName;
+        }
+    }
+
+}



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