james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/10] james-project git commit: JAMES-2370 Allow mailboxProbeImpl to use AppendCommand
Date Wed, 18 Apr 2018 00:37:00 GMT
JAMES-2370 Allow mailboxProbeImpl to use AppendCommand


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f4a32161
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f4a32161
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f4a32161

Branch: refs/heads/master
Commit: f4a32161990853cded85ffd48481200616a26560
Parents: 8063fc2
Author: benwa <btellier@linagora.com>
Authored: Mon Apr 9 14:04:08 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Apr 18 07:35:39 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MessageManager.java    |  4 +++
 .../apache/james/FixingGhostMailboxTest.java    | 25 ++++++++--------
 .../apache/james/modules/MailboxProbeImpl.java  |  8 ++++++
 .../integration/GetMailboxesMethodTest.java     | 30 ++++++++++----------
 .../integration/cucumber/DownloadStepdefs.java  | 11 ++++---
 .../integration/cucumber/MainStepdefs.java      |  3 +-
 .../cucumber/SetMailboxesMethodStepdefs.java    | 16 +++++------
 7 files changed, 53 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
index 00d8ef9..fbae11d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
@@ -157,6 +157,10 @@ public interface MessageManager {
             return builder().build(message);
         }
 
+        public static AppendCommand from(InputStream message) {
+            return builder().build(message);
+        }
+
         public static class Builder {
             private Optional<Date> internalDate;
             private Optional<Boolean> isRecent;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
index f5d30e3..a7fa339 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
@@ -37,15 +37,13 @@ import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.nullValue;
 
-import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-import javax.mail.Flags;
 
 import org.apache.james.backends.cassandra.ContainerLifecycleConfiguration;
 import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
 import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.cassandra.mail.task.MailboxMergingTask;
 import org.apache.james.mailbox.cassandra.mail.utils.MailboxBaseTupleUtil;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
@@ -58,7 +56,7 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.probe.ACLProbe;
-import org.apache.james.mailbox.store.probe.MailboxProbe;
+import org.apache.james.mime4j.dom.Message;
 import org.apache.james.modules.ACLProbeImpl;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
@@ -110,7 +108,7 @@ public class FixingGhostMailboxTest {
     private String bob;
     private String cedric;
     private GuiceJamesServer jmapServer;
-    private MailboxProbe mailboxProbe;
+    private MailboxProbeImpl mailboxProbe;
     private ACLProbe aclProbe;
     private Session session;
     private CassandraTypesProvider cassandraTypesProvider;
@@ -164,14 +162,13 @@ public class FixingGhostMailboxTest {
         simulateGhostMailboxBug();
     }
 
-    private void simulateGhostMailboxBug() throws MailboxException {
+    private void simulateGhostMailboxBug() throws MailboxException, IOException {
         // State before ghost mailbox bug
         // Alice INBOX is delegated to Bob and contains one message
         aliceInboxPath = MailboxPath.forUser(alice, MailboxConstants.INBOX);
         aliceGhostInboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice,
MailboxConstants.INBOX);
         aclProbe.addRights(aliceInboxPath, bob, MailboxACL.FULL_RIGHTS);
-        message1 = mailboxProbe.appendMessage(alice, aliceInboxPath,
-            generateMessageContent(), new Date(), !RECENT, new Flags());
+        message1 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
         rule.await();
 
         // Simulate ghost mailbox bug
@@ -189,13 +186,15 @@ public class FixingGhostMailboxTest {
             .statusCode(200);
 
         // Received a new message
-        message2 = mailboxProbe.appendMessage(alice, aliceInboxPath,
-            generateMessageContent(), new Date(), !RECENT, new Flags());
+        message2 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
         rule.await();
     }
 
-    private ByteArrayInputStream generateMessageContent() {
-        return new ByteArrayInputStream("Subject: toto\r\n\r\ncontent".getBytes(StandardCharsets.UTF_8));
+    private Message generateMessageContent() throws IOException {
+        return Message.Builder.of()
+            .setSubject("toto")
+            .setBody("content", StandardCharsets.UTF_8)
+            .build();
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
index a603408..ce3d08d 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
@@ -168,6 +168,14 @@ public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
         return messageManager.appendMessage(message, internalDate, mailboxSession, isRecent,
flags);
     }
 
+    public ComposedMessageId appendMessage(String username, MailboxPath mailboxPath, MessageManager.AppendCommand
appendCommand)
+            throws MailboxException {
+
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+        MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+        return messageManager.appendMessage(appendCommand, mailboxSession);
+    }
+
     @Override
     public void copyMailbox(String srcBean, String dstBean) throws Exception {
         throw new NotImplementedException();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 0cda516..35c2063 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -46,20 +46,17 @@ import static org.hamcrest.Matchers.isEmptyOrNullString;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.nullValue;
 
-import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
 
-import javax.mail.Flags;
-
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.jmap.model.mailbox.MailboxNamespace;
 import org.apache.james.mailbox.DefaultMailboxes;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -70,8 +67,8 @@ import org.apache.james.mailbox.quota.QuotaSize;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
 import org.apache.james.mailbox.store.probe.ACLProbe;
-import org.apache.james.mailbox.store.probe.MailboxProbe;
 import org.apache.james.mailbox.store.probe.QuotaProbe;
+import org.apache.james.mime4j.dom.Message;
 import org.apache.james.modules.ACLProbeImpl;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.modules.QuotaProbesImpl;
@@ -96,9 +93,11 @@ public abstract class GetMailboxesMethodTest {
 
     private AccessToken accessToken;
     private GuiceJamesServer jmapServer;
-    private MailboxProbe mailboxProbe;
+    private MailboxProbeImpl mailboxProbe;
     private ACLProbe aclProbe;
     private QuotaProbe quotaProbe;
+
+    private Message message;
     
     @Before
     public void setup() throws Throwable {
@@ -118,6 +117,11 @@ public abstract class GetMailboxesMethodTest {
         dataProbe.addUser(ALICE, ALICE_PASSWORD);
         dataProbe.addUser(BOB, BOB_PASSWORD);
         accessToken = authenticateJamesUser(baseUri(jmapServer), ALICE, ALICE_PASSWORD);
+
+        message = Message.Builder.of()
+            .setSubject("test")
+            .setBody("testmail", StandardCharsets.UTF_8)
+            .build();
     }
 
     @After
@@ -379,8 +383,7 @@ public abstract class GetMailboxesMethodTest {
     public void getMailboxesShouldReturnMailboxesWhenAvailable() throws Exception {
         mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "name");
 
-        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "name"),
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new
Date(), false, new Flags());
+        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "name"), AppendCommand.from(message));
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -397,8 +400,7 @@ public abstract class GetMailboxesMethodTest {
     public void getMailboxesShouldReturnMailboxPropertiesWhenAvailable() throws Exception
{
         String myMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE,
ALICE, "name").serialize();
 
-        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "name"),
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new
Date(), false, new Flags());
+        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "name"), AppendCommand.from(message));
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -865,10 +867,8 @@ public abstract class GetMailboxesMethodTest {
     @Test
     public void getMailboxesShouldReturnUpdatedQuotasForInboxWhenMailReceived() throws Exception
{
         String mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE,
DefaultMailboxes.INBOX).serialize();
-        String message = "Subject: hello\r\n\r\nContent";
-        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, DefaultMailboxes.INBOX),
-                new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)),
-                new Date(), true, new Flags());
+
+        mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, DefaultMailboxes.INBOX),
AppendCommand.from(message));
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -879,7 +879,7 @@ public abstract class GetMailboxesMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
             .body(ARGUMENTS + ".list", hasSize(1))
