1 package info.magnolia.cms.mail; 2 3 import info.magnolia.cms.mail.handlers.SimpleMailHandler; 4 5 import java.io.File ; 6 import java.util.regex.Matcher ; 7 import java.util.regex.Pattern ; 8 9 import junit.framework.TestCase; 10 11 import org.slf4j.Logger; 12 import org.slf4j.LoggerFactory; 13 import org.subethamail.wiser.Wiser; 14 15 16 20 public abstract class AbstractMailTest extends TestCase { 21 22 25 protected Logger log = LoggerFactory.getLogger(getClass()); 26 27 public final static String TEST_RECIPIENT = "niko@macnica.com"; 28 29 public final static String TEST_SENDER = "niko@magnolia.com"; 30 31 public static final String TEST_FILE_JPG = "magnolia.jpg"; 32 33 public static final String TEST_FILE_PDF = "magnolia.pdf"; 34 35 public static int SMTP_PORT = 25025; 36 37 protected MgnlMailFactory factory; 38 39 protected SimpleMailHandler handler; 40 41 protected Wiser wiser = new Wiser(); 42 43 public File getResourceFile(String filename) { 44 return new File (getClass().getResource("/" + filename).getFile()); 45 } 46 47 public String getResourcePath(String filename) { 48 return getResourceFile(filename).getAbsolutePath(); 49 } 50 51 54 public void setUp() throws Exception { 55 super.setUp(); 56 57 handler = new SimpleMailHandler(); 58 factory = MgnlMailFactory.getInstance(); 59 factory.initParam(MgnlMailFactory.SMTP_SERVER, "localhost"); 60 factory.initParam(MgnlMailFactory.SMTP_PORT, Integer.toString(SMTP_PORT)); 61 62 wiser.setPort(SMTP_PORT); 63 wiser.start(); 64 } 65 66 69 public void tearDown() throws Exception { 70 wiser.stop(); 71 super.tearDown(); 72 } 73 74 81 protected boolean hasMatchingSubject(String message, String subject) { 82 Pattern pattern = Pattern.compile("Subject: " + subject); 83 Matcher matcher = pattern.matcher(message); 84 return matcher.find(); 85 } 86 87 } 88 | Popular Tags |