activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r540474 - in /activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail: MailComponentTest.java MailMessageTest.java
Date Tue, 22 May 2007 08:35:53 GMT
Author: jstrachan
Date: Tue May 22 01:35:51 2007
New Revision: 540474

URL: http://svn.apache.org/viewvc?view=rev&rev=540474
Log:
added another test case to check the header handling

Added:
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
      - copied, changed from r539381, activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
Modified:
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java?view=diff&rev=540474&r1=540473&r2=540474
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
Tue May 22 01:35:51 2007
@@ -19,6 +19,14 @@
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
+import org.apache.camel.util.ObjectHelper;
+
+import javax.mail.Session;
+import javax.mail.Message;
+import javax.mail.Address;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.InternetAddress;
+import java.util.Properties;
 
 /**
  * @version $Revision: 1.1 $
@@ -51,6 +59,7 @@
         assertEquals("getPort()", 30, config.getPort());
         assertEquals("getUsername()", "james", config.getUsername());
     }
+
 
     @Override
     protected MailEndpoint resolveMandatoryEndpoint(String uri) {

Copied: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
(from r539381, activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java?view=diff&rev=540474&p1=activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java&r1=539381&p2=activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java&r2=540474
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
Tue May 22 01:35:51 2007
@@ -19,37 +19,67 @@
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
+import org.apache.camel.util.ObjectHelper;
+
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.util.Properties;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class MailComponentTest extends ContextTestSupport {
+public class MailMessageTest extends ContextTestSupport {
+    protected Session mailSession;
+    protected MimeMessage mimeMessage;
+    protected MailEndpoint endpoint;
+    protected String body = "Hello World!";
+
+    public void testMailMessageHandlesMultipleHeaders() throws Exception {
+        mimeMessage.setRecipients(Message.RecipientType.TO, new Address[]{
+                new InternetAddress("james@localhost"), new InternetAddress("bar@localhost")
+        });
+
+        MailExchange exchange = endpoint.createExchange(mimeMessage);
+        MailMessage in = exchange.getIn();
+        Object header = in.getHeader("TO");
+        String[] values = assertIsInstanceOf(String[].class, header);
+        log.debug("Found values: " + ObjectHelper.asString(values));
+        assertEquals("Size", 2, values.length);
+        assertEquals("values[0]", "james@localhost", values[0]);
+        assertEquals("values[1]", "bar@localhost", values[1]);
 
-    public void testMailEndpointsAreConfiguredProperlyWhenUsingSmtp() throws Exception {
-        MailEndpoint endpoint = resolveMandatoryEndpoint("smtp://james@myhost:30/subject");
-        MailConfiguration config = endpoint.getConfiguration();
-        assertEquals("getProtocol()", "smtp", config.getProtocol());
-        assertEquals("getHost()", "myhost", config.getHost());
-        assertEquals("getPort()", 30, config.getPort());
-        assertEquals("getUsername()", "james", config.getUsername());
+        assertEquals("body", body, in.getBody());
     }
 
-    public void testMailEndpointsAreConfiguredProperlyWhenUsingImap() throws Exception {
-        MailEndpoint endpoint = resolveMandatoryEndpoint("imap://james@myhost:30/subject");
-        MailConfiguration config = endpoint.getConfiguration();
-        assertEquals("getProtocol()", "imap", config.getProtocol());
-        assertEquals("getHost()", "myhost", config.getHost());
-        assertEquals("getPort()", 30, config.getPort());
-        assertEquals("getUsername()", "james", config.getUsername());
+    public void testMailMessageHandlesSingleHeader() throws Exception {
+        mimeMessage.setRecipients(Message.RecipientType.TO, new Address[]{
+                new InternetAddress("james@localhost")
+        });
+
+        MailExchange exchange = endpoint.createExchange(mimeMessage);
+        MailMessage in = exchange.getIn();
+        Object header = in.getHeader("TO");
+        String value = assertIsInstanceOf(String.class, header);
+        assertEquals("value", "james@localhost", value);
+
+        assertEquals("body", body, in.getBody());
     }
 
-    public void testMailEndpointsAreConfiguredProperlyWhenUsingPop() throws Exception {
-        MailEndpoint endpoint = resolveMandatoryEndpoint("pop3://james@myhost:30/subject");
-        MailConfiguration config = endpoint.getConfiguration();
-        assertEquals("getProtocol()", "pop3", config.getProtocol());
-        assertEquals("getHost()", "myhost", config.getHost());
-        assertEquals("getPort()", 30, config.getPort());
-        assertEquals("getUsername()", "james", config.getUsername());
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        endpoint = resolveMandatoryEndpoint("pop3://james@myhost:30/subject");
+
+        Properties properties = new Properties();
+        properties.put("mail.smtp.host", "localhost");
+        mailSession = Session.getInstance(properties, null);
+
+        mimeMessage = new MimeMessage(mailSession);
+        mimeMessage.setText(body);
     }
 
     @Override
@@ -57,4 +87,4 @@
         Endpoint endpoint = super.resolveMandatoryEndpoint(uri);
         return assertIsInstanceOf(MailEndpoint.class, endpoint);
     }
-}
+}
\ No newline at end of file



Mime
View raw message