1 19 20 21 package org.apache.james.transport.matchers; 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.MockMatcherConfig; 27 import org.apache.james.test.util.Util; 28 import org.apache.mailet.Matcher; 29 import org.apache.mailet.RFC2822Headers; 30 31 import javax.mail.MessagingException ; 32 import javax.mail.internet.MimeMessage ; 33 import java.io.UnsupportedEncodingException ; 34 import java.util.Collection ; 35 36 public class NESSpamCheckTest extends TestCase { 37 38 private MimeMessage mockedMimeMessage; 39 40 private MockMail mockedMail; 41 42 private Matcher matcher; 43 44 private String headerName = "defaultHeaderName"; 45 46 private String headerValue = "defaultHeaderValue"; 47 48 public NESSpamCheckTest(String arg0) throws UnsupportedEncodingException { 49 super(arg0); 50 } 51 52 private void setHeaderName(String headerName) { 53 this.headerName = headerName; 54 } 55 56 private void setHeaderValue(String headerValue) { 57 this.headerValue = headerValue; 58 } 59 60 private void setupMockedMimeMessage() throws MessagingException { 61 mockedMimeMessage = Util.createMimeMessage(headerName, headerValue); 62 } 63 64 private void setupMatcher() throws MessagingException { 65 setupMockedMimeMessage(); 66 matcher = new NESSpamCheck(); 67 MockMatcherConfig mci = new MockMatcherConfig("NESSpamCheck", new MockMailContext()); 68 matcher.init(mci); 69 } 70 71 public void testNESSpamCheckMatched() throws MessagingException { 72 setHeaderName(RFC2822Headers.RECEIVED); 73 setHeaderValue("xxxxxxxxxxxxxxxxxxxxx"); 74 75 setupMockedMimeMessage(); 76 mockedMail = Util.createMockMail2Recipients(mockedMimeMessage); 77 setupMatcher(); 78 79 Collection matchedRecipients = matcher.match(mockedMail); 80 81 assertNotNull(matchedRecipients); 82 assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size()); 83 } 84 85 public void testNESSpamCheckNotMatched() throws MessagingException { 86 setupMockedMimeMessage(); 87 mockedMail = Util.createMockMail2Recipients(mockedMimeMessage); 88 setupMatcher(); 89 90 Collection matchedRecipients = matcher.match(mockedMail); 91 92 assertNull(matchedRecipients); 93 } 94 } 95 | Popular Tags |