james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [06/10] james-project git commit: JAMES-1818 Use more MailboxId instead of String when possible
Date Mon, 05 Sep 2016 12:44:02 GMT
JAMES-1818 Use more MailboxId instead of String when possible


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

Branch: refs/heads/master
Commit: 8ec9ab9360470d4cdf7a6ca74937332e9c6af227
Parents: 460b650
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Tue Aug 30 12:13:47 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Mon Sep 5 14:42:00 2016 +0200

----------------------------------------------------------------------
 .../integration/GetMailboxesMethodTest.java     | 18 ++++++-
 .../integration/SetMailboxesMethodTest.java     | 28 +++++++---
 .../MailboxParentNotFoundException.java         | 14 +++--
 .../james/jmap/methods/GetMailboxesMethod.java  |  3 +-
 .../jmap/methods/GetMessageListMethod.java      |  2 +-
 .../methods/SetMailboxesCreationProcessor.java  | 39 ++++++++++----
 .../SetMailboxesDestructionProcessor.java       | 25 ++++-----
 .../methods/SetMailboxesUpdateProcessor.java    | 17 +++---
 .../james/jmap/model/GetMailboxesRequest.java   | 11 ++--
 .../org/apache/james/jmap/model/Message.java    | 13 ++---
 .../apache/james/jmap/model/MessageFactory.java |  2 +-
 .../james/jmap/model/SetMailboxesRequest.java   | 21 ++++----
 .../james/jmap/model/SetMailboxesResponse.java  | 45 ++++++++--------
 .../james/jmap/model/mailbox/Mailbox.java       | 21 ++++----
 .../model/mailbox/MailboxCreateRequest.java     | 11 ++--
 .../model/mailbox/MailboxUpdateRequest.java     | 11 ++--
 .../apache/james/jmap/utils/MailboxUtils.java   | 19 ++++---
 .../james/jmap/json/ParsingWritingObjects.java  |  4 +-
 .../jmap/json/ParsingWritingObjectsTest.java    | 16 ++++--
 .../jmap/methods/GetMailboxesMethodTest.java    |  5 +-
 .../jmap/methods/JmapRequestParserImplTest.java | 12 ++---
 .../methods/JmapResponseWriterImplTest.java     | 20 ++++----
 .../SetMailboxesCreationProcessorTest.java      | 12 +++--
 .../jmap/methods/SetMailboxesMethodTest.java    |  6 ++-
 .../SetMailboxesUpdateProcessorTest.java        |  5 +-
 .../SetMessagesCreationProcessorTest.java       |  6 +--
 .../jmap/model/GetMailboxesRequestTest.java     |  5 +-
 .../james/jmap/model/MessageFactoryTest.java    |  6 +--
 .../apache/james/jmap/model/MessageTest.java    | 15 +++---
 .../jmap/model/SetMailboxesRequestTest.java     |  6 ++-
 .../jmap/model/SetMailboxesResponseTest.java    | 22 ++++----
 .../jmap/model/SetMessagesResponseTest.java     |  3 +-
 .../james/jmap/model/mailbox/MailboxTest.java   | 20 +++-----
 .../model/mailbox/MailboxUpdateRequestTest.java | 10 ++--
 .../apache/james/jmap/send/MailFactoryTest.java |  4 +-
 .../james/jmap/utils/MailboxUtilsTest.java      | 38 ++++++--------
 .../SortingHierarchicalCollectionsTest.java     | 54 +++++++++++---------
 .../jmap/src/test/resources/json/message.json   |  2 +-
 38 files changed, 330 insertions(+), 241 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 3c74002..f59850a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -101,10 +101,13 @@ public abstract class GetMailboxesMethodTest {
     @Test
     public void getMailboxesShouldReturnEmptyWhenIdsDoesntMatch() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "name");
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved");
+        String removedId = jmapServer.serverProbe().getMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved").getMailboxId().serialize();
+        jmapServer.serverProbe().deleteMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved");
 
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMailboxes\", {\"ids\": [\"notAMailboxId\"]}, \"#0\"]]")
+            .body("[[\"getMailboxes\", {\"ids\": [\"" + removedId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -114,6 +117,19 @@ public abstract class GetMailboxesMethodTest {
     }
 
     @Test
+    public void getMailboxesShouldReturnErrorWhenInvalidMailboxId() throws Exception {
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {\"ids\": [\"invalid id\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("error"))
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"));
+    }
+
+    @Test
     public void getMailboxesShouldReturnMailboxesWhenIdsMatch() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "INBOX");
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "myMailbox");

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index a1046a8..1fa49cc 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -39,6 +39,8 @@ import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.jmap.JmapAuthentication;
 import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.hamcrest.Matchers;
 import org.junit.After;
@@ -565,11 +567,12 @@ public abstract class SetMailboxesMethodTest {
 
     @Test
     public void setMailboxesShouldReturnNotDestroyedWhenMailboxDoesntExist() {
+        String nonExistantMailboxId = getRemovedMailboxId().serialize();
         String requestBody =
             "[" +
                 "  [ \"setMailboxes\"," +
                 "    {" +
-                "      \"destroy\": [\"123\"]" +
+                "      \"destroy\": [\"" + nonExistantMailboxId + "\"]" +
                 "    }," +
                 "    \"#0\"" +
                 "  ]" +
@@ -584,9 +587,9 @@ public abstract class SetMailboxesMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("mailboxesSet"))
             .body(ARGUMENTS + ".notDestroyed", aMapWithSize(1))
-            .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo("123"), Matchers.allOf(
+            .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(nonExistantMailboxId), Matchers.allOf(
                     hasEntry(equalTo("type"), equalTo("notFound")),
-                    hasEntry(equalTo("description"), equalTo("The mailbox '123' was not found.")))));
+                    hasEntry(equalTo("description"), equalTo("The mailbox '" + nonExistantMailboxId + "' was not found.")))));
     }
 
     @Test
@@ -705,14 +708,22 @@ public abstract class SetMailboxesMethodTest {
             .body(ARGUMENTS + ".destroyed", containsInAnyOrder(parentMailboxId, childMailboxId));
     }
 
+    private MailboxId getRemovedMailboxId() {
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved");
+        MailboxId removedId = jmapServer.serverProbe().getMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved").getMailboxId();
+        jmapServer.serverProbe().deleteMailbox(MailboxConstants.USER_NAMESPACE, username, "quicklyRemoved");
+        return removedId;
+    }
+
     @Test
     public void setMailboxesShouldReturnNotUpdatedWhenUnknownMailbox() {
+        String unknownMailboxId = getRemovedMailboxId().serialize();
         String requestBody =
                 "[" +
                     "  [ \"setMailboxes\"," +
                     "    {" +
                     "      \"update\": {" +
-                    "        \"unknown-update-id01\" : {" +
+                    "        \"" + unknownMailboxId + "\" : {" +
                     "          \"name\" : \"yolo\"" +
                     "        }" +
                     "      }" +
@@ -729,9 +740,9 @@ public abstract class SetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("mailboxesSet"))
-            .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo("unknown-update-id01"), Matchers.allOf(
+            .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(unknownMailboxId), Matchers.allOf(
                     hasEntry(equalTo("type"), equalTo("notFound")),
-                    hasEntry(equalTo("description"), containsString("unknown-update-id01")))));
+                    hasEntry(equalTo("description"), containsString(unknownMailboxId)))));
     }
 
     @Test
