1 17 package org.apache.servicemix.components.email; 18 19 import java.util.Date ; 20 import java.util.List ; 21 22 import javax.jbi.messaging.InOnly; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.xml.namespace.QName ; 25 import javax.xml.transform.Source ; 26 27 import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver; 28 import org.apache.servicemix.tck.TestSupport; 29 import org.springframework.context.support.AbstractXmlApplicationContext; 30 import org.springframework.mail.SimpleMailMessage; 31 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 32 33 36 public class SimpleMailTest extends TestSupport { 37 38 public void testUsingXPathExpressionsInSimpleEmail() throws Exception { 39 40 QName xpathSender = new QName ("http://servicemix.org/cheese/", "simpleMailSenderWithExpressions"); 42 ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender); 43 44 InOnly exchange = client.createInOnlyExchange(resolver); 45 46 Source source = getSourceFromClassPath("request.xml"); 47 exchange.getInMessage().setContent(source); 48 49 client.send(exchange); 50 52 StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender"); 54 sender.assertMessagesReceived(1); 55 56 List messages = sender.getMessages(); 57 assertEquals("message size: " + messages, 1, messages.size()); 58 59 SimpleMailMessage message = (SimpleMailMessage) messages.get(0); 60 61 System.out.println("Created message: " + message); 62 63 assertEquals("text", "Hello there James how are you today?", message.getText()); 64 assertEquals("from", "james@nowhere.com", message.getFrom()); 65 } 66 67 public void testUsingPropertyExpressionsInSimpleEmail() throws Exception { 68 QName xpathSender = new QName ("http://servicemix.org/cheese/", "simpleMailSenderWithPropertyExpressions"); 70 ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender); 71 72 InOnly exchange = client.createInOnlyExchange(resolver); 73 NormalizedMessage message = exchange.getInMessage(); 74 75 message.setProperty("to", "scm@servicemix.org"); 76 message.setProperty("from", "junit@servicemix.org"); 77 message.setProperty("text", "Hi from test case: " + getName() + " running at: " + new Date ()); 78 79 client.send(exchange); 80 82 StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender"); 84 sender.assertMessagesReceived(1); 85 86 List messages = sender.getMessages(); 87 88 assertEquals("message size: " + messages, 1, messages.size()); 89 90 SimpleMailMessage mailMessage = (SimpleMailMessage) messages.get(0); 91 92 System.out.println("Created message: " + mailMessage); 93 94 assertEquals("subject", "Subject came from expression", mailMessage.getSubject()); 95 assertEquals("from", "junit@servicemix.org", mailMessage.getFrom()); 96 } 97 98 protected AbstractXmlApplicationContext createBeanFactory() { 99 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/email/simpleMail.xml"); 100 } 101 } 102 | Popular Tags |