1 package org.paneris.jammyjoes.mail; 2 3 import java.io.IOException; 4 import java.io.StringBufferInputStream; 5 import java.util.Properties; 6 import java.util.Vector; 7 8 import javax.mail.Session; 9 10 import org.jmock.Mock; 11 import org.jmock.MockObjectTestCase; 12 13 import com.quiotix.html.parser.HtmlDocument; 14 import com.quiotix.html.parser.ParseException; 15 16 public class TestCaseJammyMail extends MockObjectTestCase { 17 18 19 private Session session; 20 21 protected void setUp() throws Exception { 22 super.setUp(); 23 session = Session.getDefaultInstance(new Properties()); 24 } 25 26 public void testFindName() { 27 ImageTranslator translator = new ImageTranslator(System.out, null); 28 Vector tag = new Vector(); 29 tag.add(new HtmlDocument.Attribute("a","b")); 30 tag.add(new HtmlDocument.Attribute("c","d")); 31 tag.add(new HtmlDocument.Attribute("src","\"imagename\"")); 32 assertEquals("imagename", translator.findName(tag)); 33 } 34 35 36 public void testHtmlImageParser() throws ParseException, IOException { 37 38 String firstimage = "firstimage"; 39 String secondimage = "secondimage"; 40 Mock newsletterControl = new Mock(NewsletterInterface.class); 41 newsletterControl.expects(once()).method("addImage").with(eq(firstimage),eq(0)); 42 newsletterControl.expects(once()).method("addImage").with(eq(secondimage),eq(1)); 43 newsletterControl.expects(once()).method("getInputStream").will(returnValue(new StringBufferInputStream("<h1>hello</h1><img src=\"firstimage\" width=\"1\"><img src=\"secondimage\">"))); 44 NewsletterInterface newsletter = (NewsletterInterface)newsletterControl.proxy(); 45 46 ImageParser parser = new HtmlImageParser(newsletter); 47 assertEquals("<h1>hello</h1><img src=\"cid:image0\" width=\"1\" ><img src=\"cid:image1\" >", parser.getText()); 48 newsletterControl.verify(); 49 } 50 51 public void testSettingSmtpServer() { 52 MailFascade unit = new MailFascade("smtp server"); 53 assertEquals("smtp server", unit.getProperty("mail.smtp.host")); 54 } 55 56 }