geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r739496 - in /geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test: java/org/apache/geronimo/javamail/store/imap/ java/org/apache/geronimo/javamail/store/pop3/ resources/imap/ resources/messages/
Date Sat, 31 Jan 2009 03:08:04 GMT
Author: gawor
Date: Sat Jan 31 03:08:04 2009
New Revision: 739496

URL: http://svn.apache.org/viewvc?rev=739496&view=rev
Log:
added tests for pop3 store - same as for imap

Added:
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
  (with props)
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/resources/messages/
  (props changed)
      - copied from r739377, geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/resources/imap/
Removed:
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/resources/imap/
Modified:
    geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/imap/IMAPStoreTest.java

Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/imap/IMAPStoreTest.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/imap/IMAPStoreTest.java?rev=739496&r1=739495&r2=739496&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/imap/IMAPStoreTest.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/imap/IMAPStoreTest.java
Sat Jan 31 03:08:04 2009
@@ -57,8 +57,8 @@
         
         Session session = Session.getInstance(props);
         // Send messages for the current test to GreenMail
-        sendMessage(session, "/imap/multipart.msg");
-        sendMessage(session, "/imap/simple.msg");
+        sendMessage(session, "/messages/multipart.msg");
+        sendMessage(session, "/messages/simple.msg");
         
         // Load the message from IMAP
         Store store = session.getStore("imap");
@@ -95,7 +95,7 @@
         checkMessage(msg1);
         
         MimeMessage msg2 = (MimeMessage)messages[1];
-        assertEquals("Foo Bar", msg2.getContent());
+        assertEquals("Foo Bar", msg2.getContent().toString().trim());
         checkMessage(msg2);
     }
     

Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java?rev=739496&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
(added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
Sat Jan 31 03:08:04 2009
@@ -0,0 +1,116 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.javamail.store.pop3;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.mail.Address;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import junit.framework.TestCase;
+
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetupTest;
+
+public class POP3StoreTest extends TestCase {
+    
+    private GreenMail greenMail;
+    private Message[] messages;
+    
+    @Override
+    protected void setUp() throws Exception {
+        // Setup GreenMail
+        greenMail = new GreenMail(ServerSetupTest.SMTP_POP3);       
+        greenMail.start();
+        greenMail.setUser("test@localhost", "test", "test");
+        // Setup JavaMail session
+        Properties props = new Properties();
+        props.setProperty("mail.smtp.port", String.valueOf(greenMail.getSmtp().getPort()));
+        props.setProperty("mail.pop3.port", String.valueOf(greenMail.getPop3().getPort()));
+        
+        System.out.println("stmp.port: " + greenMail.getSmtp().getPort());
+        System.out.println("pop3 port: " + greenMail.getPop3().getPort());
+        
+        Session session = Session.getInstance(props);
+        // Send messages for the current test to GreenMail
+        sendMessage(session, "/messages/multipart.msg");
+        sendMessage(session, "/messages/simple.msg");
+        
+        // Load the message from POP3
+        Store store = session.getStore("pop3");
+        store.connect("localhost", "test", "test");
+        Folder folder = store.getFolder("INBOX");
+        folder.open(Folder.READ_ONLY);
+        this.messages = folder.getMessages();
+        assertEquals(2, messages.length);
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        greenMail.stop();
+    }
+
+    private void sendMessage(Session session, String msgFile) throws Exception {
+        MimeMessage message;
+        InputStream in = POP3StoreTest.class.getResourceAsStream(msgFile);
+        try {
+            message = new MimeMessage(session, in);
+        } finally {
+            in.close();
+        }
+        Transport.send(message, new Address[] { new InternetAddress("test@localhost") });
+    }
+    
+    public void testMessages() throws Exception {
+        MimeMessage msg1 = (MimeMessage)messages[0];
+        Object content = msg1.getContent();
+        assertTrue(content instanceof MimeMultipart);
+        MimeMultipart multipart = (MimeMultipart)content;
+        assertEquals("First part", multipart.getBodyPart(0).getContent());
+        assertEquals("Second part", multipart.getBodyPart(1).getContent());        
+        checkMessage(msg1);
+        
+        MimeMessage msg2 = (MimeMessage)messages[1];
+        assertEquals("Foo Bar", msg2.getContent().toString().trim());
+        checkMessage(msg2);
+    }
+    
+    private void checkMessage(MimeMessage input) throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        input.writeTo(out);
+        
+        Properties props = new Properties();
+        Session s = Session.getInstance(props);
+        
+        byte [] inputData = out.toByteArray();
+        System.out.println(new String(inputData, 0, inputData.length));
+        
+        MimeMessage output = new MimeMessage(s, new ByteArrayInputStream(inputData));
+        
+        assertEquals(input.getContentType().toLowerCase(), output.getContentType().toLowerCase());
       
+    }
+}

Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/java/org/apache/geronimo/javamail/store/pop3/POP3StoreTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/test/resources/messages/
------------------------------------------------------------------------------
    svn:mergeinfo = 



Mime
View raw message