camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r650382 - in /activemq/camel/trunk/components/camel-mail: ./ src/test/java/org/apache/camel/component/mail/ src/test/resources/
Date Tue, 22 Apr 2008 05:03:13 GMT
Author: davsclaus
Date: Mon Apr 21 22:03:02 2008
New Revision: 650382

URL: http://svn.apache.org/viewvc?rev=650382&view=rev
Log:
CAMEL-335
- Prepared for mail imrpovment by improving unit tests
- Upgraded pom to use latest mock-mail

Modified:
    activemq/camel/trunk/components/camel-mail/pom.xml
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailComponentTest.java
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMessageConsumeTest.java
    activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MultipleDestinationConsumeTest.java
    activemq/camel/trunk/components/camel-mail/src/test/resources/log4j.properties

Modified: activemq/camel/trunk/components/camel-mail/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/pom.xml?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/pom.xml (original)
+++ activemq/camel/trunk/components/camel-mail/pom.xml Mon Apr 21 22:03:02 2008
@@ -20,73 +20,78 @@
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
 
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
 
-  <parent>
-    <groupId>org.apache.camel</groupId>
-    <artifactId>camel-parent</artifactId>
-    <version>1.4-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>camel-mail</artifactId>
-  <packaging>bundle</packaging>
-  <name>Camel :: Mail</name>
-  <description>Camel Mail support</description>
-
-  <properties>
-	<camel.osgi.export.pkg>org.apache.camel.component.mail.*</camel.osgi.export.pkg>
-  </properties>
-
-  <repositories>
-    <repository>
-      <id>maven2-repository.dev.java.net</id>
-      <name>Java.net Repository for Maven</name>
-      <url>http://download.java.net/maven/2/</url>
-      <layout>default</layout>
-    </repository>
-  </repositories>
-
-  <dependencies>
-
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-spring</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-context-support</artifactId>
-	  <version>${spring-version}</version>
-    </dependency>
-    <dependency>
-      <groupId>javax.mail</groupId>
-      <artifactId>mail</artifactId>
-    </dependency>
-
-
-    <!-- testing -->
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-      <type>test-jar</type>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jvnet.mock-javamail</groupId>
-      <artifactId>mock-javamail</artifactId>
-      <version>1.1</version>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>1.4-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-mail</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: Mail</name>
+    <description>Camel Mail support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.mail.*</camel.osgi.export.pkg>
+    </properties>
+
+    <repositories>
+        <!-- for jvnet mock-mail -->
+        <repository>
+            <id>maven2-repository.dev.java.net</id>
+            <name>Java.net Repository for Maven</name>
+            <url>http://download.java.net/maven/2/</url>
+            <layout>default</layout>
+        </repository>
+    </repositories>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context-support</artifactId>
+            <version>${spring-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+        </dependency>
+
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <type>test-jar</type>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jvnet.mock-javamail</groupId>
+            <artifactId>mock-javamail</artifactId>
+            <version>1.7</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
 </project>

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?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- 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
Mon Apr 21 22:03:02 2008
@@ -31,6 +31,8 @@
         assertEquals("getHost()", "myhost", config.getHost());
         assertEquals("getPort()", 30, config.getPort());
         assertEquals("getUsername()", "james", config.getUsername());
+        assertEquals("getDestination()", "james@myhost", config.getDestination());
+        assertEquals("folder", "INBOX", config.getFolderName());
     }
 
     public void testMailEndpointsAreConfiguredProperlyWhenUsingImap() throws Exception {
@@ -40,6 +42,8 @@
         assertEquals("getHost()", "myhost", config.getHost());
         assertEquals("getPort()", 30, config.getPort());
         assertEquals("getUsername()", "james", config.getUsername());
+        assertEquals("getDestination()", "james@myhost", config.getDestination());
+        assertEquals("folder", "INBOX", config.getFolderName());
     }
 
     public void testMailEndpointsAreConfiguredProperlyWhenUsingPop() throws Exception {
@@ -49,8 +53,41 @@
         assertEquals("getHost()", "myhost", config.getHost());
         assertEquals("getPort()", 30, config.getPort());
         assertEquals("getUsername()", "james", config.getUsername());
+        assertEquals("getDestination()", "james@myhost", config.getDestination());
+        assertEquals("folder", "INBOX", config.getFolderName());
     }
 
