james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r420591 - /james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
Date Mon, 10 Jul 2006 17:36:12 GMT
Author: norman
Date: Mon Jul 10 10:36:11 2006
New Revision: 420591

URL: http://svn.apache.org/viewvc?rev=420591&view=rev
Log:
Add junit test for MailAttrbutesToMimeHeaders mailet. See JAMES-563

Added:
    james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java

Added: james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java?rev=420591&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
Mon Jul 10 10:36:11 2006
@@ -0,0 +1,113 @@
+/***********************************************************************
+ * 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.mailets;
+
+import junit.framework.TestCase;
+import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.james.test.mock.mailet.MockMailContext;
+import org.apache.james.test.mock.mailet.MockMailetConfig;
+import org.apache.james.test.util.Util;
+import org.apache.mailet.Mailet;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+
+import java.io.UnsupportedEncodingException;
+
+public class MailAttributesToMimeHeadersTest extends TestCase {
+
+    private Mailet mailet;
+
+    private final String HEADER_NAME1 = "JUNIT";
+
+    private final String HEADER_NAME2 = "JUNIT2";
+
+    private final String MAIL_ATTRIBUTE_VALUE1 = "test1";
+
+    private final String MAIL_ATTRIBUTE_VALUE2 = "test2";
+
+    private final String MAIL_ATTRIBUTE_NAME1 = "org.apache.james.test";
+
+    private final String MAIL_ATTRIBUTE_NAME2 = "org.apache.james.test2";
+
+    private String config1 = MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1;
+
+    private String config2 = MAIL_ATTRIBUTE_NAME2 + "; " + HEADER_NAME2;
+
+    public MailAttributesToMimeHeadersTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    private void setConfig1(String config1) {
+        this.config1 = config1;
+    }
+
+    private String getConfig1() {
+        return config1;
+    }
+
+    private void setupMailet() throws MessagingException {
+        mailet = new MailAttributesToMimeHeaders();
+        MockMailetConfig mci = new MockMailetConfig("Test",
+                new MockMailContext());
+        mci.setProperty("simplemapping", getConfig1());
+        mci.setProperty("simplemapping", config2);
+        mailet.init(mci);
+    }
+
+    private MockMail setupMail(MimeMessage m) throws ParseException {
+        MockMail mockedMail = Util.createMockMail2Recipients(m);
+        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, MAIL_ATTRIBUTE_VALUE1);
+        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME2, MAIL_ATTRIBUTE_VALUE2);
+        return mockedMail;
+    }
+
+    // test if the Headers were added
+    public void testHeadersArePresent() throws MessagingException {
+        MockMail mockedMail = setupMail(Util.createMimeMessage());
+        setupMailet();
+
+        mailet.service(mockedMail);
+
+        assertEquals(MAIL_ATTRIBUTE_VALUE1, mockedMail.getMessage().getHeader(
+                HEADER_NAME1)[0]);
+
+        assertEquals(MAIL_ATTRIBUTE_VALUE2, mockedMail.getMessage().getHeader(
+                HEADER_NAME2)[0]);
+
+    }
+
+    // test if exception was thrown
+    public void testInvalidConfig() throws MessagingException {
+        boolean exception = false;
+        MockMail mockedMail = setupMail(Util.createMimeMessage());
+        setConfig1("test");
+
+        try {
+            setupMailet();
+            mailet.service(mockedMail);
+        } catch (MessagingException e) {
+            exception = true;
+        }
+
+        assertTrue(exception);
+
+    }
+}



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