james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/10] james-project git commit: JAMES-1773 Complete HasHeaderTest
Date Thu, 18 Aug 2016 10:19:25 GMT
JAMES-1773 Complete HasHeaderTest

What was not tested ?

 - multi-conditions
 - header present multiples times (buggy)
 - header with value specified


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

Branch: refs/heads/master
Commit: 1b9a1075d9baf5aea358eb40858c27118e571c3a
Parents: c94a99f
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Aug 9 11:46:14 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeaderTest.java | 80 ++++++++++++++++++++
 1 file changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1b9a1075/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
index 6b40cec..ca7ed5d 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
@@ -22,9 +22,13 @@ 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.Matcher;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
@@ -38,6 +42,7 @@ public class HasHeaderTest {
     private static final String HEADER_NAME_1 = "JUNIT";
     private static final String HEADER_NAME_2 = "defaultHeaderName";
     private static final String HEADER_VALUE_1 = "defaultHeaderValue";
+    private static final String HEADER_VALUE_2 = "defaultHeaderValue2";
 
     private FakeMail mockedMail;
     private Matcher matcher;
@@ -62,4 +67,79 @@ public class HasHeaderTest {
 
         assertThat(matcher.match(mockedMail)).isNull();
     }
+
+    @Test
+    public void matchShouldReturnAddressesWhenGoodHeaderNameAndValue() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1,
new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenWrongValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_2,
new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenWrongHeaderNameWithValueSpecified() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_2 + "=" + HEADER_VALUE_2,
new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldIgnoreExtraEquals() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1
+ "=any", new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldNotMatchMailsWithNoHeaderWhenValueSpecified() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1,
new FakeMailContext()));
+        Mail mail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
+
+        assertThat(matcher.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldNotMatchMailsWithNoHeaderWhenValueNotSpecified() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1, new FakeMailContext()));
+        Mail mail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
+
+        assertThat(matcher.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenOneConditionIsNotTrue() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "+" + HEADER_NAME_2,
new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnAddressesWhenAllConditionsMatch() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "+" + HEADER_NAME_2,
new FakeMailContext()));
+        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_1);
+        mimeMessage.addHeader(HEADER_NAME_2, HEADER_VALUE_2);
+        mimeMessage.saveChanges();
+        Mail mail = MailUtil.createMockMail2Recipients(mimeMessage);
+
+        assertThat(matcher.match(mail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldFindTheRightHeaderLineWhenUsedWithValue() throws MessagingException
{
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_2,
new FakeMailContext()));
+        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_1);
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_2);
+        mimeMessage.saveChanges();
+        Mail mail = MailUtil.createMockMail2Recipients(mimeMessage);
+
+        assertThat(matcher.match(mail)).containsAll(mockedMail.getRecipients());
+    }
 }


---------------------------------------------------------------------
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