1 19 20 21 package org.apache.james.transport.mailets; 22 23 import junit.framework.TestCase; 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.james.test.util.Util; 28 import org.apache.mailet.Mailet; 29 30 import javax.mail.MessagingException ; 31 import javax.mail.internet.MimeMessage ; 32 import java.io.UnsupportedEncodingException ; 33 34 public class SetMimeHeaderTest extends TestCase { 35 36 private Mailet mailet; 37 38 private final String HEADER_NAME = "JUNIT"; 39 40 private final String HEADER_VALUE = "test-value"; 41 42 private String headerName = "defaultHeaderName"; 43 44 private String headerValue = "defaultHeaderValue"; 45 46 public SetMimeHeaderTest(String arg0) throws UnsupportedEncodingException { 47 super(arg0); 48 } 49 50 private void setHeaderName(String headerName) { 51 this.headerName = headerName; 52 } 53 54 private void setHeaderValue(String headerValue) { 55 this.headerValue = headerValue; 56 } 57 58 private void setupMailet() throws MessagingException { 59 mailet = new SetMimeHeader(); 60 MockMailetConfig mci = new MockMailetConfig("Test", 61 new MockMailContext()); 62 mci.setProperty("name", HEADER_NAME); 63 mci.setProperty("value", HEADER_VALUE); 64 65 mailet.init(mci); 66 } 67 68 public void testHeaderIsPresent() throws MessagingException { 70 MimeMessage mockedMimeMessage = Util.createMimeMessage(headerName, headerValue); 71 MockMail mockedMail = Util.createMockMail2Recipients(mockedMimeMessage); 72 setupMailet(); 73 74 mailet.service(mockedMail); 75 76 assertEquals(HEADER_VALUE, mockedMail.getMessage().getHeader( 77 HEADER_NAME)[0]); 78 79 } 80 81 public void testHeaderIsReplaced() throws MessagingException { 83 setHeaderName(HEADER_NAME); 84 setHeaderValue(headerValue); 85 86 MimeMessage mockedMimeMessage = Util.createMimeMessage(headerName, headerValue); 87 MockMail mockedMail = Util.createMockMail2Recipients(mockedMimeMessage); 88 setupMailet(); 89 90 mailet.service(mockedMail); 91 92 assertEquals(HEADER_VALUE, mockedMail.getMessage().getHeader( 93 HEADER_NAME)[0]); 94 95 } 96 } 97 | Popular Tags |