james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r413310 - in /james/server/trunk/src/test/org/apache/james/transport/matchers: AbstractSenderIsTest.java SenderIsTest.java
Date Sat, 10 Jun 2006 14:34:04 GMT
Author: norman
Date: Sat Jun 10 07:34:03 2006
New Revision: 413310

URL: http://svn.apache.org/viewvc?rev=413310&view=rev
Log:
Add junit test for SenderIs matcher

Added:
    james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSenderIsTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/SenderIsTest.java

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSenderIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSenderIsTest.java?rev=413310&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSenderIsTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractSenderIsTest.java
Sat Jun 10 07:34:03 2006
@@ -0,0 +1,195 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+
+import junit.framework.TestCase;
+
+import org.apache.james.test.mock.mailet.MockMailContext;
+import org.apache.james.test.mock.mailet.MockMatcherConfig;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+
+public abstract class AbstractSenderIsTest extends TestCase {
+
+    protected Mail mockedMail;
+
+    protected Matcher matcher;
+
+    private MailAddress sender;
+
+    public AbstractSenderIsTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    protected void setSender(MailAddress sender) {
+        this.sender = sender;
+    }
+
+    protected void setupMockedMail() {
+        mockedMail = new Mail() {
+
+            private static final long serialVersionUID = 1L;
+
+            public String getName() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setName(String newName) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public MimeMessage getMessage() throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Collection getRecipients() {
+                ArrayList r = new ArrayList();
+                try {
+                    r.add(new MailAddress("test@localhost"));
+                } catch (ParseException e) {
+                }
+                return r;
+            }
+
+            public void setRecipients(Collection recipients) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public MailAddress getSender() {
+                return sender;
+            }
+
+            public String getState() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public String getRemoteHost() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public String getRemoteAddr() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public String getErrorMessage() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setErrorMessage(String msg) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setMessage(MimeMessage message) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setState(String state) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Serializable getAttribute(String name) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Iterator getAttributeNames() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public boolean hasAttributes() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Serializable removeAttribute(String name) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void removeAllAttributes() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Serializable setAttribute(String name, Serializable object) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public long getMessageSize() throws MessagingException {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public Date getLastUpdated() {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+            public void setLastUpdated(Date lastUpdated) {
+                throw new UnsupportedOperationException(
+                        "Unimplemented mock service");
+            }
+
+        };
+
+    }
+
+    protected void setupMatcher() throws MessagingException {
+        matcher = createMatcher();
+        MockMatcherConfig mci = new MockMatcherConfig(getConfigOption()
+                + getConfigValue(), new MockMailContext());
+        matcher.init(mci);
+    }
+
+    protected void setupAll() throws MessagingException {
+        setupMockedMail();
+        setupMatcher();
+    }
+
+    protected abstract String getConfigOption();
+
+    protected abstract String getConfigValue();
+
+    protected abstract Matcher createMatcher();
+}

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/SenderIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/SenderIsTest.java?rev=413310&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/SenderIsTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/SenderIsTest.java Sat
Jun 10 07:34:03 2006
@@ -0,0 +1,73 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+
+public class SenderIsTest extends AbstractSenderIsTest {
+
+    private final String SENDER_NAME = "test@james.apache.org";
+
+    public SenderIsTest(String arg0) throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    // test if matched
+    public void testSenderIsMatchedAllRecipients() throws MessagingException {
+        setSender(new MailAddress(SENDER_NAME));
+
+        setupMockedMail();
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNotNull(matchedRecipients);
+        assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
+                .size());
+    }
+
+    // test if not matched
+    public void testSenderIsNotMatchedAllRecipients() throws MessagingException {
+        setSender(new MailAddress("t@james.apache.org"));
+
+        setupMockedMail();
+        setupMatcher();
+
+        Collection matchedRecipients = matcher.match(mockedMail);
+
+        assertNull(matchedRecipients);
+    }
+
+    protected Matcher createMatcher() {
+        return new SenderIs();
+    }
+
+    protected String getConfigOption() {
+        return "SenderIs=";
+    }
+
+    protected String getConfigValue() {
+        return SENDER_NAME;
+    }
+}



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


Mime
View raw message