@@ -1177,13 +1188,14 @@ public abstract class SetMailboxesMethodTest {
         jmapServer.serverProbe().createMailbox("#private", username, "myBox");
         Mailbox mailbox = jmapServer.serverProbe().getMailbox("#private", username, "myBox");
         String mailboxId = mailbox.getMailboxId().serialize();
+        String badParentId = getRemovedMailboxId().serialize();
         String requestBody =
                 "[" +
                     "  [ \"setMailboxes\"," +
                     "    {" +
                     "      \"update\": {" +
                     "        \"" + mailboxId + "\" : {" +
-                    "          \"parentId\" : \"badParent\"" +
+                    "          \"parentId\" : \"" + badParentId + "\"" +
                     "        }" +
                     "      }" +
                     "    }," +
@@ -1201,7 +1213,7 @@ public abstract class SetMailboxesMethodTest {
             .body(NAME, equalTo("mailboxesSet"))
             .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(mailboxId), Matchers.allOf(
                     hasEntry(equalTo("type"), equalTo("notFound")),
-                    hasEntry(equalTo("description"), containsString("badParent")))));
+                    hasEntry(equalTo("description"), containsString(badParentId)))));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxParentNotFoundException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxParentNotFoundException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxParentNotFoundException.java
index aadf5eb..bfa3b38 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxParentNotFoundException.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxParentNotFoundException.java
@@ -19,13 +19,21 @@
 
 package org.apache.james.jmap.exceptions;
 