-            .body(FIRST_MAILBOX + ".quotas['#private&alice@domain.tld']['STORAGE'].used",
equalTo(message.length()))
+            .body(FIRST_MAILBOX + ".quotas['#private&alice@domain.tld']['STORAGE'].used",
equalTo(85))
             .body(FIRST_MAILBOX + ".quotas['#private&alice@domain.tld']['MESSAGE'].used",
equalTo(1));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
index a4365ac..1ff185b 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
@@ -26,13 +26,11 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 
 import javax.inject.Inject;
-import javax.mail.Flags;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.http.Header;
@@ -42,6 +40,7 @@ import org.apache.http.client.fluent.Response;
 import org.apache.http.client.utils.URIBuilder;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.jmap.model.AttachmentAccessToken;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -96,7 +95,7 @@ public class DownloadStepdefs {
         MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox);
 
         ComposedMessageId composedMessageId = mainStepdefs.mailboxProbe.appendMessage(user,
mailboxPath,
-            ClassLoader.getSystemResourceAsStream("eml/oneAttachment.eml"), new Date(), false,
new Flags());
+            AppendCommand.from(ClassLoader.getSystemResourceAsStream("eml/oneAttachment.eml")));
 
         inputToMessageId.put(messageId, composedMessageId.getMessageId());
     }
