james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [07/10] james-project git commit: MAILET-101 add a test about multivaluated header
Date Mon, 05 Sep 2016 13:42:06 GMT
MAILET-101 add a test about multivaluated header


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

Branch: refs/heads/master
Commit: 1081d8f50c2957f5706b1aa28301aaa00cfbea98
Parents: b7c2a0b
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Mon Aug 29 10:51:08 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Mon Sep 5 14:17:51 2016 +0200

----------------------------------------------------------------------
 .../mailet/base/test/FakeMimeMessage.java       | 65 --------------------
 .../MailAttributesToMimeHeadersTest.java        | 18 ++++++
 .../transport/mailets/SetMimeHeaderTest.java    |  2 -
 3 files changed, 18 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1081d8f5/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
index df22a1c..d1842cb 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
@@ -46,7 +46,6 @@ public class FakeMimeMessage extends MimeMessage {
     private String[] m_contentLanguage;
     private String m_fileName;
     private DataHandler m_dataHandler;
-    private final HashMap<String, String> m_contentHeaders = new HashMap<String,
String>();
     private final Flags m_setFlags = new Flags();
     private boolean m_doMatch;
 
@@ -290,34 +289,10 @@ public class FakeMimeMessage extends MimeMessage {
         // trivial implementation
     }
 
-    public String[] getHeader(String name) throws MessagingException {
-        String value = 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<String> getAllHeaders() throws MessagingException {
-        return Collections.enumeration(m_contentHeaders.values());
-    }
-
     public Enumeration<String> getMatchingHeaders(String[] names) throws MessagingException
{
         ArrayList<String> matchingHeaders = new ArrayList<String>();
         for (String name : names) {
@@ -328,19 +303,6 @@ public class FakeMimeMessage extends MimeMessage {
         return Collections.enumeration(matchingHeaders);
     }
 
-    public Enumeration<String> getNonMatchingHeaders(String[] names) throws MessagingException
{
-        List<String> existingHeaders = Arrays.asList(names);
-
-        ArrayList<String> nonMatchingHeaders = new ArrayList<String>();
-
-        for (String name : m_contentHeaders.keySet()) {
-            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(":");
@@ -349,19 +311,6 @@ public class FakeMimeMessage extends MimeMessage {
         addHeader(headerLine.substring(0, separatorIndex), headerLine.substring(separatorIndex,
headerLine.length()));
     }
 
-    public Enumeration<String> getAllHeaderLines() throws MessagingException {
-        return Collections.enumeration(getHeadersAsStrings(m_contentHeaders));
-    }
-
-    private ArrayList<String> getHeadersAsStrings(HashMap<String, String> contentHeaders)
{
-        ArrayList<String> headerLines = new ArrayList<String>();
-        for (String key : contentHeaders.keySet()) {
-            String value = contentHeaders.get(key);
-            headerLines.add(key + ":" + value);
-        }
-        return headerLines;
-    }
-
     public Enumeration<String> getMatchingHeaderLines(String[] names) throws MessagingException
{
         ArrayList<String> matchingHeaders = new ArrayList<String>();
         for (String name : names) {
@@ -372,20 +321,6 @@ public class FakeMimeMessage extends MimeMessage {
         return Collections.enumeration(matchingHeaders);
     }
 
-    public Enumeration<String> getNonMatchingHeaderLines(String[] names) throws MessagingException
{
-        List<String> existingHeaders = names != null ? Arrays.asList(names) : null;
-
-        ArrayList<String> nonMatchingHeaders = new ArrayList<String>();
-
-        for (String name : m_contentHeaders.keySet()) {
-            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);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1081d8f5/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
index df62e87..bd5764d 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
@@ -29,6 +29,7 @@ import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
+import org.apache.mailet.base.test.FakeMimeMessage;
 import org.apache.mailet.base.test.MailUtil;
 import org.junit.Before;
 import org.junit.Rule;
@@ -76,6 +77,23 @@ public class MailAttributesToMimeHeadersTest {
     }
 
     @Test
+    public void shouldAddAttributeIntoHeadersWhenHeaderAlreadyPresent() throws MessagingException
{
+        FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+        mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1);
+        mailet.init(mailetConfig);
+        
+        FakeMimeMessage mimeMessage = MailUtil.createMimeMessage();
+        mimeMessage.addHeader(HEADER_NAME1, "first value");
+		FakeMail mockedMail = MailUtil.createMockMail2Recipients(mimeMessage);
+        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, MAIL_ATTRIBUTE_VALUE1);
+        
+        mailet.service(mockedMail);
+
+        assertThat(mockedMail.getMessage().getHeader(HEADER_NAME1)).containsExactly("first
value", MAIL_ATTRIBUTE_VALUE1);
+    }
+
+    
+    @Test
     public void shouldThrowAtInitWhenNoSemicolumnInConfigurationEntry() throws MessagingException
{
         FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
         mailetConfig.setProperty("simplemapping", "invalidConfigEntry");

http://git-wip-us.apache.org/repos/asf/james-project/blob/1081d8f5/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
index d1d9921..ba32971 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
@@ -34,7 +34,6 @@ import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.apache.mailet.base.test.MailUtil;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -65,7 +64,6 @@ public class SetMimeHeaderTest {
         assertThat(mail.getMessage().getHeader("header-name")).containsExactly("test-value");
     }
 
-    @Ignore("need multivaluated headers in FakeMail")
     @Test
     public void shouldAddHeaderWhenAlreadyPresent() throws MessagingException {
         FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());


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