1 19 20 21 package org.apache.james.transport.matchers; 22 23 import org.apache.mailet.GenericMatcher; 24 25 import javax.mail.MessagingException ; 26 import java.util.Collection ; 27 28 public class HasMailAttributeWithValueRegexTest extends 29 AbstractHasMailAttributeTest { 30 31 private String regex = ".*"; 32 33 public HasMailAttributeWithValueRegexTest() { 34 super(); 35 } 36 37 private void setRegex(String regex) { 38 this.regex = regex; 39 } 40 41 protected String getHasMailAttribute() { 42 return MAIL_ATTRIBUTE_NAME + ", " + regex; 43 } 44 45 protected GenericMatcher createMatcher() { 46 return new HasMailAttributeWithValueRegex(); 47 } 48 49 public void testAttributeIsMatched() throws MessagingException { 51 init(); 52 setRegex(".*"); 53 setupAll(); 54 55 Collection matchedRecipients = matcher.match(mockedMail); 56 57 assertNotNull(matchedRecipients); 58 assertEquals(matchedRecipients.size(), mockedMail.getRecipients() 59 .size()); 60 } 61 62 public void testHeaderIsNotMatched() throws MessagingException { 64 setRegex("\\d"); 65 setupAll(); 66 67 Collection matchedRecipients = matcher.match(mockedMail); 68 69 assertNull(matchedRecipients); 70 } 71 72 public void testHeaderIsNotMatchedCauseValue() throws MessagingException { 74 75 String invalidRegex = "(!("; 76 String regexException = null; 77 String exception = "Malformed pattern: " + invalidRegex; 78 79 setRegex(invalidRegex); 80 setupMockedMail(mockedMimeMessage); 81 82 try { 83 setupMatcher(); 84 } catch (MessagingException m) { 85 regexException = m.getMessage(); 86 } 87 88 Collection matchedRecipients = matcher.match(mockedMail); 89 90 assertNull(matchedRecipients); 91 assertEquals(regexException, exception); 92 93 } 94 95 protected String getConfigOption() { 96 return "HasMailAttributeWithValueRegex="; 97 } 98 } 99 | Popular Tags |