+    public void testDefaultConfiguration() throws Exception {
+        MailEndpoint endpoint = resolveMandatoryEndpoint("smtp://james@myhost?password=secret");
+        MailConfiguration config = endpoint.getConfiguration();
+        assertEquals("getProtocol()", "smtp", config.getProtocol());
+        assertEquals("getHost()", "myhost", config.getHost());
+        assertEquals("getPort()", -1, config.getPort());
+        assertEquals("getUsername()", "james", config.getUsername());
+        assertEquals("getDestination()", "james@myhost", config.getDestination());
+        assertEquals("folder", "INBOX", config.getFolderName());
+        assertEquals("encoding", null, config.getDefaultEncoding());
+        assertEquals("from", "camel@localhost", config.getFrom());
+        assertEquals("password", "secret", config.getPassword());
+        assertEquals(true, config.isDeleteProcessedMessages());
+        assertEquals(false, config.isIgnoreUriScheme());
+    }
+
+    public void testManyConfigurations() throws Exception {
+        MailEndpoint endpoint = resolveMandatoryEndpoint("smtp://james@myhost:30/subject?password=secret&from=me@camelriders.org&DeleteProcessedMessages=false&defaultEncoding=iso-8859-1&folderName=riders");
+        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("getDestination()", "james@myhost", config.getDestination());
+        assertEquals("folder", "riders", config.getFolderName());
+        assertEquals("encoding", "iso-8859-1", config.getDefaultEncoding());
+        assertEquals("from", "me@camelriders.org", config.getFrom());
+        assertEquals("password", "secret", config.getPassword());
+        assertEquals(false, config.isDeleteProcessedMessages());
+        assertEquals(false, config.isIgnoreUriScheme());
+    }
 
     @Override
     protected MailEndpoint resolveMandatoryEndpoint(String uri) {

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMessageTest.java
Mon Apr 21 22:03:02 2008
@@ -31,27 +31,21 @@
  * @version $Revision$
  */
 public class MailMessageTest extends ContextTestSupport {
-    protected Session mailSession;
-    protected MimeMessage mimeMessage;
-    protected MailEndpoint endpoint;
-    protected String body = "Hello World!";
+    private Session mailSession;
+    private MimeMessage mimeMessage;
+    private MailEndpoint endpoint;
+    private 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();
-        String value = in.getHeader("TO", String.class);
-        assertEquals("value", "james@localhost, bar@localhost", value);
-        /*
-         * 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]);
-         */
 
-        assertEquals("body", body, in.getBody());
+        assertEquals("mail body", body, in.getBody());
+
+        String to = in.getHeader("TO", String.class);
+        assertEquals("should have 2 receivers", "james@localhost, bar@localhost", to);
     }
 
     public void testMailMessageHandlesSingleHeader() throws Exception {

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
Mon Apr 21 22:03:02 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.util.HashMap;
-
 import javax.mail.Message;
 import javax.mail.Message.RecipientType;
 import javax.mail.MessagingException;
@@ -27,19 +26,15 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-
 import org.jvnet.mock_javamail.Mailbox;
 
-import static org.apache.camel.util.ObjectHelper.asString;
-
 /**
  * @version $Revision$
  */
 public class MailRouteTest extends ContextTestSupport {
-    private MockEndpoint resultEndpoint;
 
     public void testSendAndReceiveMails() throws Exception {
-        resultEndpoint = getMockEndpoint("mock:result");
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedBodiesReceived("hello world!");
 
         HashMap<String, Object> headers = new HashMap<String, Object>();
@@ -49,8 +44,7 @@
         // lets test the first sent worked
         assertMailboxReceivedMessages("route-test-james@localhost");
 
-        // lets sleep to check that the mail poll does not redeliver duplicate
-        // mails
+        // lets sleep to check that the mail poll does not redeliver duplicate mails
         Thread.sleep(3000);
 
         // lets test the receive worked
@@ -70,7 +64,9 @@
 
         Message message = mailbox.get(0);
         assertNotNull(name + " should have received at least one mail!", message);
-        logMessage(message);
+        assertEquals("hello world!", message.getContent());
+        assertEquals("camel@localhost", message.getFrom()[0].toString());
+        assertEquals(name, message.getRecipients(RecipientType.TO)[0].toString());
     }
 
     @Override
@@ -84,7 +80,4 @@
         };
     }
 
-    protected void logMessage(Message message) throws IOException, MessagingException {
-        log.info("Received: " + message.getContent() + " from: " + asString(message.getFrom())
+ " to: " + asString(message.getRecipients(RecipientType.TO)));
-    }
 }

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMessageConsumeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMessageConsumeTest.java?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMessageConsumeTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMessageConsumeTest.java
Mon Apr 21 22:03:02 2008
@@ -36,11 +36,10 @@
  * @version $Revision$
  */
 public class MimeMessageConsumeTest extends ContextTestSupport {
-    protected MockEndpoint resultEndpoint;
-    protected String body = "hello world!";
+    private String body = "hello world!";
 
     public void testSendAndReceiveMails() throws Exception {
-        resultEndpoint = getMockEndpoint("mock:result");
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedMinimumMessageCount(1);
 
         Properties properties = new Properties();
@@ -53,17 +52,13 @@
 
         Transport.send(message);
 
-
-
         // lets test the receive worked
         resultEndpoint.assertIsSatisfied();
 
         Exchange exchange = resultEndpoint.getReceivedExchanges().get(0);
 
-        log.info("Received: " + exchange.getIn().getBody());
-
         String text = exchange.getIn().getBody(String.class);
-        assertEquals("body", body, text);
+        assertEquals("mail body", body, text);
     }
 
     /**

Modified: activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MultipleDestinationConsumeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MultipleDestinationConsumeTest.java?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MultipleDestinationConsumeTest.java
(original)
+++ activemq/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MultipleDestinationConsumeTest.java
Mon Apr 21 22:03:02 2008
@@ -37,12 +37,11 @@
  * @version $Revision$
  */
 public class MultipleDestinationConsumeTest extends ContextTestSupport {
-    protected MockEndpoint resultEndpoint;
-    protected String body = "hello world!";
-    protected Session mailSession;
+    private String body = "hello world!";
+    private Session mailSession;
 
     public void testSendAndReceiveMails() throws Exception {
-        resultEndpoint = getMockEndpoint("mock:result");
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedMinimumMessageCount(1);
 
         MimeMessage message = new MimeMessage(mailSession);
@@ -60,14 +59,18 @@
         Exchange exchange = resultEndpoint.getReceivedExchanges().get(0);
 
         org.apache.camel.Message in = exchange.getIn();
-        log.debug("Received: " + in.getBody());
-
-        String text = in.getBody(String.class);
-        log.debug("Has headers: " + in.getHeaders());
+        assertNotNull("Should have headers", in.getHeaders());
 
         MailExchange mailExchange = (MailExchange) exchange;
         Message inMessage = mailExchange.getIn().getMessage();
         assertNotNull("In message has no JavaMail message!", inMessage);
+
+        String text = in.getBody(String.class);
+        assertEquals("mail body", body, text);
+
+        String to = in.getHeader("TO", String.class);
+        assertEquals("TO Header", "james@localhost, bar@localhost", to);
+
         Enumeration iter = inMessage.getAllHeaders();
         while (iter.hasMoreElements()) {
             Header header = (Header) iter.nextElement();
@@ -75,13 +78,6 @@
             log.debug("Header: " + header.getName() + " has value: " + ObjectHelper.asString(value));
         }
 
-        assertEquals("body", body, text);
-        Object value = in.getHeader("TO");
-        assertEquals("TO Header", "james@localhost, bar@localhost", value);
-/*
-        List list = assertIsInstanceOf(List.class, value);
-        assertEquals("to list", 2, list.size());
-*/
     }
 
     @Override

Modified: activemq/camel/trunk/components/camel-mail/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/test/resources/log4j.properties?rev=650382&r1=650381&r2=650382&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-mail/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-mail/src/test/resources/log4j.properties Mon Apr
21 22:03:02 2008
@@ -16,15 +16,20 @@
 ## ------------------------------------------------------------------------
 
 #
-# The logging properties used for eclipse testing, We want to see debug output on the console.
+# The logging properties used during tests..
 #
-log4j.rootLogger=INFO, out
-
-#log4j.logger.org.apache.activemq=DEBUG
-#log4j.logger.org.apache.camel=DEBUG
+log4j.rootLogger=INFO, file
 
 # CONSOLE appender not used by default
-log4j.appender.out=org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-mail-test.log
+
+# debug logging for Camel
+log4j.logger.org.apache.camel.component.mail=DEBUG
\ No newline at end of file



Mime
View raw message