You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/07/27 16:16:03 UTC

svn commit: r426084 - in /james/server/trunk/src: java/org/apache/james/transport/mailets/RemoveMailAttribute.java test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java

Author: norman
Date: Thu Jul 27 07:16:03 2006
New Revision: 426084

URL: http://svn.apache.org/viewvc?rev=426084&view=rev
Log:
Throw an exception on invalidConfig
Add junit test

Added:
    james/server/trunk/src/test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
Modified:
    james/server/trunk/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java?rev=426084&r1=426083&r2=426084&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java Thu Jul 27 07:16:03 2006
@@ -69,6 +69,8 @@
                 String attribute_name = st.nextToken().trim() ;
                 attributesToRemove.add(attribute_name);
             }
+        } else {
+            throw new MailetException("Please configure at least one attribute to remove");
         }
     }
 

Added: james/server/trunk/src/test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java?rev=426084&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/transport/mailets/RemoveMailAttributeTest.java Thu Jul 27 07:16:03 2006
@@ -0,0 +1,86 @@
+/****************************************************************
+ * 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.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.mailet.Mail;
+import org.apache.mailet.Mailet;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.ParseException;
+
+public class RemoveMailAttributeTest extends TestCase {
+
+    public static final String MAIL_ATTRIBUTE_NAME1 = "org.apache.james.test.junit";
+
+    public static final String MAIL_ATTRIBUTE_NAME2 = "org.apache.james.test.junit2";
+
+    private Mail setupMockedMail() throws ParseException {
+        Mail mockedMail = new MockMail();
+        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, "true");
+        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME2, "true");
+        return mockedMail;
+    }
+
+    private Mailet setupMailet(String attribute) throws MessagingException {
+        Mailet mailet = new RemoveMailAttribute();
+        MockMailetConfig mci = new MockMailetConfig("Test",
+                new MockMailContext());
+        if (attribute != null) {
+            mci.setProperty("name", attribute);
+        }
+
+        mailet.init(mci);
+        return mailet;
+    }
+
+
+    public void testRemoveMailAttribute() throws MessagingException {
+        Mail m = setupMockedMail();
+        Mailet mailet = setupMailet(MAIL_ATTRIBUTE_NAME1);
+
+        // check if the mail has a attribute
+        assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1));
+        assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME2));
+
+        mailet.service(m);
+
+        // Check if the attribute was removed
+        assertNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1));
+        assertNotNull("Attribute deleted",m.getAttribute(MAIL_ATTRIBUTE_NAME2));
+    }
+
+
+    public void testInvalidConfig() throws MessagingException {
+        boolean exception = false;
+        try {
+            setupMailet(null);
+        } catch (MessagingException e) {
+            exception = true;
+        }
+
+        assertTrue("invalid Config", exception);
+    }
+
+}



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