1 19 20 21 package org.apache.james.transport.mailets; 22 23 import junit.framework.TestCase; 24 import org.apache.james.test.mock.mailet.MockMailContext; 25 import org.apache.james.test.mock.mailet.MockMailetConfig; 26 import org.apache.james.test.util.Util; 27 import org.apache.mailet.Mail; 28 import org.apache.mailet.Mailet; 29 30 import javax.mail.MessagingException ; 31 import java.io.UnsupportedEncodingException ; 32 33 public class SetMailAttributeTest extends TestCase { 34 35 private Mail mockedMail; 36 37 private Mailet mailet; 38 39 private final String ATTRIBUTE_NAME1 = "org.apache.james.junit1"; 40 41 private final String ATTRIBUTE_NAME2 = "org.apache.james.junit2"; 42 43 public SetMailAttributeTest(String arg0) 44 throws UnsupportedEncodingException { 45 super(arg0); 46 } 47 48 private void setupMailet() throws MessagingException { 49 mailet = new SetMailAttribute(); 50 MockMailetConfig mci = new MockMailetConfig("Test", 51 new MockMailContext()); 52 mci.setProperty(ATTRIBUTE_NAME1, "true"); 53 mci.setProperty(ATTRIBUTE_NAME2, "true"); 54 55 mailet.init(mci); 56 } 57 58 public void testMailAttributeAdded() throws MessagingException { 60 mockedMail = Util.createMockMail2Recipients(null); 61 setupMailet(); 62 63 assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME1)); 64 assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME2)); 65 mailet.service(mockedMail); 66 67 assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME1)); 68 assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME2)); 69 } 70 } 71 | Popular Tags |