1 19 20 package org.apache.james.transport.mailets; 21 22 import junit.framework.TestCase; 23 24 import org.apache.james.test.mock.mailet.MockMail; 25 import org.apache.james.test.mock.mailet.MockMailContext; 26 import org.apache.james.test.mock.mailet.MockMailetConfig; 27 import org.apache.mailet.Mail; 28 import org.apache.mailet.Mailet; 29 30 import javax.mail.MessagingException ; 31 import javax.mail.internet.ParseException ; 32 33 public class RemoveMailAttributeTest extends TestCase { 34 35 public static final String MAIL_ATTRIBUTE_NAME1 = "org.apache.james.test.junit"; 36 37 public static final String MAIL_ATTRIBUTE_NAME2 = "org.apache.james.test.junit2"; 38 39 private Mail setupMockedMail() throws ParseException { 40 Mail mockedMail = new MockMail(); 41 mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, "true"); 42 mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME2, "true"); 43 return mockedMail; 44 } 45 46 private Mailet setupMailet(String attribute) throws MessagingException { 47 Mailet mailet = new RemoveMailAttribute(); 48 MockMailetConfig mci = new MockMailetConfig("Test", 49 new MockMailContext()); 50 if (attribute != null) { 51 mci.setProperty("name", attribute); 52 } 53 54 mailet.init(mci); 55 return mailet; 56 } 57 58 59 public void testRemoveMailAttribute() throws MessagingException { 60 Mail m = setupMockedMail(); 61 Mailet mailet = setupMailet(MAIL_ATTRIBUTE_NAME1); 62 63 assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1)); 65 assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME2)); 66 67 mailet.service(m); 68 69 assertNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1)); 71 assertNotNull("Attribute deleted",m.getAttribute(MAIL_ATTRIBUTE_NAME2)); 72 } 73 74 75 public void testInvalidConfig() throws MessagingException { 76 boolean exception = false; 77 try { 78 setupMailet(null); 79 } catch (MessagingException e) { 80 exception = true; 81 } 82 83 assertTrue("invalid Config", exception); 84 } 85 86 } 87 | Popular Tags |