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/14 16:57:02 UTC

svn commit: r804246 [3/3] - in /james/server/sandbox/active/smtp_refactor: avalon-socket-library/src/main/java/org/apache/james/socket/ core-library/src/main/java/org/apache/james/core/ smtpserver-function/src/main/java/org/apache/james/smtpserver/ smt...

Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java?rev=804246&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java Fri Aug 14 14:57:00 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/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java?rev=804246&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java Fri Aug 14 14:57:00 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/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java?rev=804246&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java Fri Aug 14 14:57:00 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