james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/5] james-project git commit: MAILBOX-326 Allow to append MIME4J messages into MessageManager::append
Date Fri, 06 Apr 2018 08:27:11 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
index 5e96ac9..da27f4b 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
@@ -27,6 +27,8 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
+import java.nio.charset.StandardCharsets;
+
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
@@ -36,6 +38,7 @@ import org.apache.james.mailbox.DefaultMailboxes;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -49,6 +52,7 @@ import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResultIterator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mime4j.dom.Message;
 import org.apache.james.queue.api.MailQueue;
 import org.apache.james.queue.api.MailQueue.MailQueueItem;
 import org.apache.mailet.Mail;
@@ -70,6 +74,7 @@ public class PostDequeueDecoratorTest {
     private MailQueueItem mockedMailQueueItem;
     private Mail mail;
     private PostDequeueDecorator testee;
+    private Message message;
 
     @Before
     public void init() throws Exception {
@@ -82,6 +87,11 @@ public class PostDequeueDecoratorTest {
         when(mockedMailQueueItem.getMail()).thenReturn(mail);
         testee = new PostDequeueDecorator(mockedMailQueueItem, mailboxManager, new InMemoryMessageId.Factory(),

                 inMemoryIntegrationResources.createMessageIdManager(mailboxManager), new
SystemMailboxesProviderImpl(mailboxManager));
+
+        message = Message.Builder.of()
+            .setSubject("test")
+            .setBody("testmail", StandardCharsets.UTF_8)
+            .build();
     }
     
     @Test
@@ -101,8 +111,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId sentMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId sentMessageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, sentMessageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -114,8 +123,7 @@ public class PostDequeueDecoratorTest {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 
@@ -128,8 +136,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -146,8 +153,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -164,8 +170,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -182,8 +187,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(AppendCommand.from(message), mailboxSession);
         
         testee.done(true);
         
@@ -198,8 +202,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail".getBytes()), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         
         testee.done(true);
@@ -215,8 +218,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(AppendCommand.from(message), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
         testee.done(true);
@@ -232,8 +234,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(AppendCommand.from(message), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, "invalid");
         
@@ -254,8 +255,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         MailboxId sentMailboxId = mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession).get();
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 
@@ -284,8 +284,7 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession).get();
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message),
mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
index 9be3f16..849fb63 100644
--- a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
+++ b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.ByteArrayOutputStream;
 import java.io.Reader;
 import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
 
@@ -44,6 +45,7 @@ import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.FakeAuthorizator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mime4j.dom.Message;
 import org.apache.james.pop3server.netty.POP3Server;
 import org.apache.james.protocols.api.utils.ProtocolServerUtils;
 import org.apache.james.protocols.lib.POP3BeforeSMTPHelper;
@@ -390,8 +392,11 @@ public class POP3ServerTest {
 
         int msgCount = 100;
         for (int i = 0; i < msgCount; i++) {
-            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder()
-                .build("Subject: test\r\n\r\n" + i), session);
+            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.from(
+                Message.Builder.of()
+                    .setSubject("test")
+                    .setBody(String.valueOf(i), StandardCharsets.UTF_8)),
+                session);
         }
 
         pop3Client.login("foo2", "bar2");
@@ -440,8 +445,10 @@ public class POP3ServerTest {
 
         int msgCount = 100;
         for (int i = 0; i < msgCount; i++) {
-            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder()
-                .build(("Subject: test\r\n\r\n" + i)), session);
+            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.from(
+                Message.Builder.of()
+                    .setSubject("test")
+                    .setBody(String.valueOf(i), StandardCharsets.UTF_8)), session);
         }
 
         pop3Client.login("foo2", "bar2");


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message