You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/01/24 05:49:01 UTC

[01/15] james-project git commit: JAMES-1785 Improve constants in SetMessagesMethodTest

Repository: james-project
Updated Branches:
  refs/heads/master 8813d2e57 -> 339880196


JAMES-1785 Improve constants in SetMessagesMethodTest


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

Branch: refs/heads/master
Commit: f96b6d2b5697d3ca862f5bc0c4cef34f11a105e0
Parents: 8813d2e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Jan 17 14:07:23 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:41:40 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 194 +++++++++----------
 1 file changed, 97 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f96b6d2b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 1cbfa7a..4eec224 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -88,6 +88,8 @@ public abstract class SetMessagesMethodTest {
     private static final String SECOND_NAME = "[1][0]";
     private static final String SECOND_ARGUMENTS = "[1][1]";
     private static final String USERS_DOMAIN = "domain.tld";
+    private static final String USERNAME = "username@" + USERS_DOMAIN;
+    public static final MailboxPath USER_MAILBOX = new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
     private static final String NOT_UPDATED = ARGUMENTS + ".notUpdated";
 
     private ConditionFactory calmlyAwait;
@@ -99,7 +101,6 @@ public abstract class SetMessagesMethodTest {
     protected abstract void await();
 
     private AccessToken accessToken;
-    private String username;
     private JmapJamesServer jmapServer;
 
     @Before
@@ -115,14 +116,13 @@ public abstract class SetMessagesMethodTest {
                 .build();
         RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 
-        username = "username@" + USERS_DOMAIN;
         String password = "password";
         jmapServer.serverProbe().addDomain(USERS_DOMAIN);
-        jmapServer.serverProbe().addUser(username, password);
-        jmapServer.serverProbe().createMailbox("#private", username, "inbox");
-        accessToken = JmapAuthentication.authenticateJamesUser(username, password);
+        jmapServer.serverProbe().addUser(USERNAME, password);
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, "inbox");
+        accessToken = JmapAuthentication.authenticateJamesUser(USERNAME, password);
 
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "outbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "outbox");
         await();
 
         Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
@@ -207,7 +207,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldReturnNotDestroyedWhenNoMatchingMessage() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         String messageId = randomMessageId().serialize();
         given()
@@ -230,9 +230,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldReturnDestroyedWhenMatchingMessage() throws Exception {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -253,9 +253,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldDeleteMessageWhenMatchingMessage() throws Exception {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -284,15 +284,15 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldReturnDestroyedNotDestroyWhenMixed() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -321,15 +321,15 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldDeleteMatchingMessagesWhenMixed() throws Exception {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -361,9 +361,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsUnreadPassedToFalse() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -395,9 +395,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMarkAsReadWhenIsUnreadPassedToFalse() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -424,9 +424,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsUnreadPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
@@ -446,9 +446,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMarkAsUnreadWhenIsUnreadPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
@@ -475,9 +475,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsFlaggedPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -497,9 +497,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMarkAsFlaggedWhenIsFlaggedPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -524,8 +524,8 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldRejectUpdateWhenPropertyHasWrongType() throws MailboxException {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
+        jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         await();
@@ -552,13 +552,13 @@ public abstract class SetMessagesMethodTest {
     @Test
     @Ignore("Jackson json deserializer stops after first error found")
     public void setMessagesShouldRejectUpdateWhenPropertiesHaveWrongTypes() throws MailboxException {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
+        jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         await();
 
-        String messageId = username + "|mailbox|1";
+        String messageId = USERNAME + "|mailbox|1";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -580,9 +580,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMarkMessageAsAnsweredWhenIsAnsweredPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -602,9 +602,9 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMarkAsAnsweredWhenIsAnsweredPassed() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
@@ -629,7 +629,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessageShouldReturnNotFoundWhenUpdateUnknownMessage() {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         String nonExistingMessageId = randomMessageId().serialize();
 
@@ -651,7 +651,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessageShouldReturnCreatedMessageWhenSendingMessage() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -702,7 +702,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessageShouldReturnCreatedMessageWithEmptySubjectWhenSubjectIsNull() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -736,7 +736,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessageShouldReturnCreatedMessageWithEmptySubjectWhenSubjectIsEmpty() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -770,7 +770,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessageShouldReturnCreatedMessageWithNonASCIICharactersInSubjectWhenPresent() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -804,7 +804,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessageShouldSupportArbitraryMessageId() {
         String messageCreationId = "1717fcd1-603e-44a5-b2a6-1234dbcd5723";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+
@@ -838,7 +838,7 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldCreateMessageInOutboxWhenSendingMessage() throws MailboxException {
         // Given
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String messageSubject = "Thank you for joining example.com!";
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
@@ -885,10 +885,10 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldMoveMessageInSentWhenMessageIsSent() throws MailboxException {
         // Given
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String messageCreationId = "creationId1337";
         String messageSubject = "Thank you for joining example.com!";
         String requestBody = "[" +
@@ -938,7 +938,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldRejectWhenSendingMessageHasNoValidAddress() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1011,7 +1011,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldSucceedWhenSendingMessageWithOnlyFromAddress() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1048,7 +1048,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldSucceedWithHtmlBody() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1084,11 +1084,11 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldMoveToSentWhenSendingMessageWithOnlyFromAddress() {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1120,7 +1120,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldNotRejectWhenSendingMessageHasMissingSubject() {
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1189,7 +1189,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldDeliverMessageToRecipient() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         // Recipient
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
         String password = "password";
@@ -1199,7 +1199,7 @@ public abstract class SetMessagesMethodTest {
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1232,7 +1232,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldStripBccFromDeliveredEmail() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         // Recipient
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
         String bccRecipient = "bob@" + USERS_DOMAIN;
@@ -1244,7 +1244,7 @@ public abstract class SetMessagesMethodTest {
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1289,7 +1289,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldKeepBccInSentMailbox() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
         // Recipient
@@ -1300,7 +1300,7 @@ public abstract class SetMessagesMethodTest {
         await();
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1345,7 +1345,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldSendMessageToBcc() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         // Recipient
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
@@ -1360,7 +1360,7 @@ public abstract class SetMessagesMethodTest {
         AccessToken bccToken = JmapAuthentication.authenticateJamesUser(bccAddress, password);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1424,7 +1424,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldSendAReadableHtmlMessage() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         // Recipient
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
         String password = "password";
@@ -1434,7 +1434,7 @@ public abstract class SetMessagesMethodTest {
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1466,7 +1466,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesWhenSavingToDraftsShouldNotSendMessage() throws Exception {
-        String sender = username;
+        String sender = USERNAME;
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, sender, "sent");
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, sender, "drafts");
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
@@ -1479,7 +1479,7 @@ public abstract class SetMessagesMethodTest {
         String senderDraftsMailboxId = getMailboxId(accessToken, Role.DRAFTS);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1514,7 +1514,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesWhenSavingToRegularMailboxShouldNotSendMessage() throws Exception {
-        String sender = username;
+        String sender = USERNAME;
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, sender, "sent");
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, sender, "drafts");
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, sender, "regular");
@@ -1525,7 +1525,7 @@ public abstract class SetMessagesMethodTest {
         await();
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1579,7 +1579,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldSendAReadableTextPlusHtmlMessage() throws Exception {
         // Sender
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         // Recipient
         String recipientAddress = "recipient" + "@" + USERS_DOMAIN;
         String password = "password";
@@ -1589,7 +1589,7 @@ public abstract class SetMessagesMethodTest {
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1639,14 +1639,14 @@ public abstract class SetMessagesMethodTest {
     }
 
     @Test
-    public void movingAMessageIsNotSupported() throws Exception {
+    public void movingShouldBeSupported() throws Exception {
         String newMailboxName = "heartFolder";
-        jmapServer.serverProbe().createMailbox("#private", username, newMailboxName);
-        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", username, newMailboxName);
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
         String heartFolderId = heartFolder.getMailboxId().serialize();
 
         ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
-        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath("#private", username, "inbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
                 new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
 
         String messageToMoveId = message.getMessageId().serialize();
@@ -1680,10 +1680,10 @@ public abstract class SetMessagesMethodTest {
     
     @Test
     public void setMessagesShouldReturnAttachmentsNotFoundWhenBlobIdDoesntExist() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         await();
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -1723,7 +1723,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldReturnAttachmentsWhenMessageHasAttachment() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes("attachment".getBytes(Charsets.UTF_8))
@@ -1737,7 +1737,7 @@ public abstract class SetMessagesMethodTest {
         uploadAttachment(attachment2);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -1794,7 +1794,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldReturnAttachmentsWithNonASCIINames() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes("attachment".getBytes(Charsets.UTF_8))
@@ -1813,7 +1813,7 @@ public abstract class SetMessagesMethodTest {
         uploadAttachment(attachment3);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -1882,7 +1882,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void filenamesAttachmentsWithNonASCIICharactersShouldBeRetrievedWhenChainingSetMessagesAndGetMessages() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes("attachment".getBytes(Charsets.UTF_8))
@@ -1903,7 +1903,7 @@ public abstract class SetMessagesMethodTest {
         uploadAttachment(attachment3);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2006,7 +2006,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void attachmentsShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesBinaryAttachment() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         byte[] rawBytes = new byte[]{-128,-127,-126,-125,-124,-123,-122,-121,-120,-119,-118,-117,-116,-115,-114,-113,-112,-111,-110,-109,-108,-107,-106,-105,-104,-103,-102,-101,-100,
                 -99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,
@@ -2023,7 +2023,7 @@ public abstract class SetMessagesMethodTest {
         String expectedBlobId = attachment.getAttachmentId().getId();
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2086,7 +2086,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void attachmentsShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesTextAttachment() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes(ByteStreams.toByteArray(new ZeroedInputStream(_1MB)))
@@ -2096,7 +2096,7 @@ public abstract class SetMessagesMethodTest {
         String expectedBlobId = attachment.getAttachmentId().getId();
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2179,7 +2179,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void attachmentsAndBodysShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesWithMixedTextAndHtmlBodyAndHtmlAttachment() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes(("<html>\n" +
@@ -2190,7 +2190,7 @@ public abstract class SetMessagesMethodTest {
         uploadTextAttachment(attachment);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2255,7 +2255,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void attachmentsAndBodyShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesWithTextBodyAndHtmlAttachment() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes(("<html>\n" +
@@ -2266,7 +2266,7 @@ public abstract class SetMessagesMethodTest {
         uploadTextAttachment(attachment);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2329,7 +2329,7 @@ public abstract class SetMessagesMethodTest {
     }
     @Test
     public void attachmentAndEmptyBodyShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesWithTextAttachmentWithoutMailBody() throws Exception {
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
                 .bytes(("some text").getBytes(Charsets.UTF_8))
@@ -2338,7 +2338,7 @@ public abstract class SetMessagesMethodTest {
         uploadTextAttachment(attachment);
 
         String messageCreationId = "creationId";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
                 "  [" +
@@ -2405,9 +2405,9 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().addUser(toUsername, password);
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, toUsername, "inbox");
 
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+
@@ -2443,9 +2443,9 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().addUser(toUsername, password);
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, toUsername, "inbox");
 
-        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
         String messageCreationId = "creationId1337";
-        String fromAddress = username;
+        String fromAddress = USERNAME;
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+


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


[13/15] james-project git commit: JAMES-1785 Improve SetMessagesMethodTest.java with indents

Posted by bt...@apache.org.
JAMES-1785 Improve SetMessagesMethodTest.java
with indents


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

Branch: refs/heads/master
Commit: 91e352e41c0c325d1a3a624ba069c234253ae383
Parents: d30b24e
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Thu Jan 19 12:46:31 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 1404 +++++++++---------
 1 file changed, 702 insertions(+), 702 deletions(-)
----------------------------------------------------------------------



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


[05/15] james-project git commit: JAMES-1785 Implement move feature on JMAP using setInMailboxes

Posted by bt...@apache.org.
JAMES-1785 Implement move feature on JMAP using setInMailboxes


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

Branch: refs/heads/master
Commit: 89994c30809c7a963938a7a6eebe9b62baa62774
Parents: 54fe9a4
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Wed Jan 18 11:29:33 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:46:05 2017 +0700

----------------------------------------------------------------------
 .../methods/SetMessagesUpdateProcessor.java     | 49 ++++++++++++++++++--
 .../james/jmap/model/UpdateMessagePatch.java    | 32 +++++++------
 .../methods/SetMessagesUpdateProcessorTest.java |  4 +-
 3 files changed, 64 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/89994c30/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index ba55a8d..f04e180 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -28,21 +28,28 @@ import java.util.stream.Stream;
 import javax.inject.Inject;
 import javax.mail.Flags;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.model.MessageProperties;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMessagesRequest;
 import org.apache.james.jmap.model.SetMessagesResponse;
 import org.apache.james.jmap.model.UpdateMessagePatch;
+import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.jmap.utils.SystemMailboxesProvider;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxId.Factory;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -54,13 +61,21 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
 
     private final UpdateMessagePatchConverter updatePatchConverter;
     private final MessageIdManager messageIdManager;
+    private final Factory mailboxIdFactory;
+    private final MailboxManager mailboxManager;
+    private final SystemMailboxesProvider systemMailboxesProvider;
 
     @Inject
     @VisibleForTesting SetMessagesUpdateProcessor(
-            UpdateMessagePatchConverter updatePatchConverter,
-            MessageIdManager messageIdManager) {
+        UpdateMessagePatchConverter updatePatchConverter,
+        MessageIdManager messageIdManager,
+        Factory mailboxIdFactory,
+        MailboxManager mailboxManager, SystemMailboxesProvider systemMailboxesProvider) {
         this.updatePatchConverter = updatePatchConverter;
         this.messageIdManager = messageIdManager;
+        this.mailboxIdFactory = mailboxIdFactory;
+        this.mailboxManager = mailboxManager;
+        this.systemMailboxesProvider = systemMailboxesProvider;
     }
 
     public SetMessagesResponse process(SetMessagesRequest request,  MailboxSession mailboxSession) {
@@ -78,14 +93,16 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
                         SetMessagesResponse.Builder builder) {
         try {
             List<MessageResult> messages = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, mailboxSession);
+
             if (messages.isEmpty()) {
                 addMessageIdNotFoundToResponse(messageId, builder);
             } else {
+                setInMailboxes(messageId, updateMessagePatch, mailboxSession);
                 Optional<MailboxException> updateError = messages.stream()
                     .flatMap(message -> updateFlags(messageId, updateMessagePatch, mailboxSession, message))
                     .findAny();
                 if (updateError.isPresent()) {
-                    updateError.ifPresent(e -> handleMessageUpdateException(messageId, builder, e));
+                    handleMessageUpdateException(messageId, builder, updateError.get());
                 } else {
                     builder.updated(ImmutableList.of(messageId));
                 }
@@ -106,6 +123,28 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
         }
     }
 
+    private void setInMailboxes(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession) throws MailboxException {
+        Optional<List<String>> serializedMailboxIds = updateMessagePatch.getMailboxIds();
+        if (serializedMailboxIds.isPresent()) {
+            List<MailboxId> mailboxIds = serializedMailboxIds.get()
+                .stream()
+                .map(mailboxId -> mailboxIdFactory.fromString(mailboxId))
+                .collect(Guavate.toImmutableList());
+
+            if (isMoveToTrash(mailboxSession, mailboxIds)) {
+                throw new NotImplementedException("Do not support move to trash");
+            }
+
+            messageIdManager.setInMailboxes(messageId, mailboxIds, mailboxSession);
+        }
+    }
+
+    private boolean isMoveToTrash(MailboxSession mailboxSession, List<MailboxId> mailboxIds) throws MailboxException {
+        return mailboxIds.size() == 1
+            && mailboxIds.get(0)
+                .equals(systemMailboxesProvider.findMailbox(Role.TRASH, mailboxSession).getId());
+    }
+
     private void addMessageIdNotFoundToResponse(MessageId messageId, SetMessagesResponse.Builder builder) {
         builder.notUpdated(ImmutableMap.of(messageId,
                 SetError.builder()
@@ -115,11 +154,11 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
                         .build()));
     }
 
-    private void handleMessageUpdateException(MessageId messageId,
+    private SetMessagesResponse.Builder handleMessageUpdateException(MessageId messageId,
                                               SetMessagesResponse.Builder builder,
                                               MailboxException e) {
         LOGGER.error("An error occurred when updating a message", e);
-        builder.notUpdated(ImmutableMap.of(messageId, SetError.builder()
+        return builder.notUpdated(ImmutableMap.of(messageId, SetError.builder()
                 .type("anErrorOccurred")
                 .description("An error occurred when updating a message")
                 .build()));

http://git-wip-us.apache.org/repos/asf/james-project/blob/89994c30/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
index 9ffac27..cc0e184 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
@@ -25,14 +25,14 @@ import java.util.Set;
 
 import javax.mail.Flags;
 
-import com.google.common.collect.ImmutableSet;
-
-import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.methods.ValidationResult;
+
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
 
 @JsonDeserialize(builder = UpdateMessagePatch.Builder.class)
 public class UpdateMessagePatch {
@@ -43,16 +43,14 @@ public class UpdateMessagePatch {
 
     @JsonPOJOBuilder(withPrefix = "")
     public static class Builder {
-        private ImmutableList.Builder<String> mailboxIds = ImmutableList.builder();
+        private Optional<List<String>> mailboxIds = Optional.empty();
         private Optional<Boolean> isFlagged = Optional.empty();
         private Optional<Boolean> isUnread = Optional.empty();
         private Optional<Boolean> isAnswered = Optional.empty();
-        private Set<ValidationResult> validationResult = ImmutableSet.of();
+        private Set<ValidationResult> validationResult = Sets.newHashSet();
 
-        public Builder mailboxIds(Optional<List<String>> mailboxIds) {
-            if (mailboxIds.isPresent()) {
-                throw new NotImplementedException("moving a message is not supported");
-            }
+        public Builder mailboxIds(List<String> mailboxIds) {
+            this.mailboxIds = Optional.of(ImmutableList.copyOf(mailboxIds));
             return this;
         }
 
@@ -72,16 +70,22 @@ public class UpdateMessagePatch {
         }
 
         public Builder validationResult(Set<ValidationResult> validationResult) {
-            this.validationResult = ImmutableSet.copyOf(validationResult);
+            this.validationResult.addAll(validationResult);
             return this;
         }
 
         public UpdateMessagePatch build() {
-            return new UpdateMessagePatch(mailboxIds.build(), isUnread, isFlagged, isAnswered, ImmutableList.copyOf(validationResult));
+            if (mailboxIds.isPresent() && mailboxIds.get().isEmpty()) {
+                validationResult(ImmutableSet.of(ValidationResult.builder()
+                    .property("mailboxIds")
+                    .message("mailboxIds property is not supposed to be empty")
+                    .build()));
+            }
+            return new UpdateMessagePatch(mailboxIds, isUnread, isFlagged, isAnswered, ImmutableList.copyOf(validationResult));
         }
     }
 
-    private final List<String> mailboxIds;
+    private final Optional<List<String>> mailboxIds;
     private final Optional<Boolean> isUnread;
     private final Optional<Boolean> isFlagged;
     private final Optional<Boolean> isAnswered;
@@ -89,7 +93,7 @@ public class UpdateMessagePatch {
     private final ImmutableList<ValidationResult> validationErrors;
 
     @VisibleForTesting
-    UpdateMessagePatch(List<String> mailboxIds,
+    UpdateMessagePatch(Optional<List<String>> mailboxIds,
                        Optional<Boolean> isUnread,
                        Optional<Boolean> isFlagged,
                        Optional<Boolean> isAnswered,
@@ -102,7 +106,7 @@ public class UpdateMessagePatch {
         this.validationErrors = validationResults;
     }
 
-    public List<String> getMailboxIds() {
+    public Optional<List<String>> getMailboxIds() {
         return mailboxIds;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/89994c30/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
index d6478ff..5b0387a 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
@@ -42,7 +42,7 @@ public class SetMessagesUpdateProcessorTest {
 
     @Test
     public void processShouldReturnEmptyUpdatedWhenRequestHasEmptyUpdate() {
-        SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(null, null);
+        SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(null, null, null, null, null);
         SetMessagesRequest requestWithEmptyUpdate = SetMessagesRequest.builder().build();
 
         SetMessagesResponse result = sut.process(requestWithEmptyUpdate, null);
@@ -66,7 +66,7 @@ public class SetMessagesUpdateProcessorTest {
         when(mockConverter.fromJsonNode(any(ObjectNode.class)))
                 .thenReturn(mockInvalidPatch);
 
-        SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(mockConverter, null);
+        SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(mockConverter, null, null, null, null);
         MessageId requestMessageId = TestMessageId.of(1);
         SetMessagesRequest requestWithInvalidUpdate = SetMessagesRequest.builder()
                 .update(ImmutableMap.of(requestMessageId, JsonNodeFactory.instance.objectNode()))


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


[02/15] james-project git commit: JAMES-1785 Add more binding for SystemMailboxesProvider

Posted by bt...@apache.org.
JAMES-1785 Add more binding for SystemMailboxesProvider


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

Branch: refs/heads/master
Commit: c996365e12637ab8c5d13669e8b86b34bc377e6d
Parents: f96b6d2
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Wed Jan 18 11:20:14 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:41:41 2017 +0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/james/jmap/JMAPModule.java             | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c996365e/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
index af78a3a..7269cb1 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -65,6 +65,7 @@ public class JMAPModule extends AbstractModule {
         bind(RequestHandler.class).in(Scopes.SINGLETON);
         bind(UploadHandler.class).in(Scopes.SINGLETON);
         bind(MailboxBasedHtmlTextExtractor.class).in(Scopes.SINGLETON);
+        bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
 
         bind(HtmlTextExtractor.class).to(MailboxBasedHtmlTextExtractor.class);
         Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(RequiredCapabilitiesPrecondition.class);


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


[12/15] james-project git commit: JAMES-1785 Improve SetMessagesMethodTest.java with indents

Posted by bt...@apache.org.
http://git-wip-us.apache.org/repos/asf/james-project/blob/91e352e4/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 587dec3..caf57a2 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -144,20 +144,20 @@ public abstract class SetMessagesMethodTest {
 
     private String getMailboxId(AccessToken accessToken, Role role) {
         return getAllMailboxesIds(accessToken).stream()
-                .filter(x -> x.get("role").equals(role.serialize()))
-                .map(x -> x.get("id"))
-                .findFirst().get();
+            .filter(x -> x.get("role").equals(role.serialize()))
+            .map(x -> x.get("id"))
+            .findFirst().get();
     }
     
     private List<Map<String, String>> getAllMailboxesIds(AccessToken accessToken) {
         return with()
-                .header("Authorization", accessToken.serialize())
-                .body("[[\"getMailboxes\", {\"properties\": [\"role\", \"id\"]}, \"#0\"]]")
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"properties\": [\"role\", \"id\"]}, \"#0\"]]")
         .post("/jmap")
-                .andReturn()
-                .body()
-                .jsonPath()
-                .getList(ARGUMENTS + ".list");
+            .andReturn()
+            .body()
+            .jsonPath()
+            .getList(ARGUMENTS + ".list");
     }
 
     @Test
@@ -203,9 +203,9 @@ public abstract class SetMessagesMethodTest {
             .body(NAME, equalTo("messagesSet"))
             .body(ARGUMENTS + ".destroyed", empty())
             .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(unknownMailboxMessageId), Matchers.allOf(
-                    hasEntry("type", "notFound"),
-                    hasEntry("description", "The message " + unknownMailboxMessageId + " can't be found"),
-                    hasEntry(equalTo("properties"), isEmptyOrNullString())))
+                hasEntry("type", "notFound"),
+                hasEntry("description", "The message " + unknownMailboxMessageId + " can't be found"),
+                hasEntry(equalTo("properties"), isEmptyOrNullString())))
             );
     }
 
@@ -225,9 +225,9 @@ public abstract class SetMessagesMethodTest {
             .body(NAME, equalTo("messagesSet"))
             .body(ARGUMENTS + ".destroyed", empty())
             .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(messageId), Matchers.allOf(
-                    hasEntry("type", "notFound"),
-                    hasEntry("description", "The message " + messageId + " can't be found"),
-                    hasEntry(equalTo("properties"), isEmptyOrNullString())))
+                hasEntry("type", "notFound"),
+                hasEntry("description", "The message " + messageId + " can't be found"),
+                hasEntry(equalTo("properties"), isEmptyOrNullString())))
             );
     }
 
@@ -237,7 +237,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         given()
@@ -260,7 +260,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         // When
@@ -291,22 +291,22 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String missingMessageId = randomMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
             .body(String.format("[[\"setMessages\", {\"destroy\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
-                    message1.getMessageId().serialize(),
-                    missingMessageId,
-                    message3.getMessageId().serialize()))
+                message1.getMessageId().serialize(),
+                missingMessageId,
+                message3.getMessageId().serialize()))
         .when()
             .post("/jmap")
         .then()
@@ -317,8 +317,8 @@ public abstract class SetMessagesMethodTest {
             .body(ARGUMENTS + ".notDestroyed", aMapWithSize(1))
             .body(ARGUMENTS + ".destroyed", contains(message1.getMessageId().serialize(), message3.getMessageId().serialize()))
             .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(missingMessageId), Matchers.allOf(
-                    hasEntry("type", "notFound"),
-                    hasEntry("description", "The message " + missingMessageId + " can't be found")))
+                hasEntry("type", "notFound"),
+                hasEntry("description", "The message " + missingMessageId + " can't be found")))
             );
     }
 
@@ -328,31 +328,31 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         // When
         with()
             .header("Authorization", accessToken.serialize())
             .body(String.format("[[\"setMessages\", {\"destroy\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
-                    message1.getMessageId().serialize(),
-                    randomMessageId().serialize(),
-                    message3.getMessageId().serialize()))
+                message1.getMessageId().serialize(),
+                randomMessageId().serialize(),
+                message3.getMessageId().serialize()))
         .post("/jmap");
         
         // Then
         given()
             .header("Authorization", accessToken.serialize())
             .body(String.format("[[\"getMessages\", {\"ids\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
-                    message1.getMessageId().serialize(),
-                    message2.getMessageId().serialize(),
-                    message3.getMessageId().serialize()))
+                message1.getMessageId().serialize(),
+                message2.getMessageId().serialize(),
+                message3.getMessageId().serialize()))
         .when()
             .post("/jmap")
         .then()
@@ -368,7 +368,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -387,12 +387,12 @@ public abstract class SetMessagesMethodTest {
 
     private ResponseSpecification getSetMessagesUpdateOKResponseAssertions(String messageId) {
         ResponseSpecBuilder builder = new ResponseSpecBuilder()
-                .expectStatusCode(200)
-                .expectBody(NAME, equalTo("messagesSet"))
-                .expectBody(ARGUMENTS + ".updated", hasSize(1))
-                .expectBody(ARGUMENTS + ".updated", contains(messageId))
-                .expectBody(ARGUMENTS + ".error", isEmptyOrNullString())
-                .expectBody(NOT_UPDATED, not(hasKey(messageId)));
+            .expectStatusCode(200)
+            .expectBody(NAME, equalTo("messagesSet"))
+            .expectBody(ARGUMENTS + ".updated", hasSize(1))
+            .expectBody(ARGUMENTS + ".updated", contains(messageId))
+            .expectBody(ARGUMENTS + ".error", isEmptyOrNullString())
+            .expectBody(NOT_UPDATED, not(hasKey(messageId)));
         return builder.build();
     }
 
@@ -402,7 +402,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -431,7 +431,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -453,7 +453,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -482,7 +482,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -504,7 +504,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -530,7 +530,7 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldRejectUpdateWhenPropertyHasWrongType() throws MailboxException {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
         jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         await();
 
@@ -558,7 +558,7 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldRejectUpdateWhenPropertiesHaveWrongTypes() throws MailboxException {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
         jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         await();
 
@@ -587,7 +587,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -609,7 +609,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox");
 
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, USER_MAILBOX,
-                new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
+            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         String serializedMessageId = message.getMessageId().serialize();
@@ -657,20 +657,20 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -688,17 +688,17 @@ public abstract class SetMessagesMethodTest {
             .body(ARGUMENTS + ".created", aMapWithSize(1))
             // assert server-set attributes are returned
             .body(ARGUMENTS + ".created", hasEntry(equalTo(messageCreationId), Matchers.allOf(
-                    hasEntry(equalTo("id"), not(isEmptyOrNullString())),
-                    hasEntry(equalTo("blobId"), not(isEmptyOrNullString())),
-                    hasEntry(equalTo("threadId"), not(isEmptyOrNullString())),
-                    hasEntry(equalTo("size"), not(isEmptyOrNullString()))
+                hasEntry(equalTo("id"), not(isEmptyOrNullString())),
+                hasEntry(equalTo("blobId"), not(isEmptyOrNullString())),
+                hasEntry(equalTo("threadId"), not(isEmptyOrNullString())),
+                hasEntry(equalTo("size"), not(isEmptyOrNullString()))
             )))
             // assert that message flags are all unset
             .body(ARGUMENTS + ".created", hasEntry(equalTo(messageCreationId), Matchers.allOf(
-                    hasEntry(equalTo("isDraft"), equalTo(false)),
-                    hasEntry(equalTo("isUnread"), equalTo(false)),
-                    hasEntry(equalTo("isFlagged"), equalTo(false)),
-                    hasEntry(equalTo("isAnswered"), equalTo(false))
+                hasEntry(equalTo("isDraft"), equalTo(false)),
+                hasEntry(equalTo("isUnread"), equalTo(false)),
+                hasEntry(equalTo("isFlagged"), equalTo(false)),
+                hasEntry(equalTo("isAnswered"), equalTo(false))
             )))
             ;
     }
@@ -708,19 +708,19 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": null," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": null," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -742,19 +742,19 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -776,19 +776,19 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"\u062a\u0635\u0648\u0631 \u0648\u0627\u0636\u062d \u0644\u0644\u0639\u0644\u0627\u0642\u0629 \u0628\u064a\u0646 \u0627\u0644\u0646\u0645\u0648\u0630\u062c \u0627\u0644\u0631\u064a\u0627\u0636\u064a \u0627\u0644\u0645\u062b\u0627\u0644\u064a \u0648\u0645\u0646\u0638\u0648\u0645\u0629 \u0627\u0644\u0638\u0648\u0627\u0647\u0631\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"\u062a\u0635\u0648\u0631 \u0648\u0627\u0636\u062d \u0644\u0644\u0639\u0644\u0627\u0642\u0629 \u0628\u064a\u0646 \u0627\u0644\u0646\u0645\u0648\u0630\u062c \u0627\u0644\u0631\u064a\u0627\u0636\u064a \u0627\u0644\u0645\u062b\u0627\u0644\u064a \u0648\u0645\u0646\u0638\u0648\u0645\u0629 \u0627\u0644\u0638\u0648\u0627\u0647\u0631\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -846,20 +846,20 @@ public abstract class SetMessagesMethodTest {
         String messageSubject = "Thank you for joining example.com!";
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"" + messageSubject + "\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + outboxId + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"" + messageSubject + "\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         String messageId = with()
             .header("Authorization", accessToken.serialize())
@@ -896,27 +896,27 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String messageSubject = "Thank you for joining example.com!";
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"" + messageSubject + "\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"" + messageSubject + "\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
-                .header("Authorization", accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> messageHasBeenMovedToSentBox(sentMailboxId));
@@ -925,14 +925,14 @@ public abstract class SetMessagesMethodTest {
     private boolean messageHasBeenMovedToSentBox(String sentMailboxId) {
         try {
             with()
-                    .header("Authorization", accessToken.serialize())
-                    .body("[[\"getMessageList\", {\"fetchMessages\":true, \"filter\":{\"inMailboxes\":[\"" + sentMailboxId + "\"]}}, \"#0\"]]")
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"fetchMessages\":true, \"filter\":{\"inMailboxes\":[\"" + sentMailboxId + "\"]}}, \"#0\"]]")
             .when()
-                    .post("/jmap")
+                .post("/jmap")
             .then()
-                    .statusCode(200)
-                    .body(SECOND_NAME, equalTo("messages"))
-                    .body(SECOND_ARGUMENTS + ".list", hasSize(1));
+                .statusCode(200)
+                .body(SECOND_NAME, equalTo("messages"))
+                .body(SECOND_ARGUMENTS + ".list", hasSize(1));
             return true;
         } catch(AssertionError e) {
             return false;
@@ -944,21 +944,21 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -980,20 +980,20 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldRejectWhenSendingMessageHasMissingFrom() {
         String messageCreationId = "creationId1337";
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -1017,21 +1017,21 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -1054,21 +1054,21 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"htmlBody\": \"Hello <i>someone</i>, and thank <b>you</b> for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"htmlBody\": \"Hello <i>someone</i>, and thank <b>you</b> for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -1094,29 +1094,29 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> messageHasBeenMovedToSentBox(sentMailboxId));
     }
@@ -1126,20 +1126,20 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -1205,29 +1205,29 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInRecipientsMailboxes(recipientToken));
@@ -1250,30 +1250,30 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"" + bccRecipient + "\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"" + bccRecipient + "\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInRecipientsMailboxes(recipientToken));
@@ -1306,30 +1306,30 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"bob@" + USERS_DOMAIN + "\" }]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"bob@" + USERS_DOMAIN + "\" }]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> messageHasBeenMovedToSentBox(sentMailboxId));
@@ -1366,30 +1366,30 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"" + bccAddress + "\" }]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"recipient\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"bcc\": [{ \"name\": \"BOB\", \"email\": \"" + bccAddress + "\" }]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInRecipientsMailboxes(bccToken));
@@ -1409,14 +1409,14 @@ public abstract class SetMessagesMethodTest {
     private boolean isAnyMessageFoundInRecipientsMailboxes(AccessToken recipientToken) {
         try {
             with()
-                    .header("Authorization", recipientToken.serialize())
-                    .body("[[\"getMessageList\", {}, \"#0\"]]")
+                .header("Authorization", recipientToken.serialize())
+                .body("[[\"getMessageList\", {}, \"#0\"]]")
             .when()
-                    .post("/jmap")
+                .post("/jmap")
             .then()
-                    .statusCode(200)
-                    .body(NAME, equalTo("messageList"))
-                    .body(ARGUMENTS + ".messageIds", hasSize(1));
+                .statusCode(200)
+                .body(NAME, equalTo("messageList"))
+                .body(ARGUMENTS + ".messageIds", hasSize(1));
             return true;
             
         } catch (AssertionError e) {
@@ -1440,28 +1440,28 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"htmlBody\": \"Hello <b>someone</b>, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"htmlBody\": \"Hello <b>someone</b>, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isHtmlMessageReceived(recipientToken));
@@ -1485,22 +1485,22 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + senderDraftsMailboxId + "\"], " +
-                "        \"isDraft\": false" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + senderDraftsMailboxId + "\"], " +
+            "        \"isDraft\": false" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", this.accessToken.serialize())
@@ -1531,21 +1531,21 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"cc\": [{ \"name\": \"ALICE\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
-                "        \"mailboxIds\": [\"" + regularMailbox.getMailboxId().serialize() + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + regularMailbox.getMailboxId().serialize() + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         String notCreatedMessage = ARGUMENTS + ".notCreated[\""+messageCreationId+"\"]";
         given()
@@ -1595,29 +1595,29 @@ public abstract class SetMessagesMethodTest {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
-                "        \"subject\": \"Thank you for joining example.com!\"," +
-                "        \"htmlBody\": \"Hello <b>someone</b>, and thank you for joining example.com!\"," +
-                "        \"textBody\": \"Hello someone, and thank you for joining example.com, text version!\"," +
-                "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"" + recipientAddress + "\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"htmlBody\": \"Hello <b>someone</b>, and thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com, text version!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         // Given
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", this.accessToken.serialize())
+            .body(requestBody)
         // When
         .when()
-                .post("/jmap");
+            .post("/jmap");
 
         // Then
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isTextPlusHtmlMessageReceived(recipientToken));
@@ -1665,9 +1665,9 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .log().ifValidationFails()
             .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId));
     }
@@ -1699,16 +1699,16 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap");
 
         String firstMessage = ARGUMENTS + ".list[0]";
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .statusCode(200)
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
@@ -1796,9 +1796,9 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .statusCode(200)
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
@@ -1829,16 +1829,16 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap");
 
         String firstMessage = ARGUMENTS + ".list[0]";
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .statusCode(200)
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
@@ -1874,9 +1874,9 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .log().ifValidationFails()
             .statusCode(200)
             .body(NAME, equalTo("messagesSet"))
@@ -1907,9 +1907,9 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .log().ifValidationFails()
             .statusCode(200)
             .body(NAME, equalTo("messagesSet"))
@@ -1948,9 +1948,9 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .log().ifValidationFails()
             .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId));
     }
@@ -1983,16 +1983,16 @@ public abstract class SetMessagesMethodTest {
         given()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-            .when()
+        .when()
             .post("/jmap");
 
         String firstMessage = ARGUMENTS + ".list[0]";
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
-            .when()
+        .when()
             .post("/jmap")
-            .then()
+        .then()
             .statusCode(200)
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
@@ -2086,24 +2086,24 @@ public abstract class SetMessagesMethodTest {
         String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"Message with a broken blobId\"," +
-                "        \"textBody\": \"Test body\"," +
-                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
-                "        \"attachments\": [" +
-                "                {\"blobId\" : \"brokenId1\", \"type\" : \"image/gif\", \"size\" : 1337}," +
-                "                {\"blobId\" : \"brokenId2\", \"type\" : \"image/jpeg\", \"size\" : 1337}" +
-                "             ]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"Message with a broken blobId\"," +
+            "        \"textBody\": \"Test body\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+            "        \"attachments\": [" +
+            "                {\"blobId\" : \"brokenId1\", \"type\" : \"image/gif\", \"size\" : 1337}," +
+            "                {\"blobId\" : \"brokenId2\", \"type\" : \"image/jpeg\", \"size\" : 1337}" +
+            "             ]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         String notCreatedPath = ARGUMENTS + ".notCreated[\""+messageCreationId+"\"]";
 
@@ -2126,44 +2126,44 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
-                .bytes("attachment".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment);
         Attachment attachment2 = Attachment.builder()
-                .bytes("attachment2".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment2".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment2);
 
         String messageCreationId = "creationId";
         String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "        \"subject\": \"Message with two attachments\"," +
-                "        \"textBody\": \"Test body\"," +
-                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
-                "        \"attachments\": [" +
-                "               {\"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
-                "               \"type\" : \"" + attachment.getType() + "\", " +
-                "               \"size\" : " + attachment.getSize() + "}," +
-                "               {\"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
-                "               \"type\" : \"" + attachment2.getType() + "\", " +
-                "               \"size\" : " + attachment2.getSize() + ", " +
-                "               \"cid\" : \"123456789\", " +
-                "               \"isInline\" : true }" +
-                "           ]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"subject\": \"Message with two attachments\"," +
+            "        \"textBody\": \"Test body\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+            "        \"attachments\": [" +
+            "               {\"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
+            "               \"type\" : \"" + attachment.getType() + "\", " +
+            "               \"size\" : " + attachment.getSize() + "}," +
+            "               {\"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
+            "               \"type\" : \"" + attachment2.getType() + "\", " +
+            "               \"size\" : " + attachment2.getSize() + ", " +
+            "               \"cid\" : \"123456789\", " +
+            "               \"isInline\" : true }" +
+            "           ]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         String createdPath = ARGUMENTS + ".created[\""+messageCreationId+"\"]";
         String firstAttachment = createdPath + ".attachments[0]";
@@ -2197,67 +2197,67 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
-                .bytes("attachment".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment);
         Attachment attachment2 = Attachment.builder()
-                .bytes("attachment2".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment2".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment2);
         Attachment attachment3 = Attachment.builder()
-                .bytes("attachment3".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment3".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment3);
 
         String messageCreationId = "creationId";
         String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\":" +
-                "      {" +
-                "        \"" + messageCreationId  + "\" : "+
-                "        {" +
-                "          \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "          \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
-                "          \"subject\": \"Message with three attachments with non ASCII name\"," +
-                "          \"textBody\": \"Test body\"," +
-                "          \"mailboxIds\": [\"" + outboxId + "\"], " +
-                "          \"attachments\":" +
-                "          [" +
-                "            {" +
-                "              \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment.getType() + "\", " +
-                "              \"size\" : " + attachment.getSize() + "," +
-                "              \"name\" : \"\u062f\u064a\u0646\u0627\u0635\u0648\u0631.png\", " +
-                "              \"isInline\" : false" +
-                "            }," +
-                "            {" +
-                "              \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment2.getType() + "\", " +
-                "              \"size\" : " + attachment2.getSize() + "," +
-                "              \"name\" : \"\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c.png\", " +
-                "              \"isInline\" : false" +
-                "            }," +
-                "            {" +
-                "              \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment3.getType() + "\", " +
-                "              \"size\" : " + attachment3.getSize() + "," +
-                "              \"name\" : \"\u8fdb\u5316\u8fd8\u662f\u4e0d.png\"," +
-                "              \"isInline\" : false" +
-                "            }" +
-                "          ]" +
-                "        }" +
-                "      }" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\":" +
+            "      {" +
+            "        \"" + messageCreationId  + "\" : "+
+            "        {" +
+            "          \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "          \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "          \"subject\": \"Message with three attachments with non ASCII name\"," +
+            "          \"textBody\": \"Test body\"," +
+            "          \"mailboxIds\": [\"" + outboxId + "\"], " +
+            "          \"attachments\":" +
+            "          [" +
+            "            {" +
+            "              \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment.getType() + "\", " +
+            "              \"size\" : " + attachment.getSize() + "," +
+            "              \"name\" : \"\u062f\u064a\u0646\u0627\u0635\u0648\u0631.png\", " +
+            "              \"isInline\" : false" +
+            "            }," +
+            "            {" +
+            "              \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment2.getType() + "\", " +
+            "              \"size\" : " + attachment2.getSize() + "," +
+            "              \"name\" : \"\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c.png\", " +
+            "              \"isInline\" : false" +
+            "            }," +
+            "            {" +
+            "              \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment3.getType() + "\", " +
+            "              \"size\" : " + attachment3.getSize() + "," +
+            "              \"name\" : \"\u8fdb\u5316\u8fd8\u662f\u4e0d.png\"," +
+            "              \"isInline\" : false" +
+            "            }" +
+            "          ]" +
+            "        }" +
+            "      }" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         String createdPath = ARGUMENTS + ".created[\""+messageCreationId+"\"]";
         String firstAttachment = createdPath + ".attachments[0]";
@@ -2285,69 +2285,69 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
-                .bytes("attachment".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment);
 
         Attachment attachment2 = Attachment.builder()
-                .bytes("attachment2".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment2".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment2);
 
         Attachment attachment3 = Attachment.builder()
-                .bytes("attachment3".getBytes(Charsets.UTF_8))
-                .type("application/octet-stream")
-                .build();
+            .bytes("attachment3".getBytes(Charsets.UTF_8))
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment3);
 
         String messageCreationId = "creationId";
         String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\":" +
-                "      {" +
-                "        \"" + messageCreationId  + "\" : "+
-                "        {" +
-                "          \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "          \"to\": [{ \"name\": \"BOB\", \"email\": \"" + fromAddress + "\"}]," +
-                "          \"subject\": \"Message with three attachments with non ASCII name\"," +
-                "          \"textBody\": \"Test body\"," +
-                "          \"mailboxIds\": [\"" + outboxId + "\"], " +
-                "          \"attachments\":" +
-                "          [" +
-                "            {" +
-                "              \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment.getType() + "\", " +
-                "              \"size\" : " + attachment.getSize() + "," +
-                "              \"name\" : \"\u062f\u064a\u0646\u0627\u0635\u0648\u0631.png\", " +
-                "              \"isInline\" : false" +
-                "            }," +
-                "            {" +
-                "              \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment2.getType() + "\", " +
-                "              \"size\" : " + attachment2.getSize() + "," +
-                "              \"name\" : \"\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c.png\", " +
-                "              \"isInline\" : false" +
-                "            }," +
-                "            {" +
-                "              \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " +
-                "              \"type\" : \"" + attachment3.getType() + "\", " +
-                "              \"size\" : " + attachment3.getSize() + "," +
-                "              \"name\" : \"\u8fdb\u5316\u8fd8\u662f\u4e0d.png\"," +
-                "              \"isInline\" : false" +
-                "            }" +
-                "          ]" +
-                "        }" +
-                "      }" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\":" +
+            "      {" +
+            "        \"" + messageCreationId  + "\" : "+
+            "        {" +
+            "          \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "          \"to\": [{ \"name\": \"BOB\", \"email\": \"" + fromAddress + "\"}]," +
+            "          \"subject\": \"Message with three attachments with non ASCII name\"," +
+            "          \"textBody\": \"Test body\"," +
+            "          \"mailboxIds\": [\"" + outboxId + "\"], " +
+            "          \"attachments\":" +
+            "          [" +
+            "            {" +
+            "              \"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment.getType() + "\", " +
+            "              \"size\" : " + attachment.getSize() + "," +
+            "              \"name\" : \"\u062f\u064a\u0646\u0627\u0635\u0648\u0631.png\", " +
+            "              \"isInline\" : false" +
+            "            }," +
+            "            {" +
+            "              \"blobId\" : \"" + attachment2.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment2.getType() + "\", " +
+            "              \"size\" : " + attachment2.getSize() + "," +
+            "              \"name\" : \"\u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c.png\", " +
+            "              \"isInline\" : false" +
+            "            }," +
+            "            {" +
+            "              \"blobId\" : \"" + attachment3.getAttachmentId().getId() + "\", " +
+            "              \"type\" : \"" + attachment3.getType() + "\", " +
+            "              \"size\" : " + attachment3.getSize() + "," +
+            "              \"name\" : \"\u8fdb\u5316\u8fd8\u662f\u4e0d.png\"," +
+            "              \"isInline\" : false" +
+            "            }" +
+            "          ]" +
+            "        }" +
+            "      }" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -2367,7 +2367,7 @@ public abstract class SetMessagesMethodTest {
             with()
                 .header("Authorization", accessToken.serialize())
                 .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
-            .post("/jmap")
+                .post("/jmap")
             .then()
                 .extract()
                 .path(ARGUMENTS + ".messageIds[0]");
@@ -2393,7 +2393,7 @@ public abstract class SetMessagesMethodTest {
             .header("Authorization", accessToken.serialize())
             .contentType(attachment.getType())
             .content(attachment.getStream())
-        .post("/upload");
+            .post("/upload");
     }
 
     private void uploadTextAttachment(Attachment attachment) throws IOException {
@@ -2401,7 +2401,7 @@ public abstract class SetMessagesMethodTest {
             .header("Authorization", accessToken.serialize())
             .contentType(attachment.getType())
             .content(new String(IOUtils.toByteArray(attachment.getStream()), Charsets.UTF_8))
-        .post("/upload");
+            .post("/upload");
     }
 
     @Test
@@ -2409,16 +2409,16 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         byte[] rawBytes = new byte[]{-128,-127,-126,-125,-124,-123,-122,-121,-120,-119,-118,-117,-116,-115,-114,-113,-112,-111,-110,-109,-108,-107,-106,-105,-104,-103,-102,-101,-100,
-                -99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,
-                -50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,
-                0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
-                50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
-                100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127};
+            -99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,
+            -50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,
+            0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
+            50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
+            100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127};
         
         Attachment attachment = Attachment.builder()
-                .bytes(rawBytes)
-                .type("application/octet-stream")
-                .build();
+            .bytes(rawBytes)
+            .type("application/octet-stream")
+            .build();
         uploadAttachment(attachment);
         String expectedBlobId = attachment.getAttachmentId().getId();
 
@@ -2426,27 +2426,27 @@ public abstract class SetMessagesMethodTest {
         String fromAddress = USERNAME;
         String outboxId = getOutboxId(accessToken);
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"create\": { \"" + messageCreationId  + "\" : {" +
-                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
-                "        \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}]," +
-                "        \"subject\": \"Message with an attachment\"," +
-                "        \"textBody\": \"Test body\"," +
-                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
-                "        \"attachments\": [" +
-                "               {\"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
-                "               \"type\" : \"" + attachment.getType() + "\", " +
-                "               \"size\" : " + attachment.getSize() + ", " +
-                "               \"cid\" : \"123456789\", " +
-                "               \"isInline\" : true }" +
-                "           ]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+            "        \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}]," +
+            "        \"subject\": \"Message with an attachment\"," +
+            "        \"textBody\": \"Test body\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+            "        \"attachments\": [" +
+            "               {\"blobId\" : \"" + attachment.getAttachmentId().getId() + "\", " +
+            "               \"type\" : \"" + attachment.getType() + "\", " +
+            "               \"size\" : " + attachment.getSize() + ", " +
+            "               \"cid\" : \"123456789\", " +
+            "               \"isInline\" : true }" +
+            "           ]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         with()
             .header("Authorization", accessToken.serialize())
@@ -2489,9 +2489,9 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "sent");
 
         Attachment attachment = Attachment.builder()
-                .bytes(ByteStreams.toByteArray(new ZeroedInputStream(_1MB)))
-                .type("application/octet-stream")
-                .build();
+            .bytes(ByteStreams.toByteArray(new ZeroedInputStream(_1MB)))


<TRUNCATED>

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


[10/15] james-project git commit: JAMES-1785 Improve UpdateMessagePatchValidator

Posted by bt...@apache.org.
JAMES-1785 Improve UpdateMessagePatchValidator


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

Branch: refs/heads/master
Commit: d409d2b2c7285a0737a5c63e52f0c4da747ce1ed
Parents: 17a1cb8
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Thu Jan 19 10:42:29 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 .../james/jmap/methods/UpdateMessagePatchValidator.java       | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d409d2b2/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/UpdateMessagePatchValidator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/UpdateMessagePatchValidator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/UpdateMessagePatchValidator.java
index 963c074..fc77821 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/UpdateMessagePatchValidator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/UpdateMessagePatchValidator.java
@@ -50,20 +50,19 @@ public class UpdateMessagePatchValidator implements Validator<ObjectNode> {
 
     @Override
     public Set<ValidationResult> validate(ObjectNode json) {
-        ImmutableSet<ValidationResult> compilation = ImmutableSet.of();
         try {
             parser.readValue(json.toString(), UpdateMessagePatch.class);
         } catch (JsonMappingException e) {
-            compilation = ImmutableSet.of(ValidationResult.builder()
+            return ImmutableSet.of(ValidationResult.builder()
                     .property(firstFieldFrom(e.getPath()).orElse(ValidationResult.UNDEFINED_PROPERTY))
                     .message(e.getMessage())
                     .build());
         } catch (IOException e) {
-            compilation = ImmutableSet.of(ValidationResult.builder()
+            return ImmutableSet.of(ValidationResult.builder()
                     .message(e.getMessage())
                     .build());
         }
-        return compilation;
+        return ImmutableSet.of();
     }
 
     private Optional<String> firstFieldFrom(List<JsonMappingException.Reference> references) {


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


[06/15] james-project git commit: JAMES-1785 Copying a message to trash is allowed

Posted by bt...@apache.org.
JAMES-1785 Copying a message to trash is allowed


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

Branch: refs/heads/master
Commit: b0e8e3ed38e2069acecc6fdf81e10e21ea5f87fa
Parents: 52be7f0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Jan 17 15:09:33 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:46:06 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b0e8e3ed/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 3fb43cd..93b7a50 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -1718,6 +1718,50 @@ public abstract class SetMessagesMethodTest {
             .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties[0]", equalTo("inMailboxes"))
             .body(ARGUMENTS + ".updated", hasSize(0));
     }
+
+    @Test
+    public void copyToTrashShouldWork() throws Exception {
+        String newMailboxName = "heartFolder";
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        String trashId = jmapServer.serverProbe().getMailbox("#private", USERNAME, "trash").getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String mailboxId = message.getMailboxId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + trashId + "," + mailboxId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", contains(trashId, mailboxId));
+    }
     
     @Test
     public void setMessagesShouldReturnAttachmentsNotFoundWhenBlobIdDoesntExist() throws Exception {


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


[08/15] james-project git commit: JAMES-1785 Adding integration tests for inMailboxes

Posted by bt...@apache.org.
JAMES-1785 Adding integration tests for inMailboxes


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

Branch: refs/heads/master
Commit: 17a1cb861427138defa47d2078141e6b5cbabcb4
Parents: b0e8e3e
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Thu Jan 19 12:02:41 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:14 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 375 +++++++++++++++++--
 .../methods/SetMessagesUpdateProcessor.java     |   9 +-
 2 files changed, 350 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/17a1cb86/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 93b7a50..587dec3 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -24,7 +24,9 @@ import static com.jayway.restassured.RestAssured.with;
 import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.notIn;
 import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.equalTo;
@@ -1641,7 +1643,37 @@ public abstract class SetMessagesMethodTest {
     }
 
     @Test
-    public void movingShouldBeSupported() throws Exception {
+    public void mailboxIdsShouldReturnUpdatedWhenNoChange() throws Exception {
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String mailboxId = message.getMailboxId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + mailboxId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap")
+            .then()
+            .log().ifValidationFails()
+            .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId));
+    }
+
+    @Test
+    public void mailboxIdsShouldBeInDestinationWhenUsingForMove() throws Exception {
         String newMailboxName = "heartFolder";
         jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
         Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
@@ -1649,54 +1681,105 @@ public abstract class SetMessagesMethodTest {
 
         ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
-                new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
 
         String messageToMoveId = message.getMessageId().serialize();
         String requestBody = "[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"update\": { \"" + messageToMoveId + "\" : {" +
-                "        \"mailboxIds\": [\"" + heartFolderId + "\"]" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]";
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + heartFolderId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
 
         given()
-                .header("Authorization", this.accessToken.serialize())
-                .body(requestBody)
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+            .when()
+            .post("/jmap")
+            .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", contains(heartFolderId));
+    }
+
+    @Test
+    public void mailboxIdsShouldNotBeAnymoreInSourceWhenUsingForMove() throws Exception {
+        String newMailboxName = "heartFolder";
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
+        String heartFolderId = heartFolder.getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String inboxId = message.getMailboxId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + heartFolderId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
         .when()
-                .post("/jmap")
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
         .then()
-                .statusCode(200)
-                .body(NAME, equalTo("messagesSet"))
-                .body(NOT_UPDATED, hasKey(messageToMoveId))
-                .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].type", equalTo("invalidProperties"))
-                .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties[0]", equalTo("mailboxIds"))
-                .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].description", equalTo("mailboxIds: moving a message is not supported "
-                        + "(through reference chain: org.apache.james.jmap.model.Builder[\"mailboxIds\"])"))
-               .body(ARGUMENTS + ".updated", hasSize(0));
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", not(contains(inboxId)));
     }
 
     @Test
-    public void moveToTrashIsNotYetSupported() throws Exception {
+    public void mailboxIdsShouldBeInBothMailboxWhenUsingForCopy() throws Exception {
         String newMailboxName = "heartFolder";
         jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
-        String trashId = jmapServer.serverProbe().getMailbox("#private", USERNAME, "trash").getMailboxId().serialize();
+        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
+        String heartFolderId = heartFolder.getMailboxId().serialize();
 
         ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
         ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
             new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
 
         String messageToMoveId = message.getMessageId().serialize();
+        String inboxId = message.getMailboxId().serialize();
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+
             "    {" +
             "      \"update\": { \"" + messageToMoveId + "\" : {" +
-            "        \"mailboxIds\": [\"" + trashId + "\"]" +
+            "        \"mailboxIds\": [\"" + heartFolderId + "\",\"" + inboxId + "\"]" +
             "      }}" +
             "    }," +
             "    \"#0\"" +
@@ -1707,19 +1790,251 @@ public abstract class SetMessagesMethodTest {
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
         .when()
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+            .when()
             .post("/jmap")
-        .then()
+            .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", containsInAnyOrder(heartFolderId, inboxId));
+    }
+
+    @Test
+    public void mailboxIdsShouldBeInOriginalMailboxWhenNoChange() throws Exception {
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String mailboxId = message.getMailboxId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + mailboxId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+            .when()
+            .post("/jmap")
+            .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", contains(mailboxId));
+    }
+
+    @Test
+    public void mailboxIdsShouldReturnErrorWhenMovingToADeletedMailbox() throws Exception {
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "any");
+        String mailboxId = jmapServer.serverProbe().getMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "any")
+            .getMailboxId()
+            .serialize();
+        jmapServer.serverProbe().deleteMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "any");
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + mailboxId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap")
+            .then()
+            .log().ifValidationFails()
+            .statusCode(200)
+            .body(NAME, equalTo("messagesSet"))
+            .body(NOT_UPDATED, hasKey(messageToMoveId))
+            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].type", equalTo("anErrorOccurred"))
+            .body(ARGUMENTS + ".updated", hasSize(0));
+    }
+
+    @Test
+    public void mailboxIdsShouldReturnErrorWhenSetToEmpty() throws Exception {
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": []" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap")
+            .then()
             .log().ifValidationFails()
             .statusCode(200)
             .body(NAME, equalTo("messagesSet"))
             .body(NOT_UPDATED, hasKey(messageToMoveId))
             .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].type", equalTo("invalidProperties"))
             .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties", hasSize(1))
-            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties[0]", equalTo("inMailboxes"))
+            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties[0]", equalTo("mailboxIds"))
             .body(ARGUMENTS + ".updated", hasSize(0));
     }
 
     @Test
+    public void updateShouldNotReturnErrorWithFlagsAndMailboxUpdate() throws Exception {
+        String newMailboxName = "heartFolder";
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
+        String heartFolderId = heartFolder.getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + heartFolderId + "\"]," +
+            "        \"isUnread\": true" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap")
+            .then()
+            .log().ifValidationFails()
+            .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId));
+    }
+
+    @Test
+    public void updateShouldWorkWithFlagsAndMailboxUpdate() throws Exception {
+        String newMailboxName = "heartFolder";
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", USERNAME, newMailboxName);
+        String heartFolderId = heartFolder.getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + heartFolderId + "\"]," +
+            "        \"isUnread\": true" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+            .when()
+            .post("/jmap");
+
+        String firstMessage = ARGUMENTS + ".list[0]";
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageToMoveId + "\"]}, \"#0\"]]")
+            .when()
+            .post("/jmap")
+            .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(firstMessage + ".mailboxIds", contains(heartFolderId))
+            .body(firstMessage + ".isUnread", equalTo(true));
+    }
+
+    @Test
+    public void moveToTrashIsNotYetSupported() throws Exception {
+        String trashId = jmapServer.serverProbe().getMailbox("#private", USERNAME, "trash").getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + trashId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .log().ifValidationFails()
+            .statusCode(200)
+            .body(NAME, equalTo("error"))
+            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+    }
+
+    @Test
     public void copyToTrashShouldWork() throws Exception {
         String newMailboxName = "heartFolder";
         jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
@@ -1736,7 +2051,7 @@ public abstract class SetMessagesMethodTest {
             "    \"setMessages\","+
             "    {" +
             "      \"update\": { \"" + messageToMoveId + "\" : {" +
-            "        \"mailboxIds\": [\"" + trashId + "," + mailboxId + "\"]" +
+            "        \"mailboxIds\": [\"" + trashId + "\",\"" + mailboxId + "\"]" +
             "      }}" +
             "    }," +
             "    \"#0\"" +
@@ -1760,7 +2075,7 @@ public abstract class SetMessagesMethodTest {
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
             .body(ARGUMENTS + ".list", hasSize(1))
-            .body(firstMessage + ".mailboxIds", contains(trashId, mailboxId));
+            .body(firstMessage + ".mailboxIds", containsInAnyOrder(trashId, mailboxId));
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/17a1cb86/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index f04e180..5ceaba0 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -67,10 +67,11 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
 
     @Inject
     @VisibleForTesting SetMessagesUpdateProcessor(
-        UpdateMessagePatchConverter updatePatchConverter,
-        MessageIdManager messageIdManager,
-        Factory mailboxIdFactory,
-        MailboxManager mailboxManager, SystemMailboxesProvider systemMailboxesProvider) {
+            UpdateMessagePatchConverter updatePatchConverter,
+            MessageIdManager messageIdManager,
+            Factory mailboxIdFactory,
+            MailboxManager mailboxManager,
+            SystemMailboxesProvider systemMailboxesProvider) {
         this.updatePatchConverter = updatePatchConverter;
         this.messageIdManager = messageIdManager;
         this.mailboxIdFactory = mailboxIdFactory;


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


[11/15] james-project git commit: JAMES-1785 Update message documentation

Posted by bt...@apache.org.
JAMES-1785 Update message documentation


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

Branch: refs/heads/master
Commit: 3398801964cebc727eac423b5ed64df6f73a0951
Parents: 91e352e
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Thu Jan 19 12:56:11 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 server/protocols/jmap/doc/specs/spec/message.mdwn | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/33988019/server/protocols/jmap/doc/specs/spec/message.mdwn
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/doc/specs/spec/message.mdwn b/server/protocols/jmap/doc/specs/spec/message.mdwn
index ab144cb..debcd8a 100644
--- a/server/protocols/jmap/doc/specs/spec/message.mdwn
+++ b/server/protocols/jmap/doc/specs/spec/message.mdwn
@@ -247,7 +247,6 @@ The *setMessages* method encompasses:
 - Changing the flags of a message (unread/flagged status)
 
 - Adding/removing a message to/from mailboxes (moving a message)
-<aside class="warning">Not implemented</aside>
 - Deleting messages
 
 It takes the following arguments:
@@ -328,6 +327,7 @@ If any of the properties in the update are invalid (immutable and different to t
 If the *id* given does not correspond to a Message in the given account, reject the update with a `notFound` error.
 
 To **delete a message** to trash, simply change the `mailboxIds` property so it is now in the mailbox with `role == "trash"`. If the mailbox has the property `mustBeOnlyMailbox == true`, it must be removed from all other mailboxes. Otherwise, leave it in those mailboxes so that it will be restored to its previous state if undeleted.
+<aside class="warning">Not implemented</aside>
 
 #### Sending messages
 


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


[04/15] james-project git commit: JAMES-1785 Testing for SystemMailboxesProviderImpl

Posted by bt...@apache.org.
JAMES-1785 Testing for SystemMailboxesProviderImpl


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

Branch: refs/heads/master
Commit: 54fe9a4bd00b69cc048d554464ee987f3c302343
Parents: 1acd459
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Wed Jan 18 16:29:53 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:46:01 2017 +0700

----------------------------------------------------------------------
 .../utils/SystemMailboxesProviderImplTest.java  | 137 ++++++++++++++++++-
 1 file changed, 132 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/54fe9a4b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
index 3ee868d..1d40c41 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
@@ -19,15 +19,142 @@
 
 package org.apache.james.jmap.utils;
 
-import org.junit.Ignore;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.stream.Stream;
+
+import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
+import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.manager.MailboxManagerFixture;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxQuery;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.store.SimpleMailboxMetaData;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.ImmutableList;
 
 public class SystemMailboxesProviderImplTest {
 
-    @Ignore("1716 this class needs a test suite")
+    private static final MailboxPath INBOX = MailboxManagerFixture.MAILBOX_PATH1;
+    private static final MailboxPath OUTBOX = MailboxManagerFixture.MAILBOX_PATH2;
+    private static final char DELIMITER = '.';
+
+    private static final MailboxId inboxId = TestId.of(1);
+    private static final MailboxId outboxId = TestId.of(2);
+
+    private static final MailboxMetaData inboxMetadata = new SimpleMailboxMetaData(INBOX, inboxId, DELIMITER);
+    private static final MailboxMetaData outboxMetadata = new SimpleMailboxMetaData(OUTBOX, outboxId, DELIMITER);
+
+    private MailboxSession mailboxSession = new MockMailboxSession("user");
+    private SystemMailboxesProviderImpl systemMailboxProvider;
+
+    private MailboxManager mailboxManager;
+
+    private MessageManager inboxMessageManager;
+    private MessageManager outboxMessageManager;
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Before
+    public void setUp() throws Exception {
+        mailboxManager = mock(MailboxManager.class);
+        inboxMessageManager = mock(MessageManager.class);
+        outboxMessageManager = mock(MessageManager.class);
+
+        systemMailboxProvider = new SystemMailboxesProviderImpl(mailboxManager);
+    }
+
+    @Test
+    public void findMailboxesShouldReturnEmptyWhenEmptySearchResult() throws Exception {
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of());
+
+        assertThat(systemMailboxProvider.listMailboxes(Role.INBOX, mailboxSession)).isEmpty();
+    }
+
+    @Test
+    public void findMailboxesShouldFilterTheMailboxByItsRole() throws Exception {
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of(inboxMetadata, outboxMetadata));
+        when(mailboxManager.getMailbox(eq(INBOX), eq(mailboxSession))).thenReturn(inboxMessageManager);
+
+        Stream<MessageManager> result = systemMailboxProvider.listMailboxes(Role.INBOX, mailboxSession);
+
+        assertThat(result).hasSize(1).containsOnly(inboxMessageManager);
+    }
+
+    @Test
+    public void findMailboxesShouldThrowWhenMailboxManagerHasErrorWhenSearching() throws Exception {
+        expectedException.expect(MailboxException.class);
+
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenThrow(MailboxException.class);
+
+        systemMailboxProvider.listMailboxes(Role.INBOX, mailboxSession);
+    }
+
+    @Test
+    public void findMailboxesShouldBeEmptyWhenMailboxManagerCanNotGetMailbox() throws Exception {
+        expectedException.expect(MailboxException.class);
+
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of(inboxMetadata, outboxMetadata));
+        when(mailboxManager.getMailbox(eq(INBOX), eq(mailboxSession))).thenThrow(MailboxException.class);
+
+        assertThat(systemMailboxProvider.listMailboxes(Role.INBOX, mailboxSession)).isEmpty();
+    }
+
+    @Test
+    public void findMailboxesShouldReturnWhenMailboxManagerCanNotGetMailboxOfNonFilterMailbox() throws Exception {
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of(inboxMetadata, outboxMetadata));
+
+        when(mailboxManager.getMailbox(eq(INBOX), eq(mailboxSession))).thenReturn(inboxMessageManager);
+        when(mailboxManager.getMailbox(eq(OUTBOX), eq(mailboxSession))).thenThrow(MailboxException.class);
+
+        Stream<MessageManager> result = systemMailboxProvider.listMailboxes(Role.INBOX, mailboxSession);
+
+        assertThat(result).hasSize(1).containsOnly(inboxMessageManager);
+
+    }
+
     @Test
-    public void missingTestSuite() {
-        //TODO this class needs a test suite
+    public void findMailboxShouldThrowWhenEmptySearchResult() throws Exception {
+        expectedException.expect(MailboxRoleNotFoundException.class);
+
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of());
+
+        systemMailboxProvider.findMailbox(Role.INBOX, mailboxSession);
+    }
+
+    @Test
+    public void findMailboxShouldThrowWhenCanNotFindAny() throws Exception {
+        expectedException.expect(MailboxRoleNotFoundException.class);
+
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of(outboxMetadata));
+
+        systemMailboxProvider.findMailbox(Role.INBOX, mailboxSession);
     }
-    
+
+    @Test
+    public void findMailboxShouldReturnMailboxByRole() throws Exception {
+        when(mailboxManager.search(any(MailboxQuery.class), eq(mailboxSession))).thenReturn(ImmutableList.of(inboxMetadata, outboxMetadata));
+        when(mailboxManager.getMailbox(eq(INBOX), eq(mailboxSession))).thenReturn(inboxMessageManager);
+
+        MessageManager result = systemMailboxProvider.findMailbox(Role.INBOX, mailboxSession);
+
+        assertThat(result).isEqualTo(inboxMessageManager);
+    }
+
 }


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


[09/15] james-project git commit: JAMES-1785 Improve MailboxNotFoundException with an error message

Posted by bt...@apache.org.
JAMES-1785 Improve MailboxNotFoundException with an error message


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

Branch: refs/heads/master
Commit: d30b24e42cd902688fc4be4a6c9d623626e63f94
Parents: 9875a46
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 18 10:26:02 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/exception/MailboxNotFoundException.java    | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d30b24e4/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNotFoundException.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNotFoundException.java b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNotFoundException.java
index 8301d76..2e538cb 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNotFoundException.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxNotFoundException.java
@@ -44,6 +44,7 @@ public class MailboxNotFoundException extends MailboxException {
      *            name of the mailbox, not null
      */
     public MailboxNotFoundException(MailboxPath mailboxPath) {
+        super(mailboxPath + " can not be found");
         this.mailboxName = mailboxPath.toString();
     }
 


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


[15/15] james-project git commit: JAMES-1785 GetMessages with multiple mailboxes integration tests

Posted by bt...@apache.org.
JAMES-1785 GetMessages with multiple mailboxes integration tests

Also includes builder enhancements


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

Branch: refs/heads/master
Commit: 9875a46b7920371a9103eeb60306f3d54563d154
Parents: bd6bd22
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 18 10:25:04 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/utils/JmapGuiceProbe.java  | 23 ++++++++++++++-
 .../cucumber/GetMessagesMethodStepdefs.java     | 31 ++++++++++++++++++++
 .../test/resources/cucumber/GetMessages.feature |  9 ++++++
 .../james/jmap/methods/GetMessagesMethod.java   |  1 +
 .../org/apache/james/jmap/model/Message.java    |  8 +++--
 .../apache/james/jmap/model/MessageFactory.java | 11 +++----
 .../james/jmap/model/MessageFactoryTest.java    |  2 +-
 .../apache/james/jmap/model/MessageTest.java    | 24 +++++++--------
 .../jmap/model/SetMessagesResponseTest.java     |  4 +--
 9 files changed, 89 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
index cfbbbb6..05e1646 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.utils;
 
+import java.util.Arrays;
+
 import javax.inject.Inject;
 
 import org.apache.james.jmap.JMAPServer;
@@ -26,16 +28,30 @@ import org.apache.james.jmap.api.vacation.AccountId;
 import org.apache.james.jmap.api.vacation.Vacation;
 import org.apache.james.jmap.api.vacation.VacationPatch;
 import org.apache.james.jmap.api.vacation.VacationRepository;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageIdManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class JmapGuiceProbe implements GuiceProbe {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(JmapGuiceProbe.class);
+
     private final VacationRepository vacationRepository;
     private final JMAPServer jmapServer;
+    private final MessageIdManager messageIdManager;
+    private final MailboxManager mailboxManager;
 
     @Inject
-    private JmapGuiceProbe(VacationRepository vacationRepository, JMAPServer jmapServer) {
+    private JmapGuiceProbe(VacationRepository vacationRepository, JMAPServer jmapServer, MessageIdManager messageIdManager, MailboxManager mailboxManager) {
         this.vacationRepository = vacationRepository;
         this.jmapServer = jmapServer;
+        this.messageIdManager = messageIdManager;
+        this.mailboxManager = mailboxManager;
     }
 
     public int getJmapPort() {
@@ -49,4 +65,9 @@ public class JmapGuiceProbe implements GuiceProbe {
     public Vacation retrieveVacation(AccountId accountId) {
         return vacationRepository.retrieveVacation(accountId).join();
     }
+
+    public void setInMailboxes(MessageId messageId, String username, MailboxId... mailboxIds) throws MailboxException {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username, LOGGER);
+        messageIdManager.setInMailboxes(messageId, Arrays.asList(mailboxIds), mailboxSession);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 26b1e29..85c38d8 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -41,13 +41,16 @@ import org.apache.http.HttpResponse;
 import org.apache.http.client.fluent.Request;
 import org.apache.james.jmap.methods.integration.cucumber.util.TableRow;
 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.mailbox.model.MessageId;
 import org.javatuples.Pair;
 
+import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Charsets;
 import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
 import com.jayway.jsonpath.Configuration;
 import com.jayway.jsonpath.DocumentContext;
@@ -59,6 +62,7 @@ import cucumber.api.java.en.Given;
 import cucumber.api.java.en.Then;
 import cucumber.api.java.en.When;
 import cucumber.runtime.java.guice.ScenarioScoped;
+import net.minidev.json.JSONArray;
 
 @ScenarioScoped
 public class GetMessagesMethodStepdefs {
@@ -87,6 +91,16 @@ public class GetMessagesMethodStepdefs {
         this.messageIdsByName = new HashMap<>();
     }
 
+    @Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" and \"([^\"]*)\" mailboxes with subject \"([^\"]*)\", content \"([^\"]*)\"$")
+    public void appendMessageInTwoMailboxes(String messageName, String mailbox1, String mailbox2, String subject, String content) throws Throwable {
+        MessageId id = appendMessage(mailbox1, ContentType.noContentType(), subject, content, NO_HEADERS);
+        MailboxId mailboxId1 = mainStepdefs.jmapServer.serverProbe().getMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, mailbox1).getMailboxId();
+        MailboxId mailboxId2 = mainStepdefs.jmapServer.serverProbe().getMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, mailbox2).getMailboxId();
+
+        mainStepdefs.jmapServer.getJmapProbe().setInMailboxes(id, userStepdefs.lastConnectedUser, mailboxId1, mailboxId2);
+        messageIdsByName.put(messageName, id);
+    }
+
     @Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox with subject \"([^\"]*)\", content \"([^\"]*)\"$")
     public void appendMessage(String messageName, String mailbox, String subject, String content) throws Throwable {
         MessageId id = appendMessage(mailbox, ContentType.noContentType(), subject, content, NO_HEADERS);
@@ -315,6 +329,23 @@ public class GetMessagesMethodStepdefs {
         assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".id")).isEqualTo(id.serialize());
     }
 
+    @Then("^the message is in \"([^\"]*)\" mailboxes")
+    public void assertMailboxIdsOfTheFirstMessage(String mailboxIds) throws Throwable {
+        List<String> values = Splitter.on(",")
+            .splitToList(mailboxIds).stream()
+            .map(Throwing.function(name -> mainStepdefs.jmapServer
+                .serverProbe()
+                .getMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, name)
+                .getMailboxId()
+                .serialize()))
+            .distinct()
+            .collect(Guavate.toImmutableList());
+
+        assertThat(jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
+            .hasSize(2)
+            .containsOnlyElementsOf(values);
+    }
+
     @Then("^the threadId of the message is \"([^\"]*)\"$")
     public void assertThreadIdOfTheFirstMessage(String threadId) throws Throwable {
         MessageId id = messageIdsByName.get(threadId);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index a559e08..d06a81a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -7,6 +7,15 @@ Feature: GetMessages method
     And a connected user "username@domain.tld"
     And "username@domain.tld" has a mailbox "inbox"
 
+  Scenario: Retrieving a message in several mailboxes should return a single message in these mailboxes
+    Given "username@domain.tld" has a mailbox "custom"
+    And the user has a message "m1" in "inbox" and "custom" mailboxes with subject "my test subject", content "testmail"
+    When the user ask for messages "m1"
+    Then no error is returned
+    And the list should contain 1 message
+    And the id of the message is "m1"
+    And the message is in "custom,inbox" mailboxes
+
   Scenario: Retrieving messages with a non null accountId should return a NotSupported error
     When the user ask for messages using its accountId
     Then an error "Not yet implemented" is returned

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 41f68ae..404e404 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -131,6 +131,7 @@ public class GetMessagesMethod implements Method {
                     .collect(Guavate.toImmutableList());
                 List<MailboxId> mailboxIds = messageResults.stream()
                     .map(MessageResult::getMailboxId)
+                    .distinct()
                     .collect(Guavate.toImmutableList());
                 return messageResults.stream()
                     .findFirst()

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
index f504871..5937560 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.model;
 
 import java.time.ZonedDateTime;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -99,16 +100,17 @@ public class Message {
             return this;
         }
 
+        @JsonIgnore
         public Builder mailboxId(MailboxId mailboxId) {
-            return this.mailboxIds(ImmutableList.of(mailboxId));
+            return this.fluentMailboxIds(mailboxId);
         }
 
         @JsonIgnore
-        public Builder mailboxIds(MailboxId... mailboxIds) {
+        public Builder fluentMailboxIds(MailboxId... mailboxIds) {
             return this.mailboxIds(Arrays.asList((mailboxIds)));
         }
 
-        public Builder mailboxIds(List<MailboxId> mailboxIds) {
+        public Builder mailboxIds(Collection<MailboxId> mailboxIds) {
             this.mailboxIds = ImmutableList.copyOf(mailboxIds);
             return this;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index bc92fc5..9dc1acf 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -27,6 +27,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.TimeZone;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -55,8 +56,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Multimaps;
+import com.google.common.collect.Sets;
 
 public class MessageFactory {
 
@@ -235,7 +236,7 @@ public class MessageFactory {
             private InputStream content;
             private SharedInputStream sharedContent;
             private List<MessageAttachment> attachments;
-            private List<MailboxId> mailboxIds = Lists.newArrayList();
+            private Set<MailboxId> mailboxIds = Sets.newHashSet();
             private MessageId messageId;
 
             public Builder uid(MessageUid uid) {
@@ -317,10 +318,10 @@ public class MessageFactory {
         private final InputStream content;
         private final SharedInputStream sharedContent;
         private final List<MessageAttachment> attachments;
-        private final List<MailboxId> mailboxIds;
+        private final Set<MailboxId> mailboxIds;
         private final MessageId messageId;
 
-        private MetaDataWithContent(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, SharedInputStream sharedContent, List<MessageAttachment> attachments, List<MailboxId> mailboxIds, MessageId messageId) {
+        private MetaDataWithContent(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, SharedInputStream sharedContent, List<MessageAttachment> attachments, Set<MailboxId> mailboxIds, MessageId messageId) {
             this.uid = uid;
             this.modSeq = modSeq;
             this.flags = flags;
@@ -370,7 +371,7 @@ public class MessageFactory {
             return attachments;
         }
 
-        public List<MailboxId> getMailboxIds() {
+        public Set<MailboxId> getMailboxIds() {
             return mailboxIds;
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
index 9381043..c0bd1f3 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
@@ -148,7 +148,7 @@ public class MessageFactoryTest {
                 .id(TestMessageId.of(2))
                 .blobId(BlobId.of("2"))
                 .threadId("2")
-                .mailboxIds(ImmutableList.of(MAILBOX_ID))
+                .mailboxId(MAILBOX_ID)
                 .inReplyToMessageId("<SN...@phx.gbl>")
                 .headers(headersMap)
                 .from(user)

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
index 7cb3db2..0407c36 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
@@ -60,41 +60,41 @@ public class MessageTest {
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenHeadersIsNull() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).build();
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenSubjectIsNull() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build();
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of()).build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenSubjectIsEmpty() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of())
             .subject("").build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenSizeIsNull() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of())
             .subject("subject").build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenDateIsNull() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of())
             .subject("subject").size(123).build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenPreviewIsNull() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of())
             .subject("subject").size(123).date(ZonedDateTime.now()).build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void buildShouldThrowWhenPreviewIsEmpty() {
-        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+        Message.builder().id(TestMessageId.of(1)).blobId(BlobId.of("blobId")).threadId("threadId").fluentMailboxIds().headers(ImmutableMap.of())
             .subject("subject").size(123).date(ZonedDateTime.now()).preview("").build();
     }
 
@@ -107,7 +107,7 @@ public class MessageTest {
                 .id(TestMessageId.of(1))
                 .blobId(BlobId.of("blobId"))
                 .threadId("threadId")
-                .mailboxIds(ImmutableList.of(InMemoryId.of(456)))
+                .mailboxId(InMemoryId.of(456))
                 .headers(ImmutableMap.of("key", "value"))
                 .subject("subject")
                 .size(123)
@@ -131,7 +131,7 @@ public class MessageTest {
             .id(TestMessageId.of(1))
             .blobId(BlobId.of("blobId"))
             .threadId("threadId")
-            .mailboxIds(ImmutableList.of(InMemoryId.of(456)))
+            .mailboxId(InMemoryId.of(456))
             .headers(ImmutableMap.of("key", "value"))
             .subject("subject")
             .size(123)
@@ -187,7 +187,7 @@ public class MessageTest {
             .id(TestMessageId.of(1))
             .blobId(BlobId.of("blobId"))
             .threadId("threadId")
-            .mailboxIds(ImmutableList.of(InMemoryId.of(456)))
+            .mailboxId(InMemoryId.of(456))
             .inReplyToMessageId("inReplyToMessageId")
             .isUnread(true)
             .isFlagged(true)
@@ -217,7 +217,7 @@ public class MessageTest {
             .id(TestMessageId.of(1))
             .blobId(BlobId.of("blobId"))
             .threadId("threadId")
-            .mailboxIds(ImmutableList.of(InMemoryId.of(456)))
+            .mailboxId(InMemoryId.of(456))
             .headers(ImmutableMap.of("key", "value"))
             .subject("subject")
             .size(1)
@@ -237,7 +237,7 @@ public class MessageTest {
             .id(TestMessageId.of(1))
             .blobId(BlobId.of("blobId"))
             .threadId("threadId")
-            .mailboxIds(ImmutableList.of(InMemoryId.of(456)))
+            .mailboxId(InMemoryId.of(456))
             .headers(ImmutableMap.of("key", "value"))
             .subject("subject")
             .size(1)

http://git-wip-us.apache.org/repos/asf/james-project/blob/9875a46b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
index 9340c7a..b75b47c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
@@ -61,7 +61,7 @@ public class SetMessagesResponseTest {
                 .id(TestMessageId.of(1))
                 .blobId(BlobId.of("blobId"))
                 .threadId("threadId")
-                .mailboxIds(ImmutableList.of(InMemoryId.of(123)))
+                .mailboxId(InMemoryId.of(123))
                 .headers(ImmutableMap.of("key", "value"))
                 .subject("subject")
                 .size(123)
@@ -111,7 +111,7 @@ public class SetMessagesResponseTest {
                 .id(messageId)
                 .blobId(BlobId.of("blobId"))
                 .threadId("threadId")
-                .mailboxIds(ImmutableList.of())
+                .fluentMailboxIds()
                 .headers(ImmutableMap.of())
                 .subject("subject")
                 .size(0)


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


[07/15] james-project git commit: JAMES-1785 Moving to trash is not yet supported

Posted by bt...@apache.org.
JAMES-1785 Moving to trash is not yet supported


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

Branch: refs/heads/master
Commit: 52be7f0373ad321574b08985d5b91bafa43e148d
Parents: 89994c3
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Jan 17 14:41:16 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:46:06 2017 +0700

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/52be7f03/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 4eec224..3fb43cd 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -123,6 +123,8 @@ public abstract class SetMessagesMethodTest {
         accessToken = JmapAuthentication.authenticateJamesUser(USERNAME, password);
 
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "outbox");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "trash");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "draft");
         await();
 
         Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
@@ -1677,6 +1679,45 @@ public abstract class SetMessagesMethodTest {
                         + "(through reference chain: org.apache.james.jmap.model.Builder[\"mailboxIds\"])"))
                .body(ARGUMENTS + ".updated", hasSize(0));
     }
+
+    @Test
+    public void moveToTrashIsNotYetSupported() throws Exception {
+        String newMailboxName = "heartFolder";
+        jmapServer.serverProbe().createMailbox("#private", USERNAME, newMailboxName);
+        String trashId = jmapServer.serverProbe().getMailbox("#private", USERNAME, "trash").getMailboxId().serialize();
+
+        ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(USERNAME, new MailboxPath("#private", USERNAME, "inbox"),
+            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
+
+        String messageToMoveId = message.getMessageId().serialize();
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageToMoveId + "\" : {" +
+            "        \"mailboxIds\": [\"" + trashId + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .log().ifValidationFails()
+            .statusCode(200)
+            .body(NAME, equalTo("messagesSet"))
+            .body(NOT_UPDATED, hasKey(messageToMoveId))
+            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].type", equalTo("invalidProperties"))
+            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties", hasSize(1))
+            .body(NOT_UPDATED + "[\""+messageToMoveId+"\"].properties[0]", equalTo("inMailboxes"))
+            .body(ARGUMENTS + ".updated", hasSize(0));
+    }
     
     @Test
     public void setMessagesShouldReturnAttachmentsNotFoundWhenBlobIdDoesntExist() throws Exception {


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


[14/15] james-project git commit: JAMES-1785 Adding tests for GetMessages on message in multiple mailboxes

Posted by bt...@apache.org.
JAMES-1785 Adding tests for GetMessages on message in multiple mailboxes


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

Branch: refs/heads/master
Commit: bd6bd22379434ca494ea774fad9b70f68d607c37
Parents: d409d2b
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 18 09:40:07 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:58:20 2017 +0700

----------------------------------------------------------------------
 .../james/jmap/methods/GetMessagesMethod.java   | 22 +++++++---
 .../apache/james/jmap/methods/JmapResponse.java |  2 +-
 .../james/jmap/model/GetMessagesResponse.java   |  7 ++++
 .../org/apache/james/jmap/model/Message.java    |  7 ++++
 .../apache/james/jmap/model/MessageFactory.java | 26 +++++++-----
 .../jmap/methods/GetMessagesMethodTest.java     | 42 ++++++++++++++++++++
 6 files changed, 90 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 15fbceb..41f68ae 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -39,7 +39,9 @@ import org.apache.james.jmap.model.MessageProperties.HeaderProperty;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageResult;
 
 import com.fasterxml.jackson.databind.ser.PropertyFilter;
 import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
@@ -104,7 +106,7 @@ public class GetMessagesMethod implements Method {
     }
 
     private GetMessagesResponse getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
-        getMessagesRequest.getAccountId().ifPresent(GetMessagesMethod::notImplemented);
+        getMessagesRequest.getAccountId().ifPresent((input) -> notImplemented());
         
         Function<MessageId, Stream<MetaDataWithContent>> loadMessages = loadMessage(mailboxSession);
         Function<MetaDataWithContent, Message> convertToJmapMessage = Throwing.function(messageFactory::fromMetaDataWithContent).sneakyThrow();
@@ -117,18 +119,28 @@ public class GetMessagesMethod implements Method {
         return GetMessagesResponse.builder().messages(result).expectedMessageIds(getMessagesRequest.getIds()).build();
     }
 
-    private static void notImplemented(String input) {
+    private static void notImplemented() {
         throw new NotImplementedException();
     }
 
     private Function<MessageId, Stream<MetaDataWithContent>> loadMessage(MailboxSession mailboxSession) {
-        ThrowingFunction<MessageId, Stream<MetaDataWithContent>> toMetaDataWithContentStream = (MessageId messageId) -> {
-            return messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.FULL_CONTENT, mailboxSession)
+        ThrowingFunction<MessageId, Stream<MetaDataWithContent>> toMetaDataWithContentStream =
+            (MessageId messageId) -> {
+                ImmutableList<MessageResult> messageResults = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.FULL_CONTENT, mailboxSession)
                     .stream()
+                    .collect(Guavate.toImmutableList());
+                List<MailboxId> mailboxIds = messageResults.stream()
+                    .map(MessageResult::getMailboxId)
+                    .collect(Guavate.toImmutableList());
+                return messageResults.stream()
+                    .findFirst()
+                    .map(Stream::of)
+                    .orElse(Stream.of())
                     .map(Throwing.function(MetaDataWithContent::builderFromMessageResult).sneakyThrow())
                     .map(builder -> builder.messageId(messageId))
+                    .map(builder -> builder.mailboxIds(mailboxIds))
                     .map(MetaDataWithContent.Builder::build);
-        };
+            };
         return Throwing.function(toMetaDataWithContentStream).sneakyThrow();
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
index bab4dbc..6a80c43 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
@@ -118,7 +118,7 @@ public class JmapResponse {
         return method;
     }
     
-    public Object getResponse() {
+    public Method.Response getResponse() {
         return response;
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMessagesResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMessagesResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMessagesResponse.java
index e09335b..a561d29 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMessagesResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMessagesResponse.java
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
 import org.apache.james.jmap.methods.Method;
 import org.apache.james.mailbox.model.MessageId;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -47,6 +48,12 @@ public class GetMessagesResponse implements Method.Response {
             this.messages = ImmutableList.of();
         }
 
+        @JsonIgnore
+        public Builder message(Message message) {
+            this.messages = ImmutableList.of(message);
+            return this;
+        }
+
         public Builder messages(List<Message> messages) {
             this.messages = ImmutableList.copyOf(messages);
             return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
index 6b673bd..f504871 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.model;
 
 import java.time.ZonedDateTime;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -31,6 +32,7 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 
 import com.fasterxml.jackson.annotation.JsonFilter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
 import com.google.common.annotations.VisibleForTesting;
@@ -101,6 +103,11 @@ public class Message {
             return this.mailboxIds(ImmutableList.of(mailboxId));
         }
 
+        @JsonIgnore
+        public Builder mailboxIds(MailboxId... mailboxIds) {
+            return this.mailboxIds(Arrays.asList((mailboxIds)));
+        }
+
         public Builder mailboxIds(List<MailboxId> mailboxIds) {
             this.mailboxIds = ImmutableList.copyOf(mailboxIds);
             return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 1bb5942..bc92fc5 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -55,6 +55,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Multimaps;
 
 public class MessageFactory {
@@ -80,7 +81,7 @@ public class MessageFactory {
                 .id(message.getMessageId())
                 .blobId(BlobId.of(String.valueOf(message.getUid().asLong())))
                 .threadId(message.getMessageId().serialize())
-                .mailboxIds(ImmutableList.of(message.getMailboxId()))
+                .mailboxIds(message.getMailboxIds())
                 .inReplyToMessageId(getHeader(mimeMessage, "in-reply-to"))
                 .isUnread(! message.getFlags().contains(Flags.Flag.SEEN))
                 .isFlagged(message.getFlags().contains(Flags.Flag.FLAGGED))
@@ -234,7 +235,7 @@ public class MessageFactory {
             private InputStream content;
             private SharedInputStream sharedContent;
             private List<MessageAttachment> attachments;
-            private MailboxId mailboxId;
+            private List<MailboxId> mailboxIds = Lists.newArrayList();
             private MessageId messageId;
 
             public Builder uid(MessageUid uid) {
@@ -278,7 +279,12 @@ public class MessageFactory {
             }
             
             public Builder mailboxId(MailboxId mailboxId) {
-                this.mailboxId = mailboxId;
+                this.mailboxIds.add(mailboxId);
+                return this;
+            }
+
+            public Builder mailboxIds(List<MailboxId> mailboxIds) {
+                this.mailboxIds.addAll(mailboxIds);
                 return this;
             }
             
@@ -297,9 +303,9 @@ public class MessageFactory {
                 Preconditions.checkArgument(internalDate != null);
                 Preconditions.checkArgument(content != null ^ sharedContent != null);
                 Preconditions.checkArgument(attachments != null);
-                Preconditions.checkArgument(mailboxId != null);
+                Preconditions.checkArgument(mailboxIds != null);
                 Preconditions.checkArgument(messageId != null);
-                return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, sharedContent, attachments, mailboxId, messageId);
+                return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, sharedContent, attachments, mailboxIds, messageId);
             }
         }
 
@@ -311,10 +317,10 @@ public class MessageFactory {
         private final InputStream content;
         private final SharedInputStream sharedContent;
         private final List<MessageAttachment> attachments;
-        private final MailboxId mailboxId;
+        private final List<MailboxId> mailboxIds;
         private final MessageId messageId;
 
-        private MetaDataWithContent(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, SharedInputStream sharedContent, List<MessageAttachment> attachments, MailboxId mailboxId, MessageId messageId) {
+        private MetaDataWithContent(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, SharedInputStream sharedContent, List<MessageAttachment> attachments, List<MailboxId> mailboxIds, MessageId messageId) {
             this.uid = uid;
             this.modSeq = modSeq;
             this.flags = flags;
@@ -323,7 +329,7 @@ public class MessageFactory {
             this.content = content;
             this.sharedContent = sharedContent;
             this.attachments = attachments;
-            this.mailboxId = mailboxId;
+            this.mailboxIds = mailboxIds;
             this.messageId = messageId;
         }
 
@@ -364,8 +370,8 @@ public class MessageFactory {
             return attachments;
         }
 
-        public MailboxId getMailboxId() {
-            return mailboxId;
+        public List<MailboxId> getMailboxIds() {
+            return mailboxIds;
         }
 
         public MessageId getMessageId() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/bd6bd223/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
index 1147240..dbd34ec 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
+import java.time.ZonedDateTime;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
@@ -45,13 +46,21 @@ import org.apache.james.jmap.model.MessagePreviewGenerator;
 import org.apache.james.jmap.model.MessageProperties.MessageProperty;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryMessageIdManager;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.store.MessageResultImpl;
+import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.assertj.core.api.Condition;
 import org.assertj.core.data.MapEntry;
 import org.assertj.core.groups.Tuple;
@@ -105,6 +114,7 @@ public class GetMessagesMethodTest {
 
     private MailboxSession session;
     private MailboxPath inboxPath;
+    private MailboxPath customMailboxPath;
     private ClientId clientId;
 
     @Before
@@ -121,7 +131,9 @@ public class GetMessagesMethodTest {
 
         session = new MockMailboxSession(ROBERT.username);
         inboxPath = MailboxPath.inbox(session);
+        customMailboxPath = new MailboxPath(inboxPath, "custom");
         mailboxManager.createMailbox(inboxPath, session);
+        mailboxManager.createMailbox(customMailboxPath, session);
         testee = new GetMessagesMethod(messageFactory, inMemoryIntegrationResources.createMessageIdManager(mailboxManager));
     }
     
@@ -346,4 +358,34 @@ public class GetMessagesMethodTest {
         String response = objectMapper.writer().writeValueAsString(result.get(0));
         assertThat(JsonPath.parse(response).<Map<String, String>>read("$.response.list[0].headers")).containsOnly(MapEntry.entry("From", "user@domain.tld"), MapEntry.entry("HEADer2", "Header2Content"));
     }
+
+    @Test
+    public void processShouldReturnOneMessageWhenMessageInSeveralMailboxes() throws Exception {
+        MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
+        Date now = new Date();
+        ByteArrayInputStream message1Content = new ByteArrayInputStream(("From: user@domain.tld\r\n"
+            + "header1: Header1Content\r\n"
+            + "HEADer2: Header2Content\r\n"
+            + "Subject: message 1 subject\r\n\r\nmy message").getBytes(Charsets.UTF_8));
+        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false, null);
+        MessageIdManager messageIdManager = new InMemoryMessageIdManager(mailboxManager);
+        MailboxId customMailboxId = mailboxManager.getMailbox(customMailboxPath, session).getId();
+        messageIdManager.setInMailboxes(message1.getMessageId(),
+            ImmutableList.of(message1.getMailboxId(), customMailboxId),
+            session);
+
+        GetMessagesRequest request = GetMessagesRequest.builder()
+            .ids(ImmutableList.of(message1.getMessageId()))
+            .properties(ImmutableList.of("mailboxIds"))
+            .build();
+
+        List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
+
+        assertThat(result).hasSize(1);
+        Method.Response response = result.get(0).getResponse();
+        assertThat(response).isInstanceOf(GetMessagesResponse.class);
+        GetMessagesResponse getMessagesResponse = (GetMessagesResponse) response;
+        assertThat(getMessagesResponse.list()).hasSize(1);
+        assertThat(getMessagesResponse.list().get(0).getMailboxIds()).containsOnly(customMailboxId, message1.getMailboxId());
+    }
 }


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


[03/15] james-project git commit: JAMES-1785 Using SystemMailboxesProvider to look up role and remove the redundance code

Posted by bt...@apache.org.
JAMES-1785 Using SystemMailboxesProvider to look up role and remove the redundance code


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

Branch: refs/heads/master
Commit: 1acd459ab233aa41a40cfd2985c5753b516cb452
Parents: c996365
Author: Quynh Nguyen <qn...@linagora.com>
Authored: Thu Jan 19 17:46:58 2017 +0700
Committer: Quynh Nguyen <qn...@linagora.com>
Committed: Tue Jan 24 09:45:34 2017 +0700

----------------------------------------------------------------------
 .../james/jmap/send/PostDequeueDecorator.java   | 38 +++++++-------------
 .../jmap/send/PostDequeueDecoratorFactory.java  | 10 +++---
 .../jmap/utils/SystemMailboxesProvider.java     |  6 ++++
 .../jmap/utils/SystemMailboxesProviderImpl.java |  3 +-
 .../SetMessagesCreationProcessorTest.java       |  1 +
 .../jmap/send/PostDequeueDecoratorTest.java     |  3 +-
 6 files changed, 29 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
index 9179b7e..8a122db 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -24,15 +24,13 @@ import java.util.List;
 import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
+import org.apache.james.jmap.utils.SystemMailboxesProvider;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.mailbox.model.MessageResult;
@@ -51,15 +49,18 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
     private final MailboxManager mailboxManager;
     private final Factory messageIdFactory;
     private final MessageIdManager messageIdManager;
+    private final SystemMailboxesProvider systemMailboxesProvider;
 
     public PostDequeueDecorator(MailQueueItem mailQueueItem,
-            MailboxManager mailboxManager,
-            MessageId.Factory messageIdFactory,
-            MessageIdManager messageIdManager) {
+                                MailboxManager mailboxManager,
+                                Factory messageIdFactory,
+                                MessageIdManager messageIdManager,
+                                SystemMailboxesProvider systemMailboxesProvider) {
         super(mailQueueItem);
         this.mailboxManager = mailboxManager;
         this.messageIdFactory = messageIdFactory;
         this.messageIdManager = messageIdManager;
+        this.systemMailboxesProvider = systemMailboxesProvider;
     }
 
     @Override
@@ -95,7 +96,7 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
         try {
             messageIdFactory.fromString((String) messageId);
         } catch (Exception e) {
-            LOG.error("Invalid messageId: " + (String) messageId);
+            LOG.error("Invalid messageId: " + messageId);
             return false;
         }
         return true;
@@ -123,28 +124,13 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
     }
 
     private MailboxId getSentMailboxId(MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
-        return getMailboxIdForRole(Role.SENT, session);
+        return systemMailboxesProvider.findMailbox(Role.SENT, session)
+            .getId();
     }
     
     private MailboxId getOutboxMailboxId(MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
-        return getMailboxIdForRole(Role.OUTBOX, session);
+        return systemMailboxesProvider.findMailbox(Role.OUTBOX, session)
+            .getId();
     }
     
-    private MailboxId getMailboxIdForRole(Role role, MailboxSession session) throws MailboxRoleNotFoundException, MailboxException {
-        MailboxQuery allUserMailboxesQuery = MailboxQuery.builder(session)
-            .privateUserMailboxes()
-            .build();
-        return mailboxManager.search(allUserMailboxesQuery, session)
-                .stream()
-                .filter(meta -> hasRole(meta.getPath(), role))
-                .map(MailboxMetaData::getId)
-                .findFirst()
-                .orElseThrow(() -> new MailboxRoleNotFoundException(role));
-    }
-    
-    private boolean hasRole(MailboxPath mailBoxPath, Role role) {
-        return Role.from(mailBoxPath.getName())
-                .map(role::equals)
-                .orElse(false);
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
index a43de17..5114fe8 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
@@ -21,9 +21,9 @@ package org.apache.james.jmap.send;
 
 import javax.inject.Inject;
 
+import org.apache.james.jmap.utils.SystemMailboxesProvider;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MessageIdManager;
-import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.queue.api.MailQueue.MailQueueItem;
 import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
@@ -32,18 +32,20 @@ public class PostDequeueDecoratorFactory implements MailQueueItemDecoratorFactor
     private final MailboxManager mailboxManager;
     private final Factory messageIdFactory;
     private final MessageIdManager messageIdManager;
+    private final SystemMailboxesProvider systemMailboxesProvider;
 
     @Inject
-    public PostDequeueDecoratorFactory(MailboxManager mailboxManager, MessageId.Factory messageIdFactory,
-            MessageIdManager messageIdManager) {
+    public PostDequeueDecoratorFactory(MailboxManager mailboxManager, Factory messageIdFactory,
+            MessageIdManager messageIdManager, SystemMailboxesProvider systemMailboxesProvider) {
         this.mailboxManager = mailboxManager;
         this.messageIdFactory = messageIdFactory;
         this.messageIdManager = messageIdManager;
+        this.systemMailboxesProvider = systemMailboxesProvider;
     }
 
     @Override
     public MailQueueItemDecorator decorate(MailQueueItem mailQueueItem) {
-        return new PostDequeueDecorator(mailQueueItem, mailboxManager, messageIdFactory, messageIdManager);
+        return new PostDequeueDecorator(mailQueueItem, mailboxManager, messageIdFactory, messageIdManager, systemMailboxesProvider);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
index e3d605d..bc01d52 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.utils;
 
 import java.util.stream.Stream;
 
+import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -28,4 +29,9 @@ import org.apache.james.mailbox.exception.MailboxException;
 
 public interface SystemMailboxesProvider {
     Stream<MessageManager> listMailboxes(Role aRole, MailboxSession session) throws MailboxException;
+
+    default MessageManager findMailbox(Role role, MailboxSession session) throws MailboxException {
+        return listMailboxes(role, session).findAny()
+            .orElseThrow(() -> new MailboxRoleNotFoundException(role));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
index c5d36fe..181fafd 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
@@ -41,7 +41,8 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
     private final MailboxManager mailboxManager;
 
     @Inject
-    @VisibleForTesting SystemMailboxesProviderImpl(MailboxManager mailboxManager) {
+    @VisibleForTesting
+    public SystemMailboxesProviderImpl(MailboxManager mailboxManager) {
         this.mailboxManager = mailboxManager;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index 10ba230..b5605bc 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -36,6 +36,7 @@ import java.util.stream.Stream;
 import javax.mail.Flags;
 
 import org.apache.james.jmap.exceptions.AttachmentsNotFoundException;
+import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
 import org.apache.james.jmap.methods.ValueWithId.CreationMessageEntry;
 import org.apache.james.jmap.model.Attachment;
 import org.apache.james.jmap.model.BlobId;

http://git-wip-us.apache.org/repos/asf/james-project/blob/1acd459a/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 477e371..3c6fd2e 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
@@ -31,6 +31,7 @@ import javax.mail.Flags;
 
 import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
 import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
+import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -76,7 +77,7 @@ public class PostDequeueDecoratorTest {
         mail = FakeMail.defaultFakeMail();
         when(mockedMailQueueItem.getMail()).thenReturn(mail);
         testee = new PostDequeueDecorator(mockedMailQueueItem, mailboxManager, new InMemoryMessageId.Factory(), 
-                inMemoryIntegrationResources.createMessageIdManager(mailboxManager));
+                inMemoryIntegrationResources.createMessageIdManager(mailboxManager), new SystemMailboxesProviderImpl(mailboxManager));
     }
     
     @Test


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