@@ -106,7 +105,7 @@ public class DownloadStepdefs {
         MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox);
 
         ComposedMessageId composedMessageId = mainStepdefs.mailboxProbe.appendMessage(user,
mailboxPath,
-                ClassLoader.getSystemResourceAsStream("eml/oneAttachment.eml"), new Date(),
false, new Flags());
+            AppendCommand.from(ClassLoader.getSystemResourceAsStream("eml/oneAttachment.eml")));
 
         inputToMessageId.put(messageId, composedMessageId.getMessageId());
         attachmentsByMessageId.put(messageId, attachmentId);
@@ -118,7 +117,7 @@ public class DownloadStepdefs {
         MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox);
 
         mainStepdefs.mailboxProbe.appendMessage(user, mailboxPath,
-                ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(),
false, new Flags());
+                AppendCommand.from(ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml")));
         
         attachmentsByMessageId.put(messageId, attachmentId);
     }
@@ -128,7 +127,7 @@ public class DownloadStepdefs {
         MailboxPath mailboxPath = MailboxPath.forUser(user, mailbox);
 
         mainStepdefs.mailboxProbe.appendMessage(user, mailboxPath,
-            ClassLoader.getSystemResourceAsStream("eml/sameInlinedImages.eml"), new Date(),
false, new Flags());
+            AppendCommand.from(ClassLoader.getSystemResourceAsStream("eml/sameInlinedImages.eml")));
 
         attachmentsByMessageId.put(messageName, attachmentId);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
index 3eefebb..567cd0e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
@@ -28,7 +28,6 @@ import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.probe.ACLProbe;
-import org.apache.james.mailbox.store.probe.MailboxProbe;
 import org.apache.james.modules.ACLProbeImpl;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
@@ -46,7 +45,7 @@ public class MainStepdefs {
 
     public GuiceJamesServer jmapServer;
     public DataProbe dataProbe;
-    public MailboxProbe mailboxProbe;
+    public MailboxProbeImpl mailboxProbe;
     public ACLProbe aclProbe;
     public MessageIdProbe messageIdProbe;
     public Runnable awaitMethod = () -> { };

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4a32161/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index a02db3d..6e85a8a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -24,22 +24,21 @@ import static org.apache.james.jmap.TestingConstants.NAME;
 import static org.apache.james.jmap.TestingConstants.calmlyAwait;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
-import java.util.Date;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import javax.inject.Inject;
-import javax.mail.Flags;
 
-import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mime4j.dom.Message;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.Maps;
@@ -75,11 +74,12 @@ public class SetMailboxesMethodStepdefs {
         mainStepdefs.awaitMethod.run();
     }
 
-    private void appendMessage(MailboxPath mailboxPath, int i) throws MailboxException {
-        String content = "Subject: test" + i + "\r\n\r\n"
-                + "testBody" + i;
+    private void appendMessage(MailboxPath mailboxPath, int i) throws Exception {
         mainStepdefs.mailboxProbe.appendMessage(userStepdefs.getConnectedUser(), mailboxPath,
-                new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags());
+                MessageManager.AppendCommand.from(Message.Builder.of()
+                    .setSubject("test" + i)
+                    .setBody("testBody" + i, StandardCharsets.UTF_8)
+                    .build()));
     }
 
     @Given("^\"([^\"]*)\" has a mailbox \"([^\"]*)\"$")


---------------------------------------------------------------------
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