+import org.apache.james.jmap.model.MailboxCreationId;
+import org.apache.james.mailbox.model.MailboxId;
+
 public class MailboxParentNotFoundException extends RuntimeException {
 
     private final String parentId;
 
-    public MailboxParentNotFoundException(String parentId) {
-        super(String.format("The parent mailbox '%s' was not found.", parentId));
-        this.parentId = parentId;
+    public MailboxParentNotFoundException(MailboxId parentId) {
+        super(String.format("The parent mailbox '%s' was not found.", parentId.serialize()));
+        this.parentId = parentId.serialize();
+    }
+
+    public MailboxParentNotFoundException(MailboxCreationId parentId) {
+        super(String.format("The parent mailbox '%s' was not found.", parentId.getCreationId()));
+        this.parentId = parentId.getCreationId();
     }
 
     public String getParentId() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
index 7a4e2ed..3e739ed 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
@@ -36,6 +36,7 @@ import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxQuery;
 
@@ -103,7 +104,7 @@ public class GetMailboxesMethod implements Method {
         }
     }
 
-    private Predicate<? super Mailbox> filterMailboxesById(Optional<ImmutableList<String>> ids) {
+    private Predicate<? super Mailbox> filterMailboxesById(Optional<ImmutableList<MailboxId>> ids) {
         return (mailbox -> ids.map(list -> list.contains(mailbox.getId())).orElse(true));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
index 911aa9f..5b476ef 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
@@ -149,7 +149,7 @@ public class GetMessageListMethod implements Method {
     }
 
     private void aggregate(MailboxSession mailboxSession, Multimap<MailboxPath, MessageResult> aggregation, Map.Entry<MailboxId, Collection<Long>> mailboxResults) throws MailboxNotFoundException {
-        MailboxPath mailboxPath = mailboxUtils.mailboxPathFromMailboxId(mailboxResults.getKey().serialize(), mailboxSession)
+        MailboxPath mailboxPath = mailboxUtils.mailboxPathFromMailboxId(mailboxResults.getKey(), mailboxSession)
             .orElseThrow(() -> new MailboxNotFoundException(mailboxResults.getKey().serialize()));
         MessageManager messageManager = getMessageManager(mailboxPath, mailboxSession)
             .orElseThrow(() -> new MailboxNotFoundException(mailboxPath));

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
index 06c0605..cc4cb4d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
@@ -40,11 +40,14 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxId.Factory;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.ThrowingFunction;
 import com.google.common.annotations.VisibleForTesting;
 
 public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
@@ -52,24 +55,26 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(SetMailboxesCreationProcessor.class);
 
     private final MailboxManager mailboxManager;
-    private final SortingHierarchicalCollections<Map.Entry<MailboxCreationId, MailboxCreateRequest>, String> sortingHierarchicalCollections;
+    private final SortingHierarchicalCollections<Map.Entry<MailboxCreationId, MailboxCreateRequest>, MailboxCreationId> sortingHierarchicalCollections;
     private final MailboxUtils mailboxUtils;
+    private final Factory mailboxIdFactory;
 
     @Inject
     @VisibleForTesting
-    SetMailboxesCreationProcessor(MailboxManager mailboxManager, MailboxUtils mailboxUtils) {
+    SetMailboxesCreationProcessor(MailboxManager mailboxManager, MailboxUtils mailboxUtils, MailboxId.Factory mailboxIdFactory) {
         this.mailboxManager = mailboxManager;
         this.sortingHierarchicalCollections =
-            new SortingHierarchicalCollections<>(
-                x -> x.getKey().getCreationId(),
+            new SortingHierarchicalCollections<Map.Entry<MailboxCreationId, MailboxCreateRequest>, MailboxCreationId>(
+                x -> x.getKey(),
                 x -> x.getValue().getParentId());
         this.mailboxUtils = mailboxUtils;
+        this.mailboxIdFactory = mailboxIdFactory;
     }
 
     public SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession) {
         SetMailboxesResponse.Builder builder = SetMailboxesResponse.builder();
         try {
-            Map<MailboxCreationId, String> creationIdsToCreatedMailboxId = new HashMap<>();
+            Map<MailboxCreationId, MailboxId> creationIdsToCreatedMailboxId = new HashMap<>();
             sortingHierarchicalCollections.sortFromRootToLeaf(request.getCreate().entrySet())
                 .forEach(entry -> 
                     createMailbox(entry.getKey(), entry.getValue(), mailboxSession, creationIdsToCreatedMailboxId, builder));
@@ -90,7 +95,7 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
     }
 
     private void createMailbox(MailboxCreationId mailboxCreationId, MailboxCreateRequest mailboxRequest, MailboxSession mailboxSession,
-            Map<MailboxCreationId, String> creationIdsToCreatedMailboxId, SetMailboxesResponse.Builder builder) {
+            Map<MailboxCreationId, MailboxId> creationIdsToCreatedMailboxId, SetMailboxesResponse.Builder builder) {
         try {
             ensureValidMailboxName(mailboxRequest, mailboxSession);
             MailboxPath mailboxPath = getMailboxPath(mailboxRequest, creationIdsToCreatedMailboxId, mailboxSession);
@@ -134,12 +139,12 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
         }
     }
 
-    private MailboxPath getMailboxPath(MailboxCreateRequest mailboxRequest, Map<MailboxCreationId, String> creationIdsToCreatedMailboxId, MailboxSession mailboxSession) throws MailboxException {
+    private MailboxPath getMailboxPath(MailboxCreateRequest mailboxRequest, Map<MailboxCreationId, MailboxId> creationIdsToCreatedMailboxId, MailboxSession mailboxSession) throws MailboxException {
         if (mailboxRequest.getParentId().isPresent()) {
-            String parentId = mailboxRequest.getParentId().get();
-            String parentName = mailboxUtils.getMailboxNameFromId(parentId, mailboxSession)
+            MailboxCreationId parentId = mailboxRequest.getParentId().get();
+            String parentName = getMailboxNameFromId(parentId, mailboxSession)
                     .orElseGet(Throwing.supplier(() ->
-                        mailboxUtils.getMailboxNameFromId(creationIdsToCreatedMailboxId.get(MailboxCreationId.of(parentId)), mailboxSession)
+                        mailboxUtils.getMailboxNameFromId(creationIdsToCreatedMailboxId.get(parentId), mailboxSession)
                             .orElseThrow(() -> new MailboxParentNotFoundException(parentId))
                     ));
 
@@ -148,4 +153,18 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
         }
         return new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), mailboxRequest.getName());
     }
+
+    private Optional<String> getMailboxNameFromId(MailboxCreationId creationId, MailboxSession mailboxSession) {
+        ThrowingFunction<? super MailboxId, Optional<String>> toName = parentId -> mailboxUtils.getMailboxNameFromId(parentId, mailboxSession);
+        return getMailboxIdFromCreationId(creationId)
+                .flatMap(Throwing.function(toName).sneakyThrow());
+    }
+
+    private Optional<MailboxId> getMailboxIdFromCreationId(MailboxCreationId creationId) {
+        try {
+            return Optional.of(mailboxIdFactory.fromString(creationId.getCreationId()));
+        } catch (Exception e) {
+            return Optional.empty();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
index f6e225a..9fa4aab 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
@@ -38,6 +38,7 @@ import org.apache.james.jmap.utils.SortingHierarchicalCollections;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,7 +50,7 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(SetMailboxesDestructionProcessor.class);
 
     private final MailboxManager mailboxManager;
-    private final SortingHierarchicalCollections<Map.Entry<String, Mailbox>, String> sortingHierarchicalCollections;
+    private final SortingHierarchicalCollections<Map.Entry<MailboxId, Mailbox>, MailboxId> sortingHierarchicalCollections;
     private final MailboxUtils mailboxUtils;
 
     @Inject
@@ -64,7 +65,7 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
     }
 
     public SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession) {
-        ImmutableMap<String, Mailbox> idToMailbox = mapDestroyRequests(request, mailboxSession);
+        ImmutableMap<MailboxId, Mailbox> idToMailbox = mapDestroyRequests(request, mailboxSession);
 
         SetMailboxesResponse.Builder builder = SetMailboxesResponse.builder();
         sortingHierarchicalCollections.sortFromLeafToRoot(idToMailbox.entrySet())
@@ -74,8 +75,8 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
         return builder.build();
     }
 
-    private ImmutableMap<String, Mailbox> mapDestroyRequests(SetMailboxesRequest request, MailboxSession mailboxSession) {
-        ImmutableMap.Builder<String, Mailbox> idToMailboxBuilder = ImmutableMap.builder(); 
+    private ImmutableMap<MailboxId, Mailbox> mapDestroyRequests(SetMailboxesRequest request, MailboxSession mailboxSession) {
+        ImmutableMap.Builder<MailboxId, Mailbox> idToMailboxBuilder = ImmutableMap.builder(); 
         request.getDestroy().stream()
             .map(id -> mailboxUtils.mailboxFromMailboxId(id, mailboxSession))
             .filter(Optional::isPresent)
@@ -84,13 +85,13 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
         return idToMailboxBuilder.build();
     }
 
-    private void notDestroyedRequests(SetMailboxesRequest request, ImmutableMap<String, Mailbox> idToMailbox, SetMailboxesResponse.Builder builder) {
+    private void notDestroyedRequests(SetMailboxesRequest request, ImmutableMap<MailboxId, Mailbox> idToMailbox, SetMailboxesResponse.Builder builder) {
         request.getDestroy().stream()
             .filter(id -> !idToMailbox.containsKey(id))
             .forEach(id -> notDestroy(id, builder));
     }
 
-    private void destroyMailbox(Entry<String, Mailbox> entry, MailboxSession mailboxSession, SetMailboxesResponse.Builder builder) {
+    private void destroyMailbox(Entry<MailboxId, Mailbox> entry, MailboxSession mailboxSession, SetMailboxesResponse.Builder builder) {
         try {
             Mailbox mailbox = entry.getValue();
             preconditions(mailbox, mailboxSession);
@@ -100,15 +101,15 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
         } catch (MailboxHasChildException e) {
             builder.notDestroyed(entry.getKey(), SetError.builder()
                     .type("mailboxHasChild")
-                    .description(String.format("The mailbox '%s' has a child.", entry.getKey()))
+                    .description(String.format("The mailbox '%s' has a child.", entry.getKey().serialize()))
                     .build());
         } catch (SystemMailboxNotUpdatableException e) {
             builder.notDestroyed(entry.getKey(), SetError.builder()
                     .type("invalidArguments")
-                    .description(String.format("The mailbox '%s' is a system mailbox.", entry.getKey()))
+                    .description(String.format("The mailbox '%s' is a system mailbox.", entry.getKey().serialize()))
                     .build());
         } catch (MailboxException e) {
-            String message = String.format("An error occurred when deleting the mailbox '%s'", entry.getKey());
+            String message = String.format("An error occurred when deleting the mailbox '%s'", entry.getKey().serialize());
             LOGGER.error(message, e);
             builder.notDestroyed(entry.getKey(), SetError.builder()
                     .type("anErrorOccurred")
@@ -122,7 +123,7 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
         checkRole(mailbox.getRole());
     }
 
-    private void checkForChild(String id, MailboxSession mailboxSession) throws MailboxHasChildException, MailboxException {
+    private void checkForChild(MailboxId id, MailboxSession mailboxSession) throws MailboxHasChildException, MailboxException {
         if (mailboxUtils.hasChildren(id, mailboxSession)) {
             throw new MailboxHasChildException();
         }
@@ -134,10 +135,10 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor {
         }
     }
 
-    private void notDestroy(String id, Builder builder) {
+    private void notDestroy(MailboxId id, Builder builder) {
         builder.notDestroyed(id, SetError.builder()
                 .type("notFound")
-                .description(String.format("The mailbox '%s' was not found.", id))
+                .description(String.format("The mailbox '%s' was not found.", id.serialize()))
                 .build());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 673e918..69a07fe 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -68,7 +69,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
         return responseBuilder.build();
     }
 
-    private void handleUpdate(String mailboxId, MailboxUpdateRequest updateRequest, Builder responseBuilder, MailboxSession mailboxSession) {
+    private void handleUpdate(MailboxId mailboxId, MailboxUpdateRequest updateRequest, Builder responseBuilder, MailboxSession mailboxSession) {
         try {
             validateMailboxName(updateRequest, mailboxSession);
             Mailbox mailbox = getMailbox(mailboxId, mailboxSession);
@@ -91,7 +92,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
         } catch (MailboxNotFoundException e) {
             responseBuilder.notUpdated(mailboxId, SetError.builder()
                     .type("notFound")
-                    .description(String.format("The mailbox '%s' was not found", mailboxId))
+                    .description(String.format("The mailbox '%s' was not found", mailboxId.serialize()))
                     .build());
         } catch (MailboxParentNotFoundException e) {
             responseBuilder.notUpdated(mailboxId, SetError.builder()
@@ -122,9 +123,9 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
         }
     }
 
-    private Mailbox getMailbox(String mailboxId, MailboxSession mailboxSession) throws MailboxNotFoundException {
+    private Mailbox getMailbox(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxNotFoundException {
         return mailboxUtils.mailboxFromMailboxId(mailboxId, mailboxSession)
-                .orElseThrow(() -> new MailboxNotFoundException(mailboxId));
+                .orElseThrow(() -> new MailboxNotFoundException(mailboxId.serialize()));
     }
 
     private void validateMailboxName(MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxNameException {
@@ -154,7 +155,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
     private void validateParent(Mailbox mailbox, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxException, MailboxHasChildException {
 
         if (isParentIdInRequest(updateRequest)) {
-            String newParentId = updateRequest.getParentId().get();
+            MailboxId newParentId = updateRequest.getParentId().get();
             mailboxUtils.mailboxPathFromMailboxId(newParentId, mailboxSession)
                     .orElseThrow(() -> new MailboxParentNotFoundException(newParentId));
             if (mustChangeParent(mailbox.getParentId(), newParentId) && mailboxUtils.hasChildren(mailbox.getId(), mailboxSession)) {
@@ -168,7 +169,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
                 && updateRequest.getParentId().isPresent();
     }
 
-    private boolean mustChangeParent(Optional<String> currentParentId, String newParentId) {
+    private boolean mustChangeParent(Optional<MailboxId> currentParentId, MailboxId newParentId) {
         return currentParentId
                 .map(x -> ! x.equals(newParentId))
                 .orElse(true);
@@ -183,7 +184,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
     }
 
     private MailboxPath computeNewMailboxPath(Mailbox mailbox, MailboxPath originMailboxPath, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) {
-        Optional<String> parentId = updateRequest.getParentId();
+        Optional<MailboxId> parentId = updateRequest.getParentId();
         if (parentId == null) {
             return new MailboxPath(mailboxSession.getPersonalSpace(), 
                     mailboxSession.getUser().getUserName(), 
@@ -202,7 +203,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
         return new MailboxPath(originMailboxPath, newName);
     }
 
-    private MailboxPath computeMailboxPathWithNewParentId(MailboxPath originMailboxPath, String parentMailboxId, MailboxSession mailboxSession) {
+    private MailboxPath computeMailboxPathWithNewParentId(MailboxPath originMailboxPath, MailboxId parentMailboxId, MailboxSession mailboxSession) {
         Optional<MailboxPath> newParentMailboxPath = mailboxUtils.mailboxPathFromMailboxId(parentMailboxId, mailboxSession);
         String lastName = getCurrentMailboxName(originMailboxPath, mailboxSession);
         return new MailboxPath(originMailboxPath, newParentMailboxPath.get().getName() + mailboxSession.getPathDelimiter() + lastName);

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
index a8f59d8..6e435f8 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.methods.JmapRequest;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -42,7 +43,7 @@ public class GetMailboxesRequest implements JmapRequest {
 
         private String accountId;
         private Optional<ImmutableSet<MailboxProperty>> properties;
-        private Optional<ImmutableList<String>> ids;
+        private Optional<ImmutableList<MailboxId>> ids;
 
         private Builder() {
             ids = Optional.empty();
@@ -56,7 +57,7 @@ public class GetMailboxesRequest implements JmapRequest {
             return this;
         }
 
-        public Builder ids(List<String> ids) {
+        public Builder ids(List<MailboxId> ids) {
             if (ids != null) {
                 this.ids = Optional.of(ImmutableList.copyOf(ids));
             }
@@ -79,10 +80,10 @@ public class GetMailboxesRequest implements JmapRequest {
     }
 
     private final Optional<String> accountId;
-    private final Optional<ImmutableList<String>> ids;
+    private final Optional<ImmutableList<MailboxId>> ids;
     private final Optional<ImmutableSet<MailboxProperty>> properties;
 
-    private GetMailboxesRequest(Optional<String> accountId, Optional<ImmutableList<String>> ids, Optional<ImmutableSet<MailboxProperty>> properties) {
+    private GetMailboxesRequest(Optional<String> accountId, Optional<ImmutableList<MailboxId>> ids, Optional<ImmutableSet<MailboxProperty>> properties) {
         this.accountId = accountId;
         this.ids = ids;
         this.properties = properties;
@@ -92,7 +93,7 @@ public class GetMailboxesRequest implements JmapRequest {
         return accountId;
     }
 
-    public Optional<ImmutableList<String>> getIds() {
+    public Optional<ImmutableList<MailboxId>> getIds() {
         return ids;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/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 1e334aa..e1122db 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
@@ -27,6 +27,7 @@ import java.util.function.Predicate;
 
 import org.apache.james.jmap.methods.GetMessagesMethod;
 import org.apache.james.jmap.methods.JmapResponseWriterImpl;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.annotation.JsonFilter;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -50,7 +51,7 @@ public class Message {
         private MessageId id;
         private BlobId blobId;
         private String threadId;
-        private ImmutableList<String> mailboxIds;
+        private ImmutableList<MailboxId> mailboxIds;
         private String inReplyToMessageId;
         private boolean isUnread;
         private boolean isFlagged;
@@ -95,11 +96,11 @@ public class Message {
             return this;
         }
 
-        public Builder mailboxId(String mailboxId) {
+        public Builder mailboxId(MailboxId mailboxId) {
             return this.mailboxIds(ImmutableList.of(mailboxId));
         }
 
-        public Builder mailboxIds(List<String> mailboxIds) {
+        public Builder mailboxIds(List<MailboxId> mailboxIds) {
             this.mailboxIds = ImmutableList.copyOf(mailboxIds);
             return this;
         }
@@ -234,7 +235,7 @@ public class Message {
     private final MessageId id;
     private final BlobId blobId;
     private final String threadId;
-    private final ImmutableList<String> mailboxIds;
+    private final ImmutableList<MailboxId> mailboxIds;
     private final Optional<String> inReplyToMessageId;
     private final boolean isUnread;
     private final boolean isFlagged;
@@ -257,7 +258,7 @@ public class Message {
     private final ImmutableList<Attachment> attachments;
     private final ImmutableMap<BlobId, SubMessage> attachedMessages;
 
-    @VisibleForTesting Message(MessageId id, BlobId blobId, String threadId, ImmutableList<String> mailboxIds, Optional<String> inReplyToMessageId, boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft, boolean hasAttachment, ImmutableMap<String, String> headers, Optional<Emailer> from,
+    @VisibleForTesting Message(MessageId id, BlobId blobId, String threadId, ImmutableList<MailboxId> mailboxIds, Optional<String> inReplyToMessageId, boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft, boolean hasAttachment, ImmutableMap<String, String> headers, Optional<Emailer> from,
             ImmutableList<Emailer> to, ImmutableList<Emailer> cc, ImmutableList<Emailer> bcc, ImmutableList<Emailer> replyTo, String subject, ZonedDateTime date, long size, String preview, Optional<String> textBody, Optional<String> htmlBody, ImmutableList<Attachment> attachments,
             ImmutableMap<BlobId, SubMessage> attachedMessages) {
         this.id = id;
@@ -298,7 +299,7 @@ public class Message {
         return threadId;
     }
 
-    public ImmutableList<String> getMailboxIds() {
+    public ImmutableList<MailboxId> getMailboxIds() {
         return mailboxIds;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/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 c1597c2..fe090ce 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
@@ -76,7 +76,7 @@ public class MessageFactory {
                 .id(message.getMessageId())
                 .blobId(BlobId.of(String.valueOf(message.getUid())))
                 .threadId(message.getMessageId().serialize())
-                .mailboxIds(ImmutableList.of(message.getMailboxId().serialize()))
+                .mailboxIds(ImmutableList.of(message.getMailboxId()))
                 .inReplyToMessageId(getHeader(mimeMessage, "in-reply-to"))
                 .isUnread(! message.getFlags().contains(Flags.Flag.SEEN))
                 .isFlagged(message.getFlags().contains(Flags.Flag.FLAGGED))

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesRequest.java
index a89031e..7d6552a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesRequest.java
@@ -26,6 +26,7 @@ import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.methods.JmapRequest;
 import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
 import org.apache.james.jmap.model.mailbox.MailboxUpdateRequest;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -44,8 +45,8 @@ public class SetMailboxesRequest implements JmapRequest {
     public static class Builder {
 
         private final ImmutableMap.Builder<MailboxCreationId, MailboxCreateRequest> create;
-        private final ImmutableMap.Builder<String, MailboxUpdateRequest> update;
-        private final ImmutableList.Builder<String> destroy;
+        private final ImmutableMap.Builder<MailboxId, MailboxUpdateRequest> update;
+        private final ImmutableList.Builder<MailboxId> destroy;
 
         private Builder() {
             create = ImmutableMap.builder();
@@ -71,17 +72,17 @@ public class SetMailboxesRequest implements JmapRequest {
             throw new NotImplementedException();
         }
         
-        public Builder update(String mailboxId, MailboxUpdateRequest mailboxUpdateRequest) {
+        public Builder update(MailboxId mailboxId, MailboxUpdateRequest mailboxUpdateRequest) {
             update.put(mailboxId, mailboxUpdateRequest);
             return this;
         }
         
-        public Builder update(Map<String, MailboxUpdateRequest> updates) {
+        public Builder update(Map<MailboxId, MailboxUpdateRequest> updates) {
             update.putAll(updates);
             return this;
         }
         
-        public Builder destroy(List<String> deletions) {
+        public Builder destroy(List<MailboxId> deletions) {
             destroy.addAll(deletions);
             return this;
         }
@@ -92,11 +93,11 @@ public class SetMailboxesRequest implements JmapRequest {
     }
 
     private final ImmutableMap<MailboxCreationId, MailboxCreateRequest> create;
-    private final ImmutableMap<String, MailboxUpdateRequest> update;
-    private final ImmutableList<String> destroy;
+    private final ImmutableMap<MailboxId, MailboxUpdateRequest> update;
+    private final ImmutableList<MailboxId> destroy;
 
     @VisibleForTesting
-    SetMailboxesRequest(ImmutableMap<MailboxCreationId, MailboxCreateRequest> create, ImmutableMap<String,MailboxUpdateRequest> update, ImmutableList<String> destroy) {
+    SetMailboxesRequest(ImmutableMap<MailboxCreationId, MailboxCreateRequest> create, ImmutableMap<MailboxId,MailboxUpdateRequest> update, ImmutableList<MailboxId> destroy) {
         this.create = create;
         this.update = update;
         this.destroy = destroy;
@@ -106,11 +107,11 @@ public class SetMailboxesRequest implements JmapRequest {
         return create;
     }
 
-    public ImmutableMap<String, MailboxUpdateRequest> getUpdate() {
+    public ImmutableMap<MailboxId,MailboxUpdateRequest> getUpdate() {
         return update;
     }
 
-    public ImmutableList<String> getDestroy() {
+    public ImmutableList<MailboxId> getDestroy() {
         return destroy;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
index 321aba9..eb1abf1 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import org.apache.james.jmap.methods.Method;
 import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
@@ -38,11 +39,11 @@ public class SetMailboxesResponse implements Method.Response {
     public static class Builder {
 
         private final ImmutableMap.Builder<MailboxCreationId, Mailbox> created;
-        private final ImmutableList.Builder<String> updated;
-        private final ImmutableList.Builder<String> destroyed;
+        private final ImmutableList.Builder<MailboxId> updated;
+        private final ImmutableList.Builder<MailboxId> destroyed;
         private final ImmutableMap.Builder<MailboxCreationId, SetError> notCreated;
-        private final ImmutableMap.Builder<String, SetError> notUpdated;
-        private final ImmutableMap.Builder<String, SetError> notDestroyed;
+        private final ImmutableMap.Builder<MailboxId, SetError> notUpdated;
+        private final ImmutableMap.Builder<MailboxId, SetError> notDestroyed;
 
         private Builder() {
             created = ImmutableMap.builder();
@@ -63,22 +64,22 @@ public class SetMailboxesResponse implements Method.Response {
             return this;
         }
 
-        public Builder updated(String mailboxId) {
+        public Builder updated(MailboxId mailboxId) {
             updated.add(mailboxId);
             return this;
         }
         
-        public Builder updated(List<String> mailboxIds) {
+        public Builder updated(List<MailboxId> mailboxIds) {
             updated.addAll(mailboxIds);
             return this;
         }
         
-        public Builder destroyed(String mailboxId) {
+        public Builder destroyed(MailboxId mailboxId) {
             destroyed.add(mailboxId);
             return this;
         }
         
-        public Builder destroyed(ImmutableList<String> destroyed) {
+        public Builder destroyed(ImmutableList<MailboxId> destroyed) {
             this.destroyed.addAll(destroyed);
             return this;
         }
@@ -93,22 +94,22 @@ public class SetMailboxesResponse implements Method.Response {
             return this;
         }
         
-        public Builder notUpdated(String mailboxId, SetError setError) {
+        public Builder notUpdated(MailboxId mailboxId, SetError setError) {
             notUpdated.put(mailboxId, setError);
             return this;
         }
         
-        public Builder notUpdated(Map<String, SetError> notUpdated) {
+        public Builder notUpdated(Map<MailboxId, SetError> notUpdated) {
             this.notUpdated.putAll(notUpdated);
             return this;
         }
 
-        public Builder notDestroyed(String mailboxId, SetError setError) {
+        public Builder notDestroyed(MailboxId mailboxId, SetError setError) {
             notDestroyed.put(mailboxId, setError);
             return this;
         }
 
-        public Builder notDestroyed(ImmutableMap<String, SetError> notDestroyed) {
+        public Builder notDestroyed(ImmutableMap<MailboxId, SetError> notDestroyed) {
             this.notDestroyed.putAll(notDestroyed);
             return this;
         }
@@ -119,15 +120,15 @@ public class SetMailboxesResponse implements Method.Response {
     }
 
     private final ImmutableMap<MailboxCreationId, Mailbox> created;
-    private final ImmutableList<String> updated;
-    private final ImmutableList<String> destroyed;
+    private final ImmutableList<MailboxId> updated;
+    private final ImmutableList<MailboxId> destroyed;
     private final ImmutableMap<MailboxCreationId, SetError> notCreated;
-    private final ImmutableMap<String, SetError> notUpdated;
-    private final ImmutableMap<String, SetError> notDestroyed;
+    private final ImmutableMap<MailboxId,SetError> notUpdated;
+    private final ImmutableMap<MailboxId,SetError> notDestroyed;
 
     @VisibleForTesting
-    SetMailboxesResponse(ImmutableMap<MailboxCreationId, Mailbox> created, ImmutableList<String> updated, ImmutableList<String> destroyed,
-            ImmutableMap<MailboxCreationId, SetError> notCreated, ImmutableMap<String, SetError> notUpdated, ImmutableMap<String, SetError> notDestroyed) {
+    SetMailboxesResponse(ImmutableMap<MailboxCreationId, Mailbox> created, ImmutableList<MailboxId> updated, ImmutableList<MailboxId> destroyed,
+            ImmutableMap<MailboxCreationId, SetError> notCreated, ImmutableMap<MailboxId, SetError> notUpdated, ImmutableMap<MailboxId, SetError> notDestroyed) {
         this.created = created;
         this.updated = updated;
         this.destroyed = destroyed;
@@ -140,11 +141,11 @@ public class SetMailboxesResponse implements Method.Response {
         return created;
     }
 
-    public ImmutableList<String> getUpdated() {
+    public ImmutableList<MailboxId> getUpdated() {
         return updated;
     }
 
-    public ImmutableList<String> getDestroyed() {
+    public ImmutableList<MailboxId> getDestroyed() {
         return destroyed;
     }
     
@@ -152,11 +153,11 @@ public class SetMailboxesResponse implements Method.Response {
         return notCreated;
     }
 
-    public ImmutableMap<String, SetError> getNotUpdated() {
+    public ImmutableMap<MailboxId,SetError> getNotUpdated() {
         return notUpdated;
     }
     
-    public ImmutableMap<String, SetError> getNotDestroyed() {
+    public ImmutableMap<MailboxId,SetError> getNotDestroyed() {
         return notDestroyed;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
index 52436c4..cddb101 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import java.util.Optional;
 
 import org.apache.james.jmap.methods.JmapResponseWriterImpl;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.annotation.JsonFilter;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -43,9 +44,9 @@ public class Mailbox {
     @JsonPOJOBuilder(withPrefix = "")
     public static class Builder {
 
-        private String id;
+        private MailboxId id;
         private String name;
-        private Optional<String> parentId;
+        private Optional<MailboxId> parentId;
         private Optional<Role> role;
         private SortOrder sortOrder;
         private boolean mustBeOnlyMailbox;
@@ -64,7 +65,7 @@ public class Mailbox {
             parentId = Optional.empty();
         }
 
-        public Builder id(String id) {
+        public Builder id(MailboxId id) {
             Preconditions.checkNotNull(id);
             this.id = id;
             return this;
@@ -76,7 +77,7 @@ public class Mailbox {
             return this;
         }
 
-        public Builder parentId(String parentId) {
+        public Builder parentId(MailboxId parentId) {
             this.parentId = Optional.ofNullable(parentId);
             return this;
         }
@@ -148,16 +149,16 @@ public class Mailbox {
 
         public Mailbox build() {
             Preconditions.checkState(!Strings.isNullOrEmpty(name), "'name' is mandatory");
-            Preconditions.checkState(!Strings.isNullOrEmpty(id), "'id' is mandatory");
+            Preconditions.checkState(id != null, "'id' is mandatory");
 
             return new Mailbox(id, name, parentId, role, sortOrder, mustBeOnlyMailbox, mayReadItems, mayAddItems, mayRemoveItems, mayCreateChild, mayRename, mayDelete,
                     totalMessages, unreadMessages, totalThreads, unreadThreads);
         }
     }
 
-    private final String id;
+    private final MailboxId id;
     private final String name;
-    private final Optional<String> parentId;
+    private final Optional<MailboxId> parentId;
     private final Optional<Role> role;
     private final SortOrder sortOrder;
     private final boolean mustBeOnlyMailbox;
@@ -172,7 +173,7 @@ public class Mailbox {
     private final long totalThreads;
     private final long unreadThreads;
 
-    @VisibleForTesting Mailbox(String id, String name, Optional<String> parentId, Optional<Role> role, SortOrder sortOrder, boolean mustBeOnlyMailbox,
+    @VisibleForTesting Mailbox(MailboxId id, String name, Optional<MailboxId> parentId, Optional<Role> role, SortOrder sortOrder, boolean mustBeOnlyMailbox,
             boolean mayReadItems, boolean mayAddItems, boolean mayRemoveItems, boolean mayCreateChild, boolean mayRename, boolean mayDelete,
             long totalMessages, long unreadMessages, long totalThreads, long unreadThreads) {
 
@@ -194,7 +195,7 @@ public class Mailbox {
         this.unreadThreads = unreadThreads;
     }
 
-    public String getId() {
+    public MailboxId getId() {
         return id;
     }
 
@@ -202,7 +203,7 @@ public class Mailbox {
         return name;
     }
 
-    public Optional<String> getParentId() {
+    public Optional<MailboxId> getParentId() {
         return parentId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
index cd1c89f..c0eb828 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import java.util.Optional;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.model.MailboxCreationId;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -43,7 +44,7 @@ public class MailboxCreateRequest {
 
         private Optional<String> id;
         private String name;
-        private Optional<String> parentId;
+        private Optional<MailboxCreationId> parentId;
         private Optional<Role> role;
         private Optional<SortOrder> sortOrder;
 
@@ -66,7 +67,7 @@ public class MailboxCreateRequest {
             return this;
         }
 
-        public Builder parentId(String parentId) {
+        public Builder parentId(MailboxCreationId parentId) {
             Preconditions.checkNotNull(parentId);
             this.parentId = Optional.of(parentId);
             return this;
@@ -91,12 +92,12 @@ public class MailboxCreateRequest {
 
     private final Optional<String> id;
     private final String name;
-    private final Optional<String> parentId;
+    private final Optional<MailboxCreationId> parentId;
     private final Optional<Role> role;
     private final Optional<SortOrder> sortOrder;
 
     @VisibleForTesting
-    MailboxCreateRequest(Optional<String> id, String name, Optional<String> parentId, Optional<Role> role, Optional<SortOrder> sortOrder) {
+    MailboxCreateRequest(Optional<String> id, String name, Optional<MailboxCreationId> parentId, Optional<Role> role, Optional<SortOrder> sortOrder) {
 
         this.id = id;
         this.name = name;
@@ -113,7 +114,7 @@ public class MailboxCreateRequest {
         return name;
     }
 
-    public Optional<String> getParentId() {
+    public Optional<MailboxCreationId> getParentId() {
         return parentId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequest.java
index ebffb49..65af555 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequest.java
@@ -24,6 +24,7 @@ import java.util.Optional;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -42,7 +43,7 @@ public class MailboxUpdateRequest {
     public static class Builder {
 
         private Optional<String> name;
-        private Optional<String> parentId;
+        private Optional<MailboxId> parentId;
         private Optional<Role> role;
         private Optional<SortOrder> sortOrder;
 
@@ -60,7 +61,7 @@ public class MailboxUpdateRequest {
             return this;
         }
 
-        public Builder parentId(String parentId) {
+        public Builder parentId(MailboxId parentId) {
             if (parentId == null) {
                 this.parentId = null;
             } else {
@@ -86,12 +87,12 @@ public class MailboxUpdateRequest {
     }
 
     private final Optional<String> name;
-    private final Optional<String> parentId;
+    private final Optional<MailboxId> parentId;
     private final Optional<Role> role;
     private final Optional<SortOrder> sortOrder;
 
     @VisibleForTesting
-    MailboxUpdateRequest(Optional<String> name, Optional<String> parentId, Optional<Role> role, Optional<SortOrder> sortOrder) {
+    MailboxUpdateRequest(Optional<String> name, Optional<MailboxId> parentId, Optional<Role> role, Optional<SortOrder> sortOrder) {
 
         this.name = name;
         this.parentId = parentId;
@@ -103,7 +104,7 @@ public class MailboxUpdateRequest {
         return name;
     }
 
-    public Optional<String> getParentId() {
+    public Optional<MailboxId> getParentId() {
         return parentId;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
index 6197c9c..3584420 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
@@ -41,7 +41,6 @@ import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
 
 public class MailboxUtils {
 
@@ -65,9 +64,9 @@ public class MailboxUtils {
             MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
             MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailbox, mailboxSession);
             return Optional.ofNullable(Mailbox.builder()
-                    .id(mailbox.getId().serialize())
+                    .id(mailbox.getId())
                     .name(getName(mailboxPath, mailboxSession))
-                    .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).map(MailboxId::serialize).orElse(null))
+                    .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).orElse(null))
                     .role(role)
                     .unreadMessages(mailboxMetaData.getUnseenCount())
                     .totalMessages(mailboxMetaData.getMessageCount())
@@ -97,16 +96,16 @@ public class MailboxUtils {
         return name;
     }
 
-    public Optional<String> getMailboxNameFromId(String mailboxId, MailboxSession mailboxSession) throws MailboxException {
+    public Optional<String> getMailboxNameFromId(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
         return getMailboxFromId(mailboxId, mailboxSession)
                 .map(org.apache.james.mailbox.store.mail.model.Mailbox::getName);
     }
 
-    private Optional<org.apache.james.mailbox.store.mail.model.Mailbox> getMailboxFromId(String mailboxId, MailboxSession mailboxSession) throws MailboxException {
+    private Optional<org.apache.james.mailbox.store.mail.model.Mailbox> getMailboxFromId(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
         return mailboxMapperFactory.getMailboxMapper(mailboxSession)
                 .findMailboxWithPathLike(new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), WILDCARD))
                 .stream()
-                .filter(mailbox -> mailbox.getMailboxId().serialize().equals(mailboxId))
+                .filter(mailbox -> mailbox.getMailboxId().equals(mailboxId))
                 .findFirst();
     }
 
@@ -119,7 +118,7 @@ public class MailboxUtils {
         return Optional.of(getMailboxId(parent, mailboxSession));
     }
 
-    public Optional<Mailbox> mailboxFromMailboxId(String mailboxId, MailboxSession mailboxSession) {
+    public Optional<Mailbox> mailboxFromMailboxId(MailboxId mailboxId, MailboxSession mailboxSession) {
         try {
             return getMailboxFromId(mailboxId, mailboxSession)
                 .flatMap(jamesMailbox ->
@@ -143,15 +142,15 @@ public class MailboxUtils {
         return mailbox.getName();
     }
 
-    public boolean hasChildren(String mailboxId, MailboxSession mailboxSession) throws MailboxException {
+    public boolean hasChildren(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
         return getMailboxFromId(mailboxId, mailboxSession)
                 .map(Throwing.function(mailbox -> 
                     mailboxMapperFactory.getMailboxMapper(mailboxSession).hasChildren(mailbox, mailboxSession.getPathDelimiter())))
                 .orElse(false);
     }
 
-    public Optional<MailboxPath> mailboxPathFromMailboxId(String mailboxId, MailboxSession mailboxSession) {
-        Preconditions.checkState(!Strings.isNullOrEmpty(mailboxId), "'mailboxId' is mandatory");
+    public Optional<MailboxPath> mailboxPathFromMailboxId(MailboxId mailboxId, MailboxSession mailboxSession) {
+        Preconditions.checkState(mailboxId != null, "'mailboxId' is mandatory");
         Preconditions.checkState(mailboxSession != null, "'mailboxId' is mandatory");
         return mailboxFromMailboxId(mailboxId, mailboxSession)
                 .map(mailbox -> getMailboxPath(mailbox, mailboxSession));

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
index 7723d8a..b2209a2 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
@@ -27,6 +27,8 @@ import org.apache.james.jmap.model.Emailer;
 import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.MessageId;
 import org.apache.james.jmap.model.SubMessage;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.model.MailboxId;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -37,7 +39,7 @@ public interface ParsingWritingObjects {
         MessageId MESSAGE_ID = MessageId.of("username|mailbox|1");
         BlobId BLOB_ID = BlobId.of("myBlobId");
         String THREAD_ID = "myThreadId";
-        ImmutableList<String> MAILBOX_IDS = ImmutableList.of("mailboxId1", "mailboxId2");
+        ImmutableList<MailboxId> MAILBOX_IDS = ImmutableList.of(InMemoryId.of(1), InMemoryId.of(2));
         String IN_REPLY_TO_MESSAGE_ID = "myInReplyToMessageId";
         boolean IS_UNREAD = true;
         boolean IS_FLAGGED = true;

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java
index b001060..583f560 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java
@@ -31,18 +31,26 @@ import org.apache.james.jmap.methods.JmapResponseWriterImpl;
 import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.SubMessage;
 import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
 import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
 
 public class ParsingWritingObjectsTest {
+    
+    private ObjectMapperFactory testee;
+
+    @Before
+    public void setup() {
+        testee = new ObjectMapperFactory(new InMemoryId.Factory());
+    }
 
     @Test
     public void parsingJsonShouldWorkOnSubMessage() throws Exception {
         SubMessage expected = SUB_MESSAGE;
 
-        SubMessage subMessage = new ObjectMapperFactory(new InMemoryId.Factory()).forParsing()
+        SubMessage subMessage = testee.forParsing()
             .readValue(IOUtils.toString(ClassLoader.getSystemResource("json/subMessage.json")), SubMessage.class);
 
         assertThat(subMessage).isEqualToComparingFieldByField(expected);
@@ -52,7 +60,7 @@ public class ParsingWritingObjectsTest {
     public void writingJsonShouldWorkOnSubMessage() throws Exception {
         String expected = IOUtils.toString(ClassLoader.getSystemResource("json/subMessage.json"));
 
-        String json = new ObjectMapperFactory(new InMemoryId.Factory()).forWriting()
+        String json = testee.forWriting()
                 .writeValueAsString(SUB_MESSAGE);
 
         assertThatJson(json)
@@ -65,7 +73,7 @@ public class ParsingWritingObjectsTest {
     public void parsingJsonShouldWorkOnMessage() throws Exception {
         Message expected = MESSAGE;
 
-        Message message = new ObjectMapperFactory(new InMemoryId.Factory()).forParsing()
+        Message message = testee.forParsing()
             .readValue(IOUtils.toString(ClassLoader.getSystemResource("json/message.json")), Message.class);
 
         assertThat(message).isEqualToComparingFieldByField(expected);
@@ -79,7 +87,7 @@ public class ParsingWritingObjectsTest {
                 .addFilter(JmapResponseWriterImpl.PROPERTIES_FILTER, SimpleBeanPropertyFilter.serializeAll())
                 .addFilter(GetMessagesMethod.HEADERS_FILTER, SimpleBeanPropertyFilter.serializeAll());
 
-        String json = new ObjectMapperFactory(new InMemoryId.Factory()).forWriting()
+        String json = testee.forWriting()
                 .setFilterProvider(filterProvider)
                 .writeValueAsString(MESSAGE);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index a8af679..e321085 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -46,6 +46,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.MockAuthenticator;
@@ -149,7 +150,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getId, Mailbox::getName, Mailbox::getUnreadMessages)
-                .containsOnly(Tuple.tuple("1", mailboxPath.getName(), 2L));
+                .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPath.getName(), 2L));
     }
 
     @Test
@@ -173,7 +174,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getId, Mailbox::getName)
-                .containsOnly(Tuple.tuple("1", mailboxPathToReturn.getName()));
+                .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPathToReturn.getName()));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java
index 879de19..0a04016 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java
@@ -30,20 +30,20 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 public class JmapRequestParserImplTest {
-    private JmapRequestParserImpl jmapRequestParserImpl;
+    private JmapRequestParserImpl testee;
 
     @Before
     public void setup() {
-        jmapRequestParserImpl = new JmapRequestParserImpl(new ObjectMapperFactory(new InMemoryId.Factory()));
+        testee = new JmapRequestParserImpl(new ObjectMapperFactory(new InMemoryId.Factory()));
     }
-
+    
     @Test(expected=IllegalArgumentException.class)
     public void extractJmapRequestShouldThrowWhenNullRequestClass() throws Exception {
         JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"),
                 new ObjectNode(new JsonNodeFactory(false)).putObject("{\"id\": \"id\"}"),
                 new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ;
 
-        jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), null);
+        testee.extractJmapRequest(ProtocolRequest.deserialize(nodes), null);
     }
 
     @Test
@@ -54,7 +54,7 @@ public class JmapRequestParserImplTest {
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ;
 
-        jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class);
+        testee.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class);
     }
 
     @Test
@@ -64,7 +64,7 @@ public class JmapRequestParserImplTest {
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ;
 
-        jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class);
+        testee.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class);
     }
 
     private static class RequestClass implements JmapRequest {

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
index b943a9a..48cc643 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
@@ -46,11 +46,11 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
 public class JmapResponseWriterImplTest {
-    private JmapResponseWriterImpl jmapResponseWriterImpl;
+    private JmapResponseWriterImpl testee;
 
     @Before
     public void setup() {
-        jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory(new InMemoryId.Factory()));
+        testee = new JmapResponseWriterImpl(new ObjectMapperFactory(new InMemoryId.Factory()));
     }
 
     @Ignore
@@ -60,7 +60,7 @@ public class JmapResponseWriterImplTest {
         String expectedClientId = "#1";
         String expectedId = "myId";
 
-        Stream<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(Stream.of(JmapResponse
+        Stream<ProtocolResponse> response = testee.formatMethodResponse(Stream.of(JmapResponse
                 .builder()
                 .clientId(ClientId.of(expectedClientId))
                 .response(null)
@@ -80,7 +80,7 @@ public class JmapResponseWriterImplTest {
         ResponseClass responseClass = new ResponseClass();
         responseClass.id = expectedId;
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                 .builder()
                 .responseName(Method.Response.name("unknownMethod"))
@@ -107,7 +107,7 @@ public class JmapResponseWriterImplTest {
         responseClass.list = ImmutableList.of(new ObjectResponseClass.Foo("id", "name"));
         Property property = () -> "id";
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                 .builder()
                 .responseName(Method.Response.name("unknownMethod"))
@@ -132,7 +132,7 @@ public class JmapResponseWriterImplTest {
         Property property = () -> "id";
 
         @SuppressWarnings("unused")
-        Stream<ProtocolResponse> ignoredResponse = jmapResponseWriterImpl.formatMethodResponse(
+        Stream<ProtocolResponse> ignoredResponse = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                         .builder()
                         .responseName(Method.Response.name("unknownMethod"))
@@ -141,7 +141,7 @@ public class JmapResponseWriterImplTest {
                         .response(responseClass)
                         .build()));
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                 .builder()
                 .responseName(Method.Response.name("unknownMethod"))
@@ -163,7 +163,7 @@ public class JmapResponseWriterImplTest {
         Property idProperty = () -> "id";
         Property nameProperty = () -> "name";
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                             .builder()
                             .responseName(Method.Response.name("unknownMethod"))
@@ -212,7 +212,7 @@ public class JmapResponseWriterImplTest {
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ;
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                     .builder()
                     .clientId(ProtocolRequest.deserialize(nodes).getClientId())
@@ -235,7 +235,7 @@ public class JmapResponseWriterImplTest {
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ;
 
-        List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(
+        List<ProtocolResponse> response = testee.formatMethodResponse(
                 Stream.of(JmapResponse
                     .builder()
                     .clientId(ProtocolRequest.deserialize(nodes).getClientId())

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
index d90bd63..f8f67bc 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
@@ -32,30 +32,36 @@ import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.inmemory.InMemoryId.Factory;
+import org.apache.james.mailbox.model.MailboxId;
 import org.junit.Before;
 import org.junit.Test;
 
 public class SetMailboxesCreationProcessorTest {
 
     private MailboxUtils mailboxUtils;
+    private Factory mailboxIdFactory;
     private SetMailboxesCreationProcessor sut;
 
     @Before
     public void setup() {
         mailboxUtils = mock(MailboxUtils.class);
-        sut = new SetMailboxesCreationProcessor(mock(MailboxManager.class), mailboxUtils);
+        mailboxIdFactory = new InMemoryId.Factory();
+        sut = new SetMailboxesCreationProcessor(mock(MailboxManager.class), mailboxUtils, mailboxIdFactory);
     }
 
     @Test
     public void processShouldReturnNotCreatedWhenMailboxExceptionOccured() throws Exception {
-        String parentId = "parentId";
+        MailboxCreationId parentId = MailboxCreationId.of("0");
+        MailboxId parentMailboxId = mailboxIdFactory.fromString(parentId.getCreationId());
         MailboxCreationId mailboxCreationId = MailboxCreationId.of("1");
         SetMailboxesRequest request = SetMailboxesRequest.builder()
                 .create(mailboxCreationId, MailboxCreateRequest.builder().name("name").parentId(parentId).build())
                 .build();
 
         MailboxSession mailboxSession = mock(MailboxSession.class);
-        when(mailboxUtils.getMailboxNameFromId(parentId, mailboxSession))
+        when(mailboxUtils.getMailboxNameFromId(parentMailboxId, mailboxSession))
             .thenThrow(new MailboxException());
 
         SetMailboxesResponse setMailboxesResponse = sut.process(request, mailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
index 831b70c..6be6dc8 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
@@ -34,6 +34,8 @@ import org.apache.james.jmap.model.SetMailboxesResponse;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.model.MailboxId;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -92,7 +94,7 @@ public class SetMailboxesMethodTest {
         MailboxCreateRequest fooFolder = MailboxCreateRequest.builder().name("fooFolder").build();
         SetMailboxesRequest creationRequest = SetMailboxesRequest.builder().create(creationId, fooFolder).build();
 
-        Mailbox createdfooFolder = Mailbox.builder().name("fooFolder").id("fooId").build();
+        Mailbox createdfooFolder = Mailbox.builder().name("fooFolder").id(InMemoryId.of(123)).build();
         SetMailboxesResponse creationResponse = SetMailboxesResponse.builder().created(creationId, createdfooFolder).build();
         JmapResponse jmapResponse = JmapResponse.builder()
             .response(creationResponse)
@@ -113,7 +115,7 @@ public class SetMailboxesMethodTest {
 
     @Test
     public void processShouldCallDestructorProcessorWhenCreationRequest() {
-        ImmutableList<String> deletions = ImmutableList.of("1");
+        ImmutableList<MailboxId> deletions = ImmutableList.of(InMemoryId.of(1));
         SetMailboxesRequest destructionRequest = SetMailboxesRequest.builder().destroy(deletions).build();
 
         SetMailboxesResponse destructionResponse = SetMailboxesResponse.builder().destroyed(deletions).build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
index 204365f..0fdc0a5 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
@@ -34,6 +34,7 @@ import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,8 +57,8 @@ public class SetMailboxesUpdateProcessorTest {
     @Test
     public void processShouldReturnNotUpdatedWhenMailboxExceptionOccured() throws Exception {
         // Given
-        String mailboxId = "1";
-        String newParentId = "newParentId";
+        InMemoryId mailboxId = InMemoryId.of(1);
+        InMemoryId newParentId = InMemoryId.of(2);
         MailboxPath newParentMailboxPath = new MailboxPath("#private", "user", "newParentName");
         SetMailboxesRequest request = SetMailboxesRequest.builder()
                 .update(mailboxId, MailboxUpdateRequest.builder().parentId(newParentId).build())

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ec9ab93/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 79bc2f0..e65a3c6 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
@@ -61,11 +61,11 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.AttachmentNotFoundException;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.mailet.Mail;
@@ -80,9 +80,9 @@ public class SetMessagesCreationProcessorTest {
     
     private static final String USER = "user@example.com";
     private static final String OUTBOX = "outbox";
-    private static final TestId OUTBOX_ID = TestId.of(12345);
+    private static final InMemoryId OUTBOX_ID = InMemoryId.of(12345);
     private static final String DRAFTS = "drafts";
-    private static final TestId DRAFTS_ID = TestId.of(12);
+    private static final InMemoryId DRAFTS_ID = InMemoryId.of(12);
     private static final String NAMESPACE = "#private";
 
     private final CreationMessage.Builder creationMessageBuilder = CreationMessage.builder()


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


Mime
View raw message