JAMES-1773 Provide tests for RelayLimit

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/be1be8b9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/be1be8b9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/be1be8b9

Branch: refs/heads/master
Commit: be1be8b91139de41e9130fa127af3acd8d9d5f4e
Parents: 3ef4a11
Author: Benoit Tellier <[email protected]>
Authored: Wed Aug 10 15:51:26 2016 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 mailet/standard/pom.xml                         |  10 ++
 .../transport/matchers/RelayLimitTest.java      | 115 +++++++++++++++++++
 2 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/be1be8b9/mailet/standard/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index fba213d..3b6adf8 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -67,6 +67,16 @@
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/james-project/blob/be1be8b9/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
----------------------------------------------------------------------
diff --git 
a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
 
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
new file mode 100644
index 0000000..58e2701
--- /dev/null
+++ 
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
@@ -0,0 +1,115 @@
+/****************************************************************
+ * 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.transport.matchers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Properties;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class RelayLimitTest {
+
+    private RelayLimit testee;
+    private MailAddress mailAddress;
+    private Mail mail;
+    private MimeMessage mimeMessage;
+
+    @Before
+    public void setUp() throws Exception {
+        testee = new RelayLimit();
+        mailAddress = new MailAddress("[email protected]");
+        mail = new FakeMail();
+        mail.setRecipients(ImmutableList.of(mailAddress));
+        mimeMessage = new MimeMessage(Session.getDefaultInstance(new 
Properties()));
+        mail.setMessage(mimeMessage);
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldBeANumber() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=Abc", new 
FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldBeSpecified() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=", new 
FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldNotBeNull() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=0", new 
FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldNotBeEqualToZero() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=-1", new 
FakeMailContext()));
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenNoReceivedHeader() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new 
FakeMailContext()));
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenNotEnoughReceivedHeader() throws 
Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new 
FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnAddressWhenEqualToLimit() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new 
FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).containsExactly(mailAddress);
+    }
+
+    @Test
+    public void matchShouldReturnAddressWhenOverLimit() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new 
FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).containsExactly(mailAddress);
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to