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 2019/01/08 08:00:20 UTC

[01/47] james-project git commit: MAILBOX-359 Factorize tests for SessionId ser-deserialization

Repository: james-project
Updated Branches:
  refs/heads/master 76374191d -> d5ff60a73


MAILBOX-359 Factorize tests for SessionId ser-deserialization


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

Branch: refs/heads/master
Commit: 8ca8a33073360917a2d0f3aa2ba2a440d05023fe
Parents: 7637419
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 12:59:52 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:56 2019 +0700

----------------------------------------------------------------------
 .../james/event/json/EventSerializer.scala      |  4 +-
 .../event/json/AddedSerializationTest.java      | 72 ++-----------------
 .../event/json/ExpungedSerializationTest.java   | 72 ++-----------------
 .../json/FlagsUpdatedSerializationTest.java     | 76 ++------------------
 ...MailboxACLUpdatedEventSerializationTest.java | 56 ++-------------
 .../json/MailboxAddedSerializationTest.java     | 34 ---------
 .../json/MailboxDeletionSerializationTest.java  | 54 ++------------
 .../json/MailboxRenamedSerializationTest.java   | 38 ++--------
 .../james/event/json/dtos/SessionIdTest.java    | 65 +++++++++++++++++
 9 files changed, 94 insertions(+), 377 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index af2785e..6418425 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -35,7 +35,7 @@ import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsStri
 
 import scala.collection.JavaConverters._
 
-private sealed trait Event {
+sealed trait Event {
   def toJava: JavaEvent
 }
 
@@ -190,7 +190,7 @@ private object ScalaConverter {
   }
 }
 
-private class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
+class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
   implicit val systemFlagsWrites: Writes[SystemFlag] = Writes.enumNameWrites
   implicit val userWriters: Writes[User] = (user: User) => JsString(user.asString)
   implicit val quotaRootWrites: Writes[QuotaRoot] = quotaRoot => JsString(quotaRoot.getValue)

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index a96de11..82afcd2 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -510,72 +510,10 @@ class AddedSerializationTest {
 
     @Nested
     class DeserializationErrors {
-
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void addedShouldThrowWhenMissingSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenNullSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": null," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void addedShouldThrowWhenMissingSessionId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Added\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -595,12 +533,10 @@ class AddedSerializationTest {
                     "        \"messageId\": \"42\"" +
                     "      }" +
                     "    }," +
-                    "    \"sessionId\": \"42\"," +
                     "    \"user\": \"user\"" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 7676b6f..85987f5 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -509,72 +509,10 @@ class ExpungedSerializationTest {
 
     @Nested
     class DeserializationErrors {
-
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void expungedShouldThrowWhenMissingSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenNullSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": null," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void expungedShouldThrowWhenMissingSessionId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Expunged\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -594,12 +532,10 @@ class ExpungedSerializationTest {
                     "        \"messageId\": \"42\"" +
                     "      }" +
                     "    }," +
-                    "    \"sessionId\": \"42\"," +
                     "    \"user\": \"user\"" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index e6e12ba..76fdba3 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -433,76 +433,10 @@ class FlagsUpdatedSerializationTest {
 
     @Nested
     class DeserializationError {
-
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void flagsUpdatedShouldThrowWhenMissingSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenNullSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"sessionId\": null," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void flagsUpdatedShouldThrowWhenMissingSessionId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"FlagsUpdated\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -510,7 +444,6 @@ class FlagsUpdatedSerializationTest {
                     "      \"name\": \"mailboxName\"" +
                     "    }," +
                     "    \"mailboxId\": \"18\"," +
-                    "    \"sessionId\": \"42\"," +
                     "    \"updatedFlags\": [" +
                     "      {" +
                     "        \"uid\": 123456," +
@@ -529,7 +462,6 @@ class FlagsUpdatedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index 14d3bf1..da5b509 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -270,54 +270,10 @@ class MailboxACLUpdatedEventSerializationTest {
 
     @Nested
     class DeserializationErrors {
-
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"user\":\"bob\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenNullSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"user\":\"bob\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":null," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxACLUpdated\":{" +
                     "    \"mailboxPath\":{" +
                     "       \"namespace\":\"#private\"," +
@@ -328,12 +284,10 @@ class MailboxACLUpdatedEventSerializationTest {
                     "       \"oldACL\":{}," +
                     "       \"newACL\":{\"$any\":\"ar\"}}," +
                     "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":\"123\"," +
                     "    \"user\":\"user\"" +
                     "   }" +
                     "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index 339e4d6..f880328 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -149,40 +149,6 @@ class MailboxAddedSerializationTest {
     class DeserializationErrors {
 
         @Test
-        void fromJsonShouldRejectNullSessionId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":null" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectStringSessionId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":\"invalid\"" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
         void fromJsonShouldRejectMissingSessionId() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
                 "  \"MailboxAdded\":{" +

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index cc5da61..4c92630 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -277,56 +277,11 @@ class MailboxDeletionSerializationTest {
 
     @Nested
     class DeserializationErrors {
-
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenNullSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":null," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingSessionId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":\"3652\"," +
                     "    \"user\":\"user\"," +
                     "    \"path\":{" +
                     "      \"namespace\":\"#private\"," +
@@ -340,7 +295,6 @@ class MailboxDeletionSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index 557eac7..e5ffc7e 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -358,35 +358,10 @@ class MailboxRenamedSerializationTest {
             }
         }
 
-        @Nested
-        class DeserializationErrorOnSessionId {
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenStringSessionId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":\"123456789\"," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNullSessionId() {
-                String eventWithNullSessionId =
-                    "{" +
+        @Test
+        void mailboxRenamedDeSerializeShouldThrowWhenMissingSessionId() {
+            String eventWithNullSessionId =
+                "{" +
                     "  \"MailboxRenamed\":{" +
                     "    \"user\":\"user\"," +
                     "    \"path\":{" +
@@ -402,9 +377,8 @@ class MailboxRenamedSerializationTest {
                     "     }" +
                     "  }" +
                     "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithNullSessionId).get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithNullSessionId).get())
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/8ca8a330/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
new file mode 100644
index 0000000..49ad7eb
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
@@ -0,0 +1,65 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class SessionIdTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void sessionIdShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)).toString())
+            .isEqualTo("18");
+    }
+
+    @Test
+    void sessionIdShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isEqualTo(new JsSuccess<>(MailboxSession.SessionId.of(18), new JsPath(List.empty())));
+    }
+
+    @Test
+    void sessionIdShouldReturnErrorWhenString() {
+        assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsString("18")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void sessionIdShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.sessionIdReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+}


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


[36/47] james-project git commit: JAMES-2636 Reorder RecipientRewriteTable API order

Posted by bt...@apache.org.
JAMES-2636 Reorder RecipientRewriteTable API order

Classes go first, then constants, then methods. Note that I inlined a
short method that was not related to the API. This avoids poluting the API
with useless methods


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

Branch: refs/heads/master
Commit: 887f3c5aa9d4f31cfeedee54d2ebf37f0f77e8ea
Parents: 9a4ce2f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Jan 4 09:43:42 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:45:33 2019 +0700

----------------------------------------------------------------------
 .../james/rrt/api/RecipientRewriteTable.java    | 48 ++++++++------------
 1 file changed, 19 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/887f3c5a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index fed9ea0..5c85ed7 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -34,6 +34,24 @@ import com.google.common.base.Preconditions;
  * Interface which should be implemented of classes which map recipients.
  */
 public interface RecipientRewriteTable {
+    class ErrorMappingException extends Exception {
+        private static final long serialVersionUID = 2348752938798L;
+
+        public ErrorMappingException(String string) {
+            super(string);
+        }
+    }
+
+    class TooManyMappingException extends ErrorMappingException {
+        public TooManyMappingException(String string) {
+            super(string);
+        }
+    }
+
+    EnumSet<Mapping.Type> listSourcesSupportedType = EnumSet.of(
+        Mapping.Type.Group,
+        Mapping.Type.Forward,
+        Mapping.Type.Address);
 
     void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException;
 
@@ -91,7 +109,7 @@ public interface RecipientRewriteTable {
     Map<MappingSource, Mappings> getAllMappings() throws RecipientRewriteTableException;
 
     default List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
-        Preconditions.checkArgument(supportsSourceListing(mapping),
+        Preconditions.checkArgument(listSourcesSupportedType.contains(mapping.getType()),
             String.format("Not supported mapping of type %s", mapping.getType()));
 
         return getAllMappings().entrySet().stream()
@@ -99,32 +117,4 @@ public interface RecipientRewriteTable {
             .map(Map.Entry::getKey)
             .collect(Guavate.toImmutableList());
     }
-
-    EnumSet<Mapping.Type> listSourcesSupportedType = EnumSet.of(
-        Mapping.Type.Group,
-        Mapping.Type.Forward,
-        Mapping.Type.Address);
-
-    default boolean supportsSourceListing(Mapping mapping) {
-        return listSourcesSupportedType.contains(
-            mapping.getType());
-    }
-
-    class ErrorMappingException extends Exception {
-
-        private static final long serialVersionUID = 2348752938798L;
-
-        public ErrorMappingException(String string) {
-            super(string);
-        }
-
-    }
-
-    class TooManyMappingException extends ErrorMappingException {
-        
-        public TooManyMappingException(String string) {
-            super(string);
-        }
-
-    }
 }


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


[02/47] james-project git commit: MAILBOX-359 Factorize tests for ACLDiffTest ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for ACLDiffTest ser-deserialization


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

Branch: refs/heads/master
Commit: 19710d410fc1274b8cdaaeba93b0715a3a22cb31
Parents: b458e40
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 15:58:44 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 ...MailboxACLUpdatedEventSerializationTest.java | 402 -------------------
 .../james/event/json/dtos/ACLDiffTest.java      | 108 +++++
 2 files changed, 108 insertions(+), 402 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/19710d41/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index 7176c91..a4cefb3 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -29,7 +29,6 @@ import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -38,8 +37,6 @@ import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
-import com.fasterxml.jackson.core.JsonParseException;
-
 class MailboxACLUpdatedEventSerializationTest {
 
     private static final User USER = User.fromUsername("user");
@@ -230,405 +227,6 @@ class MailboxACLUpdatedEventSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnOldACL {
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingOldACLinACLDiff() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Nested
-            class DeserializationErrorOnOldACLEntryKey {
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"$\":\"ar\"}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(IllegalStateException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{1234:\"ar\"}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(JsonParseException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"\":\"ar\"}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(IllegalArgumentException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNullEntryKey() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{null:\"ar\"}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(JsonParseException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"-\":\"ar\"}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(StringIndexOutOfBoundsException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnOldACLRight {
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInMailboxACL() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"$any\":\"unsupported\"}," +
-                        "       \"newACL\":{\"$any\":\"a\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(UnsupportedRightException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"$any\":null}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenRightIsNotStringInMailboxACL() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"$any\":1234}}," +
-                        "       \"newACL\":{}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-            }
-        }
-
-        @Nested
-        class DeserializationErrorOnNewACL {
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingNewACLinACLDiff() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Nested
-            class DeserializationErrorOnNewACLEntryKey {
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"user\":\"bob\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                        .isInstanceOf(IllegalStateException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{1234:\"ar\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(JsonParseException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"\":\"ar\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(IllegalArgumentException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNullEntryKey() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{null:\"ar\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(JsonParseException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"-\":\"ar\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(StringIndexOutOfBoundsException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnNewACLRight {
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInNewACL() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{\"$any\":\"a\"}," +
-                        "       \"newACL\":{\"$any\":\"unsupported\"}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(UnsupportedRightException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":null}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenRightIsNotString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":\"#private\"," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":1234}}," +
-                        "    \"mailboxId\":\"23\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-        }
-
         @Test
         void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(

http://git-wip-us.apache.org/repos/asf/james-project/blob/19710d41/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
new file mode 100644
index 0000000..8288261
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
@@ -0,0 +1,108 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsString;
+import play.api.libs.json.Json;
+import scala.math.BigDecimal;
+
+class ACLDiffTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void deSerializeShouldThrowWhenNewACLIsMissing() {
+        assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+            "{\"oldACL\":{}}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void deSerializeShouldThrowWhenOldACLIsMissing() {
+        assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+            "{\"newACL\":{}}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Nested
+    class EntryKeyTest {
+        @Test
+        void deSerializeShouldThrowWhenNotIncludedNameInEntryKey() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$")))
+                .isInstanceOf(IllegalStateException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenNameInEntryKeyIsEmpty() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("")))
+                .isInstanceOf(IllegalArgumentException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenNameInEntryKeyIsNotWellFormatted() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-")))
+                .isInstanceOf(StringIndexOutOfBoundsException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenNameInEntryKeyIsNull() {
+            assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$))
+                .isInstanceOf(JsError.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenNameInEntryKeyIsNotString() {
+            assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+                .isInstanceOf(JsError.class);
+        }
+    }
+
+    @Nested
+    class RightTest {
+        @Test
+        void deSerializeShouldThrowWhenUnsupportedRightInNewACL() {
+            assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsString("\"unsupported\"")))
+                .isInstanceOf(JsError.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenNull() {
+            assertThat(JSON_SERIALIZE.aclDiffReads().reads(JsNull$.MODULE$))
+                .isInstanceOf(JsError.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenRightIsNotString() {
+            assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+                .isInstanceOf(JsError.class);
+        }
+    }
+}


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


[16/47] james-project git commit: MAILBOX-359 Use val to avoid too much class instanciations

Posted by bt...@apache.org.
MAILBOX-359 Use val to avoid too much class instanciations


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

Branch: refs/heads/master
Commit: 6f8cb2291c5747105df6fc2689726f9da8a746bf
Parents: 0cdd567
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 25 15:59:19 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:38 2019 +0700

----------------------------------------------------------------------
 .../org/apache/james/event/json/EventSerializer.scala  | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6f8cb229/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 3628e37..6daf248 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -311,17 +311,16 @@ class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: Messa
     def fromJson(json: String): JsResult[Event] = Json.fromJson[Event](Json.parse(json))
   }
 
-  def toJson(event: JavaEvent): String = new EventSerializerPrivateWrapper().toJson(ScalaConverter.toScala(event))
-  def fromJson(json: String): JsResult[JavaEvent] = new EventSerializerPrivateWrapper().fromJson(json)
+  private val eventSerializerPrivateWrapper = new EventSerializerPrivateWrapper()
+  def toJson(event: JavaEvent): String = eventSerializerPrivateWrapper.toJson(ScalaConverter.toScala(event))
+  def fromJson(json: String): JsResult[JavaEvent] = eventSerializerPrivateWrapper.fromJson(json)
     .map(event => event.toJava)
 }
 
 class EventSerializer(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
-  def toJson(event: JavaEvent): String = new JsonSerialize(mailboxIdFactory, messageIdFactory).toJson(event)
+  private val jsonSerialize = new JsonSerialize(mailboxIdFactory, messageIdFactory)
 
-  def fromJson(json: String): JsResult[JavaEvent] = {
-    new JsonSerialize(mailboxIdFactory, messageIdFactory)
-      .fromJson(json)
-  }
+  def toJson(event: JavaEvent): String = jsonSerialize.toJson(event)
+  def fromJson(json: String): JsResult[JavaEvent] = jsonSerialize.fromJson(json)
 }
 


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


[22/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for MailboxDeletion event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for MailboxDeletion event


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

Branch: refs/heads/master
Commit: 7ceb951cba15df620a63f28d5dfd313527aaa430
Parents: 886ad16
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 12:03:00 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 53 +++++++++++++++-----
 .../store/event/MailboxEventDispatcher.java     |  8 ++-
 .../event/MailboxAnnotationListenerTest.java    | 18 +++----
 3 files changed, 56 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index e87f967..a05e561 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -51,7 +51,7 @@ public class EventFactory {
         protected User user;
         protected MailboxSession.SessionId sessionId;
 
-        abstract T backReference();
+        protected abstract T backReference();
 
         public T mailbox(Mailbox mailbox) {
             path(mailbox.generateAssociatedPath());
@@ -85,7 +85,7 @@ public class EventFactory {
             return backReference();
         }
 
-        void mailboxEventChecks() {
+        protected void mailboxEventChecks() {
             Preconditions.checkState(user != null, "Field `user` is compulsory");
             Preconditions.checkState(mailboxId != null, "Field `mailboxId` is compulsory");
             Preconditions.checkState(path != null, "Field `path` is compulsory");
@@ -95,7 +95,7 @@ public class EventFactory {
 
     public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
         @Override
-        MailboxAddedBuilder backReference() {
+        protected MailboxAddedBuilder backReference() {
             return this;
         }
 
@@ -106,6 +106,41 @@ public class EventFactory {
         }
     }
 
+    public static class MailboxDeletionBuilder extends MailboxEventBuilder<MailboxDeletionBuilder> {
+        private QuotaRoot quotaRoot;
+        private QuotaCount deletedMessageCount;
+        private QuotaSize totalDeletedSize;
+
+        @Override
+        protected MailboxDeletionBuilder backReference() {
+            return this;
+        }
+
+        public MailboxDeletionBuilder quotaRoot(QuotaRoot quotaRoot) {
+            this.quotaRoot = quotaRoot;
+            return this;
+        }
+
+        public MailboxDeletionBuilder deletedMessageCount(QuotaCount deletedMessageCount) {
+            this.deletedMessageCount = deletedMessageCount;
+            return this;
+        }
+
+        public MailboxDeletionBuilder totalDeletedSize(QuotaSize totalDeletedSize) {
+            this.totalDeletedSize = totalDeletedSize;
+            return this;
+        }
+
+        public MailboxListener.MailboxDeletion build() {
+            mailboxEventChecks();
+            Preconditions.checkState(quotaRoot != null, "Field `quotaRoot` is compulsory");
+            Preconditions.checkState(deletedMessageCount != null, "Field `deletedMessageCount` is compulsory");
+            Preconditions.checkState(totalDeletedSize != null, "Field `totalDeletedSize` is compulsory");
+
+            return new MailboxListener.MailboxDeletion(sessionId, user, path, quotaRoot, deletedMessageCount, totalDeletedSize, mailboxId);
+        }
+    }
+
     public static class FlagsUpdatedBuilder extends MailboxEventBuilder<FlagsUpdatedBuilder> {
         private final ImmutableList.Builder<UpdatedFlags> updatedFlags;
 
@@ -124,7 +159,7 @@ public class EventFactory {
         }
 
         @Override
-        FlagsUpdatedBuilder backReference() {
+        protected FlagsUpdatedBuilder backReference() {
             return this;
         }
 
@@ -165,14 +200,8 @@ public class EventFactory {
         return new MailboxListener.MailboxRenamed(sessionId, user, from, to.getMailboxId(), to.generateAssociatedPath());
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot,
-                                                          QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return mailboxDeleted(session.getSessionId(), session.getUser(), mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
-    }
-
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
-                                                          QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return new MailboxListener.MailboxDeletion(sessionId, user, mailbox.generateAssociatedPath(), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
+    public MailboxDeletionBuilder mailboxDeleted() {
+        return new MailboxDeletionBuilder();
     }
 
     public MailboxAddedBuilder mailboxAdded() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index aabd204..ca4076f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -149,7 +149,13 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        event(eventFactory.mailboxDeleted(session, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
+        event(eventFactory.mailboxDeleted()
+            .mailboxSession(session)
+            .mailbox(mailbox)
+            .quotaRoot(quotaRoot)
+            .deletedMessageCount(deletedMessageCount)
+            .totalDeletedSize(totalDeletedSize)
+            .build());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 1ccca6a..cb6f7e1 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -42,8 +42,6 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -69,8 +67,6 @@ public class MailboxAnnotationListenerTest {
     @Mock private AnnotationMapper annotationMapper;
     @Mock private MailboxId mailboxId;
 
-    private Mailbox mailbox;
-    private EventFactory eventFactory;
     private MailboxAnnotationListener listener;
     private MailboxListener.MailboxEvent deleteEvent;
     private MailboxSession mailboxSession;
@@ -80,13 +76,15 @@ public class MailboxAnnotationListenerTest {
         MockitoAnnotations.initMocks(this);
         mailboxSession = MailboxSessionUtil.create("test");
         listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager);
-        eventFactory = new EventFactory();
-        mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, mailboxId);
 
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
-        QuotaCount quotaCount = QuotaCount.count(123);
-        QuotaSize quotaSize = QuotaSize.size(456);
-        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
+        deleteEvent = new EventFactory().mailboxDeleted()
+            .mailboxSession(mailboxSession)
+            .mailboxId(mailboxId)
+            .path(MailboxPath.forUser("user", "name"))
+            .quotaRoot(QuotaRoot.quotaRoot("root", Optional.empty()))
+            .deletedMessageCount(QuotaCount.count(123))
+            .totalDeletedSize(QuotaSize.size(456))
+            .build();
 
         when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
             .thenReturn(mailboxSession);


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


[11/47] james-project git commit: MAILBOX-359 Factorize tests for MessageMetaData ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for MessageMetaData ser-deserialization


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

Branch: refs/heads/master
Commit: c6aebcc7dc82fdd6012cbae4e38d137a01bfddba
Parents: ba9ff0d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 15:17:44 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      | 595 +-----------------
 .../event/json/ExpungedSerializationTest.java   | 596 +------------------
 .../james/event/json/dtos/MessageIdTest.java    |  71 +++
 .../event/json/dtos/MessageMetaDataTest.java    | 348 +++++++++++
 4 files changed, 461 insertions(+), 1149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index 8246e77..327d5ba 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -139,112 +139,6 @@ class AddedSerializationTest {
     }
 
     @Nested
-    class WithInternalDate {
-
-        @Test
-        void addedShouldDeserializeWhenInternalDateIsInGoodISOFormat() {
-            SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID));
-            MailboxListener.Added eventRoundToMillis = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51+00:00\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMillis);
-        }
-
-        @Test
-        void addedShouldDeserializeWhenInternalDateIsMissingMilliSeconds() {
-            SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID));
-            MailboxListener.Added eventRoundToMillis = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMillis);
-        }
-
-        @Test
-        void addedShouldDeserializeWhenInternalDateIsMissingSeconds() {
-            SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:00Z")), MESSAGE_ID));
-            MailboxListener.Added eventRoundToMinute = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMinute);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void addedShouldThrowWhenMissingSessionId() {
@@ -358,12 +252,10 @@ class AddedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnAddedMap {
-            @Test
-            void addedShouldThrowWhenMapKeyIsNull() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void addedShouldThrowWhenMapKeyIsNull() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Added\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -377,469 +269,24 @@ class AddedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenMessageUidIsMissing() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Nested
-            class DeserializationErrorOnModSeq {
-
-                @Test
-                void addedShouldThrowWhenModSeqIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenModSeqIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": null," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnSize {
-
-                @Test
-                void addedShouldThrowWhenSizeIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": \"45\",  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSizeIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": null,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMessageId {
-
-                @Test
-                void addedShouldThrowWhenMessageIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": 42" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenMessageIdIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": null" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnInternalDate {
-                @Test
-                void addedShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14 12:52:36+07:00\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateContainsOnlyDate() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateIsMissingHourPart() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14TZ\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateIsMissingTimeZone() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateIsMissingHours() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateIsEmpty() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenInternalDateIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": null," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        }
 
-            @Test
-            void addedShouldThrowWhenFlagsIsNull() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": null," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+        @Test
+        void addedShouldThrowWhenMissingAdded() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"Added\": {" +
+                    "    \"path\": {" +
+                    "      \"namespace\": \"#private\"," +
+                    "      \"user\": \"user\"," +
+                    "      \"name\": \"mailboxName\"" +
+                    "    }," +
+                    "    \"mailboxId\": \"18\"," +
+                    "    \"sessionId\": 42," +
+                    "    \"user\": \"user\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 2f1ca46..0e46b59 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -139,112 +139,6 @@ class ExpungedSerializationTest {
     }
 
     @Nested
-    class WithInternalDate {
-
-        @Test
-        void expungedShouldDeserializeWhenInternalDateIsInGoodISOFormat() {
-            Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID));
-            MailboxListener.Expunged eventRoundToMillis = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51+00:00\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMillis);
-        }
-
-        @Test
-        void expungedShouldDeserializeWhenInternalDateIsMissingMilliSeconds() {
-            Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID));
-            MailboxListener.Expunged eventRoundToMillis = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMillis);
-        }
-
-        @Test
-        void expungedShouldDeserializeWhenInternalDateIsMissingSeconds() {
-            Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of(
-                MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:00Z")), MESSAGE_ID));
-            MailboxListener.Expunged eventRoundToMinute = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged);
-
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(eventRoundToMinute);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void expungedShouldThrowWhenMissingSessionId() {
@@ -358,12 +252,10 @@ class ExpungedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnExpungedMap {
-            @Test
-            void expungedShouldThrowWhenMapKeyIsNull() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void expungedShouldThrowWhenMapKeyIsNull() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Expunged\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -377,470 +269,24 @@ class ExpungedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenMessageUidIsMissing() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Nested
-            class DeserializationErrorOnModSeq {
-
-                @Test
-                void expungedShouldThrowWhenModSeqIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenModSeqIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": null," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-
-            @Nested
-            class DeserializationErrorOnSize {
-
-                @Test
-                void expungedShouldThrowWhenSizeIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": \"45\",  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenSizeIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": null,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMessageId {
-
-                @Test
-                void expungedShouldThrowWhenMessageIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": 42" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenMessageIdIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": null" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnInternalDate {
-                @Test
-                void expungedShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14 12:52:36+07:00\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateContainsOnlyDate() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateIsMissingHourPart() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14TZ\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateIsMissingTimeZone() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateIsMissingHours() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateIsEmpty() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenInternalDateIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": null," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        }
 
-            @Test
-            void addedShouldThrowWhenFlagsIsNull() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": null," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+        @Test
+        void expungedShouldThrowWhenMissingExpunged() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"Expunged\": {" +
+                    "    \"path\": {" +
+                    "      \"namespace\": \"#private\"," +
+                    "      \"user\": \"user\"," +
+                    "      \"name\": \"mailboxName\"" +
+                    "    }," +
+                    "    \"mailboxId\": \"18\"," +
+                    "    \"sessionId\": 42," +
+                    "    \"user\": \"user\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
new file mode 100644
index 0000000..21426fa
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class MessageIdTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void messageIdShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.messageIdWrites().writes(TestMessageId.of(18)))
+            .isEqualTo(new JsString("18"));
+    }
+
+    @Test
+    void messageIdShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsString("18")))
+            .isEqualTo(new JsSuccess<>(TestMessageId.of(18), new JsPath(List.empty())));
+    }
+
+    @Test
+    void messageIdDeserializationShouldReturnErrorWhenNumber() {
+        assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void messageIdDeserializationShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void messageIdDeserializationShouldThrowWhenInvalid() {
+        assertThatThrownBy(() -> JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid")))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
new file mode 100644
index 0000000..b8169b5
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
@@ -0,0 +1,348 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.time.Instant;
+import java.util.NoSuchElementException;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.Json;
+
+class MessageMetaDataTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Nested
+    class StructureTest {
+        @Test
+        void deserializeShouldThrowWhenNoFlags() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenNoUid() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenNoModSeq() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenNoSize() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenNoInternalDate() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenNoMessageId() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+    }
+
+    @Nested
+    class ModSeqTest {
+        @Test
+        void deserializeShouldThrowWhenNullModSeq() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": null," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenStringModSeq() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": \"42\"," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+    }
+
+    @Nested
+    class SizeTest {
+        @Test
+        void deserializeShouldThrowWhenNullSize() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": null," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deserializeShouldThrowWhenStringSize() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": \"42\"," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+    }
+
+    @Nested
+    class DeserializationErrorOnInternalDate {
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14 12:52:36+07:00\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateContainsOnlyDate() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsMissingHourPart() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14TZ\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsMissingTimeZone() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsMissingHours() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsEmpty() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldThrowWhenInternalDateIsNull() {
+            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": null," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void deSerializeShouldParseValidISOInstants() {
+            assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51+00:00\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get()
+                    .internalDate())
+                .isEqualTo(Instant.parse("2018-12-14T09:41:51Z"));
+        }
+
+        @Test
+        void deSerializeShouldParseWhenInternalDateIsMissingMilliSeconds() {
+            assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+                    "        \"uid\": 123456," +
+                    "        \"size\": 42," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"modSeq\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51+00:00\"," +
+                    "        \"messageId\": \"42\"" +
+                    "}"))
+                    .get()
+                    .internalDate())
+                .isEqualTo(Instant.parse("2018-12-14T09:41:51Z"));
+        }
+    }
+}
\ No newline at end of file


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


[12/47] james-project git commit: MAILBOX-359 Factorize tests for MessageUid ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for MessageUid ser-deserialization


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

Branch: refs/heads/master
Commit: ba9ff0d6c6d67cafb5e58f5feb0eb64a27632599
Parents: 5d365c1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 14:44:04 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      | 43 +---------
 .../event/json/ExpungedSerializationTest.java   | 43 +---------
 .../json/FlagsUpdatedSerializationTest.java     | 83 --------------------
 .../james/event/json/dtos/MessageUidTest.java   | 65 +++++++++++++++
 4 files changed, 73 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ba9ff0d6/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index 61ce957..8246e77 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -379,43 +379,10 @@ class AddedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
             }
 
-            @Nested
-            class DeserializationErrorOnMessageUid {
-
-                @Test
-                void addedShouldThrowWhenMessageUidIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": \"123456\"," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenMessageUidIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
+            @Test
+            void addedShouldThrowWhenMessageUidIsMissing() {
+                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                    "{" +
                         "  \"Added\": {" +
                         "    \"path\": {" +
                         "      \"namespace\": \"#private\"," +
@@ -425,7 +392,6 @@ class AddedSerializationTest {
                         "    \"mailboxId\": \"18\"," +
                         "    \"added\": {" +
                         "      \"123456\": {" +
-                        "        \"uid\": null," +
                         "        \"modSeq\": 35," +
                         "        \"flags\": {" +
                         "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
@@ -440,7 +406,6 @@ class AddedSerializationTest {
                         "  }" +
                         "}").get())
                     .isInstanceOf(NoSuchElementException.class);
-                }
             }
 
             @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/ba9ff0d6/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 336aafa..2f1ca46 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -379,43 +379,10 @@ class ExpungedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
             }
 
-            @Nested
-            class DeserializationErrorOnMessageUid {
-
-                @Test
-                void expungedShouldThrowWhenMessageUidIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": \"123456\"," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenMessageUidIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
+            @Test
+            void expungedShouldThrowWhenMessageUidIsMissing() {
+                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                    "{" +
                         "  \"Expunged\": {" +
                         "    \"path\": {" +
                         "      \"namespace\": \"#private\"," +
@@ -425,7 +392,6 @@ class ExpungedSerializationTest {
                         "    \"mailboxId\": \"18\"," +
                         "    \"expunged\": {" +
                         "      \"123456\": {" +
-                        "        \"uid\": null," +
                         "        \"modSeq\": 35," +
                         "        \"flags\": {" +
                         "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
@@ -440,7 +406,6 @@ class ExpungedSerializationTest {
                         "  }" +
                         "}").get())
                     .isInstanceOf(NoSuchElementException.class);
-                }
             }
 
             @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/ba9ff0d6/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 2c9bc1e..12874ee 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -299,89 +299,6 @@ class FlagsUpdatedSerializationTest {
 
         @Nested
         class DeserializationErrorOnUpdatedFlags {
-
-            @Nested
-            class DeserializationErrorOnUid {
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUidIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": \"123456\"," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUidIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": null," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUidIsNotALongNumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 12563.3564," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
             @Nested
             class DeserializationErrorOnMoqSeq {
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ba9ff0d6/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
new file mode 100644
index 0000000..55f2a25
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
@@ -0,0 +1,65 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class MessageUidTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void messageUidShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18)))
+            .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
+    }
+
+    @Test
+    void messageUidShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isEqualTo(new JsSuccess<>(MessageUid.of(18), new JsPath(List.empty())));
+    }
+
+    @Test
+    void messageUidShouldReturnErrorWhenString() {
+        assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsString("18")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void messageUidShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+}


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


[41/47] james-project git commit: JAMES-2641 Remove MailboxEventDispatcher

Posted by bt...@apache.org.
http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 6ec668d..4b5e994 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -65,8 +65,8 @@ import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -133,36 +133,25 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
     private static final Logger LOG = LoggerFactory.getLogger(StoreMessageManager.class);
 
     private final EnumSet<MailboxManager.MessageCapabilities> messageCapabilities;
-
+    private final DelegatingMailboxListener delegatingMailboxListener;
     private final Mailbox mailbox;
-
-    private final MailboxEventDispatcher dispatcher;
-
     private final MailboxSessionMapperFactory mapperFactory;
-
     private final MessageSearchIndex index;
-
     private final StoreRightManager storeRightManager;
-
     private final QuotaManager quotaManager;
-
     private final QuotaRootResolver quotaRootResolver;
-
     private final MailboxPathLocker locker;
-
     private final MessageParser messageParser;
-
     private final Factory messageIdFactory;
-    
-    private BatchSizes batchSizes = BatchSizes.defaultValues();
+    private final BatchSizes batchSizes;
 
-    public StoreMessageManager(EnumSet<MailboxManager.MessageCapabilities> messageCapabilities, MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher,
+    public StoreMessageManager(EnumSet<MailboxManager.MessageCapabilities> messageCapabilities, MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, DelegatingMailboxListener delegatingMailboxListener,
                                MailboxPathLocker locker, Mailbox mailbox,
                                QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser, MessageId.Factory messageIdFactory, BatchSizes batchSizes,
                                StoreRightManager storeRightManager) {
         this.messageCapabilities = messageCapabilities;
+        this.delegatingMailboxListener = delegatingMailboxListener;
         this.mailbox = mailbox;
-        this.dispatcher = dispatcher;
         this.mapperFactory = mapperFactory;
         this.index = index;
         this.locker = locker;
@@ -188,15 +177,6 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
     }
 
     /**
-     * Return the {@link MailboxEventDispatcher} for this Mailbox
-     * 
-     * @return dispatcher
-     */
-    protected MailboxEventDispatcher getDispatcher() {
-        return dispatcher;
-    }
-
-    /**
      * Return the underlying {@link Mailbox}
      * 
      * @return mailbox
@@ -276,7 +256,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         }
         Map<MessageUid, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession);
 
-        dispatcher.event(EventFactory.expunged()
+        delegatingMailboxListener.event(EventFactory.expunged()
             .mailboxSession(mailboxSession)
             .mailbox(getMailboxEntity())
             .metaData(ImmutableSortedMap.copyOf(uids))
@@ -422,7 +402,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
                         Mailbox mailbox = getMailboxEntity();
                         MailboxMessage copy = copyMessage(message);
-                        dispatcher.event(EventFactory.added()
+                        delegatingMailboxListener.event(EventFactory.added()
                             .mailboxSession(mailboxSession)
                             .mailbox(mailbox)
                             .addMessage(copy)
@@ -583,7 +563,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         Iterator<UpdatedFlags> it = messageMapper.execute(() -> messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(flags, flagsUpdateMode), set));
         List<UpdatedFlags> updatedFlags = Iterators.toStream(it).collect(Guavate.toImmutableList());
 
-        dispatcher.event(EventFactory.flagsUpdated()
+        delegatingMailboxListener.event(EventFactory.flagsUpdated()
             .mailboxSession(mailboxSession)
             .mailbox(getMailboxEntity())
             .updatedFlags(updatedFlags)
@@ -746,12 +726,12 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
             messageIds.add(message.getMessageId());
         }
 
-        dispatcher.event(EventFactory.added()
+        delegatingMailboxListener.event(EventFactory.added()
             .mailboxSession(session)
             .mailbox(to.getMailboxEntity())
             .metaData(copiedUids)
             .build());
-        dispatcher.event(EventFactory.moved()
+        delegatingMailboxListener.event(EventFactory.moved()
             .session(session)
             .messageMoves(MessageMoves.builder()
                 .previousMailboxIds(getMailboxEntity().getMailboxId())
@@ -774,17 +754,17 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
             messageIds.add(message.getMessageId());
         }
 
-        dispatcher.event(EventFactory.added()
+        delegatingMailboxListener.event(EventFactory.added()
             .mailboxSession(session)
             .mailbox(to.getMailboxEntity())
             .metaData(moveUids)
             .build());
-        dispatcher.event(EventFactory.expunged()
+        delegatingMailboxListener.event(EventFactory.expunged()
             .mailboxSession(session)
             .mailbox(getMailboxEntity())
             .addMetaData(moveResult.getOriginalMessages())
             .build());
-        dispatcher.event(EventFactory.moved()
+        delegatingMailboxListener.event(EventFactory.moved()
             .messageMoves(MessageMoves.builder()
                 .previousMailboxIds(getMailboxEntity().getMailboxId())
                 .targetMailboxIds(to.getMailboxEntity().getMailboxId())

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index df0924c..bcd6959 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -43,8 +43,8 @@ import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
@@ -55,7 +55,7 @@ import com.google.common.collect.ImmutableMap;
 public class StoreRightManager implements RightManager {
     public static final boolean GROUP_FOLDER = true;
 
-    private final MailboxEventDispatcher dispatcher;
+    private final DelegatingMailboxListener delegatingMailboxListener;
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
     private final MailboxACLResolver aclResolver;
     private final GroupMembershipResolver groupMembershipResolver;
@@ -64,11 +64,11 @@ public class StoreRightManager implements RightManager {
     public StoreRightManager(MailboxSessionMapperFactory mailboxSessionMapperFactory,
                              MailboxACLResolver aclResolver,
                              GroupMembershipResolver groupMembershipResolver,
-                             MailboxEventDispatcher dispatcher) {
+                             DelegatingMailboxListener delegatingMailboxListener) {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
         this.aclResolver = aclResolver;
         this.groupMembershipResolver = groupMembershipResolver;
-        this.dispatcher = dispatcher;
+        this.delegatingMailboxListener = delegatingMailboxListener;
     }
 
     @Override
@@ -139,7 +139,7 @@ public class StoreRightManager implements RightManager {
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
         ACLDiff aclDiff = mapper.updateACL(mailbox, mailboxACLCommand);
 
-        dispatcher.event(EventFactory.aclUpdated()
+        delegatingMailboxListener.event(EventFactory.aclUpdated()
             .mailboxSession(session)
             .mailbox(mailbox)
             .aclDiff(aclDiff)
@@ -221,7 +221,7 @@ public class StoreRightManager implements RightManager {
     private void setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
         ACLDiff aclDiff = mapper.setACL(mailbox, mailboxACL);
 
-        dispatcher.event(EventFactory.aclUpdated()
+        delegatingMailboxListener.event(EventFactory.aclUpdated()
             .mailboxSession(session)
             .mailbox(mailbox)
             .aclDiff(aclDiff)

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
deleted file mode 100644
index d3d02ea..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.store.event;
-
-import javax.inject.Inject;
-
-import org.apache.james.mailbox.Event;
-import org.apache.james.mailbox.MailboxListener;
-
-/**
- * Helper class to dispatch {@link org.apache.james.mailbox.Event}'s to registerend MailboxListener
- */
-public class MailboxEventDispatcher {
-    private final MailboxListener listener;
-
-    @Inject
-    public MailboxEventDispatcher(DelegatingMailboxListener delegatingMailboxListener) {
-        this.listener = delegatingMailboxListener;
-    }
-    
-    public void event(Event event) {
-        listener.event(event);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index baa33fe..e27bccc 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -30,8 +30,8 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,14 +41,14 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
 
     private final StoreCurrentQuotaManager currentQuotaManager;
     private final QuotaRootResolver quotaRootResolver;
-    private final MailboxEventDispatcher dispatcher;
+    private final DelegatingMailboxListener delegatingMailboxListener;
     private final QuotaManager quotaManager;
 
     @Inject
-    public ListeningCurrentQuotaUpdater(StoreCurrentQuotaManager currentQuotaManager, QuotaRootResolver quotaRootResolver, MailboxEventDispatcher dispatcher, QuotaManager quotaManager) {
+    public ListeningCurrentQuotaUpdater(StoreCurrentQuotaManager currentQuotaManager, QuotaRootResolver quotaRootResolver, DelegatingMailboxListener delegatingMailboxListener, QuotaManager quotaManager) {
         this.currentQuotaManager = currentQuotaManager;
         this.quotaRootResolver = quotaRootResolver;
-        this.dispatcher = dispatcher;
+        this.delegatingMailboxListener = delegatingMailboxListener;
         this.quotaManager = quotaManager;
     }
 
@@ -89,7 +89,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.event(
+        delegatingMailboxListener.event(
             EventFactory.quotaUpdated()
                 .user(expunged.getUser())
                 .quotaRoot(quotaRoot)
@@ -110,7 +110,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.event(
+        delegatingMailboxListener.event(
             EventFactory.quotaUpdated()
                 .user(added.getUser())
                 .quotaRoot(quotaRoot)

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
index f1f2c2f..0ea9730 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
@@ -51,7 +51,7 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.util.EventCollector;
 import org.assertj.core.api.AbstractListAssert;
@@ -87,7 +87,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
     private EventCollector eventCollector;
     private DefaultDelegatingMailboxListener delegatingMailboxListener;
 
-    protected abstract MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception;
+    protected abstract MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) throws Exception;
 
     public void setUp() throws Exception {
         delegatingMailboxListener = new DefaultDelegatingMailboxListener();
@@ -95,7 +95,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         quotaManager = mock(QuotaManager.class);
 
         session = MailboxSessionUtil.create(ALICE);
-        testingData = createTestSystem(quotaManager, new MailboxEventDispatcher(delegatingMailboxListener));
+        testingData = createTestSystem(quotaManager, delegatingMailboxListener);
         messageIdManager = testingData.getMessageIdManager();
 
         mailbox1 = testingData.createMailbox(MailboxFixture.INBOX_ALICE, session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index 0e549fe..fd31281 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -82,7 +82,7 @@ public class MessageIdManagerTestSystem {
             Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
             MailboxMessage message = createMessage(mailboxId, flags, messageId, uid);
             mapperFactory.getMessageMapper(mailboxSession).add(mailbox, message);
-            mailboxManager.getEventDispatcher().event(EventFactory.added()
+            mailboxManager.getDelegationListener().event(EventFactory.added()
                 .mailboxSession(mailboxSession)
                 .mailbox(mailbox)
                 .addMessage(message)

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
index 1d29356..71e0e93 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
@@ -43,7 +43,6 @@ import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.model.search.PrefixedRegex;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -77,15 +76,14 @@ public class StoreMailboxManagerTest {
         authenticator.addUser(ADMIN, ADMIN_PASSWORD);
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
 
         StoreRightManager storeRightManager = new StoreRightManager(mockedMapperFactory, new UnionMailboxACLResolver(),
-                                                                    new SimpleGroupMembershipResolver(), mailboxEventDispatcher);
+                                                                    new SimpleGroupMembershipResolver(), delegatingListener);
 
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mockedMapperFactory, storeRightManager);
         storeMailboxManager = new StoreMailboxManager(mockedMapperFactory, authenticator, FakeAuthorizator.forUserAndAdmin(ADMIN, CURRENT_USER),
                 new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory,
-                annotationManager, mailboxEventDispatcher, delegatingListener, storeRightManager);
+                annotationManager, delegatingListener, storeRightManager);
         storeMailboxManager.init();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index 0902262..5643181 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -46,7 +46,7 @@ import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -69,14 +69,11 @@ public class StoreRightManagerTest {
         mockedMailboxMapper = mock(MailboxMapper.class);
         mailboxAclResolver = new UnionMailboxACLResolver();
         groupMembershipResolver = new SimpleGroupMembershipResolver();
-        MailboxEventDispatcher dispatcher = mock(MailboxEventDispatcher.class);
+        DelegatingMailboxListener delegatingMailboxListener = mock(DelegatingMailboxListener.class);
         when(mockedMapperFactory.getMailboxMapper(aliceSession))
             .thenReturn(mockedMailboxMapper);
 
-        storeRightManager = new StoreRightManager(mockedMapperFactory,
-                                                  mailboxAclResolver,
-                                                  groupMembershipResolver,
-                                                  dispatcher);
+        storeRightManager = new StoreRightManager(mockedMapperFactory, mailboxAclResolver, groupMembershipResolver, delegatingMailboxListener);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index 0d62a90..27a38b2 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -42,7 +42,7 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.junit.Before;
 import org.junit.Test;
@@ -66,7 +66,7 @@ public class ListeningCurrentQuotaUpdaterTest {
         mockedQuotaRootResolver = mock(QuotaRootResolver.class);
         mockedCurrentQuotaManager = mock(StoreCurrentQuotaManager.class);
         testee = new ListeningCurrentQuotaUpdater(mockedCurrentQuotaManager, mockedQuotaRootResolver,
-            mock(MailboxEventDispatcher.class), mock(QuotaManager.class));
+            mock(DelegatingMailboxListener.class), mock(QuotaManager.class));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index 6df19d7..b78c89f 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -44,7 +44,6 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
@@ -85,13 +84,12 @@ public class CassandraHostSystem extends JamesImapHostSystem {
             messageIdFactory);
 
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), delegatingMailboxListener);
 
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
         mailboxManager = new CassandraMailboxManager(mapperFactory, authenticator, authorizator,
             new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory,
-            mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
+            delegatingMailboxListener, annotationManager, storeRightManager);
         QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory);
 
         perUserMaxQuotaManager = new CassandraPerUserMaxQuotaManager(
@@ -103,7 +101,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
 
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
 
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxEventDispatcher, quotaManager);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, delegatingMailboxListener, quotaManager);
 
         mailboxManager.setQuotaRootResolver(quotaRootResolver);
         mailboxManager.setQuotaManager(quotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 3e4f238..ff04b10 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -76,7 +76,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
 
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
 
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getDelegationListener(), quotaManager);
 
         mailboxManager.setQuotaRootResolver(quotaRootResolver);
         mailboxManager.setQuotaManager(quotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index c540145..641f0e3 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -48,7 +48,6 @@ import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
@@ -97,18 +96,16 @@ public class JPAHostSystem extends JamesImapHostSystem {
         MessageParser messageParser = new MessageParser();
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver, delegatingListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
         mailboxManager = new OpenJPAMailboxManager(mapperFactory, authenticator, authorizator,
-            messageParser, new DefaultMessageId.Factory(), delegatingListener,
-            mailboxEventDispatcher, annotationManager, storeRightManager);
+            messageParser, new DefaultMessageId.Factory(), delegatingListener, annotationManager, storeRightManager);
 
         DefaultUserQuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory);
         JpaCurrentQuotaManager currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);
         maxQuotaManager = new JPAPerUserMaxQuotaManager(new JPAPerUserMaxQuotaDAO(entityManagerFactory));
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager);
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, delegatingListener, storeQuotaManager);
 
         mailboxManager.setQuotaManager(storeQuotaManager);
         mailboxManager.setQuotaUpdater(quotaUpdater);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index b33b896..8a62e53 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -46,7 +46,6 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
@@ -98,10 +97,9 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
        
         try {
             DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
-            MailboxEventDispatcher dispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
-            
+
             InMemoryMailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
-            StoreRightManager rightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), dispatcher);
+            StoreRightManager rightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), delegatingMailboxListener);
             JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
             InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
             mailboxManager = new InMemoryMailboxManager(mapperFactory,
@@ -110,7 +108,6 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
                 locker,
                 new MessageParser(),
                 messageIdFactory,
-                dispatcher,
                 delegatingMailboxListener,
                 new StoreMailboxAnnotationManager(mapperFactory, rightManager),
                 rightManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
index a55cf7b..04ba896 100644
--- a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
+++ b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
@@ -41,7 +41,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
@@ -76,12 +75,10 @@ public class MaildirHostSystem extends JamesImapHostSystem {
         MessageParser messageParser = new MessageParser();
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, aclResolver, groupMembershipResolver, delegatingListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
         mailboxManager = new StoreMailboxManager(mailboxSessionMapperFactory, authenticator, authorizator, locker,
-            messageParser, new DefaultMessageId.Factory(), annotationManager,
-            mailboxEventDispatcher, delegatingListener, storeRightManager);
+            messageParser, new DefaultMessageId.Factory(), annotationManager, delegatingListener, storeRightManager);
         mailboxManager.init();
 
         ImapProcessor defaultImapProcessorFactory =

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
index ca41b79..ebd268f 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
@@ -84,7 +84,6 @@ import org.apache.james.mailbox.store.StoreBlobManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
@@ -142,7 +141,6 @@ public class CassandraMailboxModule extends AbstractModule {
         bind(CassandraMessageId.Factory.class).in(Scopes.SINGLETON);
         bind(CassandraModSeqProvider.class).in(Scopes.SINGLETON);
         bind(CassandraUidProvider.class).in(Scopes.SINGLETON);
-        bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);
         bind(NoMailboxPathLocker.class).in(Scopes.SINGLETON);
         bind(UserRepositoryAuthenticator.class).in(Scopes.SINGLETON);
         bind(UserRepositoryAuthorizator.class).in(Scopes.SINGLETON);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
index 85c4c5f..1847203 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
@@ -53,7 +53,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
@@ -117,7 +116,6 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(InMemoryMailboxManager.class).in(Scopes.SINGLETON);
         bind(InMemoryMessageId.Factory.class).in(Scopes.SINGLETON);
         bind(StoreMessageIdManager.class).in(Scopes.SINGLETON);
-        bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);
         bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
         bind(StoreRightManager.class).in(Scopes.SINGLETON);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index aab5c34..9456080 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -149,10 +149,6 @@
     </bean>
 
     <!-- Event system -->
-    <bean id="dispatcher" class="org.apache.james.mailbox.store.event.MailboxEventDispatcher">
-        <constructor-arg index="0" ref="delegating-listener"/>
-    </bean>
-
     <import resource="classpath:META-INF/spring/event-system.xml"/>
 
     <!-- Mailbox Copier -->


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


[44/47] james-project git commit: MAILBOX-367 Add mockito timeouts in EventBus contracts

Posted by bt...@apache.org.
MAILBOX-367 Add mockito timeouts in EventBus contracts

This allow asynchronous EventBus implementations
EventBusContract should also use verify no interaction in time window


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

Branch: refs/heads/master
Commit: f1ac8368ac641c7d5bc819a878ac725c649cdb27
Parents: a15bd70
Author: datph <dp...@linagora.com>
Authored: Mon Jan 7 10:27:25 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:47:47 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/events/EventBusContract.java  | 56 ++++++++++++--------
 1 file changed, 34 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f1ac8368/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
index 23743a5..465ed77 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
@@ -23,16 +23,17 @@ import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertTimeout;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.after;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 import java.time.Duration;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.james.core.User;
@@ -44,6 +45,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.TestId;
 import org.junit.jupiter.api.Test;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSortedMap;
 
@@ -58,11 +60,14 @@ public interface EventBusContract {
 
     class GroupB extends Group {}
 
+    int ONE_SECOND = 1000;
+    int FIVE_HUNDRED_MS = 500;
     MailboxId ID_1 = TestId.of(18);
     MailboxId ID_2 = TestId.of(24);
     ImmutableSet<RegistrationKey> NO_KEYS = ImmutableSet.of();
     MailboxIdRegistrationKey KEY_1 = new MailboxIdRegistrationKey(ID_1);
     MailboxIdRegistrationKey KEY_2 = new MailboxIdRegistrationKey(ID_2);
+    List<Class<? extends Group>> ALL_GROUPS = ImmutableList.of(GroupA.class, GroupB.class);
 
     EventBus eventBus();
 
@@ -80,7 +85,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -138,8 +143,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
 
-        verify(listener, times(1)).event(any());
-        verify(listener2, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
+        verify(listener2, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -150,7 +155,8 @@ public interface EventBusContract {
         registration.unregister();
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -195,7 +201,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -205,7 +211,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
 
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -215,7 +222,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_2)).block();
 
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -225,7 +233,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -237,8 +245,9 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verify(listener, times(1)).event(any());
-        verifyZeroInteractions(listener2);
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
+        verify(listener2, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -250,8 +259,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verify(listener, times(1)).event(any());
-        verify(listener2, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
+        verify(listener2, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -262,7 +271,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -273,7 +282,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -285,7 +295,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -296,7 +307,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -317,7 +328,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1, KEY_2)).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -328,7 +339,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1, KEY_2)).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test
@@ -338,7 +349,8 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
-        verifyZeroInteractions(listener);
+        verify(listener, after(FIVE_HUNDRED_MS).never())
+            .event(any());
     }
 
     @Test
@@ -349,7 +361,7 @@ public interface EventBusContract {
 
         eventBus().dispatch(EVENT, NO_KEYS).block();
 
-        verify(listener, times(1)).event(any());
+        verify(listener, timeout(ONE_SECOND).times(1)).event(any());
     }
 
     @Test


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


[43/47] james-project git commit: MAILBOX-367 RabbitMQEvenBus should publish events

Posted by bt...@apache.org.
MAILBOX-367 RabbitMQEvenBus should publish events


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

Branch: refs/heads/master
Commit: b1e241c4dc8e39174efa12eb400cd2a2f0cc633b
Parents: f1ac836
Author: datph <dp...@linagora.com>
Authored: Mon Jan 7 10:33:37 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:47:47 2019 +0700

----------------------------------------------------------------------
 .../backend/rabbitmq/RabbitMQExtension.java     |   9 +-
 mailbox/event/event-rabbitmq/pom.xml            | 101 ++++++++++++++++
 .../james/mailbox/events/RabbitMQEventBus.java  |  89 ++++++++++++++
 .../events/RabbitMQEventBusPublishingTest.java  | 121 +++++++++++++++++++
 mailbox/pom.xml                                 |   1 +
 pom.xml                                         |   7 +-
 6 files changed, 325 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQExtension.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQExtension.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQExtension.java
index d6d2ead..a64c95f 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQExtension.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQExtension.java
@@ -43,6 +43,7 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
 
     private DockerRabbitMQ rabbitMQ;
     private SimpleChannelPool simpleChannelPool;
+    private RabbitMQConnectionFactory connectionFactory;
 
     @Override
     public void beforeAll(ExtensionContext context) {
@@ -52,7 +53,7 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
 
     @Override
     public void beforeEach(ExtensionContext extensionContext) throws Exception {
-        RabbitMQConnectionFactory connectionFactory = createRabbitConnectionFactory();
+        connectionFactory = createRabbitConnectionFactory();
         this.simpleChannelPool = new SimpleChannelPool(connectionFactory);
     }
 
@@ -84,6 +85,10 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
         return rabbitMQ;
     }
 
+    public RabbitMQConnectionFactory getConnectionFactory() {
+        return connectionFactory;
+    }
+
     private RabbitMQConnectionFactory createRabbitConnectionFactory() throws URISyntaxException {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(rabbitMQ.amqpUri())
@@ -98,4 +103,4 @@ public class RabbitMQExtension implements BeforeAllCallback, BeforeEachCallback,
             rabbitMQConfiguration,
             new AsyncRetryExecutor(Executors.newSingleThreadScheduledExecutor(threadFactory)));
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/mailbox/event/event-rabbitmq/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/pom.xml b/mailbox/event/event-rabbitmq/pom.xml
new file mode 100644
index 0000000..c671468
--- /dev/null
+++ b/mailbox/event/event-rabbitmq/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>apache-james-mailbox</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.3.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>apache-james-mailbox-event-rabbitmq</artifactId>
+    <name>Apache James :: Mailbox :: Event :: RabbitMQ implementation</name>
+    <description>RabbitMQ implementation for the eventbus API</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-backends-rabbitmq</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-backends-rabbitmq</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-event-json</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.jayway.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor.rabbitmq</groupId>
+            <artifactId>reactor-rabbitmq</artifactId>
+            <version>1.0.0.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
new file mode 100644
index 0000000..4ce792a
--- /dev/null
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/RabbitMQEventBus.java
@@ -0,0 +1,89 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.events;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Set;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.james.backend.rabbitmq.RabbitMQConnectionFactory;
+import org.apache.james.event.json.EventSerializer;
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.MailboxListener;
+
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+import reactor.rabbitmq.ExchangeSpecification;
+import reactor.rabbitmq.OutboundMessage;
+import reactor.rabbitmq.RabbitFlux;
+import reactor.rabbitmq.Sender;
+import reactor.rabbitmq.SenderOptions;
+
+public class RabbitMQEventBus implements EventBus {
+    static final String MAILBOX_EVENT = "mailboxEvent";
+    static final String MAILBOX_EVENT_EXCHANGE_NAME = MAILBOX_EVENT + "-exchange";
+    static final String EMPTY_ROUTING_KEY = "";
+
+    private static final boolean DURABLE = true;
+    private static final String DIRECT_EXCHANGE = "direct";
+
+    private final EventSerializer eventSerializer;
+    private final Sender sender;
+
+    RabbitMQEventBus(RabbitMQConnectionFactory rabbitMQConnectionFactory, EventSerializer eventSerializer) {
+        this.eventSerializer = eventSerializer;
+        SenderOptions senderOption = new SenderOptions().connectionMono(Mono.fromSupplier(rabbitMQConnectionFactory::create));
+        this.sender = RabbitFlux.createSender(senderOption);
+    }
+
+    Mono<Void> start() {
+        return sender.declareExchange(ExchangeSpecification.exchange(MAILBOX_EVENT_EXCHANGE_NAME)
+                .durable(DURABLE)
+                .type(DIRECT_EXCHANGE))
+            .subscribeOn(Schedulers.elastic())
+            .then();
+    }
+
+    @Override
+    public Registration register(MailboxListener listener, RegistrationKey key) {
+        throw new NotImplementedException("will implement latter");
+    }
+
+    @Override
+    public Registration register(MailboxListener listener, Group group) {
+        throw new NotImplementedException("will implement latter");
+    }
+
+    @Override
+    public Mono<Void> dispatch(Event event, Set<RegistrationKey> key) {
+        Mono<OutboundMessage> outboundMessage = Mono.just(event)
+            .publishOn(Schedulers.parallel())
+            .map(this::serializeEvent)
+            .map(payload -> new OutboundMessage(MAILBOX_EVENT_EXCHANGE_NAME, EMPTY_ROUTING_KEY, payload));
+
+        Mono<Void> publishMono = sender.send(outboundMessage).cache();
+        publishMono.subscribe();
+        return publishMono;
+    }
+
+    private byte[] serializeEvent(Event event) {
+        return eventSerializer.toJson(event).getBytes(StandardCharsets.UTF_8);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusPublishingTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusPublishingTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusPublishingTest.java
new file mode 100644
index 0000000..50a37ca
--- /dev/null
+++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusPublishingTest.java
@@ -0,0 +1,121 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.events;
+
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_DELETE;
+import static org.apache.james.backend.rabbitmq.Constants.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.EXCLUSIVE;
+import static org.apache.james.backend.rabbitmq.Constants.NO_ARGUMENTS;
+import static org.apache.james.mailbox.events.EventBusContract.EVENT;
+import static org.apache.james.mailbox.events.EventBusContract.NO_KEYS;
+import static org.apache.james.mailbox.events.RabbitMQEventBus.EMPTY_ROUTING_KEY;
+import static org.apache.james.mailbox.events.RabbitMQEventBus.MAILBOX_EVENT;
+import static org.apache.james.mailbox.events.RabbitMQEventBus.MAILBOX_EVENT_EXCHANGE_NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.james.backend.rabbitmq.RabbitMQConnectionFactory;
+import org.apache.james.backend.rabbitmq.RabbitMQExtension;
+import org.apache.james.event.json.EventSerializer;
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import com.google.common.collect.ImmutableSet;
+
+import reactor.core.publisher.Mono;
+import reactor.rabbitmq.BindingSpecification;
+import reactor.rabbitmq.QueueSpecification;
+import reactor.rabbitmq.RabbitFlux;
+import reactor.rabbitmq.Receiver;
+import reactor.rabbitmq.ReceiverOptions;
+import reactor.rabbitmq.Sender;
+import reactor.rabbitmq.SenderOptions;
+
+class RabbitMQEventBusPublishingTest {
+    private static final String MAILBOX_WORK_QUEUE_NAME = MAILBOX_EVENT + "-workQueue";
+
+    @RegisterExtension
+    static RabbitMQExtension rabbitMQExtension = new RabbitMQExtension();
+
+    private RabbitMQEventBus eventBus;
+    private EventSerializer eventSerializer;
+    private RabbitMQConnectionFactory connectionFactory;
+
+    @BeforeEach
+    void setUp() {
+        connectionFactory = rabbitMQExtension.getConnectionFactory();
+
+        eventSerializer = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
+        eventBus = new RabbitMQEventBus(connectionFactory, eventSerializer);
+        eventBus.start().block();
+
+        createQueue();
+    }
+
+    private void createQueue() {
+        SenderOptions senderOption = new SenderOptions()
+            .connectionMono(Mono.fromSupplier(connectionFactory::create));
+        Sender sender = RabbitFlux.createSender(senderOption);
+
+        sender.declareQueue(QueueSpecification.queue(MAILBOX_WORK_QUEUE_NAME)
+            .durable(DURABLE)
+            .exclusive(!EXCLUSIVE)
+            .autoDelete(!AUTO_DELETE)
+            .arguments(NO_ARGUMENTS))
+            .block();
+        sender.bind(BindingSpecification.binding()
+            .exchange(MAILBOX_EVENT_EXCHANGE_NAME)
+            .queue(MAILBOX_WORK_QUEUE_NAME)
+            .routingKey(EMPTY_ROUTING_KEY))
+            .block();
+    }
+
+    @Test
+    void dispatchShouldPublishSerializedEventToRabbitMQ() {
+        eventBus.dispatch(EVENT, NO_KEYS).block();
+
+        assertThat(dequeueEvent()).isEqualTo(EVENT);
+    }
+
+    @Test
+    void dispatchShouldPublishSerializedEventToRabbitMQWhenNotBlocking() {
+        eventBus.dispatch(EVENT, NO_KEYS);
+
+        assertThat(dequeueEvent()).isEqualTo(EVENT);
+    }
+
+
+    private Event dequeueEvent() {
+        RabbitMQConnectionFactory connectionFactory = rabbitMQExtension.getConnectionFactory();
+        Receiver receiver = RabbitFlux.createReceiver(new ReceiverOptions().connectionMono(Mono.just(connectionFactory.create())));
+
+        byte[] eventInBytes = receiver.consumeAutoAck(MAILBOX_WORK_QUEUE_NAME)
+            .blockFirst()
+            .getBody();
+
+        return eventSerializer.fromJson(new String(eventInBytes, StandardCharsets.UTF_8))
+            .get();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/pom.xml b/mailbox/pom.xml
index f7f7869..e363b7e 100644
--- a/mailbox/pom.xml
+++ b/mailbox/pom.xml
@@ -42,6 +42,7 @@
         <module>elasticsearch</module>
 
         <module>event/event-memory</module>
+        <module>event/event-rabbitmq</module>
         <module>event/json</module>
 
         <module>jpa</module>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b1e241c4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1cc4a2d..56486ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -762,6 +762,11 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-mailbox-event-json</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
                 <artifactId>apache-james-mailbox-event-memory</artifactId>
                 <version>${project.version}</version>
             </dependency>
@@ -3376,4 +3381,4 @@
             -->
         </plugins>
     </reporting>
-</project>
+</project>
\ No newline at end of file


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


[29/47] james-project git commit: MAILBOX-359 Remove MailboxEventDispatcher::ofMailboxListener

Posted by bt...@apache.org.
MAILBOX-359 Remove MailboxEventDispatcher::ofMailboxListener


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

Branch: refs/heads/master
Commit: 1371fad66676f151dd349c6075b36823e3f488cc
Parents: 4eb7990
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 20 11:32:16 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../cassandra/CassandraCombinationManagerTest.java      |  8 ++++----
 .../cassandra/CassandraMessageIdManagerStorageTest.java |  8 ++++----
 .../mailbox/store/event/MailboxEventDispatcher.java     | 12 +-----------
 .../james/mailbox/store/MailboxEventDispatcherTest.java |  5 ++++-
 4 files changed, 13 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1371fad6/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
index f20e7fc..b2d0850 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
@@ -19,14 +19,12 @@
 
 package org.apache.james.mailbox.cassandra;
 
-import static org.mockito.Mockito.mock;
-
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule;
 import org.apache.james.mailbox.store.AbstractCombinationManagerTest;
 import org.apache.james.mailbox.store.CombinationManagerTestSystem;
+import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.junit.After;
@@ -64,7 +62,9 @@ public class CassandraCombinationManagerTest extends AbstractCombinationManagerT
     
     @Override
     public CombinationManagerTestSystem createTestingData() throws Exception {
-        return CassandraCombinationManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), MailboxEventDispatcher.ofListener(mock(MailboxListener.class)));
+        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
+        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(mailboxListener);
+        return CassandraCombinationManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), mailboxEventDispatcher);
     }
     
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1371fad6/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
index ae35def..6b9a519 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
@@ -19,14 +19,12 @@
 
 package org.apache.james.mailbox.cassandra;
 
-import static org.mockito.Mockito.mock;
-
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule;
 import org.apache.james.mailbox.store.AbstractMessageIdManagerStorageTest;
 import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
+import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.junit.After;
@@ -64,6 +62,8 @@ public class CassandraMessageIdManagerStorageTest extends AbstractMessageIdManag
     
     @Override
     protected MessageIdManagerTestSystem createTestingData() throws Exception {
-        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), MailboxEventDispatcher.ofListener(mock(MailboxListener.class)));
+        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
+        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(mailboxListener);
+        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), mailboxEventDispatcher);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1371fad6/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index f1deaab..5de959c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -46,7 +46,6 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedMap;
@@ -55,20 +54,11 @@ import com.google.common.collect.ImmutableSortedMap;
  * Helper class to dispatch {@link org.apache.james.mailbox.Event}'s to registerend MailboxListener
  */
 public class MailboxEventDispatcher {
-    @VisibleForTesting
-    public static MailboxEventDispatcher ofListener(MailboxListener mailboxListener) {
-        return new MailboxEventDispatcher(mailboxListener);
-    }
-
     private final MailboxListener listener;
 
     @Inject
     public MailboxEventDispatcher(DelegatingMailboxListener delegatingMailboxListener) {
-        this((MailboxListener) delegatingMailboxListener);
-    }
-
-    private MailboxEventDispatcher(MailboxListener listener) {
-        this.listener = listener;
+        this.listener = delegatingMailboxListener;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/1371fad6/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
index 955231b..24f5cab 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -68,7 +69,9 @@ public class MailboxEventDispatcherTest {
     public void setUp() throws Exception {
         collector = new EventCollector();
 
-        dispatcher = MailboxEventDispatcher.ofListener(collector);
+        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
+        mailboxListener.addGlobalListener(collector, session);
+        dispatcher = new MailboxEventDispatcher(mailboxListener);
         result = mock(MessageResult.class);
         mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, MAILBOX_ID);
 


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


[28/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for MailboxRenamed event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for MailboxRenamed event


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

Branch: refs/heads/master
Commit: b5608ad26ee9b306e5d9ee97e7aa5d15bf11f529
Parents: 098dbe4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 13:52:52 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 39 +++++++++++++++++---
 .../store/event/MailboxEventDispatcher.java     |  7 +++-
 2 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b5608ad2/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index de9ed6e..cc8a2f6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -242,6 +242,37 @@ public class EventFactory {
         }
     }
 
+    public static class MailboxRenamedBuilder extends MailboxEventBuilder<MailboxRenamedBuilder> {
+        private MailboxPath newPath;
+
+        @Override
+        protected MailboxRenamedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxRenamedBuilder newPath(MailboxPath newPath) {
+            this.newPath = newPath;
+            return this;
+        }
+
+        public MailboxRenamedBuilder oldPath(MailboxPath oldPath) {
+            this.path = oldPath;
+            return this;
+        }
+
+        public MailboxListener.MailboxRenamed build() {
+            mailboxEventChecks();
+            Preconditions.checkState(path != null, "Field `newPath` is compulsory");
+
+            return new MailboxListener.MailboxRenamed(
+                sessionId,
+                user,
+                path,
+                mailboxId,
+                newPath);
+        }
+    }
+
     public static class FlagsUpdatedBuilder extends MailboxEventBuilder<FlagsUpdatedBuilder> {
         private final ImmutableList.Builder<UpdatedFlags> updatedFlags;
 
@@ -285,12 +316,8 @@ public class EventFactory {
         return new FlagsUpdatedBuilder();
     }
 
-    public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        return mailboxRenamed(session.getSessionId(), session.getUser(), from, to);
-    }
-
-    public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession.SessionId sessionId, User user, MailboxPath from, Mailbox to) {
-        return new MailboxListener.MailboxRenamed(sessionId, user, from, to.getMailboxId(), to.generateAssociatedPath());
+    public MailboxRenamedBuilder mailboxRenamed() {
+        return new MailboxRenamedBuilder();
     }
 
     public MailboxDeletionBuilder mailboxDeleted() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/b5608ad2/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index da360d5..e7a8a4f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -149,7 +149,12 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        event(eventFactory.mailboxRenamed(session, from, to));
+        event(eventFactory.mailboxRenamed()
+            .mailboxSession(session)
+            .mailboxId(to.getMailboxId())
+            .oldPath(from)
+            .newPath(to.generateAssociatedPath())
+            .build());
     }
 
     /**


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


[10/47] james-project git commit: MAILBOX-359 Re-arrange QuotaUsageUpdatedEventSerializationTest

Posted by bt...@apache.org.
MAILBOX-359 Re-arrange QuotaUsageUpdatedEventSerializationTest

WithTime success case is strictly equivalent to the success case


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

Branch: refs/heads/master
Commit: 5383b12ebd3a1f020f67782f239a5ebc04bcee92
Parents: c6aebcc
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 15:25:59 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 ...QuotaUsageUpdatedEventSerializationTest.java | 81 +++++++-------------
 1 file changed, 26 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5383b12e/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index af95172..f0cbe7f 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -51,19 +51,6 @@ class QuotaUsageUpdatedEventSerializationTest {
         .computedLimit(QuotaSize.size(10000))
         .build();
     private static final Instant INSTANT = Instant.parse("2018-11-13T12:00:55Z");
-    private static final MailboxListener.QuotaUsageUpdatedEvent DEFAULT_QUOTA_EVENT =
-        new MailboxListener.QuotaUsageUpdatedEvent(USER, QUOTA_ROOT, QUOTA_COUNT, QUOTA_SIZE, INSTANT);
-
-    private static final String DEFAULT_QUOTA_EVENT_JSON =
-        "{" +
-            "\"QuotaUsageUpdatedEvent\":{" +
-            "\"quotaRoot\":\"foo\"," +
-            "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-            "\"time\":\"2018-11-13T12:00:55Z\"," +
-            "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-            "\"user\":\"user\"" +
-            "}" +
-        "}";
 
     private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
 
@@ -540,52 +527,36 @@ class QuotaUsageUpdatedEventSerializationTest {
         }
     }
 
-    @Nested
-    class WithTime {
-
-        @Test
-        void toJsonShouldReturnSerializedJsonEventWhenTimeIsValid() {
-            assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_QUOTA_EVENT))
-                .isEqualTo(DEFAULT_QUOTA_EVENT_JSON);
-        }
-
-        @Test
-        void fromJsonShouldReturnDeSerializedEventWhenTimeIsValid() {
-            assertThat(EVENT_SERIALIZER.fromJson(DEFAULT_QUOTA_EVENT_JSON).get())
-                .isEqualTo(DEFAULT_QUOTA_EVENT);
-        }
-
-        @Test
-        void fromJsonShouldThrowResultWhenTimeIsNull() {
-            String quotaUsageUpdatedEvent =
-                "{" +
-                    "\"QuotaUsageUpdatedEvent\":{" +
-                    "\"quotaRoot\":\"foo\"," +
-                    "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
-                    "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                    "\"user\":\"user\"" +
-                    "}" +
+    @Test
+    void fromJsonShouldThrowResultWhenTimeIsNull() {
+        String quotaUsageUpdatedEvent =
+            "{" +
+                "\"QuotaUsageUpdatedEvent\":{" +
+                "\"quotaRoot\":\"foo\"," +
+                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
+                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+                "\"user\":\"user\"" +
+                "}" +
                 "}";
 
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
+        assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isInstanceOf(NoSuchElementException.class);
+    }
 
-        @Test
-        void fromJsonShouldThrowResultWhenTimeIsEmpty() {
-            String quotaUsageUpdatedEvent =
-                "{" +
-                    "\"QuotaUsageUpdatedEvent\":{" +
-                    "\"quotaRoot\":\"foo\"," +
-                    "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
-                    "\"time\":\"\"," +
-                    "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                    "\"user\":\"user\"" +
-                    "}" +
+    @Test
+    void fromJsonShouldThrowResultWhenTimeIsEmpty() {
+        String quotaUsageUpdatedEvent =
+            "{" +
+                "\"QuotaUsageUpdatedEvent\":{" +
+                "\"quotaRoot\":\"foo\"," +
+                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
+                "\"time\":\"\"," +
+                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+                "\"user\":\"user\"" +
+                "}" +
                 "}";
 
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
+        assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isInstanceOf(NoSuchElementException.class);
     }
 }


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


[30/47] james-project git commit: MAILBOX-364 EventFactory methods can be statics

Posted by bt...@apache.org.
MAILBOX-364 EventFactory methods can be statics


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

Branch: refs/heads/master
Commit: 4eb79904c6c01b7cc087fb92df2a956f5a0c99cf
Parents: 2713b4d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 14:02:14 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../spamassassin/SpamAssassinListenerTest.java  |  4 ++--
 .../james/mailbox/store/event/EventFactory.java | 16 ++++++-------
 .../store/event/MailboxEventDispatcher.java     | 25 +++++++++-----------
 .../event/MailboxAnnotationListenerTest.java    |  2 +-
 .../base/MailboxEventAnalyserTest.java          | 16 ++++++-------
 .../processor/base/SelectedMailboxImplTest.java |  2 +-
 6 files changed, 30 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index ff0db16..a46d836 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -232,7 +232,7 @@ public class SpamAssassinListenerTest {
     public void eventShouldCallSpamAssassinHamLearningWhenTheMessageIsAddedInInbox() throws Exception {
         SimpleMailboxMessage message = createMessage(inbox);
 
-        MailboxListener.Added addedEvent = new EventFactory().added()
+        MailboxListener.Added addedEvent = EventFactory.added()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(inbox)
             .addMessage(message)
@@ -247,7 +247,7 @@ public class SpamAssassinListenerTest {
     public void eventShouldNotCallSpamAssassinHamLearningWhenTheMessageIsAddedInAMailboxOtherThanInbox() throws Exception {
         SimpleMailboxMessage message = createMessage(mailbox1);
 
-        MailboxListener.Added addedEvent = new EventFactory().added()
+        MailboxListener.Added addedEvent = EventFactory.added()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(mailbox1)
             .addMessage(message)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 1c0a477..c581816 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -300,35 +300,35 @@ public class EventFactory {
         }
     }
 
-    public AddedBuilder added() {
+    public static AddedBuilder added() {
         return new AddedBuilder();
     }
 
-    public ExpungedBuilder expunged() {
+    public static ExpungedBuilder expunged() {
         return new ExpungedBuilder();
     }
 
-    public FlagsUpdatedBuilder flagsUpdated() {
+    public static FlagsUpdatedBuilder flagsUpdated() {
         return new FlagsUpdatedBuilder();
     }
 
-    public MailboxRenamedBuilder mailboxRenamed() {
+    public static MailboxRenamedBuilder mailboxRenamed() {
         return new MailboxRenamedBuilder();
     }
 
-    public MailboxDeletionBuilder mailboxDeleted() {
+    public static MailboxDeletionBuilder mailboxDeleted() {
         return new MailboxDeletionBuilder();
     }
 
-    public MailboxAddedBuilder mailboxAdded() {
+    public static MailboxAddedBuilder mailboxAdded() {
         return new MailboxAddedBuilder();
     }
 
-    public MailboxAclUpdatedBuilder aclUpdated() {
+    public static MailboxAclUpdatedBuilder aclUpdated() {
         return new MailboxAclUpdatedBuilder();
     }
 
-    public MessageMoveEvent.Builder moved() {
+    public static MessageMoveEvent.Builder moved() {
         return MessageMoveEvent.builder();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index d161338..f1deaab 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -55,23 +55,20 @@ import com.google.common.collect.ImmutableSortedMap;
  * Helper class to dispatch {@link org.apache.james.mailbox.Event}'s to registerend MailboxListener
  */
 public class MailboxEventDispatcher {
-
     @VisibleForTesting
     public static MailboxEventDispatcher ofListener(MailboxListener mailboxListener) {
-        return new MailboxEventDispatcher(mailboxListener, new EventFactory());
+        return new MailboxEventDispatcher(mailboxListener);
     }
 
     private final MailboxListener listener;
-    private final EventFactory eventFactory;
 
     @Inject
     public MailboxEventDispatcher(DelegatingMailboxListener delegatingMailboxListener) {
-        this(delegatingMailboxListener, new EventFactory());
+        this((MailboxListener) delegatingMailboxListener);
     }
 
-    private MailboxEventDispatcher(MailboxListener listener, EventFactory eventFactory) {
+    private MailboxEventDispatcher(MailboxListener listener) {
         this.listener = listener;
-        this.eventFactory = eventFactory;
     }
 
     /**
@@ -83,7 +80,7 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(eventFactory.added()
+        event(EventFactory.added()
             .mailbox(mailbox)
             .mailboxSession(session)
             .addMetaData(uids.values())
@@ -114,7 +111,7 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(eventFactory.expunged()
+        event(EventFactory.expunged()
             .mailbox(mailbox)
             .mailboxSession(session)
             .addMetaData(uids.values())
@@ -133,7 +130,7 @@ public class MailboxEventDispatcher {
      * registered MailboxListener will get triggered then
      */
     public void flagsUpdated(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        event(eventFactory.flagsUpdated()
+        event(EventFactory.flagsUpdated()
             .mailbox(mailbox)
             .mailboxSession(session)
             .updatedFags(uflags)
@@ -149,7 +146,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        event(eventFactory.mailboxRenamed()
+        event(EventFactory.mailboxRenamed()
             .mailboxSession(session)
             .mailboxId(to.getMailboxId())
             .oldPath(from)
@@ -162,7 +159,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        event(eventFactory.mailboxDeleted()
+        event(EventFactory.mailboxDeleted()
             .mailboxSession(session)
             .mailbox(mailbox)
             .quotaRoot(quotaRoot)
@@ -176,14 +173,14 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        event(eventFactory.mailboxAdded()
+        event(EventFactory.mailboxAdded()
             .mailbox(mailbox)
             .mailboxSession(session)
             .build());
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        event(eventFactory.aclUpdated()
+        event(EventFactory.aclUpdated()
             .mailboxSession(session)
             .path(mailboxPath)
             .mailboxId(mailboxId)
@@ -192,7 +189,7 @@ public class MailboxEventDispatcher {
     }
 
     public void moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {
-        event(eventFactory.moved()
+        event(EventFactory.moved()
             .session(session)
             .messageMoves(messageMoves)
             .messageId(messageIds)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index cb6f7e1..fe8eaf1 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -77,7 +77,7 @@ public class MailboxAnnotationListenerTest {
         mailboxSession = MailboxSessionUtil.create("test");
         listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager);
 
-        deleteEvent = new EventFactory().mailboxDeleted()
+        deleteEvent = EventFactory.mailboxDeleted()
             .mailboxSession(mailboxSession)
             .mailboxId(mailboxId)
             .path(MailboxPath.forUser("user", "name"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 165ff04..9115010 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -114,14 +114,13 @@ public class MailboxEventAnalyserTest {
     private static final TestId MAILBOX_ID = TestId.of(36);
     private static final int UID_VALIDITY = 1024;
     private static final SimpleMailbox DEFAULT_MAILBOX = new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY, MAILBOX_ID);
-    private static final MailboxListener.Added ADDED = new EventFactory().added()
+    private static final MailboxListener.Added ADDED = EventFactory.added()
         .mailboxSession(MAILBOX_SESSION)
         .mailbox(DEFAULT_MAILBOX)
         .addMetaData(new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId()))
         .build();
 
     private SelectedMailboxImpl testee;
-    private EventFactory eventFactory;
 
     @Before
     public void setUp() throws MailboxException {
@@ -152,7 +151,6 @@ public class MailboxEventAnalyserTest {
             .thenReturn(new SingleMessageResultIterator(messageResult));
 
         testee = new SelectedMailboxImpl(mailboxManager, imapSession, MAILBOX_PATH);
-        eventFactory = new EventFactory();
     }
 
     @Test
@@ -182,7 +180,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldNotSetUidWhenNoSystemFlagChange() {
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(NOOP_UPDATED_FLAGS)
@@ -195,7 +193,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldSetUidWhenSystemFlagChange() {
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(OTHER_MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
@@ -210,7 +208,7 @@ public class MailboxEventAnalyserTest {
     public void testShouldClearFlagUidsUponReset() {
         SelectedMailboxImpl analyser = this.testee;
 
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
@@ -225,7 +223,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() {
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(OTHER_MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
@@ -240,7 +238,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode() {
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(NOOP_UPDATED_FLAGS)
@@ -255,7 +253,7 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() {
-        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+        MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
             .updatedFags(ADD_RECENT_UPDATED_FLAGS)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb79904/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 86a5023..2622c4b 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -163,7 +163,7 @@ public class SelectedMailboxImplTest {
     }
 
     private void emitEvent(MailboxListener mailboxListener) {
-        mailboxListener.event(new EventFactory().added()
+        mailboxListener.event(EventFactory.added()
             .mailbox(mailbox)
             .addMetaData(new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()))
             .mailboxSession(MailboxSessionUtil.create("user"))


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


[25/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for Expunged event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for Expunged event


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

Branch: refs/heads/master
Commit: 2c46d620f1687b4ec7d72a0c137e384eac1f3038
Parents: e829c8e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 13:35:05 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 38 ++++++++++++++------
 .../store/event/MailboxEventDispatcher.java     |  6 +++-
 2 files changed, 33 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2c46d620/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index cd8a38c..0205560 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -20,7 +20,6 @@
 package org.apache.james.mailbox.store.event;
 
 import java.util.Collection;
-import java.util.Map;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -43,6 +42,7 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSortedMap;
 
 public class EventFactory {
     public abstract static class MailboxEventBuilder<T extends MailboxEventBuilder> {
@@ -124,6 +124,12 @@ public class EventFactory {
             this.metaData.addAll(metaData);
             return backReference();
         }
+
+        protected ImmutableSortedMap<MessageUid, MessageMetaData> metaDataAsMap() {
+            return metaData.build()
+                .stream()
+                .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid));
+        }
     }
 
     public static class AddedBuilder extends MessageMetaDataEventBuilder<AddedBuilder> {
@@ -140,9 +146,25 @@ public class EventFactory {
                 user,
                 path,
                 mailboxId,
-                metaData.build()
-                    .stream()
-                    .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid)));
+                metaDataAsMap());
+        }
+    }
+
+    public static class ExpungedBuilder extends MessageMetaDataEventBuilder<ExpungedBuilder> {
+        @Override
+        protected ExpungedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxListener.Expunged build() {
+            mailboxEventChecks();
+            
+            return new MailboxListener.Expunged(
+                sessionId,
+                user,
+                path,
+                mailboxId,
+                metaDataAsMap());
         }
     }
 
@@ -229,12 +251,8 @@ public class EventFactory {
         return new AddedBuilder();
     }
 
-    public MailboxListener.Expunged expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return expunged(session.getSessionId(), session.getUser(), uids, mailbox);
-    }
-
-    public MailboxListener.Expunged expunged(MailboxSession.SessionId sessionId, User user, Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return new MailboxListener.Expunged(sessionId, user, mailbox.generateAssociatedPath(), mailbox.getMailboxId(), uids);
+    public ExpungedBuilder expunged() {
+        return new ExpungedBuilder();
     }
 
     public FlagsUpdatedBuilder flagsUpdated() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2c46d620/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 6684b8a..122394f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -114,7 +114,11 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(eventFactory.expunged(session, uids, mailbox));
+        event(eventFactory.expunged()
+            .mailbox(mailbox)
+            .mailboxSession(session)
+            .addMetaData(uids.values())
+            .build());
     }
 
     public void expunged(MailboxSession session,  MessageMetaData messageMetaData, Mailbox mailbox) {


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


[09/47] james-project git commit: MAILBOX-359 Factorize tests for MailboxId ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for MailboxId ser-deserialization


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

Branch: refs/heads/master
Commit: e64e8e1d24cc0473ce37771acda398d77504fa18
Parents: 21eff06
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 13:23:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      |  71 +------
 .../event/json/ExpungedSerializationTest.java   |  71 +------
 .../json/FlagsUpdatedSerializationTest.java     |  75 +-------
 ...MailboxACLUpdatedEventSerializationTest.java | 183 +++++++------------
 .../json/MailboxAddedSerializationTest.java     |  51 ------
 .../json/MailboxDeletionSerializationTest.java  |  53 +-----
 .../json/MailboxRenamedSerializationTest.java   |  33 +---
 .../james/event/json/dtos/MailboxIdTest.java    |  71 +++++++
 8 files changed, 158 insertions(+), 450 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index a299389..3af5c28 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -568,78 +568,16 @@ class AddedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxId {
-            @Test
-            void addedShouldThrowWhenMissingMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": null," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenMailboxIdIsANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void addedShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Added\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
                     "      \"user\": \"user\"," +
                     "      \"name\": \"mailboxName\"" +
                     "    }," +
-                    "    \"mailboxId\": 18," +
                     "    \"added\": {" +
                     "      \"123456\": {" +
                     "        \"uid\": 123456," +
@@ -657,7 +595,6 @@ class AddedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 3d60dab..2aee596 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -567,78 +567,16 @@ class ExpungedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxId {
-            @Test
-            void expungedShouldThrowWhenMissingMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": null," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenMailboxIdIsANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void expungedShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Expunged\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
                     "      \"user\": \"user\"," +
                     "      \"name\": \"mailboxName\"" +
                     "    }," +
-                    "    \"mailboxId\": 18," +
                     "    \"expunged\": {" +
                     "      \"123456\": {" +
                     "        \"uid\": 123456," +
@@ -656,7 +594,6 @@ class ExpungedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 091a259..abef4bd 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -495,82 +495,16 @@ class FlagsUpdatedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxId {
-            @Test
-            void flagsUpdatedShouldThrowWhenMissingMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": null," +
-                    "    \"sessionId\": 42," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": \"user\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenMailboxIdIsANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void flagsUpdatedShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"FlagsUpdated\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
                     "      \"user\": \"user\"," +
                     "      \"name\": \"mailboxName\"" +
                     "    }," +
-                    "    \"mailboxId\": 18," +
                     "    \"sessionId\": 42," +
                     "    \"updatedFlags\": [" +
                     "      {" +
@@ -590,7 +524,6 @@ class FlagsUpdatedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index 45f7605..0855c64 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -309,13 +309,10 @@ class MailboxACLUpdatedEventSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnACLDiff {
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingACLDiff() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxACLUpdatedShouldThrowWhenMissingACLDiff() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxACLUpdated\":{" +
                     "    \"mailboxPath\":{" +
                     "       \"namespace\":\"#private\"," +
@@ -326,8 +323,7 @@ class MailboxACLUpdatedEventSerializationTest {
                     "    \"user\":\"user\"" +
                     "   }" +
                     "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested
@@ -728,55 +724,11 @@ class MailboxACLUpdatedEventSerializationTest {
                 }
             }
         }
-    }
-
-        @Nested
-        class DeserializationErrorOnMailboxId {
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"user\":\"bob\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"user\":\"bob\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":null," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
 
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMailboxIdIsANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxACLUpdated\":{" +
                     "    \"mailboxPath\":{" +
                     "       \"namespace\":\"#private\"," +
@@ -786,13 +738,11 @@ class MailboxACLUpdatedEventSerializationTest {
                     "    \"aclDiff\":{" +
                     "       \"oldACL\":{}," +
                     "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":123," +
                     "    \"sessionId\":6," +
                     "    \"user\":\"user\"" +
                     "   }" +
                     "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested
@@ -804,20 +754,20 @@ class MailboxACLUpdatedEventSerializationTest {
                 void mailboxACLUpdatedShouldThrowWhenNameSpaceIsNotAString() {
                     assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
                         "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":230192.06," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":\"ar\"}}," +
-                        "    \"mailboxId\":\"123\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
+                            "  \"MailboxACLUpdated\":{" +
+                            "    \"mailboxPath\":{" +
+                            "       \"namespace\":230192.06," +
+                            "       \"user\":\"bob\"," +
+                            "       \"name\":\"mailboxName\"" +
+                            "      }," +
+                            "    \"aclDiff\":{" +
+                            "       \"oldACL\":{}," +
+                            "       \"newACL\":{\"$any\":\"ar\"}}," +
+                            "    \"mailboxId\":\"123\"," +
+                            "    \"sessionId\":6," +
+                            "    \"user\":\"user\"" +
+                            "   }" +
+                            "}").get())
                         .isInstanceOf(NoSuchElementException.class);
                 }
             }
@@ -828,20 +778,20 @@ class MailboxACLUpdatedEventSerializationTest {
                 void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
                     assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
                         "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":230192.06," +
-                        "       \"user\":180806," +
-                        "       \"name\":\"mailboxName\"" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":\"ar\"}}," +
-                        "    \"mailboxId\":\"123\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
+                            "  \"MailboxACLUpdated\":{" +
+                            "    \"mailboxPath\":{" +
+                            "       \"namespace\":230192.06," +
+                            "       \"user\":180806," +
+                            "       \"name\":\"mailboxName\"" +
+                            "      }," +
+                            "    \"aclDiff\":{" +
+                            "       \"oldACL\":{}," +
+                            "       \"newACL\":{\"$any\":\"ar\"}}," +
+                            "    \"mailboxId\":\"123\"," +
+                            "    \"sessionId\":6," +
+                            "    \"user\":\"user\"" +
+                            "   }" +
+                            "}").get())
                         .isInstanceOf(NoSuchElementException.class);
                 }
             }
@@ -853,20 +803,20 @@ class MailboxACLUpdatedEventSerializationTest {
                 void mailboxACLUpdatedShouldThrowWhenNullMailboxName() {
                     assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
                         "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":230192.06," +
-                        "       \"user\":180806," +
-                        "       \"name\":null" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":\"ar\"}}," +
-                        "    \"mailboxId\":\"123\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
+                            "  \"MailboxACLUpdated\":{" +
+                            "    \"mailboxPath\":{" +
+                            "       \"namespace\":230192.06," +
+                            "       \"user\":180806," +
+                            "       \"name\":null" +
+                            "      }," +
+                            "    \"aclDiff\":{" +
+                            "       \"oldACL\":{}," +
+                            "       \"newACL\":{\"$any\":\"ar\"}}," +
+                            "    \"mailboxId\":\"123\"," +
+                            "    \"sessionId\":6," +
+                            "    \"user\":\"user\"" +
+                            "   }" +
+                            "}").get())
                         .isInstanceOf(NoSuchElementException.class);
                 }
 
@@ -874,23 +824,24 @@ class MailboxACLUpdatedEventSerializationTest {
                 void mailboxACLUpdatedShouldThrowWhenMailboxNameIdIsANumber() {
                     assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
                         "{" +
-                        "  \"MailboxACLUpdated\":{" +
-                        "    \"mailboxPath\":{" +
-                        "       \"namespace\":230192.06," +
-                        "       \"user\":\"bob\"," +
-                        "       \"name\":160205" +
-                        "      }," +
-                        "    \"aclDiff\":{" +
-                        "       \"oldACL\":{}," +
-                        "       \"newACL\":{\"$any\":\"ar\"}}," +
-                        "    \"mailboxId\":\"123\"," +
-                        "    \"sessionId\":6," +
-                        "    \"user\":\"user\"" +
-                        "   }" +
-                        "}").get())
+                            "  \"MailboxACLUpdated\":{" +
+                            "    \"mailboxPath\":{" +
+                            "       \"namespace\":230192.06," +
+                            "       \"user\":\"bob\"," +
+                            "       \"name\":160205" +
+                            "      }," +
+                            "    \"aclDiff\":{" +
+                            "       \"oldACL\":{}," +
+                            "       \"newACL\":{\"$any\":\"ar\"}}," +
+                            "    \"mailboxId\":\"123\"," +
+                            "    \"sessionId\":6," +
+                            "    \"user\":\"user\"" +
+                            "   }" +
+                            "}").get())
                         .isInstanceOf(NoSuchElementException.class);
                 }
             }
         }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index c491c9f..4ee0db7 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -275,56 +275,5 @@ class MailboxAddedSerializationTest {
                 "}").get())
                 .isInstanceOf(NoSuchElementException.class);
         }
-
-        @Test
-        void fromJsonShouldRejectLongMailboxId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":18," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectNullMailboxId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":null," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectInvalidMailboxId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"invalid\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NumberFormatException.class);
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index e0ae086..fc7a708 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -470,12 +470,10 @@ class MailboxDeletionSerializationTest {
             }
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxId {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
                     "    \"sessionId\":3652," +
                     "    \"user\":\"user\"," +
@@ -490,49 +488,6 @@ class MailboxDeletionSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":null" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenMailboxIdIsANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":789" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index b19b20c..7ef472d 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -329,12 +329,10 @@ class MailboxRenamedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailBoxId {
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNumberMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxRenamedDeSerializeShouldThrowWhenMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxRenamed\":{" +
                     "    \"sessionId\":123456789," +
                     "    \"user\":\"user\"," +
@@ -352,29 +350,6 @@ class MailboxRenamedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNullMailboxId() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
new file mode 100644
index 0000000..d54505c
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class MailboxIdTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void mailboxIdShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.mailboxIdWrites().writes(TestId.of(18)))
+            .isEqualTo(new JsString("18"));
+    }
+
+    @Test
+    void mailboxIdShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsString("18")))
+            .isEqualTo(new JsSuccess<>(TestId.of(18), new JsPath(List.empty())));
+    }
+
+    @Test
+    void mailboxIdDeserializationShouldReturnErrorWhenNumber() {
+        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxIdDeserializationShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxIdDeserializationShouldThrowWhenInvalid() {
+        assertThatThrownBy(() -> JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid")))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+}


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


[24/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for MailboxAdded event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for MailboxAdded event


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

Branch: refs/heads/master
Commit: 8550ce9d2668a11f7371e3a5f21849306a007d5b
Parents: 4d6a372
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 11:26:09 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 57 +++++++++++++++++---
 .../store/event/MailboxEventDispatcher.java     |  5 +-
 2 files changed, 55 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8550ce9d/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 4dfd76c..13c6f9d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -41,7 +41,56 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
+import com.google.common.base.Preconditions;
+
 public class EventFactory {
+    public static class MailboxAddedBuilder {
+        private MailboxPath path;
+        private MailboxId mailboxId;
+        private User user;
+        private MailboxSession.SessionId sessionId;
+
+        public MailboxAddedBuilder mailbox(Mailbox mailbox) {
+            path(mailbox.generateAssociatedPath());
+            mailboxId(mailbox.getMailboxId());
+            return this;
+        }
+
+        public MailboxAddedBuilder mailboxSession(MailboxSession mailboxSession) {
+            user(mailboxSession.getUser());
+            sessionId(mailboxSession.getSessionId());
+            return this;
+        }
+
+        public MailboxAddedBuilder mailboxId(MailboxId mailboxId) {
+            this.mailboxId = mailboxId;
+            return this;
+        }
+
+        public MailboxAddedBuilder path(MailboxPath path) {
+            this.path = path;
+            return this;
+        }
+
+        public MailboxAddedBuilder user(User user) {
+            this.user = user;
+            return this;
+        }
+
+        public MailboxAddedBuilder sessionId(MailboxSession.SessionId sessionId) {
+            this.sessionId = sessionId;
+            return this;
+        }
+
+        public MailboxListener.MailboxAdded build() {
+            Preconditions.checkState(user != null, "Field `user` is compulsory");
+            Preconditions.checkState(mailboxId != null, "Field `mailboxId` is compulsory");
+            Preconditions.checkState(path != null, "Field `path` is compulsory");
+            Preconditions.checkState(sessionId != null, "Field `sessionId` is compulsory");
+
+            return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId);
+        }
+    }
 
     public MailboxListener.Added added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         return added(session.getSessionId(), session.getUser(), uids, mailbox);
@@ -81,12 +130,8 @@ public class EventFactory {
         return new MailboxListener.MailboxDeletion(sessionId, user, mailbox.generateAssociatedPath(), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
     }
 
-    public MailboxListener.MailboxAdded mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        return mailboxAdded(session.getSessionId(), session.getUser(), mailbox);
-    }
-
-    public MailboxListener.MailboxAdded mailboxAdded(MailboxSession.SessionId sessionId, User user, Mailbox mailbox) {
-        return new MailboxListener.MailboxAdded(sessionId, user, mailbox.generateAssociatedPath(), mailbox.getMailboxId());
+    public MailboxAddedBuilder mailboxAdded() {
+        return new MailboxAddedBuilder();
     }
 
     public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/8550ce9d/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 3a4b113..fa0b0bc 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -153,7 +153,10 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        event(eventFactory.mailboxAdded(session, mailbox));
+        listener.event(eventFactory.mailboxAdded()
+            .mailbox(mailbox)
+            .mailboxSession(session)
+            .build());
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {


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


[34/47] james-project git commit: JAMES-2636 Enhence RRT API getMapping methods

Posted by bt...@apache.org.
JAMES-2636 Enhence RRT API getMapping methods

The difference between them was subtil (resolved/unresolved) and prooved
to be confusing. Hence I propose a better method naming for solving this
issue.


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

Branch: refs/heads/master
Commit: 4e2bd7fdaa77e405e55b929b658f8cff139b4098
Parents: 887f3c5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Jan 4 09:51:01 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:45:33 2019 +0700

----------------------------------------------------------------------
 .../james/rrt/api/RecipientRewriteTable.java    |  4 +-
 .../CassandraRecipientRewriteTable.java         |  2 +-
 .../rrt/file/XMLRecipientRewriteTable.java      |  2 +-
 .../rrt/file/XMLRecipientRewriteTableTest.java  |  4 +-
 .../rrt/jdbc/JDBCRecipientRewriteTable.java     |  6 +--
 .../james/rrt/jpa/JPARecipientRewriteTable.java |  6 +--
 .../rrt/lib/AbstractRecipientRewriteTable.java  |  4 +-
 .../lib/RecipientRewriteTableManagement.java    |  2 +-
 .../user/lib/AbstractJamesUsersRepository.java  |  6 +--
 .../lib/AbstractRecipientRewriteTableTest.java  | 48 ++++++++++----------
 .../james/rrt/lib/RewriteTablesStepdefs.java    |  6 +--
 .../rrt/memory/MemoryRecipientRewriteTable.java |  2 +-
 .../mailets/RecipientRewriteTableProcessor.java |  2 +-
 .../transport/matchers/IsSenderInRRTLoop.java   |  2 +-
 .../RecipientRewriteTableProcessorTest.java     | 10 ++--
 .../smtpserver/fastfail/ValidRcptHandler.java   |  2 +-
 .../webadmin/routes/DomainMappingsRoutes.java   |  2 +-
 .../james/webadmin/routes/ForwardRoutes.java    |  2 +-
 .../james/webadmin/routes/GroupsRoutes.java     |  2 +-
 .../routes/DomainMappingsRoutesTest.java        |  8 ++--
 .../webadmin/routes/ForwardRoutesTest.java      |  4 +-
 .../james/webadmin/routes/GroupsRoutesTest.java |  4 +-
 22 files changed, 65 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index 5c85ed7..bbcece6 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -88,7 +88,7 @@ public interface RecipientRewriteTable {
      * @throws ErrorMappingException
      *             get thrown if an error mapping was found
      */
-    Mappings getMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException;
+    Mappings getResolvedMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException;
 
     /**
      * Return the explicit mapping stored for the given user and domain. Return
@@ -97,7 +97,7 @@ public interface RecipientRewriteTable {
      * @return the collection which holds the mappings.
      * @throws RecipientRewriteTableException
      */
-    Mappings getUserDomainMappings(MappingSource source) throws RecipientRewriteTableException;
+    Mappings getStoredMappings(MappingSource source) throws RecipientRewriteTableException;
 
     /**
      * Return a Map which holds all mappings. The key is the user@domain and the

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
index 9df03c8..ffefd98 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
@@ -113,7 +113,7 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource source) {
+    public Mappings getStoredMappings(MappingSource source) {
         return retrieveMappings(source)
             .orElse(null);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
index 0f754a2..c192dbe 100644
--- a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
+++ b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
@@ -68,7 +68,7 @@ public class XMLRecipientRewriteTable extends AbstractRecipientRewriteTable {
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource source) {
+    public Mappings getStoredMappings(MappingSource source) {
         if (mappings == null) {
             return null;
         } else {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
index 3528b49..aaa0820 100644
--- a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
@@ -80,7 +80,7 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT
     }
 
     protected void addMappingToConfiguration(MappingSource source, String mapping, Type type) throws RecipientRewriteTableException {
-        Mappings mappings = Optional.ofNullable(virtualUserTable.getUserDomainMappings(source))
+        Mappings mappings = Optional.ofNullable(virtualUserTable.getStoredMappings(source))
             .orElse(MappingsImpl.empty());
 
         Mappings updatedMappings = MappingsImpl.from(mappings)
@@ -91,7 +91,7 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT
     }
 
     protected void removeMappingFromConfiguration(MappingSource source, String mapping, Type type) throws RecipientRewriteTableException {
-        Mappings oldMappings = Optional.ofNullable(virtualUserTable.getUserDomainMappings(source))
+        Mappings oldMappings = Optional.ofNullable(virtualUserTable.getStoredMappings(source))
             .orElseThrow(() -> new RecipientRewriteTableException("Cannot remove from null mappings"));
 
         Mappings updatedMappings = oldMappings.remove(Mapping.of(type, mapping));

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
index defea48..d6d5920 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
@@ -189,7 +189,7 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable {
 
     @Override
     public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException {
-        Mappings map = getUserDomainMappings(source);
+        Mappings map = getStoredMappings(source);
         if (map != null && map.size() != 0) {
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(source, updatedMappings.serialize());
@@ -228,7 +228,7 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable {
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource source) throws RecipientRewriteTableException {
+    public Mappings getStoredMappings(MappingSource source) throws RecipientRewriteTableException {
         Connection conn = null;
         PreparedStatement mappingStmt = null;
         try {
@@ -291,7 +291,7 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable {
 
     @Override
     public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException {
-        Mappings map = getUserDomainMappings(source);
+        Mappings map = getStoredMappings(source);
         if (map != null && map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(source, updatedMappings.serialize());

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
index cf09987..d653d3d 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
@@ -65,7 +65,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable {
 
     @Override
     public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException {
-        Mappings map = getUserDomainMappings(source);
+        Mappings map = getStoredMappings(source);
         if (!map.isEmpty()) {
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(source, updatedMappings.serialize());
@@ -111,7 +111,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable {
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource source) throws RecipientRewriteTableException {
+    public Mappings getStoredMappings(MappingSource source) throws RecipientRewriteTableException {
         EntityManager entityManager = entityManagerFactory.createEntityManager();
         final EntityTransaction transaction = entityManager.getTransaction();
         try {
@@ -164,7 +164,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable {
 
     @Override
     public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException {
-        Mappings map = getUserDomainMappings(source);
+        Mappings map = getStoredMappings(source);
         if (map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(source, updatedMappings.serialize());

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
index 7eefdcc..69e24f5 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
@@ -95,7 +95,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
     }
 
     @Override
-    public Mappings getMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
+    public Mappings getResolvedMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
         return getMappings(User.fromLocalPartWithDomain(user, domain), mappingLimit);
     }
 
@@ -312,7 +312,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
     protected abstract Mappings mapAddress(String user, Domain domain) throws RecipientRewriteTableException;
 
     private void checkDuplicateMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException {
-        Mappings mappings = getUserDomainMappings(source);
+        Mappings mappings = getStoredMappings(source);
         if (mappings != null && mappings.contains(mapping)) {
             throw new MappingAlreadyExistsException("Mapping " + mapping + " for " + source.asString() + " already exist!");
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
index ecc7b17..92cf309 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
@@ -95,7 +95,7 @@ public class RecipientRewriteTableManagement extends StandardMBean implements Re
     @Override
     public Mappings getUserDomainMappings(String user, String domain) throws RecipientRewriteTableException {
         MappingSource source = MappingSource.fromUser(user, domain);
-        return rrt.getUserDomainMappings(source);
+        return rrt.getStoredMappings(source);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
index 491accb..3913533 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
@@ -121,7 +121,7 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
     }
 
     @Override
-    public Mappings getMappings(String username, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
+    public Mappings getResolvedMappings(String username, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
         Builder mappingsBuilder = MappingsImpl.builder();
         try {
             User user = getUserByName(username);
@@ -192,7 +192,7 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
                     }
                     try {
                         MappingSource source = MappingSource.fromUser(org.apache.james.core.User.fromUsername(user));
-                        mappings.put(source, getMappings(username, domain));
+                        mappings.put(source, getResolvedMappings(username, domain));
                     } catch (ErrorMappingException e) {
                         // shold never happen here
                     }
@@ -206,7 +206,7 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource source) throws RecipientRewriteTableException {
+    public Mappings getStoredMappings(MappingSource source) throws RecipientRewriteTableException {
         return MappingsImpl.empty();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
index 671b1c8..9958804 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
@@ -74,7 +74,7 @@ public abstract class AbstractRecipientRewriteTableTest {
     public void testStoreAndGetMappings() throws Exception {
         Domain domain = Domain.of("test");
         virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.regex("prefix_.*:admin@test"));
-        assertThat(virtualUserTable.getMappings("prefix_abc", domain)).isNotEmpty();
+        assertThat(virtualUserTable.getResolvedMappings("prefix_abc", domain)).isNotEmpty();
     }
 
     @Test
@@ -87,12 +87,12 @@ public abstract class AbstractRecipientRewriteTableTest {
         String regex2 = "(.+)@test";
         String invalidRegex = ".*):";
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
 
         virtualUserTable.addMapping(source, Mapping.regex(regex));
         virtualUserTable.addMapping(source, Mapping.regex(regex2));
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
         assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
         virtualUserTable.removeMapping(source, Mapping.regex(regex));
 
@@ -104,7 +104,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.removeMapping(source, Mapping.regex(regex2));
 
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
         assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
@@ -140,19 +140,19 @@ public abstract class AbstractRecipientRewriteTableTest {
         MappingSource source = MappingSource.fromUser(USER, domain);
         String address2 = "test@james";
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
 
         virtualUserTable.addMapping(source, Mapping.address(ADDRESS));
         virtualUserTable.addMapping(source, Mapping.address(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
         assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
 
         virtualUserTable.removeMapping(source, Mapping.address(ADDRESS));
         virtualUserTable.removeMapping(source, Mapping.address(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
         assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
@@ -163,20 +163,20 @@ public abstract class AbstractRecipientRewriteTableTest {
         MappingSource source = MappingSource.fromUser(USER, domain);
         String error = "bounce!";
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
 
         virtualUserTable.addMapping(source, Mapping.error(error));
         assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
 
         assertThatThrownBy(() ->
-            virtualUserTable.getMappings(USER, domain))
+            virtualUserTable.getResolvedMappings(USER, domain))
             .describedAs("Exception thrown on to many mappings")
             .isInstanceOf(ErrorMappingException.class);
 
         virtualUserTable.removeMapping(source, Mapping.error(error));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
         assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
@@ -188,21 +188,21 @@ public abstract class AbstractRecipientRewriteTableTest {
         String address2 = "test@james";
         MappingSource source = MappingSource.fromUser(USER, domain);
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
 
         virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.address(ADDRESS));
         virtualUserTable.addMapping(source, Mapping.address(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("One mappings").hasSize(1);
-        assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("One mappings").hasSize(1);
+        assertThat(virtualUserTable.getResolvedMappings(user2, domain)).describedAs("One mappings").hasSize(1);
 
         virtualUserTable.removeMapping(source, Mapping.address(address2));
         virtualUserTable.removeMapping(MappingSource.fromDomain(domain), Mapping.address(ADDRESS));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
-        assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping")
+        assertThat(virtualUserTable.getResolvedMappings(user2, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
     }
 
@@ -224,17 +224,17 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         virtualUserTable.addMapping(source1, Mapping.address(user2 + "@" + domain2.asString()));
         virtualUserTable.addMapping(source2, Mapping.address(user3 + "@" + domain3.asString()));
-        assertThat(virtualUserTable.getMappings(user1, domain1)).containsOnly(Mapping.address(user3 + "@" + domain3.asString()));
+        assertThat(virtualUserTable.getResolvedMappings(user1, domain1)).containsOnly(Mapping.address(user3 + "@" + domain3.asString()));
         virtualUserTable.addMapping(source3, Mapping.address(user1 + "@" + domain1.asString()));
 
         assertThatThrownBy(() ->
-            virtualUserTable.getMappings(user1, domain1))
+            virtualUserTable.getResolvedMappings(user1, domain1))
             .describedAs("Exception thrown on to many mappings")
             .isInstanceOf(ErrorMappingException.class);
 
         // disable recursive mapping
         virtualUserTable.setRecursiveMapping(false);
-        assertThat(virtualUserTable.getMappings(user1, domain1)).describedAs("Not recursive mapped").containsExactly(Mapping.address(user2 + "@" + domain2.asString()));
+        assertThat(virtualUserTable.getResolvedMappings(user1, domain1)).describedAs("Not recursive mapped").containsExactly(Mapping.address(user2 + "@" + domain2.asString()));
     }
 
     @Test
@@ -249,7 +249,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), Mapping.address(user2 + "@" + domain));
         virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), Mapping.domain(Domain.of(domain)));
 
-        assertThat(virtualUserTable.getMappings(user, aliasDomain))
+        assertThat(virtualUserTable.getResolvedMappings(user, aliasDomain))
             .describedAs("Domain mapped as first, Address mapped as second")
             .isEqualTo(MappingsImpl.builder()
                 .add(Mapping.address(user + "@" + domain))
@@ -279,7 +279,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.addMapping(source, Mapping.address(ADDRESS));
         virtualUserTable.addMapping(source, Mapping.regex(ADDRESS));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).hasSize(2);
     }
 
     @Test
@@ -291,7 +291,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.addMapping(source, Mapping.forward(ADDRESS));
         virtualUserTable.addMapping(source, Mapping.forward(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).hasSize(2);
     }
 
     @Test
@@ -306,7 +306,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.removeMapping(source, Mapping.forward(ADDRESS));
         virtualUserTable.removeMapping(source, Mapping.forward(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain))
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain))
             .isEqualTo(MappingsImpl.empty());
     }
 
@@ -319,7 +319,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.addMapping(source, Mapping.group(ADDRESS));
         virtualUserTable.addMapping(source, Mapping.group(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain)).hasSize(2);
     }
 
     @Test
@@ -334,7 +334,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         virtualUserTable.removeMapping(source, Mapping.group(ADDRESS));
         virtualUserTable.removeMapping(source, Mapping.group(address2));
 
-        assertThat(virtualUserTable.getMappings(USER, domain))
+        assertThat(virtualUserTable.getResolvedMappings(USER, domain))
             .isEqualTo(MappingsImpl.empty());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
index 6c59812..17320a3 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
@@ -151,12 +151,12 @@ public class RewriteTablesStepdefs {
 
     @Then("mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should be empty")
     public void assertMappingsIsEmpty(String user, String domain) throws Throwable {
-        assertThat(rewriteTable.getMappings(user, Domain.of(domain))).isNullOrEmpty();
+        assertThat(rewriteTable.getResolvedMappings(user, Domain.of(domain))).isNullOrEmpty();
     }
 
     @Then("mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should contain only \"([^\"]*)\"")
     public void assertMappingsForUser(String user, String domain, List<String> mappings) throws Throwable {
-        assertThat(rewriteTable.getMappings(user, Domain.of(domain)).asStrings()).containsOnlyElementsOf(mappings);
+        assertThat(rewriteTable.getResolvedMappings(user, Domain.of(domain)).asStrings()).containsOnlyElementsOf(mappings);
     }
 
     @Then("a \"([^\"]*)\" exception should have been thrown")
@@ -166,7 +166,7 @@ public class RewriteTablesStepdefs {
 
     @Then("retrieving mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should raise an ErrorMappingException with message \"([^\"]*)\"")
     public void retrievingMappingsForUserAtDomainShouldRaiseAnException(String user, String domain, String message) throws Exception {
-        assertThatThrownBy(() -> rewriteTable.getMappings(user, Domain.of(domain)))
+        assertThatThrownBy(() -> rewriteTable.getResolvedMappings(user, Domain.of(domain)))
             .isInstanceOf(ErrorMappingException.class)
             .hasMessage(message);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
index fca798c..8fc2e11 100644
--- a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
+++ b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
@@ -94,7 +94,7 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable {
     }
 
     @Override
-    public Mappings getUserDomainMappings(MappingSource mappingSource) {
+    public Mappings getStoredMappings(MappingSource mappingSource) {
         return retrieveMappings(mappingSource)
             .orElse(null);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
index 0cb116d..6b31d7a 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessor.java
@@ -161,7 +161,7 @@ public class RecipientRewriteTableProcessor {
 
     private RrtExecutionResult executeRrtForRecipient(Mail mail, MailAddress recipient) {
         try {
-            Mappings mappings = virtualTableStore.getMappings(recipient.getLocalPart(), recipient.getDomain());
+            Mappings mappings = virtualTableStore.getResolvedMappings(recipient.getLocalPart(), recipient.getDomain());
 
             if (mappings != null && !mappings.isEmpty()) {
                 List<MailAddress> newMailAddresses = handleMappings(mappings, mail, recipient);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsSenderInRRTLoop.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsSenderInRRTLoop.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsSenderInRRTLoop.java
index e368104..31cb937 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsSenderInRRTLoop.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsSenderInRRTLoop.java
@@ -57,7 +57,7 @@ public class IsSenderInRRTLoop extends GenericMatcher {
     public Collection<MailAddress> match(Mail mail) {
         try {
             if (mail.hasSender()) {
-                recipientRewriteTable.getMappings(mail.getMaybeSender().get().getLocalPart(), mail.getMaybeSender().get().getDomain());
+                recipientRewriteTable.getResolvedMappings(mail.getMaybeSender().get().getLocalPart(), mail.getMaybeSender().get().getDomain());
             }
         } catch (RecipientRewriteTable.TooManyMappingException e) {
             return mail.getRecipients();

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
index 789cee9..93ab2bc 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableProcessorTest.java
@@ -221,7 +221,7 @@ public class RecipientRewriteTableProcessorTest {
     
     @Test
     public void processShouldNotRewriteRecipientWhenVirtualTableStoreReturnNullMappings() throws Exception {
-        when(virtualTableStore.getMappings(any(String.class), any(Domain.class))).thenReturn(null);
+        when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(null);
 
         mail = FakeMail.builder()
             .mimeMessage(message)
@@ -235,7 +235,7 @@ public class RecipientRewriteTableProcessorTest {
     
     @Test
     public void processShouldSendMailToAllErrorRecipientsWhenErrorMappingException() throws Exception {
-        when(virtualTableStore.getMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(ErrorMappingException.class);
+        when(virtualTableStore.getResolvedMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(ErrorMappingException.class);
 
         mail = FakeMail.builder()
             .sender(MailAddressFixture.ANY_AT_JAMES)
@@ -259,7 +259,7 @@ public class RecipientRewriteTableProcessorTest {
     
     @Test
     public void processShouldSendMailToAllErrorRecipientsWhenRecipientRewriteTableException() throws Exception {
-        when(virtualTableStore.getMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(RecipientRewriteTableException.class);
+        when(virtualTableStore.getResolvedMappings(eq("other"), eq(Domain.of(MailAddressFixture.JAMES_LOCAL)))).thenThrow(RecipientRewriteTableException.class);
 
         mail = FakeMail.builder()
             .sender(MailAddressFixture.ANY_AT_JAMES)
@@ -283,7 +283,7 @@ public class RecipientRewriteTableProcessorTest {
     
     @Test
     public void processShouldNotSendMailWhenNoErrorRecipients() throws Exception {
-        when(virtualTableStore.getMappings(any(String.class), any(Domain.class))).thenReturn(null);
+        when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(null);
 
         mail = FakeMail.builder()
             .mimeMessage(message)
@@ -297,7 +297,7 @@ public class RecipientRewriteTableProcessorTest {
     
     @Test
     public void processShouldResetMailStateToGhostWhenCanNotBuildNewRecipient() throws Exception {
-        when(virtualTableStore.getMappings(any(String.class), any(Domain.class))).thenReturn(mappings);
+        when(virtualTableStore.getResolvedMappings(any(String.class), any(Domain.class))).thenReturn(mappings);
         when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL));
 
         mail = FakeMail.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
index 8478118..0a5bdfc 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
@@ -81,7 +81,7 @@ public class ValidRcptHandler extends AbstractValidRcptHandler implements Protoc
         LOGGER.debug("Unknown user {} check if it's an alias", username);
 
         try {
-            Mappings targetString = recipientRewriteTable.getMappings(recipient.getLocalPart(), recipient.getDomain());
+            Mappings targetString = recipientRewriteTable.getResolvedMappings(recipient.getLocalPart(), recipient.getDomain());
 
             if (!targetString.isEmpty()) {
                 return true;

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java
index e74484c..cfd3ac8 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java
@@ -160,7 +160,7 @@ public class DomainMappingsRoutes implements Routes {
     public List<String> getMapping(Request request, Response response) throws RecipientRewriteTableException {
         MappingSource mappingSource = mappingSourceFrom(request);
 
-        return Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(mappingSource).select(Mapping.Type.Domain))
+        return Optional.ofNullable(recipientRewriteTable.getStoredMappings(mappingSource).select(Mapping.Type.Domain))
                 .filter(mappings -> !mappings.isEmpty())
                 .filter(mappings -> mappings.contains(Mapping.Type.Domain))
                 .map(this::toDomainList)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
index cbc0749..3be3c42 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
@@ -234,7 +234,7 @@ public class ForwardRoutes implements Routes {
     })
     public ImmutableSet<ForwardDestinationResponse> listForwardDestinations(Request request, Response response) throws RecipientRewriteTableException {
         MailAddress baseAddress = parseMailAddress(request.params(FORWARD_BASE_ADDRESS));
-        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(MappingSource.fromMailAddress(baseAddress)))
+        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getStoredMappings(MappingSource.fromMailAddress(baseAddress)))
             .orElse(MappingsImpl.empty())
             .select(Mapping.Type.Forward);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
index 06723eb..110256b 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
@@ -242,7 +242,7 @@ public class GroupsRoutes implements Routes {
     })
     public ImmutableSortedSet<String> listGroupMembers(Request request, Response response) throws RecipientRewriteTableException {
         MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS));
-        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(MappingSource.fromMailAddress(groupAddress)))
+        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getStoredMappings(MappingSource.fromMailAddress(groupAddress)))
             .orElse(MappingsImpl.empty())
             .select(Mapping.Type.Group);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
index 300d884..833efa8 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
@@ -231,7 +231,7 @@ class DomainMappingsRoutesTest {
 
             recipientRewriteTable.addAliasDomainMapping(mappingSource, Domain.of(alias));
 
-            Assumptions.assumeTrue(recipientRewriteTable.getUserDomainMappings(mappingSource) != null);
+            Assumptions.assumeTrue(recipientRewriteTable.getStoredMappings(mappingSource) != null);
 
             given()
                 .body("to.com")
@@ -247,7 +247,7 @@ class DomainMappingsRoutesTest {
         void getSpecificDomainMappingShouldRespondWithNotFoundWhenHasNoAliases() throws RecipientRewriteTableException {
             String domain = "from.com";
 
-            when(recipientRewriteTable.getUserDomainMappings(any())).thenReturn(MappingsImpl.empty());
+            when(recipientRewriteTable.getStoredMappings(any())).thenReturn(MappingsImpl.empty());
 
             when()
                 .get(domain)
@@ -263,7 +263,7 @@ class DomainMappingsRoutesTest {
         void getSpecificDomainMappingShouldRespondWithNotFoundWhenHasEmptyAliases() throws RecipientRewriteTableException {
             String domain = "from.com";
 
-            when(recipientRewriteTable.getUserDomainMappings(any())).thenReturn(MappingsImpl.empty());
+            when(recipientRewriteTable.getStoredMappings(any())).thenReturn(MappingsImpl.empty());
 
             when()
                 .get(domain)
@@ -306,7 +306,7 @@ class DomainMappingsRoutesTest {
             String aliasDomain = "a.com";
             Mappings mappings = MappingsImpl.fromMappings(Mapping.domain(Domain.of(aliasDomain)));
 
-            when(recipientRewriteTable.getUserDomainMappings(any())).thenReturn(mappings);
+            when(recipientRewriteTable.getStoredMappings(any())).thenReturn(mappings);
 
             List<String> body =
             when()

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
index 80e4e45..288b050 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
@@ -665,7 +665,7 @@ class ForwardRoutesTest {
         void getShouldReturnErrorWhenRecipientRewriteTableExceptionIsThrown() throws Exception {
             doThrow(RecipientRewriteTableException.class)
                 .when(memoryRecipientRewriteTable)
-                .getUserDomainMappings(any());
+                .getStoredMappings(any());
 
             when()
                 .get(ALICE)
@@ -677,7 +677,7 @@ class ForwardRoutesTest {
         void getShouldReturnErrorWhenRuntimeExceptionIsThrown() throws Exception {
             doThrow(RuntimeException.class)
                 .when(memoryRecipientRewriteTable)
-                .getUserDomainMappings(any());
+                .getStoredMappings(any());
 
             when()
                 .get(ALICE)

http://git-wip-us.apache.org/repos/asf/james-project/blob/4e2bd7fd/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
index 991b678..1edf80d 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
@@ -670,7 +670,7 @@ class GroupsRoutesTest {
         void getShouldReturnErrorWhenRecipientRewriteTableExceptionIsThrown() throws Exception {
             doThrow(RecipientRewriteTableException.class)
                 .when(memoryRecipientRewriteTable)
-                .getUserDomainMappings(any());
+                .getStoredMappings(any());
 
             when()
                 .get(GROUP1)
@@ -682,7 +682,7 @@ class GroupsRoutesTest {
         void getShouldReturnErrorWhenRuntimeExceptionIsThrown() throws Exception {
             doThrow(RuntimeException.class)
                 .when(memoryRecipientRewriteTable)
-                .getUserDomainMappings(any());
+                .getStoredMappings(any());
 
             when()
                 .get(GROUP1)


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


[33/47] james-project git commit: JAMES-2636 Wildcard definition needs to be covered by MappingSource

Posted by bt...@apache.org.
JAMES-2636 Wildcard definition needs to be covered by MappingSource

This constant was only used by tests and made the API confusing.
Refactoring this was easy.


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

Branch: refs/heads/master
Commit: 9a4ce2fb37396bb9d4ae43f41206e664447351a5
Parents: 5392ad9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Jan 4 09:39:08 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:45:33 2019 +0700

----------------------------------------------------------------------
 .../james/rrt/api/RecipientRewriteTable.java    | 21 --------------------
 .../james/rrt/lib/RewriteTablesStepdefs.java    | 13 +++++++++---
 2 files changed, 10 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9a4ce2fb/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index cba17a4..fed9ea0 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -35,27 +35,6 @@ import com.google.common.base.Preconditions;
  */
 public interface RecipientRewriteTable {
 
-    interface Domains {
-
-        Domain WILDCARD = new Domain(RecipientRewriteTable.WILDCARD) {
-
-            @Override
-            public String name() {
-                throw new IllegalStateException();
-            }
-
-            @Override
-            public String toString() {
-                return "Domain : * (Wildcard)";
-            }
-        };
-    }
-
-    /**
-     * The wildcard used for alias domain mappings
-     */
-    String WILDCARD = "*";
-
     void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException;
 
     void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9a4ce2fb/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
index a2e83b7..6c59812 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.List;
 
 import org.apache.james.core.Domain;
-import org.apache.james.rrt.api.RecipientRewriteTable;
 import org.apache.james.rrt.api.RecipientRewriteTable.ErrorMappingException;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 
@@ -56,6 +55,10 @@ public class RewriteTablesStepdefs {
     @Given("store \"([^\"]*)\" address mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"")
     public void storeAddressMappingForUserAtDomain(String address, String user, String domain) throws Throwable {
         MappingSource source = MappingSource.fromUser(user, domain);
+        storeAddressMappingForUserAtDomain(address, source);
+    }
+
+    private void storeAddressMappingForUserAtDomain(String address, MappingSource source) throws RecipientRewriteTableException {
         rewriteTable.addAddressMapping(source, address);
     }
 
@@ -67,7 +70,7 @@ public class RewriteTablesStepdefs {
 
     @Given("store \"([^\"]*)\" address mapping as wildcard for domain \"([^\"]*)\"")
     public void storeAddressMappingAsWildcardAtDomain(String address, String domain) throws Throwable {
-        storeAddressMappingForUserAtDomain(address, RecipientRewriteTable.WILDCARD, domain);
+        storeAddressMappingForUserAtDomain(address, MappingSource.fromDomain(Domain.of(domain)));
     }
 
     @Given("store \"([^\"]*)\" alias domain mapping for domain \"([^\"]*)\"")
@@ -106,6 +109,10 @@ public class RewriteTablesStepdefs {
     @When("user \"([^\"]*)\" at domain \"([^\"]*)\" removes a address mapping \"([^\"]*)\"")
     public void userAtDomainRemovesAddressMapping(String user, String domain, String address) throws Throwable {
         MappingSource source = MappingSource.fromUser(user, domain);
+        userAtDomainRemovesAddressMapping(address, source);
+    }
+
+    private void userAtDomainRemovesAddressMapping(String address, MappingSource source) throws RecipientRewriteTableException {
         rewriteTable.removeAddressMapping(source, address);
     }
 
@@ -129,7 +136,7 @@ public class RewriteTablesStepdefs {
 
     @When("wildcard address mapping \"([^\"]*)\" at domain \"([^\"]*)\" is removed")
     public void removeWildcardAddressMappingAtDomain(String address, String domain) throws Throwable {
-        userAtDomainRemovesAddressMapping(RecipientRewriteTable.WILDCARD, domain, address);
+        userAtDomainRemovesAddressMapping(address, MappingSource.fromDomain(Domain.of(domain)));
     }
 
     @When("alias domain mapping \"([^\"]*)\" for \"([^\"]*)\" domain is removed")


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


[27/47] james-project git commit: MAILBOX-364 EventFactory should rather link LessageMoveEvent.Builder

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should rather link LessageMoveEvent.Builder


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

Branch: refs/heads/master
Commit: 2713b4d9eea46e5a96078e54b59bfb0d7e67eab7
Parents: b5608ad
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 13:56:42 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/store/event/EventFactory.java  | 12 ++----------
 .../mailbox/store/event/MailboxEventDispatcher.java     |  6 +++++-
 2 files changed, 7 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2713b4d9/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index cc8a2f6..1c0a477 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -19,8 +19,6 @@
 
 package org.apache.james.mailbox.store.event;
 
-import java.util.Collection;
-
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
@@ -31,9 +29,7 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.MessageMoves;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -332,11 +328,7 @@ public class EventFactory {
         return new MailboxAclUpdatedBuilder();
     }
 
-    public MessageMoveEvent moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {
-        return MessageMoveEvent.builder()
-                .user(session.getUser())
-                .messageMoves(messageMoves)
-                .messageId(messageIds)
-                .build();
+    public MessageMoveEvent.Builder moved() {
+        return MessageMoveEvent.builder();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2713b4d9/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index e7a8a4f..d161338 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -192,7 +192,11 @@ public class MailboxEventDispatcher {
     }
 
     public void moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {
-        event(eventFactory.moved(session, messageMoves, messageIds));
+        event(eventFactory.moved()
+            .session(session)
+            .messageMoves(messageMoves)
+            .messageId(messageIds)
+            .build());
     }
 
     public void quota(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota) {


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


[40/47] james-project git commit: JAMES-2631 ReIndent InMemoryHostSystem

Posted by bt...@apache.org.
JAMES-2631 ReIndent InMemoryHostSystem


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

Branch: refs/heads/master
Commit: 9cdf4ba815bcbd06d2d332018e59b2f76d67739f
Parents: 185810d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 15:16:25 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:46:16 2019 +0700

----------------------------------------------------------------------
 .../inmemory/host/InMemoryHostSystem.java       | 223 ++++++++++---------
 1 file changed, 112 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9cdf4ba8/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index aa8bc22..3e4f238 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -1,111 +1,112 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mpt.imapmailbox.inmemory.host;
-
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
-import org.apache.james.imap.main.DefaultImapDecoderFactory;
-import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSessionUtil;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
-import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
-import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
-import org.apache.james.mailbox.quota.QuotaRootResolver;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.apache.james.mailbox.store.StoreSubscriptionManager;
-import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
-import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
-import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
-import org.apache.james.mailbox.store.quota.StoreQuotaManager;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
-import org.apache.james.mpt.api.ImapFeatures;
-import org.apache.james.mpt.api.ImapFeatures.Feature;
-import org.apache.james.mpt.host.JamesImapHostSystem;
-
-public class InMemoryHostSystem extends JamesImapHostSystem {
-
-    private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT,
-        Feature.MOVE_SUPPORT,
-        Feature.USER_FLAGS_SUPPORT,
-        Feature.QUOTA_SUPPORT,
-        Feature.ANNOTATION_SUPPORT,
-        Feature.MOD_SEQ_SEARCH);
-
-    private StoreMailboxManager mailboxManager;
-    private InMemoryPerUserMaxQuotaManager perUserMaxQuotaManager;
-
-    public static JamesImapHostSystem build() throws Exception {
-        return new InMemoryHostSystem();
-    }
-    
-    @Override
-    public void beforeTest() throws Exception {
-        super.beforeTest();
-        this.mailboxManager = new InMemoryIntegrationResources()
-            .createMailboxManager(new SimpleGroupMembershipResolver(), authenticator, authorizator);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
-
-        perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
-
-        InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(
-            new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver),
-            mailboxManager);
-
-        StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
-
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
-
-        mailboxManager.setQuotaRootResolver(quotaRootResolver);
-        mailboxManager.setQuotaManager(quotaManager);
-        mailboxManager.setQuotaUpdater(quotaUpdater);
-        mailboxManager.addGlobalListener(quotaUpdater, MailboxSessionUtil.create("admin"));
-
-        final ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, new StoreSubscriptionManager(mailboxManager.getMapperFactory()), quotaManager, quotaRootResolver, new DefaultMetricFactory());
-        configure(new DefaultImapDecoderFactory().buildImapDecoder(),
-                new DefaultImapEncoderFactory().buildImapEncoder(),
-                defaultImapProcessorFactory);
-    }
-
-    @Override
-    protected MailboxManager getMailboxManager() {
-        return mailboxManager;
-    }
-
-    @Override
-    public boolean supports(Feature... features) {
-        return SUPPORTED_FEATURES.supports(features);
-    }
-
-    @Override
-    public void setQuotaLimits(QuotaCount maxMessageQuota, QuotaSize maxStorageQuota) throws MailboxException {
-        perUserMaxQuotaManager.setGlobalMaxMessage(maxMessageQuota);
-        perUserMaxQuotaManager.setGlobalMaxStorage(maxStorageQuota);
-    }
-
-    @Override
-    protected void await() {
-
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.mpt.imapmailbox.inmemory.host;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
+import org.apache.james.imap.main.DefaultImapDecoderFactory;
+import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSessionUtil;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.inmemory.quota.InMemoryCurrentQuotaManager;
+import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.StoreSubscriptionManager;
+import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
+import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
+import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
+import org.apache.james.mailbox.store.quota.StoreQuotaManager;
+import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.mpt.api.ImapFeatures;
+import org.apache.james.mpt.api.ImapFeatures.Feature;
+import org.apache.james.mpt.host.JamesImapHostSystem;
+
+public class InMemoryHostSystem extends JamesImapHostSystem {
+
+    private static final ImapFeatures SUPPORTED_FEATURES = ImapFeatures.of(Feature.NAMESPACE_SUPPORT,
+        Feature.MOVE_SUPPORT,
+        Feature.USER_FLAGS_SUPPORT,
+        Feature.QUOTA_SUPPORT,
+        Feature.ANNOTATION_SUPPORT,
+        Feature.MOD_SEQ_SEARCH);
+
+    private StoreMailboxManager mailboxManager;
+    private InMemoryPerUserMaxQuotaManager perUserMaxQuotaManager;
+
+    public static JamesImapHostSystem build() throws Exception {
+        return new InMemoryHostSystem();
+    }
+    
+    @Override
+    public void beforeTest() throws Exception {
+        super.beforeTest();
+        this.mailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver(), authenticator, authorizator);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
+
+        perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
+
+        InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(
+            new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver),
+            mailboxManager);
+
+        StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, perUserMaxQuotaManager);
+
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
+
+        mailboxManager.setQuotaRootResolver(quotaRootResolver);
+        mailboxManager.setQuotaManager(quotaManager);
+        mailboxManager.setQuotaUpdater(quotaUpdater);
+        mailboxManager.addGlobalListener(quotaUpdater, MailboxSessionUtil.create("admin"));
+
+        final ImapProcessor defaultImapProcessorFactory = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, new StoreSubscriptionManager(mailboxManager.getMapperFactory()), quotaManager, quotaRootResolver, new DefaultMetricFactory());
+        configure(new DefaultImapDecoderFactory().buildImapDecoder(),
+                new DefaultImapEncoderFactory().buildImapEncoder(),
+                defaultImapProcessorFactory);
+    }
+
+    @Override
+    protected MailboxManager getMailboxManager() {
+        return mailboxManager;
+    }
+
+    @Override
+    public boolean supports(Feature... features) {
+        return SUPPORTED_FEATURES.supports(features);
+    }
+
+    @Override
+    public void setQuotaLimits(QuotaCount maxMessageQuota, QuotaSize maxStorageQuota) throws MailboxException {
+        perUserMaxQuotaManager.setGlobalMaxMessage(maxMessageQuota);
+        perUserMaxQuotaManager.setGlobalMaxStorage(maxStorageQuota);
+    }
+
+    @Override
+    protected void await() {
+
+    }
+}


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


[18/47] james-project git commit: MAILBOX-359 ReIndent QuotaUsageUpdatedEventSerializationTest

Posted by bt...@apache.org.
MAILBOX-359 ReIndent QuotaUsageUpdatedEventSerializationTest


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

Branch: refs/heads/master
Commit: 4d6a372213fef7194a9cfa2840336f96d6769126
Parents: 0781849
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 18:10:40 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:53 2019 +0700

----------------------------------------------------------------------
 ...QuotaUsageUpdatedEventSerializationTest.java | 88 ++++++++++----------
 1 file changed, 44 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4d6a3722/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index 608bee3..4ce097d 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -55,14 +55,14 @@ class QuotaUsageUpdatedEventSerializationTest {
         INSTANT);
     private final String quotaUsageUpdatedEvent =
         "{" +
-            "\"QuotaUsageUpdatedEvent\":{" +
-            "\"quotaRoot\":\"foo\"," +
-            "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-            "\"time\":\"2018-11-13T12:00:55Z\"," +
-            "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-            "\"user\":\"onlyUsername\"" +
-            "}" +
-            "}";
+        "    \"QuotaUsageUpdatedEvent\":{" +
+        "        \"quotaRoot\":\"foo\"," +
+        "        \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+        "        \"time\":\"2018-11-13T12:00:55Z\"," +
+        "        \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+        "        \"user\":\"onlyUsername\"" +
+        "    }" +
+        "}";
 
     @Test
     void fromJsonShouldReturnQuotaEvent() {
@@ -80,13 +80,13 @@ class QuotaUsageUpdatedEventSerializationTest {
     void fromJsonShouldThrowResultWhenUserIsMissing() {
         String quotaUsageUpdatedEvent =
             "{" +
-                "\"QuotaUsageUpdatedEvent\":{" +
-                "\"quotaRoot\":\"foo\"," +
-                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                "\"time\":\"2018-11-13T12:00:55Z\"," +
-                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
-                "}" +
-                "}";
+            "    \"QuotaUsageUpdatedEvent\":{" +
+            "        \"quotaRoot\":\"foo\"," +
+            "        \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+            "        \"time\":\"2018-11-13T12:00:55Z\"," +
+            "        \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
+            "    }" +
+            "}";
 
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
@@ -96,13 +96,13 @@ class QuotaUsageUpdatedEventSerializationTest {
     void fromJsonShouldThrowWhenCountQuotaIsMissing() {
         String quotaUsageUpdatedEvent =
             "{" +
-                "\"QuotaUsageUpdatedEvent\":{" +
-                "\"quotaRoot\":\"foo\"," +
-                "\"time\":\"2018-11-13T12:00:55Z\"," +
-                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                "\"user\":\"onlyUsername\"" +
-                "}" +
-                "}";
+            "    \"QuotaUsageUpdatedEvent\":{" +
+            "        \"quotaRoot\":\"foo\"," +
+            "        \"time\":\"2018-11-13T12:00:55Z\"," +
+            "        \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+            "        \"user\":\"onlyUsername\"" +
+            "        }" +
+            "}";
 
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
@@ -112,13 +112,13 @@ class QuotaUsageUpdatedEventSerializationTest {
     void fromJsonShouldThrowWhenSizeQuotaIsMissing() {
         String quotaUsageUpdatedEvent =
             "{" +
-                "\"QuotaUsageUpdatedEvent\":{" +
-                "\"quotaRoot\":\"foo\"," +
-                "\"time\":\"2018-11-13T12:00:55Z\"," +
-                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                "\"user\":\"onlyUsername\"" +
-                "}" +
-                "}";
+            "    \"QuotaUsageUpdatedEvent\":{" +
+            "        \"quotaRoot\":\"foo\"," +
+            "        \"time\":\"2018-11-13T12:00:55Z\"," +
+            "        \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+            "        \"user\":\"onlyUsername\"" +
+            "        }" +
+            "}";
 
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
@@ -128,13 +128,13 @@ class QuotaUsageUpdatedEventSerializationTest {
     void fromJsonShouldThrowResultWhenTimeIsNull() {
         String quotaUsageUpdatedEvent =
             "{" +
-                "\"QuotaUsageUpdatedEvent\":{" +
-                "\"quotaRoot\":\"foo\"," +
-                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
-                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                "\"user\":\"user\"" +
-                "}" +
-                "}";
+            "    \"QuotaUsageUpdatedEvent\":{" +
+            "        \"quotaRoot\":\"foo\"," +
+            "        \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
+            "        \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+            "        \"user\":\"user\"" +
+            "        }" +
+            "}";
 
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
@@ -144,14 +144,14 @@ class QuotaUsageUpdatedEventSerializationTest {
     void fromJsonShouldThrowResultWhenTimeIsEmpty() {
         String quotaUsageUpdatedEvent =
             "{" +
-                "\"QuotaUsageUpdatedEvent\":{" +
-                "\"quotaRoot\":\"foo\"," +
-                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
-                "\"time\":\"\"," +
-                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                "\"user\":\"user\"" +
-                "}" +
-                "}";
+            "    \"QuotaUsageUpdatedEvent\":{" +
+            "        \"quotaRoot\":\"foo\"," +
+            "        \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
+            "        \"time\":\"\"," +
+            "        \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+            "        \"user\":\"user\"" +
+            "    }" +
+            "}";
 
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);


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


[47/47] james-project git commit: Adding LICENSE for project

Posted by bt...@apache.org.
Adding LICENSE for project


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

Branch: refs/heads/master
Commit: d5ff60a7376b94e2f6514f829d9aaab75b6a6fb6
Parents: b1e241c
Author: Trần Tiến Đức <dt...@linagora.com>
Authored: Sun Jan 6 13:42:54 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:51:54 2019 +0700

----------------------------------------------------------------------
 LICENSE | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 176 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d5ff60a7/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d9a10c0
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,176 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS


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


[08/47] james-project git commit: MAILBOX-359 Factorize tests for MailboxPath ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for MailboxPath ser-deserialization


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

Branch: refs/heads/master
Commit: 70a4fd59c5220489f1c0adff2bdadae64d49d22b
Parents: e64e8e1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 13:52:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      | 267 +----------
 .../event/json/ExpungedSerializationTest.java   | 266 +----------
 .../json/FlagsUpdatedSerializationTest.java     | 286 ++----------
 ...MailboxACLUpdatedEventSerializationTest.java | 211 +--------
 .../json/MailboxAddedSerializationTest.java     | 141 ------
 .../json/MailboxDeletionSerializationTest.java  | 176 +------
 .../json/MailboxRenamedSerializationTest.java   | 457 +------------------
 .../james/event/json/dtos/MailboxPathTest.java  | 177 +++++++
 8 files changed, 296 insertions(+), 1685 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index 3af5c28..d71b9e8 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -21,7 +21,6 @@ package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
 import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
-import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -398,117 +397,6 @@ class AddedSerializationTest {
     }
 
     @Nested
-    class NullOrEmptyNameSpaceInMailboxPath {
-
-        @Test
-        void addedShouldBeWellDeSerializedWhenNullNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_ADDED_EVENT);
-        }
-
-        @Test
-        void addedShouldBeWellDeSerializedWhenEmptyNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_ADDED_EVENT);
-        }
-    }
-
-    @Nested
-    class NullUserInMailboxPath {
-        private final String nullUser = null;
-        private final MailboxListener.Added eventWithNullUserInPath = new MailboxListener.Added(
-            SESSION_ID,
-            USER,
-            new MailboxPath(USER_NAMESPACE, nullUser, MAILBOX_NAME),
-            MAILBOX_ID,
-            ADDED);
-
-        private static final String EVENT_JSON_WITH_NULL_USER_IN_PATH =
-            "{" +
-            "  \"Added\": {" +
-            "    \"path\": {" +
-            "      \"namespace\": \"#private\"," +
-            "      \"name\": \"mailboxName\"" +
-            "    }," +
-            "    \"mailboxId\": \"18\"," +
-            "    \"added\": {" +
-            "      \"123456\": {" +
-            "        \"uid\": 123456," +
-            "        \"modSeq\": 35," +
-            "        \"flags\": {" +
-            "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-            "          \"userFlags\":[\"User Custom Flag\"]}," +
-            "        \"size\": 45,  " +
-            "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-            "        \"messageId\": \"42\"" +
-            "      }" +
-            "    }," +
-            "    \"sessionId\": 42," +
-            "    \"user\": \"user\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void addedShouldBeWellSerialized() {
-            assertThatJson(EVENT_SERIALIZER.toJson(eventWithNullUserInPath))
-                .isEqualTo(EVENT_JSON_WITH_NULL_USER_IN_PATH);
-        }
-
-        @Test
-        void addedShouldBeWellDeSerialized() {
-            assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_IN_PATH).get())
-                .isEqualTo(eventWithNullUserInPath);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void addedShouldThrowWhenMissingSessionId() {
@@ -597,138 +485,29 @@ class AddedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxPath {
-
-            @Nested
-            class DeserializationErrorOnNameSpace {
-                @Test
-                void addedShouldThrowWhenNameSpaceIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 48246," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnUser {
-                @Test
-                void addedShouldThrowWhenUserIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": 265412.64," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMailboxName {
-
-                @Test
-                void addedShouldThrowWhenNullMailboxName() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenMailboxNameIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": 11861" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        @Test
+        void addedShouldThrowWhenMissingPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"Added\": {" +
+                    "    \"mailboxId\": \"18\"," +
+                    "    \"added\": {" +
+                    "      \"123456\": {" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "      }" +
+                    "    }," +
+                    "    \"sessionId\": 42," +
+                    "    \"user\": \"user\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 2aee596..40a7054 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -21,7 +21,6 @@ package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
 import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
-import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -396,116 +395,6 @@ class ExpungedSerializationTest {
             .isEqualTo(eventRoundToMinute);
         }
     }
-    @Nested
-    class NullOrEmptyNameSpaceInMailboxPath {
-
-        @Test
-        void expungedShouldBeWellDeSerializedWhenNullNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_EXPUNGED_EVENT);
-        }
-
-        @Test
-        void expungedShouldBeWellDeSerializedWhenEmptyNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                "          \"userFlags\":[\"User Custom Flag\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_EXPUNGED_EVENT);
-        }
-    }
-
-    @Nested
-    class NullUserInMailboxPath {
-        private final String nullUser = null;
-        private final MailboxListener.Expunged eventWithNullUserInPath = new MailboxListener.Expunged(
-            SESSION_ID,
-            USER,
-            new MailboxPath(USER_NAMESPACE, nullUser, MAILBOX_NAME),
-            MAILBOX_ID,
-            EXPUNGED);
-
-        private static final String EVENT_JSON_WITH_NULL_USER_IN_PATH =
-            "{" +
-            "  \"Expunged\": {" +
-            "    \"path\": {" +
-            "      \"namespace\": \"#private\"," +
-            "      \"name\": \"mailboxName\"" +
-            "    }," +
-            "    \"mailboxId\": \"18\"," +
-            "    \"expunged\": {" +
-            "      \"123456\": {" +
-            "        \"uid\": 123456," +
-            "        \"modSeq\": 35," +
-            "        \"flags\": {" +
-            "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-            "          \"userFlags\":[\"User Custom Flag\"]}," +
-            "        \"size\": 45,  " +
-            "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-            "        \"messageId\": \"42\"" +
-            "      }" +
-            "    }," +
-            "    \"sessionId\": 42," +
-            "    \"user\": \"user\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void expungedShouldBeWellSerialized() {
-            assertThatJson(EVENT_SERIALIZER.toJson(eventWithNullUserInPath))
-                .isEqualTo(EVENT_JSON_WITH_NULL_USER_IN_PATH);
-        }
-
-        @Test
-        void expungedShouldBeWellDeSerialized() {
-            assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_IN_PATH).get())
-                .isEqualTo(eventWithNullUserInPath);
-        }
-    }
 
     @Nested
     class DeserializationErrors {
@@ -596,138 +485,29 @@ class ExpungedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxPath {
-
-            @Nested
-            class DeserializationErrorOnNameSpace {
-                @Test
-                void expungedShouldThrowWhenNameSpaceIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 48246," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnUser {
-                @Test
-                void expungedShouldThrowWhenUserIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": 265412.64," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMailboxName {
-
-                @Test
-                void expungedShouldThrowWhenNullMailboxName() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void expungedShouldThrowWhenMailboxNameIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": 11861" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        @Test
+        void expungedShouldThrowWhenMissingPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"Expunged\": {" +
+                    "    \"mailboxId\": \"18\"," +
+                    "    \"expunged\": {" +
+                    "      \"123456\": {" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"flags\": {" +
+                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
+                    "          \"userFlags\":[\"User Custom Flag\"]}," +
+                    "        \"size\": 45,  " +
+                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
+                    "        \"messageId\": \"42\"" +
+                    "      }" +
+                    "    }," +
+                    "    \"sessionId\": 42," +
+                    "    \"user\": \"user\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index abef4bd..90c0a01 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -136,122 +136,6 @@ class FlagsUpdatedSerializationTest {
     }
 
     @Nested
-    class NullOrEmptyNameSpaceInMailboxPath {
-
-        @Test
-        void flagsUpdatedShouldBeWellDeSerializedWhenNullNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"FlagsUpdated\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": null," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"sessionId\": 42," +
-                "    \"updatedFlags\": [" +
-                "      {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                "      }," +
-                "      {" +
-                "        \"uid\": 654321," +
-                "        \"modSeq\": 36," +
-                "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                "      }" +
-                "    ]," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_EVENT);
-        }
-
-        @Test
-        void flagsUpdatedShouldBeWellDeSerializedWhenEmptyNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"FlagsUpdated\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"sessionId\": 42," +
-                "    \"updatedFlags\": [" +
-                "      {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                "      }," +
-                "      {" +
-                "        \"uid\": 654321," +
-                "        \"modSeq\": 36," +
-                "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                "      }" +
-                "    ]," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_EVENT);
-        }
-    }
-
-    @Nested
-    class NullUserInMailboxPath {
-        private final String nullUser = null;
-        private final MailboxListener.FlagsUpdated nullUserEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER,
-            new MailboxPath(MailboxConstants.USER_NAMESPACE, nullUser, MAILBOX_NAME),
-            MAILBOX_ID, UPDATED_FLAGS_LIST);
-
-        private static final String EVENT_JSON_WITH_NULL_USER_IN_PATH =
-            "{" +
-            "  \"FlagsUpdated\": {" +
-            "    \"path\": {" +
-            "      \"namespace\": \"#private\"," +
-            "      \"name\": \"mailboxName\"" +
-            "    }," +
-            "    \"mailboxId\": \"18\"," +
-            "    \"sessionId\": 42," +
-            "    \"updatedFlags\": [" +
-            "      {" +
-            "        \"uid\": 123456," +
-            "        \"modSeq\": 35," +
-            "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-            "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-            "      }," +
-            "      {" +
-            "        \"uid\": 654321," +
-            "        \"modSeq\": 36," +
-            "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-            "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-            "      }" +
-            "    ]," +
-            "    \"user\": \"user\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void flagsUpdatedShouldBeWellSerialized() {
-            assertThatJson(EVENT_SERIALIZER.toJson(nullUserEvent))
-                .when(Option.IGNORING_ARRAY_ORDER)
-                .isEqualTo(EVENT_JSON_WITH_NULL_USER_IN_PATH);
-        }
-
-        @Test
-        void flagsUpdatedShouldBeWellDeSerialized() {
-            assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_IN_PATH).get())
-                .isEqualTo(nullUserEvent);
-        }
-    }
-
-    @Nested
     class WithUpdatedFlags {
 
         @Nested
@@ -526,146 +410,36 @@ class FlagsUpdatedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxPath {
-
-            @Nested
-            class DeserializationErrorOnNameSpace {
-                @Test
-                void flagsUpdatedShouldThrowWhenNameSpaceIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }," +
-                        "      {" +
-                        "        \"uid\": 654321," +
-                        "        \"modSeq\": 36," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnUser {
-                @Test
-                void flagsUpdatedShouldThrowWhenUserIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": 682695," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }," +
-                        "      {" +
-                        "        \"uid\": 654321," +
-                        "        \"modSeq\": 36," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMailboxName {
-
-                @Test
-                void flagsUpdatedShouldThrowWhenNullMailboxName() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": null" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }," +
-                        "      {" +
-                        "        \"uid\": 654321," +
-                        "        \"modSeq\": 36," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenMailboxNameIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": 156.88541" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }," +
-                        "      {" +
-                        "        \"uid\": 654321," +
-                        "        \"modSeq\": 36," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        @Test
+        void flagsUpdatedShouldThrowWhenMissingMailboxPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"FlagsUpdated\": {" +
+                    "    \"path\": {" +
+                    "      \"namespace\": 482," +
+                    "      \"user\": \"user\"," +
+                    "      \"name\": \"mailboxName\"" +
+                    "    }," +
+                    "    \"mailboxId\": \"18\"," +
+                    "    \"sessionId\": 42," +
+                    "    \"updatedFlags\": [" +
+                    "      {" +
+                    "        \"uid\": 123456," +
+                    "        \"modSeq\": 35," +
+                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+                    "      }," +
+                    "      {" +
+                    "        \"uid\": 654321," +
+                    "        \"modSeq\": 36," +
+                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
+                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
+                    "      }" +
+                    "    ]," +
+                    "    \"user\": \"user\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index 0855c64..7176c91 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -87,102 +87,6 @@ class MailboxACLUpdatedEventSerializationTest {
     }
 
     @Nested
-    class NullUserInMailboxPath {
-        private final String NULL_USER = null;
-        private static final String JSON_2 = "{" +
-            "  \"MailboxACLUpdated\":{" +
-            "    \"mailboxPath\":{" +
-            "       \"namespace\":\"#private\"," +
-            "       \"name\":\"mailboxName\"" +
-            "      }," +
-            "    \"aclDiff\":{" +
-            "       \"oldACL\":{}," +
-            "       \"newACL\":{\"$any\":\"ar\"}}," +
-            "    \"mailboxId\":\"23\"," +
-            "    \"sessionId\":6," +
-            "    \"user\":\"user\"" +
-            "   }" +
-            "}";
-
-        private final MailboxACL MAILBOX_ACL= new MailboxACL(
-                new MailboxACL.Entry(ENTRY_KEY, RIGHTS));
-
-        private final MailboxListener.MailboxACLUpdated UPDATED_EVENT = new MailboxListener.MailboxACLUpdated(
-                MailboxSession.SessionId.of(6),
-                USER,
-                new MailboxPath(MailboxConstants.USER_NAMESPACE, NULL_USER, "mailboxName"),
-                ACLDiff.computeDiff(MailboxACL.EMPTY, MAILBOX_ACL),
-                TestId.of(23));
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellSerializedWithNullUser() {
-            assertThatJson(EVENT_SERIALIZER.toJson(UPDATED_EVENT))
-                .isEqualTo(JSON_2);
-        }
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
-            assertThat(EVENT_SERIALIZER.fromJson(JSON_2).get())
-                .isEqualTo(UPDATED_EVENT);
-        }
-    }
-
-    @Nested
-    class NullNameSpaceInMailboxPath {
-
-        private final MailboxACL MAILBOX_ACL = new MailboxACL(
-            new MailboxACL.Entry(ENTRY_KEY, RIGHTS));
-
-        private final MailboxListener.MailboxACLUpdated UPDATED_EVENT = new MailboxListener.MailboxACLUpdated(
-            MailboxSession.SessionId.of(6),
-            USER,
-            new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
-            ACLDiff.computeDiff(MailboxACL.EMPTY, MAILBOX_ACL),
-            TestId.of(23));
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenMissingNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxACLUpdated\":{" +
-                "    \"mailboxPath\":{" +
-                "       \"user\": \"bob\"," +
-                "       \"name\":\"mailboxName\"" +
-                "      }," +
-                "    \"aclDiff\":{" +
-                "       \"oldACL\":{}," +
-                "       \"newACL\":{\"$any\":\"ar\"}}," +
-                "    \"mailboxId\":\"23\"," +
-                "    \"sessionId\":6," +
-                "    \"user\":\"user\"" +
-                "   }" +
-                "}").get())
-                .isEqualTo(UPDATED_EVENT);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenNullNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxACLUpdated\":{" +
-                "    \"mailboxPath\":{" +
-                "       \"namespace\":null," +
-                "       \"user\": \"bob\"," +
-                "       \"name\":\"mailboxName\"" +
-                "      }," +
-                "    \"aclDiff\":{" +
-                "       \"oldACL\":{}," +
-                "       \"newACL\":{\"$any\":\"ar\"}}," +
-                "    \"mailboxId\":\"23\"," +
-                "    \"sessionId\":6," +
-                "    \"user\":\"user\"" +
-                "   }" +
-                "}").get())
-                .isEqualTo(UPDATED_EVENT);
-        }
-    }
-
-    @Nested
     class EmptyRightInMailboxACL {
 
         private final String jsonNullRight =
@@ -745,102 +649,25 @@ class MailboxACLUpdatedEventSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxPath {
-
-            @Nested
-            class DeserializationErrorOnNameSpace {
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNameSpaceIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                            "  \"MailboxACLUpdated\":{" +
-                            "    \"mailboxPath\":{" +
-                            "       \"namespace\":230192.06," +
-                            "       \"user\":\"bob\"," +
-                            "       \"name\":\"mailboxName\"" +
-                            "      }," +
-                            "    \"aclDiff\":{" +
-                            "       \"oldACL\":{}," +
-                            "       \"newACL\":{\"$any\":\"ar\"}}," +
-                            "    \"mailboxId\":\"123\"," +
-                            "    \"sessionId\":6," +
-                            "    \"user\":\"user\"" +
-                            "   }" +
-                            "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnUser {
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                            "  \"MailboxACLUpdated\":{" +
-                            "    \"mailboxPath\":{" +
-                            "       \"namespace\":230192.06," +
-                            "       \"user\":180806," +
-                            "       \"name\":\"mailboxName\"" +
-                            "      }," +
-                            "    \"aclDiff\":{" +
-                            "       \"oldACL\":{}," +
-                            "       \"newACL\":{\"$any\":\"ar\"}}," +
-                            "    \"mailboxId\":\"123\"," +
-                            "    \"sessionId\":6," +
-                            "    \"user\":\"user\"" +
-                            "   }" +
-                            "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMailboxName {
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenNullMailboxName() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                            "  \"MailboxACLUpdated\":{" +
-                            "    \"mailboxPath\":{" +
-                            "       \"namespace\":230192.06," +
-                            "       \"user\":180806," +
-                            "       \"name\":null" +
-                            "      }," +
-                            "    \"aclDiff\":{" +
-                            "       \"oldACL\":{}," +
-                            "       \"newACL\":{\"$any\":\"ar\"}}," +
-                            "    \"mailboxId\":\"123\"," +
-                            "    \"sessionId\":6," +
-                            "    \"user\":\"user\"" +
-                            "   }" +
-                            "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void mailboxACLUpdatedShouldThrowWhenMailboxNameIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                            "  \"MailboxACLUpdated\":{" +
-                            "    \"mailboxPath\":{" +
-                            "       \"namespace\":230192.06," +
-                            "       \"user\":\"bob\"," +
-                            "       \"name\":160205" +
-                            "      }," +
-                            "    \"aclDiff\":{" +
-                            "       \"oldACL\":{}," +
-                            "       \"newACL\":{\"$any\":\"ar\"}}," +
-                            "    \"mailboxId\":\"123\"," +
-                            "    \"sessionId\":6," +
-                            "    \"user\":\"user\"" +
-                            "   }" +
-                            "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        @Test
+        void mailboxACLUpdatedShouldThrowWhenMissingMailboxPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"MailboxACLUpdated\":{" +
+                    "    \"mailboxPath\":{" +
+                    "       \"namespace\":230192.06," +
+                    "       \"user\":\"bob\"," +
+                    "       \"name\":\"mailboxName\"" +
+                    "      }," +
+                    "    \"aclDiff\":{" +
+                    "       \"oldACL\":{}," +
+                    "       \"newACL\":{\"$any\":\"ar\"}}," +
+                    "    \"mailboxId\":\"123\"," +
+                    "    \"sessionId\":6," +
+                    "    \"user\":\"user\"" +
+                    "   }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index 4ee0db7..51c87e7 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -73,79 +73,6 @@ class MailboxAddedSerializationTest {
     }
 
     @Nested
-    class NullUserInMailboxPath {
-        private final String NULL_USER = null;
-        private final MailboxListener.MailboxAdded EVENT_2 = new MailboxListener.MailboxAdded(
-            MailboxSession.SessionId.of(42),
-            USER,
-            new MailboxPath(MailboxConstants.USER_NAMESPACE, NULL_USER, "mailboxName"),
-            TestId.of(18));
-
-        private static final String JSON_2 = "{" +
-            "  \"MailboxAdded\":{" +
-            "    \"mailboxPath\":{" +
-            "      \"namespace\":\"#private\"," +
-            "      \"name\":\"mailboxName\"" +
-            "     }," +
-            "     \"mailboxId\":\"18\"," +
-            "     \"user\":\"user\"," +
-            "     \"sessionId\":42" +
-            "  }" +
-            "}";
-
-        @Test
-        void mailboxAddedShouldBeWellSerializedWithNullUser() {
-            assertThatJson(EVENT_SERIALIZER.toJson(EVENT_2))
-                .isEqualTo(JSON_2);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWithNullUser() {
-            assertThat(EVENT_SERIALIZER.fromJson(JSON_2).get())
-                .isEqualTo(EVENT_2);
-        }
-    }
-
-    @Nested
-    class NullNameSpaceInMailboxPath {
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenMissingNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":42" +
-                "  }" +
-                "}").get())
-            .isEqualTo(EVENT_1);
-        }
-
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenNullNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":null," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":42" +
-                "  }" +
-                "}").get())
-            .isEqualTo(EVENT_1);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
 
         @Test
@@ -207,73 +134,5 @@ class MailboxAddedSerializationTest {
                 "}").get())
                 .isInstanceOf(NoSuchElementException.class);
         }
-
-        @Test
-        void fromJsonShouldRejectLongNamespace() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":12," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectLongUserInMailboxPath() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":12," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectLongName() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":1" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectNullName() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":null" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index fc7a708..f0f9f66 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -90,72 +90,6 @@ class MailboxDeletionSerializationTest {
     }
 
     @Nested
-    class NullOrEmptyNameSpaceInMailboxPath {
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenEmptyNameSpace() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxDeletion\":{" +
-                "    \"sessionId\":3652," +
-                "    \"user\":\"user\"," +
-                "    \"path\":{" +
-                "      \"namespace\":\"\"," +
-                "      \"user\":\"user\"," +
-                "      \"name\":\"mailboxName\"" +
-                "    }," +
-                "    \"quotaRoot\":\"user@domain\"," +
-                "    \"deletedMessageCount\":60," +
-                "    \"totalDeletedSize\":100," +
-                "    \"mailboxId\":\"789\"" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_MAILBOX_DELETION_EVENT);
-        }
-    }
-
-    @Nested
-    class NullUserInMailboxPath {
-
-        private final String nulUser = null;
-        private final MailboxListener.MailboxDeletion nullUserInMailboxPathEvent = new MailboxListener.MailboxDeletion(
-                SESSION_ID,
-                USER,
-                new MailboxPath(USER_NAMESPACE, nulUser, "mailboxName"),
-                QUOTA_ROOT,
-                DELETED_MESSAGE_COUNT,
-                TOTAL_DELETED_SIZE,
-                MAILBOX_ID);
-        private final String nullUserMailboxEventJson =
-            "{" +
-            "  \"MailboxDeletion\":{" +
-            "    \"sessionId\":3652," +
-            "    \"user\":\"user\"," +
-            "    \"path\":{" +
-            "      \"namespace\":\"#private\"," +
-            "      \"name\":\"mailboxName\"" +
-            "    }," +
-            "    \"quotaRoot\":\"user@domain\"," +
-            "    \"deletedMessageCount\":60," +
-            "    \"totalDeletedSize\":100," +
-            "    \"mailboxId\":\"789\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void mailboxAddedShouldBeWellSerializedWhenNullUserInMailboxPath() {
-            assertThatJson(EVENT_SERIALIZER.toJson(nullUserInMailboxPathEvent))
-                .isEqualTo(nullUserMailboxEventJson);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenNullUserInMailboxPath() {
-            assertThat(EVENT_SERIALIZER.fromJson(nullUserMailboxEventJson).get())
-                .isEqualTo(nullUserInMailboxPathEvent);
-        }
-    }
-
-    @Nested
     class EmptyQuotaRoot {
         private final MailboxListener.MailboxDeletion emptyQuotaRootEvent = new MailboxListener.MailboxDeletion(
                 SESSION_ID,
@@ -490,102 +424,20 @@ class MailboxDeletionSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnMailboxPath {
-
-            @Nested
-            class DeserializationErrorOnNameSpace {
-                @Test
-                void mailboxAddedShouldThrowWhenNameSpaceIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxDeletion\":{" +
-                        "    \"sessionId\":3652," +
-                        "    \"user\":\"user\"," +
-                        "    \"path\":{" +
-                        "      \"namespace\":4268.548," +
-                        "      \"user\":\"user\"," +
-                        "      \"name\":\"mailBoxName\"" +
-                        "    }," +
-                        "    \"quotaRoot\":\"user@domain\"," +
-                        "    \"deletedMessageCount\":60," +
-                        "    \"totalDeletedSize\":100," +
-                        "    \"mailboxId\":\"789\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnUser {
-                @Test
-                void mailboxAddedShouldThrowWhenUserIsNotAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxDeletion\":{" +
-                        "    \"sessionId\":3652," +
-                        "    \"user\":\"user\"," +
-                        "    \"path\":{" +
-                        "      \"namespace\":\"#private\"," +
-                        "      \"user\":153274," +
-                        "      \"name\":\"mailBoxName\"" +
-                        "    }," +
-                        "    \"quotaRoot\":\"user@domain\"," +
-                        "    \"deletedMessageCount\":60," +
-                        "    \"totalDeletedSize\":100," +
-                        "    \"mailboxId\":\"789\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnMailboxName {
-
-                @Test
-                void mailboxAddedShouldThrowWhenNullMailboxName() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxDeletion\":{" +
-                        "    \"sessionId\":3652," +
-                        "    \"user\":\"user\"," +
-                        "    \"path\":{" +
-                        "      \"namespace\":\"#private\"," +
-                        "      \"user\":\"user\"," +
-                        "      \"name\":null" +
-                        "    }," +
-                        "    \"quotaRoot\":\"user@domain\"," +
-                        "    \"deletedMessageCount\":60," +
-                        "    \"totalDeletedSize\":100," +
-                        "    \"mailboxId\":\"789\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void mailboxAddedShouldThrowWhenMailboxNameIdIsANumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"MailboxDeletion\":{" +
-                        "    \"sessionId\":3652," +
-                        "    \"user\":\"user\"," +
-                        "    \"path\":{" +
-                        "      \"namespace\":\"#private\"," +
-                        "      \"user\":\"user\"," +
-                        "      \"name\":4578" +
-                        "    }," +
-                        "    \"quotaRoot\":\"user@domain\"," +
-                        "    \"deletedMessageCount\":60," +
-                        "    \"totalDeletedSize\":100," +
-                        "    \"mailboxId\":\"789\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
+        @Test
+        void mailboxAddedShouldThrowWhenMissingPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
+                    "  \"MailboxDeletion\":{" +
+                    "    \"sessionId\":3652," +
+                    "    \"user\":\"user\"," +
+                    "    \"quotaRoot\":\"user@domain\"," +
+                    "    \"deletedMessageCount\":60," +
+                    "    \"totalDeletedSize\":100," +
+                    "    \"mailboxId\":\"789\"" +
+                    "  }" +
+                    "}").get())
+                .isInstanceOf(NoSuchElementException.class);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index 7ef472d..1989186 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -86,203 +86,6 @@ class MailboxRenamedSerializationTest {
     }
 
     @Nested
-    class NullUserInMailboxPath {
-
-        @Nested
-        class NullUserInOldPath {
-            private final String nullUser = null;
-            private final MailboxListener.MailboxRenamed eventWithNullUserOldPath = new MailboxListener.MailboxRenamed(
-                DEFAULT_SESSION_ID,
-                DEFAULT_USER,
-                new MailboxPath(USER_NAMESPACE, nullUser, OLD_MAILBOX_NAME),
-                DEFAULT_MAILBOX_ID,
-                DEFAULT_NEW_MAILBOX_PATH);
-
-            private static final String EVENT_JSON_WITH_NULL_USER_OLD_PATH = "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-
-            @Test
-            void mailboxRenamedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(eventWithNullUserOldPath))
-                    .isEqualTo(EVENT_JSON_WITH_NULL_USER_OLD_PATH);
-            }
-
-            @Test
-            void mailboxRenamedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_OLD_PATH).get())
-                    .isEqualTo(eventWithNullUserOldPath);
-            }
-        }
-
-        @Nested
-        class NullUserInNewPath {
-            private final String nullUser = null;
-            private final MailboxListener.MailboxRenamed eventWithNullUserNewPath = new MailboxListener.MailboxRenamed(
-                DEFAULT_SESSION_ID,
-                DEFAULT_USER,
-                DEFAULT_OLD_MAILBOX_PATH,
-                DEFAULT_MAILBOX_ID,
-                new MailboxPath(USER_NAMESPACE, nullUser, NEW_MAILBOX_NAME));
-
-            private static final String EVENT_JSON_WITH_NULL_USER_NEW_PATH = "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-
-            @Test
-            void mailboxRenamedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(eventWithNullUserNewPath))
-                    .isEqualTo(EVENT_JSON_WITH_NULL_USER_NEW_PATH);
-            }
-
-            @Test
-            void mailboxRenamedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_NEW_PATH).get())
-                    .isEqualTo(eventWithNullUserNewPath);
-            }
-        }
-
-        @Nested
-        class NullUserInOldPathAndNewPath {
-            private final String nullUser = null;
-            private final MailboxListener.MailboxRenamed eventWithNullUserBothPath = new MailboxListener.MailboxRenamed(
-                DEFAULT_SESSION_ID,
-                DEFAULT_USER,
-                new MailboxPath(USER_NAMESPACE, nullUser, OLD_MAILBOX_NAME),
-                DEFAULT_MAILBOX_ID,
-                new MailboxPath(USER_NAMESPACE, nullUser, NEW_MAILBOX_NAME));
-
-            private static final String EVENT_JSON_WITH_NULL_USER_BOTH_PATH =
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-
-            @Test
-            void mailboxRenamedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(eventWithNullUserBothPath))
-                    .isEqualTo(EVENT_JSON_WITH_NULL_USER_BOTH_PATH);
-            }
-
-            @Test
-            void mailboxRenamedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_NULL_USER_BOTH_PATH).get())
-                    .isEqualTo(eventWithNullUserBothPath);
-            }
-        }
-    }
-
-    @Nested
-    class EmptyNameSpaceInMailboxPath {
-
-        @Test
-        void mailboxRenamedShouldBeWellDeSerializedWhenEmptyNameSpaceOldPath() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxRenamed\":{" +
-                "    \"sessionId\":123456789," +
-                "    \"user\":\"user\"," +
-                "    \"path\":{" +
-                "      \"user\":\"user\"," +
-                "      \"namespace\":\"\"," +
-                "      \"name\":\"oldMailboxName\"" +
-                "     }," +
-                "    \"mailboxId\":\"123456\"," +
-                "    \"newPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"user\"," +
-                "      \"name\":\"newMailboxName\"" +
-                "     }" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_MAILBOX_RENAMED_EVENT);
-        }
-
-        @Test
-        void mailboxRenamedShouldBeWellDeSerializedWhenEmptyNameSpaceNewPath() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxRenamed\":{" +
-                "    \"sessionId\":123456789," +
-                "    \"user\":\"user\"," +
-                "    \"path\":{" +
-                "      \"user\":\"user\"," +
-                "      \"namespace\":\"#private\"," +
-                "      \"name\":\"oldMailboxName\"" +
-                "     }," +
-                "    \"mailboxId\":\"123456\"," +
-                "    \"newPath\":{" +
-                "      \"namespace\":\"\"," +
-                "      \"user\":\"user\"," +
-                "      \"name\":\"newMailboxName\"" +
-                "     }" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_MAILBOX_RENAMED_EVENT);
-        }
-
-        @Test
-        void mailboxRenamedShouldBeWellDeSerializedWhenEmptyNameSpaceBothPath() {
-            assertThat(EVENT_SERIALIZER.fromJson(
-                "{" +
-                "  \"MailboxRenamed\":{" +
-                "    \"sessionId\":123456789," +
-                "    \"user\":\"user\"," +
-                "    \"path\":{" +
-                "      \"user\":\"user\"," +
-                "      \"namespace\":\"\"," +
-                "      \"name\":\"oldMailboxName\"" +
-                "     }," +
-                "    \"mailboxId\":\"123456\"," +
-                "    \"newPath\":{" +
-                "      \"namespace\":\"\"," +
-                "      \"user\":\"user\"," +
-                "      \"name\":\"newMailboxName\"" +
-                "     }" +
-                "  }" +
-                "}").get())
-            .isEqualTo(DEFAULT_MAILBOX_RENAMED_EVENT);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void mailboxRenamedDeSerializeShouldThrowWhenMissingUser() {
@@ -341,7 +144,6 @@ class MailboxRenamedSerializationTest {
                     "      \"user\":\"user\"," +
                     "      \"name\":\"oldMailboxName\"" +
                     "    }," +
-                    "    \"mailboxId\":123456," +
                     "    \"newPath\":{" +
                     "      \"namespace\":\"#private\"," +
                     "      \"user\":\"user\"," +
@@ -352,216 +154,28 @@ class MailboxRenamedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnOldMailboxPath {
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingOldPathNameSpace() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenOldPathNameSpaceNotString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":999," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingOldPathUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNotStringOldPathUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":666," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingOldPathName() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNotStringOldPathName() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":1456" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingNewPathNameSpace() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNewPathNameSpaceNotString() {
-                String eventWithNumberMailboxId =
-                    "{" +
+        @Test
+        void mailboxRenamedDeSerializeShouldThrowWhenMissingOldPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxRenamed\":{" +
                     "    \"sessionId\":123456789," +
                     "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
                     "    \"mailboxId\":123456," +
                     "    \"newPath\":{" +
-                    "      \"namespace\":999," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithNumberMailboxId).get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingNewPathUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
                     "      \"namespace\":\"#private\"," +
                     "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
                     "      \"name\":\"newMailboxName\"" +
                     "     }" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
+        }
 
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNotStringNewPathUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxRenamedDeSerializeShouldThrowWhenMissingNewPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxRenamed\":{" +
                     "    \"sessionId\":123456789," +
                     "    \"user\":\"user\"," +
@@ -570,61 +184,10 @@ class MailboxRenamedSerializationTest {
                     "      \"user\":\"user\"," +
                     "      \"name\":\"oldMailboxName\"" +
                     "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":4569," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenMissingNewPathName() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"" +
-                    "     }" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNotStringNewPathName() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\":123456," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":7529" +
-                    "     }" +
+                    "    \"mailboxId\":123456" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
     }
 }


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


[04/47] james-project git commit: MAILBOX-359 Factorize tests for Flags ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for Flags ser-deserialization


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

Branch: refs/heads/master
Commit: 5d365c14313a6179b00eb0cdca3d19b637e007eb
Parents: d7910fc
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 14:40:58 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      | 372 +-------------
 .../event/json/ExpungedSerializationTest.java   | 372 +-------------
 .../json/FlagsUpdatedSerializationTest.java     | 488 +------------------
 .../apache/james/event/json/dtos/FlagsTest.java | 240 +++++++++
 4 files changed, 263 insertions(+), 1209 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5d365c14/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index d71b9e8..61ce957 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -20,7 +20,6 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
-import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -140,157 +139,6 @@ class AddedSerializationTest {
     }
 
     @Nested
-    class WithFlags {
-
-        @Nested
-        class WithEmptyFlags {
-            private final Flags emptyFlags = new FlagsBuilder().build();
-            private final MailboxListener.Added emptyFlagsAddedEvent = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableSortedMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, emptyFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String emptyFlagsAddedEventJson =
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[], " +
-                "          \"userFlags\":[]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void addedShouldBeWellSerializedWhenEmptyFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyFlagsAddedEvent))
-                    .isEqualTo(emptyFlagsAddedEventJson);
-            }
-
-            @Test
-            void addedShouldBeWellDeSerializedWhenEmptyFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(emptyFlagsAddedEventJson).get())
-                    .isEqualTo(emptyFlagsAddedEvent);
-            }
-        }
-
-        @Nested
-        class WithOnlyUserFlags {
-            private final Flags onlyUserFlags = new FlagsBuilder()
-                .add("Custom 1", "Custom 2", "")
-                .build();
-            private final MailboxListener.Added onlyUserFlagsAddedEvent = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableSortedMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, onlyUserFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String userOnlyFlagsAddedEventJson =
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[], " +
-                "          \"userFlags\":[\"Custom 1\", \"Custom 2\", \"\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void addedShouldBeWellSerializedWhenOnlyUserFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(onlyUserFlagsAddedEvent))
-                    .when(IGNORING_ARRAY_ORDER)
-                    .isEqualTo(userOnlyFlagsAddedEventJson);
-            }
-
-            @Test
-            void addedShouldBeWellDeSerializedWhenOnlyUserFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(userOnlyFlagsAddedEventJson).get())
-                    .isEqualTo(onlyUserFlagsAddedEvent);
-            }
-        }
-
-        @Nested
-        class WithOnlySystemFlags {
-            private final Flags onlySystemFlags = new FlagsBuilder()
-                .add(Flags.Flag.SEEN, Flags.Flag.ANSWERED, Flags.Flag.DELETED)
-                .build();
-            private final MailboxListener.Added onlySystemFlagsAddedEvent = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableSortedMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, onlySystemFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String systemOnlyFlagsAddedEventJson =
-                "{" +
-                "  \"Added\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"added\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Seen\",\"Answered\",\"Deleted\"], " +
-                "          \"userFlags\":[]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void addedShouldBeWellSerializedWhenOnlySystemFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(onlySystemFlagsAddedEvent))
-                    .when(IGNORING_ARRAY_ORDER)
-                    .isEqualTo(systemOnlyFlagsAddedEventJson);
-            }
-
-            @Test
-            void addedShouldBeWellDeSerializedWhenOnlySystemFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(systemOnlyFlagsAddedEventJson).get())
-                    .isEqualTo(onlySystemFlagsAddedEvent);
-            }
-        }
-    }
-
-    @Nested
     class WithInternalDate {
 
         @Test
@@ -1000,13 +848,10 @@ class AddedSerializationTest {
                 }
             }
 
-            @Nested
-            class DeserializationErrorOnFlags {
-
-                @Test
-                void addedShouldThrowWhenFlagsIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
+            @Test
+            void addedShouldThrowWhenFlagsIsNull() {
+                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                    "{" +
                         "  \"Added\": {" +
                         "    \"path\": {" +
                         "      \"namespace\": \"#private\"," +
@@ -1029,215 +874,6 @@ class AddedSerializationTest {
                         "  }" +
                         "}").get())
                     .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[null, \"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenUserFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                            "        \"flags\": {" +
-                            "          \"systemFlags\":[\"Draft\"], " +
-                            "          \"userFlags\":[\"User Custom Flag\", null]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsContainsNumberElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[42, \"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenUserFlagsContainsNumberElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                            "        \"flags\": {" +
-                            "          \"systemFlags\":[\"Draft\"], " +
-                            "          \"userFlags\":[\"User Custom Flag\", 42]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsDoNotHaveTheRightCase() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenNoSystemFlags() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Added\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"added\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenNoUserFlags() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                            "  \"Added\": {" +
-                            "    \"path\": {" +
-                            "      \"namespace\": \"#private\"," +
-                            "      \"user\": \"user\"," +
-                            "      \"name\": \"mailboxName\"" +
-                            "    }," +
-                            "    \"mailboxId\": \"18\"," +
-                            "    \"added\": {" +
-                            "      \"123456\": {" +
-                            "        \"uid\": 123456," +
-                            "        \"modSeq\": 35," +
-                            "        \"flags\": {" +
-                            "          \"systemFlags\":[\"Draft\"]}," +
-                            "        \"size\": 45,  " +
-                            "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                            "        \"messageId\": \"42\"" +
-                            "      }" +
-                            "    }," +
-                            "    \"sessionId\": 42," +
-                            "    \"user\": \"user\"" +
-                            "  }" +
-                            "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5d365c14/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 40a7054..336aafa 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -20,7 +20,6 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
-import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -140,157 +139,6 @@ class ExpungedSerializationTest {
     }
 
     @Nested
-    class WithFlags {
-
-        @Nested
-        class WithEmptyFlags {
-            private final Flags emptyFlags = new FlagsBuilder().build();
-            private final MailboxListener.Expunged emptyFlagsExpungedEvent = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, emptyFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String emptyFlagsExpungedEventJson =
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[], " +
-                "          \"userFlags\":[]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void expungedShouldBeWellSerializedWhenEmptyFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyFlagsExpungedEvent))
-                    .isEqualTo(emptyFlagsExpungedEventJson);
-            }
-
-            @Test
-            void expungedShouldBeWellDeSerializedWhenEmptyFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(emptyFlagsExpungedEventJson).get())
-                    .isEqualTo(emptyFlagsExpungedEvent);
-            }
-        }
-
-        @Nested
-        class WithOnlyUserFlags {
-            private final Flags onlyUserFlags = new FlagsBuilder()
-                .add("Custom 1", "Custom 2", "")
-                .build();
-            private final MailboxListener.Expunged onlyUserFlagsExpungedEvent = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, onlyUserFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String userOnlyFlagsExpungedEventJson =
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[], " +
-                "          \"userFlags\":[\"Custom 1\", \"Custom 2\", \"\"]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void expungedShouldBeWellSerializedWhenOnlyUserFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(onlyUserFlagsExpungedEvent))
-                    .when(IGNORING_ARRAY_ORDER)
-                    .isEqualTo(userOnlyFlagsExpungedEventJson);
-            }
-
-            @Test
-            void expungedShouldBeWellDeSerializedWhenOnlyUserFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(userOnlyFlagsExpungedEventJson).get())
-                    .isEqualTo(onlyUserFlagsExpungedEvent);
-            }
-        }
-
-        @Nested
-        class WithOnlySystemFlags {
-            private final Flags onlySystemFlags = new FlagsBuilder()
-                .add(Flags.Flag.SEEN, Flags.Flag.ANSWERED, Flags.Flag.DELETED)
-                .build();
-            private final MailboxListener.Expunged onlySystemFlagsExpungedEvent = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID,
-                ImmutableMap.of(
-                    MESSAGE_UID,
-                    new MessageMetaData(MESSAGE_UID, MOD_SEQ, onlySystemFlags, SIZE, Date.from(INSTANT), MESSAGE_ID)));
-
-            private final String systemOnlyFlagsExpungedEventJson =
-                "{" +
-                "  \"Expunged\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"expunged\": {" +
-                "      \"123456\": {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"flags\": {" +
-                "          \"systemFlags\":[\"Seen\",\"Answered\",\"Deleted\"], " +
-                "          \"userFlags\":[]}," +
-                "        \"size\": 45,  " +
-                "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                "        \"messageId\": \"42\"" +
-                "      }" +
-                "    }," +
-                "    \"sessionId\": 42," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void expungedShouldBeWellSerializedWhenOnlySystemFlags() {
-                assertThatJson(EVENT_SERIALIZER.toJson(onlySystemFlagsExpungedEvent))
-                    .when(IGNORING_ARRAY_ORDER)
-                    .isEqualTo(systemOnlyFlagsExpungedEventJson);
-            }
-
-            @Test
-            void expungedShouldBeWellDeSerializedWhenOnlySystemFlags() {
-                assertThat(EVENT_SERIALIZER.fromJson(systemOnlyFlagsExpungedEventJson).get())
-                    .isEqualTo(onlySystemFlagsExpungedEvent);
-            }
-        }
-    }
-
-    @Nested
     class WithInternalDate {
 
         @Test
@@ -1001,13 +849,10 @@ class ExpungedSerializationTest {
                 }
             }
 
-            @Nested
-            class DeserializationErrorOnFlags {
-
-                @Test
-                void addedShouldThrowWhenFlagsIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
+            @Test
+            void addedShouldThrowWhenFlagsIsNull() {
+                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                    "{" +
                         "  \"Expunged\": {" +
                         "    \"path\": {" +
                         "      \"namespace\": \"#private\"," +
@@ -1029,216 +874,7 @@ class ExpungedSerializationTest {
                         "    \"user\": \"user\"" +
                         "  }" +
                         "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[null, \"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenUserFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\", null]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsContainsNumberElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[42, \"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenUserFlagsContainsNumberElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\", 42]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenSystemFlagsDoNotHaveTheRightCase() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"draft\"], " +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenNoSystemFlags() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"userFlags\":[\"User Custom Flag\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                        .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void addedShouldThrowWhenNoUserFlags() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"Expunged\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": \"#private\"," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"expunged\": {" +
-                        "      \"123456\": {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35," +
-                        "        \"flags\": {" +
-                        "          \"systemFlags\":[\"Draft\"]}," +
-                        "        \"size\": 45,  " +
-                        "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                        "        \"messageId\": \"42\"" +
-                        "      }" +
-                        "    }," +
-                        "    \"sessionId\": 42," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
                     .isInstanceOf(NoSuchElementException.class);
-                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5d365c14/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 90c0a01..2c9bc1e 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -136,16 +136,13 @@ class FlagsUpdatedSerializationTest {
     }
 
     @Nested
-    class WithUpdatedFlags {
+    class WithEmptyUpdatedFlags {
+        private final List<UpdatedFlags> emptyUpdatedFlags = ImmutableList.of();
+        private final MailboxListener.FlagsUpdated emptyUpdatedFlagsEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER, MAILBOX_PATH,
+            MAILBOX_ID, emptyUpdatedFlags);
 
-        @Nested
-        class EmptyUpdatedFlags {
-            private final List<UpdatedFlags> emptyUpdatedFlags = ImmutableList.of();
-            private final MailboxListener.FlagsUpdated emptyUpdatedFlagsEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER, MAILBOX_PATH,
-                MAILBOX_ID, emptyUpdatedFlags);
-
-            private static final String EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS =
-                "{" +
+        private static final String EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS =
+            "{" +
                 "  \"FlagsUpdated\": {" +
                 "    \"path\": {" +
                 "      \"namespace\": \"#private\"," +
@@ -159,159 +156,17 @@ class FlagsUpdatedSerializationTest {
                 "  }" +
                 "}";
 
-            @Test
-            void flagsUpdatedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyUpdatedFlagsEvent))
-                    .when(Option.IGNORING_ARRAY_ORDER)
-                    .isEqualTo(EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS);
-            }
-
-            @Test
-            void flagsUpdatedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS).get())
-                    .isEqualTo(emptyUpdatedFlagsEvent);
-            }
-        }
-
-        @Nested
-        class EmptyOldFlags {
-            private final UpdatedFlags emptyOldFlags = UpdatedFlags.builder()
-                .uid(MESSAGE_UID_1)
-                .modSeq(MOD_SEQ_1)
-                .oldFlags(FlagsBuilder.builder().build())
-                .newFlags(NEW_FLAGS_1)
-                .build();
-            private final MailboxListener.FlagsUpdated emptyOldFlagsUpdatedFlagsEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER, MAILBOX_PATH,
-                MAILBOX_ID, ImmutableList.of(emptyOldFlags));
-
-            private static final String EVENT_JSON_WITH_EMPTY_OLD_FLAGS =
-                "{" +
-                "  \"FlagsUpdated\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"sessionId\": 42," +
-                "    \"updatedFlags\": [" +
-                "      {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"oldFlags\": {\"systemFlags\":[],\"userFlags\":[]}," +
-                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                "      }" +
-                "    ]," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void flagsUpdatedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyOldFlagsUpdatedFlagsEvent))
-                    .when(Option.IGNORING_ARRAY_ORDER)
-                    .isEqualTo(EVENT_JSON_WITH_EMPTY_OLD_FLAGS);
-            }
-
-            @Test
-            void flagsUpdatedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_EMPTY_OLD_FLAGS).get())
-                    .isEqualTo(emptyOldFlagsUpdatedFlagsEvent);
-            }
-        }
-
-        @Nested
-        class EmptyNewFlags {
-            private final UpdatedFlags emptyNewFlags = UpdatedFlags.builder()
-                .uid(MESSAGE_UID_1)
-                .modSeq(MOD_SEQ_1)
-                .oldFlags(OLD_FLAGS_1)
-                .newFlags(FlagsBuilder.builder().build())
-                .build();
-            private final MailboxListener.FlagsUpdated emptyNewFlagsUpdatedFlagsEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER, MAILBOX_PATH,
-                MAILBOX_ID, ImmutableList.of(emptyNewFlags));
-
-            private static final String EVENT_JSON_WITH_EMPTY_NEW_FLAGS =
-                "{" +
-                "  \"FlagsUpdated\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"sessionId\": 42," +
-                "    \"updatedFlags\": [" +
-                "      {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                "        \"newFlags\": {\"systemFlags\":[],\"userFlags\":[]}" +
-                "      }" +
-                "    ]," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void flagsUpdatedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyNewFlagsUpdatedFlagsEvent))
-                    .when(Option.IGNORING_ARRAY_ORDER)
-                    .isEqualTo(EVENT_JSON_WITH_EMPTY_NEW_FLAGS);
-            }
-
-            @Test
-            void flagsUpdatedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_EMPTY_NEW_FLAGS).get())
-                    .isEqualTo(emptyNewFlagsUpdatedFlagsEvent);
-            }
+        @Test
+        void flagsUpdatedShouldBeWellSerialized() {
+            assertThatJson(EVENT_SERIALIZER.toJson(emptyUpdatedFlagsEvent))
+                .when(Option.IGNORING_ARRAY_ORDER)
+                .isEqualTo(EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS);
         }
 
-        @Nested
-        class EmptyOldFlagsAndNewFlags {
-            private final UpdatedFlags emptyFlags = UpdatedFlags.builder()
-                .uid(MESSAGE_UID_1)
-                .modSeq(MOD_SEQ_1)
-                .oldFlags(FlagsBuilder.builder().build())
-                .newFlags(FlagsBuilder.builder().build())
-                .build();
-            private final MailboxListener.FlagsUpdated emptyFlagsUpdatedFlagsEvent = new MailboxListener.FlagsUpdated(SESSION_ID, USER, MAILBOX_PATH,
-                MAILBOX_ID, ImmutableList.of(emptyFlags));
-
-            private static final String EVENT_JSON_WITH_EMPTY_OLD_AND_NEW_FLAGS =
-                "{" +
-                "  \"FlagsUpdated\": {" +
-                "    \"path\": {" +
-                "      \"namespace\": \"#private\"," +
-                "      \"user\": \"user\"," +
-                "      \"name\": \"mailboxName\"" +
-                "    }," +
-                "    \"mailboxId\": \"18\"," +
-                "    \"sessionId\": 42," +
-                "    \"updatedFlags\": [" +
-                "      {" +
-                "        \"uid\": 123456," +
-                "        \"modSeq\": 35," +
-                "        \"oldFlags\": {\"systemFlags\":[],\"userFlags\":[]}," +
-                "        \"newFlags\": {\"systemFlags\":[],\"userFlags\":[]}" +
-                "      }" +
-                "    ]," +
-                "    \"user\": \"user\"" +
-                "  }" +
-                "}";
-
-            @Test
-            void flagsUpdatedShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(emptyFlagsUpdatedFlagsEvent))
-                    .when(Option.IGNORING_ARRAY_ORDER)
-                    .isEqualTo(EVENT_JSON_WITH_EMPTY_OLD_AND_NEW_FLAGS);
-            }
-
-            @Test
-            void flagsUpdatedShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_EMPTY_OLD_AND_NEW_FLAGS).get())
-                    .isEqualTo(emptyFlagsUpdatedFlagsEvent);
-            }
+        @Test
+        void flagsUpdatedShouldBeWellDeSerialized() {
+            assertThat(EVENT_SERIALIZER.fromJson(EVENT_JSON_WITH_EMPTY_UPDATED_FLAGS).get())
+                .isEqualTo(emptyUpdatedFlagsEvent);
         }
     }
 
@@ -611,7 +466,6 @@ class FlagsUpdatedSerializationTest {
 
             @Nested
             class DeserializationErrorOnOldFlags {
-
                 @Test
                 void flagsUpdatedShouldThrowWhenOldFlagsIsNull() {
                     assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
@@ -637,162 +491,6 @@ class FlagsUpdatedSerializationTest {
                         "}").get())
                     .isInstanceOf(NoSuchElementException.class);
                 }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[null,\"Draft\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUserFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Draft\"],\"userFlags\":[\"New Flag 1\", null]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsDoesNotContainString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[42,\"Draft\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsUnknownString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"unKnown\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsBadCaseString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"dRaFt\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUserFlagsDoesNotContainString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Draft\"],\"userFlags\":[\"New Flag 1\", 42]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
             }
 
             @Nested
@@ -822,162 +520,6 @@ class FlagsUpdatedSerializationTest {
                         "}").get())
                     .isInstanceOf(NoSuchElementException.class);
                 }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[null,\"Draft\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUserFlagsContainsNullElements() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Draft\"],\"userFlags\":[\"New Flag 1\", null]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsDoesNotContainString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[42,\"Draft\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsUnknownString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[\"unKnown\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenSystemFlagsContainsBadCaseString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[\"dRaFt\"],\"userFlags\":[\"New Flag 1\"]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenUserFlagsDoesNotContainString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Draft\"],\"userFlags\":[\"New Flag 1\", 42]}," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5d365c14/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
new file mode 100644
index 0000000..a41c245
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
@@ -0,0 +1,240 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.NoSuchElementException;
+
+import javax.mail.Flags;
+
+import org.apache.james.event.json.DTOs;
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.Json;
+
+class FlagsTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void emptyFlagsShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags()))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[],\"userFlags\":[]}");
+    }
+
+    @Test
+    void answeredShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.ANSWERED)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void deletedShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.DELETED)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void draftShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.DRAFT)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void flaggedShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.FLAGGED)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void recentShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.RECENT)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void seenShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags(Flags.Flag.SEEN)))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}");
+    }
+
+    @Test
+    void userFlagShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+            new Flags("user flag")))
+            .toString())
+            .isEqualTo("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}");
+    }
+
+    @Test
+    void emptyFlagsShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags());
+    }
+
+    @Test
+    void answeredShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.ANSWERED));
+    }
+
+    @Test
+    void deletedShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.DELETED));
+    }
+
+    @Test
+    void draftShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.DRAFT));
+    }
+
+    @Test
+    void flaggedShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.FLAGGED));
+    }
+
+    @Test
+    void recentShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.RECENT));
+    }
+
+    @Test
+    void seenShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}"))
+                .get()))
+            .isEqualTo(new Flags(Flags.Flag.SEEN));
+    }
+
+    @Test
+    void userFlagShouldBeWellDeSerialized() {
+        assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}"))
+                .get()))
+            .isEqualTo(new Flags("user flag"));
+    }
+
+    @Test
+    void deserializeShouldThrowWhenUnknownSystemFlag() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"unknown\"],\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenBadCaseSystemFlag() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"AnSwErEd\"],\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenNullSystemFlag() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":null,\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenSystemFlagContainsNullElements() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[null,\"Draft\"],\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenSystemFlagContainsNotStringElements() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[42,\"Draft\"],\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenUserFlagsContainsNullElements() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[null, \"a\"]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenUserFlagsContainsNonStringElements() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenNoUserFlags() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+
+    @Test
+    void deserializeShouldThrowWhenNoSystemFlags() {
+        assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
+            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}"))
+                .get()))
+            .isInstanceOf(NoSuchElementException.class);
+    }
+}


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


[15/47] james-project git commit: MAILBOX-359 Switch Scala Event trait back to private

Posted by bt...@apache.org.
MAILBOX-359 Switch Scala Event trait back to private

This needs to be done by wrapping all references to this trait as private


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

Branch: refs/heads/master
Commit: 0cdd567c3a5ef35dbf1b6a21547ec5e8a6c85cad
Parents: 0a16e7c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 25 15:47:22 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:29 2019 +0700

----------------------------------------------------------------------
 .../apache/james/event/json/EventSerializer.scala   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0cdd567c/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 6418425..3628e37 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -35,7 +35,7 @@ import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsStri
 
 import scala.collection.JavaConverters._
 
-sealed trait Event {
+private sealed trait Event {
   def toJava: JavaEvent
 }
 
@@ -304,20 +304,24 @@ class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: Messa
   implicit val messageMetaDataReads: Reads[DTOs.MessageMetaData] = Json.reads[DTOs.MessageMetaData]
   implicit val updatedFlagsReads: Reads[DTOs.UpdatedFlags] = Json.reads[DTOs.UpdatedFlags]
 
-  implicit val eventOFormat: OFormat[Event] = derived.oformat()
+  private class EventSerializerPrivateWrapper {
+    implicit val eventOFormat: OFormat[Event] = derived.oformat()
 
-  def toJson(event: Event): String = Json.toJson(event).toString()
+    def toJson(event: Event): String = Json.toJson(event).toString()
+    def fromJson(json: String): JsResult[Event] = Json.fromJson[Event](Json.parse(json))
+  }
 
-  def fromJson(json: String): JsResult[Event] = Json.fromJson[Event](Json.parse(json))
+  def toJson(event: JavaEvent): String = new EventSerializerPrivateWrapper().toJson(ScalaConverter.toScala(event))
+  def fromJson(json: String): JsResult[JavaEvent] = new EventSerializerPrivateWrapper().fromJson(json)
+    .map(event => event.toJava)
 }
 
 class EventSerializer(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
-  def toJson(event: JavaEvent): String = new JsonSerialize(mailboxIdFactory, messageIdFactory).toJson(ScalaConverter.toScala(event))
+  def toJson(event: JavaEvent): String = new JsonSerialize(mailboxIdFactory, messageIdFactory).toJson(event)
 
   def fromJson(json: String): JsResult[JavaEvent] = {
     new JsonSerialize(mailboxIdFactory, messageIdFactory)
       .fromJson(json)
-      .map(event => event.toJava)
   }
 }
 


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


[38/47] james-project git commit: JAMES-2641 AbstractMessageIdManagerSideEffectTest should not rely on mock assertions

Posted by bt...@apache.org.
JAMES-2641 AbstractMessageIdManagerSideEffectTest should not rely on mock assertions

This makes change harder to test and depends heavily on the underlying implementation


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

Branch: refs/heads/master
Commit: b4d9035a67a06592c2ecd57d89c8f34146a4f998
Parents: 8a21cb5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 11:24:41 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:46:01 2019 +0700

----------------------------------------------------------------------
 .../AbstractMessageIdManagerSideEffectTest.java | 146 +++++++++++--------
 1 file changed, 86 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b4d9035a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
index e98bd59..f1f2c2f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
@@ -22,12 +22,7 @@ package org.apache.james.mailbox.store;
 import static org.apache.james.mailbox.fixture.MailboxFixture.ALICE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.util.List;
@@ -36,11 +31,13 @@ import javax.mail.Flags;
 
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
+import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
+import org.apache.james.mailbox.MessageMoveEvent;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.OverQuotaException;
@@ -53,14 +50,18 @@ import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.util.EventCollector;
+import org.assertj.core.api.AbstractListAssert;
+import org.assertj.core.api.ObjectAssert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSortedMap;
 
 public abstract class AbstractMessageIdManagerSideEffectTest {
     private static final Quota<QuotaCount> OVER_QUOTA = Quota.<QuotaCount>builder()
@@ -70,28 +71,31 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
     private static final MessageUid messageUid1 = MessageUid.of(111);
     private static final MessageUid messageUid2 = MessageUid.of(113);
 
-    public static final Flags FLAGS = new Flags();
+    private static final Flags FLAGS = new Flags();
+    private static final MailboxSession SESSION = MailboxSessionUtil.create("any");
 
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
     private MessageIdManager messageIdManager;
-    private MailboxEventDispatcher dispatcher;
     private MailboxSession session;
     private Mailbox mailbox1;
     private Mailbox mailbox2;
     private Mailbox mailbox3;
     private QuotaManager quotaManager;
     private MessageIdManagerTestSystem testingData;
+    private EventCollector eventCollector;
+    private DefaultDelegatingMailboxListener delegatingMailboxListener;
 
     protected abstract MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception;
 
     public void setUp() throws Exception {
-        dispatcher = mock(MailboxEventDispatcher.class);
+        delegatingMailboxListener = new DefaultDelegatingMailboxListener();
+        eventCollector = new EventCollector();
         quotaManager = mock(QuotaManager.class);
 
         session = MailboxSessionUtil.create(ALICE);
-        testingData = createTestSystem(quotaManager, dispatcher);
+        testingData = createTestSystem(quotaManager, new MailboxEventDispatcher(delegatingMailboxListener));
         messageIdManager = testingData.getMessageIdManager();
 
         mailbox1 = testingData.createMailbox(MailboxFixture.INBOX_ALICE, session);
@@ -103,15 +107,22 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
     public void deleteShouldCallEventDispatcher() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
         MessageResult messageResult = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, session).get(0);
         MessageMetaData simpleMessageMetaData = messageResult.messageMetaData();
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.delete(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
 
-        verify(dispatcher).expunged(session, simpleMessageMetaData, mailbox1);
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents())
+            .hasSize(1).first()
+            .isInstanceOf(MailboxListener.Expunged.class)
+            .satisfies(e -> {
+                MailboxListener.Expunged event = (MailboxListener.Expunged) e;
+                assertThat(event.getMailboxId()).isEqualTo(mailbox1.getMailboxId());
+                assertThat(event.getMailboxPath()).isEqualTo(mailbox1.generateAssociatedPath());
+                assertThat(event.getExpunged().values()).containsOnly(simpleMessageMetaData);
+            });
     }
 
     @Test
@@ -119,75 +130,84 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         MessageId messageId1 = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
         MessageId messageId2 = testingData.persist(mailbox1.getMailboxId(), messageUid2, FLAGS, session);
-        reset(dispatcher);
 
         MessageResult messageResult1 = messageIdManager.getMessages(ImmutableList.of(messageId1), FetchGroupImpl.MINIMAL, session).get(0);
         MessageMetaData simpleMessageMetaData1 = messageResult1.messageMetaData();
         MessageResult messageResult2 = messageIdManager.getMessages(ImmutableList.of(messageId2), FetchGroupImpl.MINIMAL, session).get(0);
         MessageMetaData simpleMessageMetaData2 = messageResult2.messageMetaData();
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.delete(ImmutableList.of(messageId1, messageId2), session);
 
-        verify(dispatcher).expunged(session, simpleMessageMetaData1, mailbox1);
-        verify(dispatcher).expunged(session, simpleMessageMetaData2, mailbox1);
-        verifyNoMoreInteractions(dispatcher);
+        AbstractListAssert<?, List<? extends MailboxListener.Expunged>, MailboxListener.Expunged, ObjectAssert<MailboxListener.Expunged>> events =
+            assertThat(eventCollector.getEvents())
+                .hasSize(2)
+                .allSatisfy(event -> assertThat(event).isInstanceOf(MailboxListener.Expunged.class))
+                .extracting(event -> (MailboxListener.Expunged) event);
+        events.extracting(MailboxListener.MailboxEvent::getMailboxId).containsOnly(mailbox1.getMailboxId(), mailbox1.getMailboxId());
+        events.extracting(MailboxListener.Expunged::getExpunged)
+            .containsOnly(ImmutableSortedMap.of(simpleMessageMetaData1.getUid(), simpleMessageMetaData1),
+                ImmutableSortedMap.of(simpleMessageMetaData2.getUid(), simpleMessageMetaData2));
     }
 
     @Test
     public void deleteShouldNotCallEventDispatcherWhenMessageIsInWrongMailbox() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.delete(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
     public void setInMailboxesShouldNotCallDispatcherWhenMessageAlreadyInMailbox() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
     public void setInMailboxesShouldCallDispatcher() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
-        verify(dispatcher).added(eq(session), eq(mailbox1), any(MailboxMessage.class));
-        verify(dispatcher).moved(eq(session), any(), any());
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).hasSize(2);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MessageMoveEvent).hasSize(1);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MailboxListener.Added).hasSize(1)
+            .extracting(event -> (MailboxListener.Added) event).extracting(MailboxListener.Added::getMailboxId)
+            .containsOnly(mailbox1.getMailboxId());
     }
 
     @Test
     public void setInMailboxesShouldCallDispatcherWithMultipleMailboxes() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), mailbox3.getMailboxId()), session);
 
         messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, session);
 
-        verify(dispatcher).added(eq(session), eq(mailbox1), any(MailboxMessage.class));
-        verify(dispatcher).added(eq(session), eq(mailbox3), any(MailboxMessage.class));
-        verify(dispatcher).moved(eq(session), any(), any());
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).hasSize(3);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MessageMoveEvent).hasSize(1);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MailboxListener.Added).hasSize(2)
+            .extracting(event -> (MailboxListener.Added) event).extracting(MailboxListener.Added::getMailboxId)
+            .containsOnly(mailbox1.getMailboxId(), mailbox3.getMailboxId());
     }
 
     @Test
     public void setInMailboxesShouldThrowExceptionWhenOverQuota() throws Exception {
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
+
         when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn(
             Quota.<QuotaSize>builder().used(QuotaSize.size(2)).computedLimit(QuotaSize.unlimited()).build());
         when(quotaManager.getMessageQuota(any(QuotaRoot.class))).thenReturn(OVER_QUOTA);
@@ -204,16 +224,21 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
-        reset(dispatcher);
 
         List<MessageResult> messageResults = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, session);
         assertThat(messageResults).hasSize(2);
+
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox3.getMailboxId()), session);
 
-        verify(dispatcher).expunged(eq(session), any(MessageMetaData.class), eq(mailbox2));
-        verify(dispatcher).added(eq(session), eq(mailbox3), any(MailboxMessage.class));
-        verify(dispatcher).moved(eq(session), any(), any());
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).hasSize(3);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MessageMoveEvent).hasSize(1);
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MailboxListener.Added).hasSize(1)
+            .extracting(event -> (MailboxListener.Added) event).extracting(MailboxListener.Added::getMailboxId)
+            .containsOnly(mailbox3.getMailboxId());
+        assertThat(eventCollector.getEvents()).filteredOn(event -> event instanceof MailboxListener.Expunged).hasSize(1)
+            .extracting(event -> (MailboxListener.Expunged) event).extracting(MailboxListener.Expunged::getMailboxId)
+            .containsOnly(mailbox2.getMailboxId());
     }
 
     @Test
@@ -221,11 +246,11 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, newFlags, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox2.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
@@ -234,11 +259,11 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, newFlags, session);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox2.getMailboxId()), session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
@@ -246,11 +271,11 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox2.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
@@ -258,11 +283,11 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
@@ -271,20 +296,19 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
-        verify(dispatcher, times(2)).flagsUpdated(eq(session), any(Mailbox.class), any(UpdatedFlags.class));
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).hasSize(2).allSatisfy(event -> assertThat(event).isInstanceOf(MailboxListener.FlagsUpdated.class));
     }
 
     @Test
     public void setFlagsShouldDispatchWhenMessageBelongsToTheMailboxes() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session);
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         Flags newFlags = new Flags(Flags.Flag.SEEN);
         messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -300,8 +324,12 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
             .newFlags(newFlags)
             .build();
 
-        verify(dispatcher, times(1)).flagsUpdated(session, mailbox2, updatedFlags);
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).hasSize(1).first().isInstanceOf(MailboxListener.FlagsUpdated.class)
+            .satisfies(e -> {
+                MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) e;
+                assertThat(event.getUpdatedFlags()).containsOnly(updatedFlags);
+                assertThat(event.getMailboxId()).isEqualTo(mailbox2.getMailboxId());
+            });
     }
 
     @Test
@@ -309,11 +337,10 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         MessageId messageId = testingData.createNotUsedMessageId();
 
-        reset(dispatcher);
-
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.delete(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
@@ -321,33 +348,32 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
         givenUnlimitedQuota();
         MessageId messageId = testingData.createNotUsedMessageId();
 
-        reset(dispatcher);
-
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.delete(ImmutableList.of(messageId), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
     public void setFlagsShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.createNotUsedMessageId();
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setFlags(FLAGS, FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox2.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     @Test
     public void setInMailboxesShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception {
         givenUnlimitedQuota();
         MessageId messageId = testingData.createNotUsedMessageId();
-        reset(dispatcher);
 
+        delegatingMailboxListener.addGlobalListener(eventCollector, SESSION);
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
 
-        verifyNoMoreInteractions(dispatcher);
+        assertThat(eventCollector.getEvents()).isEmpty();
     }
 
     private void givenUnlimitedQuota() throws MailboxException {


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


[19/47] james-project git commit: MAILBOX-359 Improving QuotaScope coverage

Posted by bt...@apache.org.
MAILBOX-359 Improving QuotaScope coverage


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

Branch: refs/heads/master
Commit: 07818491e7884bd671b141bdfb7a301e58efcd04
Parents: 7776d2a
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 18:07:12 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:53 2019 +0700

----------------------------------------------------------------------
 .../james/event/json/dtos/QuotaCountTest.java     | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/07818491/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
index 88adaa6..e203cc6 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
@@ -22,6 +22,7 @@ package org.apache.james.event.json.dtos;
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
 import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.event.json.DTOs;
@@ -202,4 +203,21 @@ class QuotaCountTest {
             }
         }
     }
+
+    @Nested
+    class UnknownQuotaScope {
+        private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"Invalid\":100}}";
+
+        @Test
+        void fromJsonShouldThrowOnInvalidScope() {
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                .isInstanceOf(IllegalArgumentException.class);
+        }
+
+        @Test
+        void scopesShouldBeString() {
+            assertThat(DTO_JSON_SERIALIZE.quotaScopeReads().reads(Json.parse("3")))
+                .isInstanceOf(JsError.class);
+        }
+    }
 }


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


[32/47] james-project git commit: MAILBOX-364 Builder for QuotaUsageUpdatedEvent

Posted by bt...@apache.org.
MAILBOX-364 Builder for QuotaUsageUpdatedEvent


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

Branch: refs/heads/master
Commit: 5392ad98b35860b26a63fd8e7b7bcbe256da8966
Parents: 7097446
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Jan 3 13:46:21 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:41:11 2019 +0700

----------------------------------------------------------------------
 .../QuotaThresholdConfigurationChangesTest.java | 206 ++++++++++++++---
 .../QuotaThresholdMailingIntegrationTest.java   | 223 ++++++++++++++++---
 .../ElasticSearchQuotaMailboxListenerTest.java  |  10 +-
 .../json/QuotaRatioToElasticSearchJsonTest.java |  34 +--
 .../james/mailbox/store/event/EventFactory.java |  48 +++-
 5 files changed, 444 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5392ad98/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
index 87d720d..3114c65 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
@@ -29,10 +29,10 @@ import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.mailetC
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.eventsourcing.eventstore.EventStore;
-import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
 import org.apache.james.mailbox.quota.QuotaFixture.Counts;
 import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
 import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.junit.jupiter.api.Test;
 
@@ -56,13 +56,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -72,12 +84,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -87,12 +112,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -102,12 +140,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -117,12 +168,24 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -132,12 +195,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -147,13 +223,26 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -163,13 +252,26 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -179,13 +281,26 @@ public interface QuotaThresholdConfigurationChangesTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -196,12 +311,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -212,12 +340,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._92_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._92_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -228,12 +369,25 @@ public interface QuotaThresholdConfigurationChangesTest {
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store,
             CONFIGURATION_50_75);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50);
 
         mailetContext.resetSentMails();
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, NOW));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5392ad98/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
index f1a8343..cefec6e 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
@@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.time.Duration;
 
 import org.apache.james.eventsourcing.eventstore.EventStore;
-import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
 import org.apache.james.mailbox.quota.QuotaFixture.Counts;
 import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
 import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.util.concurrency.ConcurrentTestRunner;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.junit.jupiter.api.Test;
@@ -53,7 +53,13 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -62,10 +68,23 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenNoThresholdUpdate(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(ONE_HOUR_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -74,11 +93,29 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenThresholdOverPassedRecently(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_HOURS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(TWELVE_HOURS_AGO)
+            .build());
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(SIX_HOURS_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -88,7 +125,13 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -97,9 +140,21 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendDuplicates(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
-
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(ONE_HOUR_AGO)
+            .build());
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -108,9 +163,21 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotifySeparatelyCountAndSize(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, ONE_HOUR_AGO));
-
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._60_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(ONE_HOUR_AGO)
+            .build());
+
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(2);
     }
@@ -120,7 +187,13 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -129,11 +202,29 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldSendMailWhenThresholdOverPassedOverGracePeriod(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, TWELVE_DAYS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(TWELVE_DAYS_AGO)
+            .build());
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(SIX_DAYS_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -142,10 +233,22 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenNoThresholdUpdateForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._32_PERCENT, Sizes._55_PERCENT, TWO_DAYS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._32_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(TWO_DAYS_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._60_PERCENT, TWO_DAYS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._60_PERCENT)
+            .instant(TWO_DAYS_AGO)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -154,11 +257,29 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldNotSendMailWhenThresholdOverPassedRecentlyForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_HOURS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(TWELVE_HOURS_AGO)
+            .build());
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(SIX_HOURS_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).isEmpty();
     }
@@ -168,7 +289,13 @@ public interface QuotaThresholdMailingIntegrationTest {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_HOURS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(TWELVE_HOURS_AGO)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -177,11 +304,29 @@ public interface QuotaThresholdMailingIntegrationTest {
     default void shouldSendMailWhenThresholdOverPassedOverGracePeriodForCount(EventStore store) throws Exception {
         FakeMailContext mailetContext = mailetContext();
         QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION);
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, TWELVE_DAYS_AGO));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._30_PERCENT, SIX_DAYS_AGO));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(TWELVE_DAYS_AGO)
+            .build());
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._40_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(SIX_DAYS_AGO)
+            .build());
         mailetContext.resetSentMails();
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails()).hasSize(1);
     }
@@ -195,8 +340,20 @@ public interface QuotaThresholdMailingIntegrationTest {
                 .gracePeriod(GRACE_PERIOD)
                 .build());
 
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._30_PERCENT, NOW));
-        testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._85_PERCENT, Sizes._42_PERCENT, NOW));
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._30_PERCENT)
+            .instant(NOW)
+            .build());
+        testee.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._85_PERCENT)
+            .quotaSize(Sizes._42_PERCENT)
+            .instant(NOW)
+            .build());
 
         assertThat(mailetContext.getSentMails())
             .hasSize(2);
@@ -212,7 +369,13 @@ public interface QuotaThresholdMailingIntegrationTest {
                 .build());
 
         ConcurrentTestRunner.builder()
-            .operation((threadNb, step) -> testee.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._40_PERCENT, Sizes._55_PERCENT, NOW)))
+            .operation((threadNb, step) -> testee.event(EventFactory.quotaUpdated()
+                    .user(BOB_USER)
+                    .quotaRoot(QUOTAROOT)
+                    .quotaCount(Counts._40_PERCENT)
+                    .quotaSize(Sizes._55_PERCENT)
+                    .instant(NOW)
+                    .build()))
             .threadCount(10)
             .runSuccessfullyWithin(Duration.ofMinutes(1));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/5392ad98/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
index d749146..4f33fe5 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -34,9 +34,9 @@ import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.apache.james.mailbox.Event;
-import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
 import org.apache.james.mailbox.quota.QuotaFixture.Counts;
 import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
 import org.apache.james.quota.search.elasticsearch.QuotaSearchIndexCreationUtil;
 import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
@@ -93,7 +93,13 @@ public class ElasticSearchQuotaMailboxListenerTest {
 
     @Test
     public void eventShouldIndexEventWhenQuotaEvent() throws Exception {
-        quotaMailboxListener.event(new QuotaUsageUpdatedEvent(BOB_USER, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
+        quotaMailboxListener.event(EventFactory.quotaUpdated()
+            .user(BOB_USER)
+            .quotaRoot(QUOTAROOT)
+            .quotaCount(Counts._52_PERCENT)
+            .quotaSize(Sizes._55_PERCENT)
+            .instant(NOW)
+            .build());
 
         embeddedElasticSearch.awaitForElasticSearch();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/5392ad98/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
index 4564be1..be9a938 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
@@ -30,21 +30,22 @@ import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaFixture;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.util.ClassLoaderUtils;
 import org.junit.jupiter.api.Test;
 
-public class QuotaRatioToElasticSearchJsonTest {
+class QuotaRatioToElasticSearchJsonTest {
 
     @Test
-    public void quotaRatioShouldBeWellConvertedToJson() throws IOException {
+    void quotaRatioShouldBeWellConvertedToJson() throws IOException {
         String user = "user@domain.org";
-        QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
-                User.fromUsername(user),
-                QuotaRoot.quotaRoot("any", Optional.of(Domain.of("domain.org"))),
-                QuotaFixture.Counts._52_PERCENT,
-                QuotaFixture.Sizes._55_PERCENT,
-                Instant.now());
-        
+        QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated()
+            .user(User.fromUsername(user))
+            .quotaRoot(QuotaRoot.quotaRoot(user, Optional.of(Domain.of("domain.org"))))
+            .quotaCount(QuotaFixture.Counts._52_PERCENT)
+            .quotaSize(QuotaFixture.Sizes._55_PERCENT)
+            .instant(Instant.now())
+            .build();
 
         QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson();
         String convertToJson = quotaRatioToElasticSearchJson.convertToJson(user, event);
@@ -55,14 +56,15 @@ public class QuotaRatioToElasticSearchJsonTest {
     }
 
     @Test
-    public void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException {
+    void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException {
         String user = "user";
-        QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
-                User.fromUsername(user),
-                QuotaRoot.quotaRoot("any", Optional.empty()),
-                QuotaFixture.Counts._52_PERCENT,
-                QuotaFixture.Sizes._55_PERCENT,
-                Instant.now());
+        QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated()
+            .user(User.fromUsername(user))
+            .quotaRoot(QuotaRoot.quotaRoot(user, Optional.empty()))
+            .quotaCount(QuotaFixture.Counts._52_PERCENT)
+            .quotaSize(QuotaFixture.Sizes._55_PERCENT)
+            .instant(Instant.now())
+            .build();
 
 
         QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson();

http://git-wip-us.apache.org/repos/asf/james-project/blob/5392ad98/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 5695c6f..e4a96e8 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.store.event;
 
+import java.time.Instant;
+
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
@@ -30,6 +32,7 @@ import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -137,16 +140,31 @@ public class EventFactory {
     }
 
     @FunctionalInterface
-    public interface RequireQuotaCount<T> {
+    public interface RequireQuotaCountValue<T> {
         T quotaCount(QuotaCount quotaCount);
     }
 
     @FunctionalInterface
-    public interface RequireQuotaSize<T> {
+    public interface RequireQuotaSizeValue<T> {
         T quotaSize(QuotaSize quotaSize);
     }
 
     @FunctionalInterface
+    public interface RequireQuotaCount<T> {
+        T quotaCount(Quota<QuotaCount> quotaCount);
+    }
+
+    @FunctionalInterface
+    public interface RequireQuotaSize<T> {
+        T quotaSize(Quota<QuotaSize> quotaSize);
+    }
+
+    @FunctionalInterface
+    public interface RequireInstant<T> {
+        T instant(Instant instant);
+    }
+
+    @FunctionalInterface
     public interface RequireMailboxEvent<T> extends RequireSession<RequireMailbox<T>> {}
 
     public static class MailboxAddedFinalStage {
@@ -336,6 +354,26 @@ public class EventFactory {
         }
     }
 
+    public static final class QuotaUsageUpdatedFinalStage {
+        private final User user;
+        private final QuotaRoot quotaRoot;
+        private final Quota<QuotaCount> countQuota;
+        private final Quota<QuotaSize> sizeQuota;
+        private final Instant instant;
+
+        QuotaUsageUpdatedFinalStage(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota, Instant instant) {
+            this.user = user;
+            this.quotaRoot = quotaRoot;
+            this.countQuota = countQuota;
+            this.sizeQuota = sizeQuota;
+            this.instant = instant;
+        }
+
+        public MailboxListener.QuotaUsageUpdatedEvent build() {
+            return new MailboxListener.QuotaUsageUpdatedEvent(user, quotaRoot, countQuota, sizeQuota, instant);
+        }
+    }
+
     public static RequireMailboxEvent<RequireMetadata<AddedFinalStage>> added() {
         return user -> sessionId -> mailboxId -> path -> metaData -> new AddedFinalStage(path, mailboxId, user, sessionId, metaData);
     }
@@ -352,7 +390,7 @@ public class EventFactory {
         return user -> sessionId -> mailboxId -> oldPath -> newPath -> new MailboxRenamedFinalStage(oldPath, mailboxId, user, sessionId, newPath);
     }
 
-    public static  RequireMailboxEvent<RequireQuotaRoot<RequireQuotaCount<RequireQuotaSize<MailboxDeletionFinalStage>>>> mailboxDeleted() {
+    public static  RequireMailboxEvent<RequireQuotaRoot<RequireQuotaCountValue<RequireQuotaSizeValue<MailboxDeletionFinalStage>>>> mailboxDeleted() {
         return user -> sessionId -> mailboxId -> path -> quotaRoot -> quotaCount -> quotaSize -> new MailboxDeletionFinalStage(
             path, mailboxId, user, sessionId, quotaRoot, quotaCount, quotaSize);
     }
@@ -365,6 +403,10 @@ public class EventFactory {
         return user -> sessionId -> mailboxId -> path -> aclDiff -> new MailboxAclUpdatedFinalStage(path, mailboxId, user, sessionId, aclDiff);
     }
 
+    public static RequireUser<RequireQuotaRoot<RequireQuotaCount<RequireQuotaSize<RequireInstant<QuotaUsageUpdatedFinalStage>>>>> quotaUpdated() {
+        return user -> quotaRoot -> quotaCount -> quotaSize -> instant -> new QuotaUsageUpdatedFinalStage(user, quotaRoot, quotaCount, quotaSize, instant);
+    }
+
     public static MessageMoveEvent.Builder moved() {
         return MessageMoveEvent.builder();
     }


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


[45/47] james-project git commit: MAILBOX-367 Factorise RabbitMQ constants

Posted by bt...@apache.org.
MAILBOX-367 Factorise RabbitMQ constants


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

Branch: refs/heads/master
Commit: 0502ae1fbbecefec9bd16fcf3172c8467229058f
Parents: 31ed391
Author: datph <dp...@linagora.com>
Authored: Mon Jan 7 09:24:26 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:47:47 2019 +0700

----------------------------------------------------------------------
 .../james/backend/rabbitmq/Constants.java       | 41 ++++++++++++++++++++
 .../backend/rabbitmq/RabbitMQClusterTest.java   | 20 +++++-----
 .../james/backend/rabbitmq/RabbitMQFixture.java | 30 ++++++--------
 .../james/backend/rabbitmq/RabbitMQTest.java    | 18 ++++-----
 .../james/queue/rabbitmq/RabbitClient.java      | 24 ++++++------
 5 files changed, 82 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0502ae1f/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/Constants.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/Constants.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/Constants.java
new file mode 100644
index 0000000..4fc2410
--- /dev/null
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/Constants.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.backend.rabbitmq;
+
+import com.google.common.collect.ImmutableMap;
+import com.rabbitmq.client.AMQP;
+
+public interface Constants {
+    boolean DURABLE = true;
+    boolean AUTO_DELETE = true;
+    boolean EXCLUSIVE = true;
+
+    boolean AUTO_ACK = true;
+    boolean MULTIPLE = true;
+
+    String EMPTY_ROUTING_KEY = "";
+    boolean REQUEUE = true;
+
+    String DIRECT_EXCHANGE = "direct";
+
+    AMQP.BasicProperties NO_PROPERTIES = new AMQP.BasicProperties();
+
+    ImmutableMap<String, Object> NO_ARGUMENTS = ImmutableMap.of();
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0502ae1f/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
index 1b2496d..348d3ff 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQClusterTest.java
@@ -18,12 +18,12 @@
  ****************************************************************/
 package org.apache.james.backend.rabbitmq;
 
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.AUTO_DELETE;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DIRECT;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_DELETE;
+import static org.apache.james.backend.rabbitmq.Constants.DIRECT_EXCHANGE;
+import static org.apache.james.backend.rabbitmq.Constants.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.EXCLUSIVE;
+import static org.apache.james.backend.rabbitmq.Constants.NO_PROPERTIES;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.EXCHANGE_NAME;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.EXCLUSIVE;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.NO_PROPERTIES;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.ROUTING_KEY;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.awaitAtMostOneMinute;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -120,7 +120,7 @@ class RabbitMQClusterTest {
 
         @Test
         void queuesShouldBeShared() throws Exception {
-            node1Channel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+            node1Channel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
             node1Channel.queueDeclare(QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of()).getQueue();
             node1Channel.queueBind(QUEUE, EXCHANGE_NAME, ROUTING_KEY);
 
@@ -142,7 +142,7 @@ class RabbitMQClusterTest {
 
         @Test
         void queuesShouldBeDeclarableOnAnotherNode() throws Exception {
-            node1Channel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+            node1Channel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
             node2Channel.queueDeclare(QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of()).getQueue();
             node2Channel.queueBind(QUEUE, EXCHANGE_NAME, ROUTING_KEY);
 
@@ -191,7 +191,7 @@ class RabbitMQClusterTest {
             "See https://github.com/rabbitmq/rabbitmq-server/issues/959")
         @Test
         void nodeKillingWhenProducing(DockerRabbitMQCluster cluster) throws Exception {
-            resilientChannel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+            resilientChannel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
             resilientChannel.queueDeclare(QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of()).getQueue();
             resilientChannel.queueBind(QUEUE, EXCHANGE_NAME, ROUTING_KEY);
 
@@ -241,7 +241,7 @@ class RabbitMQClusterTest {
             try (Connection connection = node3ConnectionFactory.newConnection(clusterAddresses);
                  Channel channel = connection.createChannel()) {
 
-                channel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+                channel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
                 channel.queueDeclare(QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of()).getQueue();
                 channel.queueBind(QUEUE, EXCHANGE_NAME, ROUTING_KEY);
 
@@ -266,7 +266,7 @@ class RabbitMQClusterTest {
             "This test have roughly 4% chance to fail")
         @Test
         void nodeKillingWhenConsuming(DockerRabbitMQCluster cluster) throws Exception {
-            resilientChannel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+            resilientChannel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
             resilientChannel.queueDeclare(QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of()).getQueue();
             resilientChannel.queueBind(QUEUE, EXCHANGE_NAME, ROUTING_KEY);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/0502ae1f/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
index afa0cfe..2920513 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
@@ -26,30 +26,22 @@ import org.awaitility.Awaitility;
 import org.awaitility.Duration;
 import org.awaitility.core.ConditionFactory;
 
-import com.rabbitmq.client.AMQP;
+public interface RabbitMQFixture {
+    String EXCHANGE_NAME = "exchangeName";
+    String ROUTING_KEY = "routingKey";
+    String WORK_QUEUE = "workQueue";
 
-public class RabbitMQFixture {
-    public static final boolean DURABLE = true;
-    public static final boolean AUTO_ACK = true;
-    public static final AMQP.BasicProperties NO_PROPERTIES = null;
-    public static final String EXCHANGE_NAME = "exchangeName";
-    public static final String ROUTING_KEY = "routingKey";
-    public static final String DIRECT = "direct";
-    public static final boolean EXCLUSIVE = true;
-    public static final boolean AUTO_DELETE = true;
-    public static final String WORK_QUEUE = "workQueue";
+    String DEFAULT_USER = "guest";
+    String DEFAULT_PASSWORD_STRING = "guest";
+    char[] DEFAULT_PASSWORD = DEFAULT_PASSWORD_STRING.toCharArray();
+    RabbitMQConfiguration.ManagementCredentials DEFAULT_MANAGEMENT_CREDENTIAL = new RabbitMQConfiguration.ManagementCredentials(DEFAULT_USER, DEFAULT_PASSWORD);
 
-    static final String DEFAULT_USER = "guest";
-    static final String DEFAULT_PASSWORD_STRING = "guest";
-    static final char[] DEFAULT_PASSWORD = DEFAULT_PASSWORD_STRING.toCharArray();
-    public static final RabbitMQConfiguration.ManagementCredentials DEFAULT_MANAGEMENT_CREDENTIAL = new RabbitMQConfiguration.ManagementCredentials(DEFAULT_USER, DEFAULT_PASSWORD);
-
-    public static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
-    public static ConditionFactory calmlyAwait = Awaitility.with()
+    Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
+    ConditionFactory calmlyAwait = Awaitility.with()
         .pollInterval(slowPacedPollInterval)
         .and()
         .with()
         .pollDelay(slowPacedPollInterval)
         .await();
-    public static ConditionFactory awaitAtMostOneMinute = calmlyAwait.atMost(ONE_MINUTE);
+    ConditionFactory awaitAtMostOneMinute = calmlyAwait.atMost(ONE_MINUTE);
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0502ae1f/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQTest.java
index f4dc1bd..412340c 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQTest.java
@@ -18,13 +18,13 @@
  ****************************************************************/
 package org.apache.james.backend.rabbitmq;
 
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.AUTO_ACK;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.AUTO_DELETE;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DIRECT;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_ACK;
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_DELETE;
+import static org.apache.james.backend.rabbitmq.Constants.DIRECT_EXCHANGE;
+import static org.apache.james.backend.rabbitmq.Constants.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.EXCLUSIVE;
+import static org.apache.james.backend.rabbitmq.Constants.NO_PROPERTIES;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.EXCHANGE_NAME;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.EXCLUSIVE;
-import static org.apache.james.backend.rabbitmq.RabbitMQFixture.NO_PROPERTIES;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.ROUTING_KEY;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.WORK_QUEUE;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.awaitAtMostOneMinute;
@@ -137,7 +137,7 @@ class RabbitMQTest {
         }
 
         private String createQueue(Channel channel) throws IOException {
-            channel.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+            channel.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
             String queueName = channel.queueDeclare().getQueue();
             channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY);
             return queueName;
@@ -204,7 +204,7 @@ class RabbitMQTest {
             @Test
             void rabbitMQShouldSupportTheBroadcastCase() throws Exception {
                 // Declare a single exchange and three queues attached to it.
-                channel1.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+                channel1.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
 
                 String queue2 = channel2.queueDeclare().getQueue();
                 channel2.queueBind(queue2, EXCHANGE_NAME, ROUTING_KEY);
@@ -292,7 +292,7 @@ class RabbitMQTest {
                 String conversation4 = "c4";
 
                 // Declare the exchange and a single queue attached to it.
-                channel1.exchangeDeclare(EXCHANGE_NAME, DIRECT, DURABLE);
+                channel1.exchangeDeclare(EXCHANGE_NAME, DIRECT_EXCHANGE, DURABLE);
 
                 String queue1 = channel1.queueDeclare().getQueue();
                 // 1 will follow conversation 1 and 2

http://git-wip-us.apache.org/repos/asf/james-project/blob/0502ae1f/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitClient.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitClient.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitClient.java
index 1a12ac2..d6d0618 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitClient.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitClient.java
@@ -19,6 +19,15 @@
 
 package org.apache.james.queue.rabbitmq;
 
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_ACK;
+import static org.apache.james.backend.rabbitmq.Constants.AUTO_DELETE;
+import static org.apache.james.backend.rabbitmq.Constants.DURABLE;
+import static org.apache.james.backend.rabbitmq.Constants.EMPTY_ROUTING_KEY;
+import static org.apache.james.backend.rabbitmq.Constants.EXCLUSIVE;
+import static org.apache.james.backend.rabbitmq.Constants.MULTIPLE;
+import static org.apache.james.backend.rabbitmq.Constants.NO_ARGUMENTS;
+import static org.apache.james.backend.rabbitmq.Constants.REQUEUE;
+
 import java.io.IOException;
 import java.util.Optional;
 
@@ -27,21 +36,10 @@ import javax.inject.Inject;
 import org.apache.james.backend.rabbitmq.RabbitMQChannelPool;
 import org.apache.james.queue.api.MailQueue;
 
-import com.google.common.collect.ImmutableMap;
 import com.rabbitmq.client.AMQP;
 import com.rabbitmq.client.GetResponse;
 
 class RabbitClient {
-
-    private static final boolean AUTO_ACK = true;
-    private static final boolean AUTO_DELETE = true;
-    private static final boolean DURABLE = true;
-    private static final boolean EXCLUSIVE = true;
-    private static final boolean MULTIPLE = true;
-    private static final ImmutableMap<String, Object> NO_ARGUMENTS = ImmutableMap.of();
-    private static final String ROUTING_KEY = "";
-    public static final boolean REQUEUE = true;
-
     private final RabbitMQChannelPool channelPool;
 
     @Inject
@@ -54,7 +52,7 @@ class RabbitClient {
             try {
                 channel.exchangeDeclare(name.toRabbitExchangeName().asString(), "direct", DURABLE);
                 channel.queueDeclare(name.toWorkQueueName().asString(), DURABLE, !EXCLUSIVE, !AUTO_DELETE, NO_ARGUMENTS);
-                channel.queueBind(name.toWorkQueueName().asString(), name.toRabbitExchangeName().asString(), ROUTING_KEY);
+                channel.queueBind(name.toWorkQueueName().asString(), name.toRabbitExchangeName().asString(), EMPTY_ROUTING_KEY);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
@@ -64,7 +62,7 @@ class RabbitClient {
     void publish(MailQueueName name, byte[] message) throws MailQueue.MailQueueException {
         channelPool.execute(channel -> {
             try {
-                channel.basicPublish(name.toRabbitExchangeName().asString(), ROUTING_KEY, new AMQP.BasicProperties(), message);
+                channel.basicPublish(name.toRabbitExchangeName().asString(), EMPTY_ROUTING_KEY, new AMQP.BasicProperties(), message);
             } catch (IOException e) {
                 throw new MailQueue.MailQueueException("Unable to publish to RabbitMQ", e);
             }


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


[13/47] james-project git commit: MAILBOX-359 Factorize tests for Quota ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for Quota ser-deserialization


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

Branch: refs/heads/master
Commit: 0a16e7ca716984a3111cffd3c7a32a48b5c31268
Parents: 38ebe82
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 16:31:11 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:20 2019 +0700

----------------------------------------------------------------------
 .../json/MailboxDeletionSerializationTest.java  | 144 +-----
 ...QuotaUsageUpdatedEventSerializationTest.java | 451 ++-----------------
 .../james/event/json/dtos/QuotaCountTest.java   | 205 +++++++++
 .../james/event/json/dtos/QuotaSizeTest.java    | 199 ++++++++
 4 files changed, 438 insertions(+), 561 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0a16e7ca/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index 313dc33..b601f48 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -88,86 +88,6 @@ class MailboxDeletionSerializationTest {
     }
 
     @Nested
-    class NullQuotaCountInDeletedMessageCount {
-        private final MailboxListener.MailboxDeletion unlimitedQuotaCountDeletedMessageEvent = new MailboxListener.MailboxDeletion(
-                SESSION_ID,
-                USER,
-                MAILBOX_PATH,
-                QUOTA_ROOT,
-                QuotaCount.unlimited(),
-                TOTAL_DELETED_SIZE,
-                MAILBOX_ID);
-        private final String nullQuotaCountInDeletedMessageCountEventJson =
-            "{" +
-            "  \"MailboxDeletion\":{" +
-            "    \"sessionId\":3652," +
-            "    \"user\":\"user\"," +
-            "    \"path\":{" +
-            "      \"namespace\":\"#private\"," +
-            "      \"user\":\"user\"," +
-            "      \"name\":\"mailboxName\"" +
-            "    }," +
-            "    \"quotaRoot\":\"user@domain\"," +
-            "    \"deletedMessageCount\":null," +
-            "    \"totalDeletedSize\":100," +
-            "    \"mailboxId\":\"789\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void mailboxAddedShouldBeWellSerializedWhenNullQuotaCount() {
-            assertThatJson(EVENT_SERIALIZER.toJson(unlimitedQuotaCountDeletedMessageEvent))
-                .isEqualTo(nullQuotaCountInDeletedMessageCountEventJson);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenNullQuotaCount() {
-            assertThat(EVENT_SERIALIZER.fromJson(nullQuotaCountInDeletedMessageCountEventJson).get())
-                .isEqualTo(unlimitedQuotaCountDeletedMessageEvent);
-        }
-    }
-
-    @Nested
-    class NullQuotaSizeInTotalDeletedSize {
-        private final MailboxListener.MailboxDeletion unlimitedQuotaSizeDeletedSizeEvent = new MailboxListener.MailboxDeletion(
-                SESSION_ID,
-                USER,
-                MAILBOX_PATH,
-                QUOTA_ROOT,
-                DELETED_MESSAGE_COUNT,
-                QuotaSize.unlimited(),
-                MAILBOX_ID);
-        private final String nullQuotaSizeInTotalDeletedMessageEventJson =
-            "{" +
-            "  \"MailboxDeletion\":{" +
-            "    \"sessionId\":3652," +
-            "    \"user\":\"user\"," +
-            "    \"path\":{" +
-            "      \"namespace\":\"#private\"," +
-            "      \"user\":\"user\"," +
-            "      \"name\":\"mailboxName\"" +
-            "    }," +
-            "    \"quotaRoot\":\"user@domain\"," +
-            "    \"deletedMessageCount\":60," +
-            "    \"totalDeletedSize\":null," +
-            "    \"mailboxId\":\"789\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void mailboxAddedShouldBeWellSerializedWhenNullQuotaSize() {
-            assertThatJson(EVENT_SERIALIZER.toJson(unlimitedQuotaSizeDeletedSizeEvent))
-                .isEqualTo(nullQuotaSizeInTotalDeletedMessageEventJson);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenNullQuotaSize() {
-            assertThat(EVENT_SERIALIZER.fromJson(nullQuotaSizeInTotalDeletedMessageEventJson).get())
-                .isEqualTo(unlimitedQuotaSizeDeletedSizeEvent);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void mailboxAddedShouldThrowWhenMissingSessionId() {
@@ -229,32 +149,10 @@ class MailboxDeletionSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnDeletedMessageCount {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingQuotaCount() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenQuotaCountIsNotANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingQuotaCount() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
                     "    \"sessionId\":3652," +
                     "    \"user\":\"user\"," +
@@ -264,41 +162,17 @@ class MailboxDeletionSerializationTest {
                     "      \"name\":\"mailboxName\"" +
                     "    }," +
                     "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":\"60\"," +
                     "    \"totalDeletedSize\":100," +
                     "    \"mailboxId\":\"789\"" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
-        @Nested
-        class DeserializationErrorOnTotalDeletedSize {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingQuotaSize() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenQuotaSizeIsNotANumber() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingQuotaSize() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
                     "    \"sessionId\":3652," +
                     "    \"user\":\"user\"," +
@@ -309,12 +183,10 @@ class MailboxDeletionSerializationTest {
                     "    }," +
                     "    \"quotaRoot\":\"user@domain\"," +
                     "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":\"100\"," +
                     "    \"mailboxId\":\"789\"" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/0a16e7ca/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index 0e97545..608bee3 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -34,12 +34,9 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
-import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 class QuotaUsageUpdatedEventSerializationTest {
-
-    private static final User USER = User.fromUsername("user");
     private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("foo", Optional.empty());
     private static final Quota<QuotaCount> QUOTA_COUNT = Quota.<QuotaCount>builder()
         .used(QuotaCount.count(12))
@@ -94,433 +91,37 @@ class QuotaUsageUpdatedEventSerializationTest {
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
     }
-    
-    @Nested
-    class WithQuotaCount {
-
-        private MailboxListener.QuotaUsageUpdatedEvent quotaEventByQuotaCount(Quota<QuotaCount> countQuota) {
-            return new MailboxListener.QuotaUsageUpdatedEvent(USER, QUOTA_ROOT, countQuota, QUOTA_SIZE, INSTANT);
-        }
-
-        @Nested
-        class LimitedQuotaCount {
-
-            private Quota<QuotaCount> limitedQuotaCountByScopes(Quota.Scope scope) {
-                return Quota.<QuotaCount>builder()
-                    .used(QuotaCount.count(12))
-                    .computedLimit(QuotaCount.count(100))
-                    .limitForScope(QuotaCount.count(100), scope)
-                    .build();
-            }
-
-            @Nested
-            class LimitedQuotaGlobalScope {
-
-                private final String limitedQuotaCountEventJsonGlobalScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Global\":100}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.Global));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaCountEventJsonGlobalScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.Global));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaCountEventJsonGlobalScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class LimitedQuotaDomainScope {
-                private final String limitedQuotaCountEventJsonDomainScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.Domain));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaCountEventJsonDomainScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.Domain));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaCountEventJsonDomainScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class LimitedQuotaUserScope {
-                private final String limitedQuotaCountEventJsonUserScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"User\":100}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.User));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaCountEventJsonUserScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(limitedQuotaCountByScopes(Quota.Scope.User));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaCountEventJsonUserScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-        }
-
-        @Nested
-        class UnLimitedQuotaCount {
-
-            private Quota<QuotaCount> unLimitedQuotaCountByScopes(Quota.Scope scope) {
-                return Quota.<QuotaCount>builder()
-                    .used(QuotaCount.count(12))
-                    .computedLimit(QuotaCount.unlimited())
-                    .limitForScope(QuotaCount.unlimited(), scope)
-                    .build();
-            }
-
-            @Nested
-            class UnLimitedQuotaGlobalScope {
-                private final String unLimitedQuotaCountEventJsonGlobalScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":null,\"limits\":{\"Global\":null}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.Global));
 
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaCountEventJsonGlobalScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.Global));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaCountEventJsonGlobalScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class UnLimitedQuotaDomainScope {
-                private final String unLimitedQuotaCountEventJsonDomainScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":null,\"limits\":{\"Domain\":null}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.Domain));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaCountEventJsonDomainScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.Domain));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaCountEventJsonDomainScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class UnLimitedQuotaUserScope {
-                private final String unLimitedQuotaCountEventJsonUserScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":null,\"limits\":{\"User\":null}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.User));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaCountEventJsonUserScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaCount() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaCount(unLimitedQuotaCountByScopes(Quota.Scope.User));
+    @Test
+    void fromJsonShouldThrowWhenCountQuotaIsMissing() {
+        String quotaUsageUpdatedEvent =
+            "{" +
+                "\"QuotaUsageUpdatedEvent\":{" +
+                "\"quotaRoot\":\"foo\"," +
+                "\"time\":\"2018-11-13T12:00:55Z\"," +
+                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+                "\"user\":\"onlyUsername\"" +
+                "}" +
+                "}";
 
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaCountEventJsonUserScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-        }
+        assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isInstanceOf(NoSuchElementException.class);
     }
 
-    
-    @Nested
-    class WithQuotaSize {
-
-        private MailboxListener.QuotaUsageUpdatedEvent quotaEventByQuotaSize(Quota<QuotaSize> quotaSize) {
-            return new MailboxListener.QuotaUsageUpdatedEvent(USER, QUOTA_ROOT, QUOTA_COUNT, quotaSize, INSTANT);
-        }
-
-        @Nested
-        class LimitedQuotaSize {
-
-            private Quota<QuotaSize> limitedQuotaSizeByScopes(Quota.Scope scope) {
-                return Quota.<QuotaSize>builder()
-                    .used(QuotaSize.size(1234))
-                    .computedLimit(QuotaSize.size(10000))
-                    .limitForScope(QuotaSize.size(10000), scope)
-                    .build();
-            }
-
-            @Nested
-            class LimitedQuotaSizeGlobalScope {
-
-                private final String limitedQuotaSizeEventJsonGlobalScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{\"Global\":10000}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.Global));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaSizeEventJsonGlobalScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.Global));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaSizeEventJsonGlobalScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class LimitedQuotaSizeDomainScope {
-                private final String limitedQuotaSizeEventJsonDomainScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{\"Domain\":10000}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.Domain));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaSizeEventJsonDomainScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.Domain));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaSizeEventJsonDomainScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class LimitedQuotaSizeUserScope {
-                private final String limitedQuotaSizeEventJsonUserScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{\"User\":10000}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.User));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(limitedQuotaSizeEventJsonUserScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(limitedQuotaSizeByScopes(Quota.Scope.User));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(limitedQuotaSizeEventJsonUserScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-        }
-
-        @Nested
-        class UnLimitedQuotaSize {
-
-            private Quota<QuotaSize> unLimitedQuotaSizeByScopes(Quota.Scope scope) {
-                return Quota.<QuotaSize>builder()
-                    .used(QuotaSize.size(1234))
-                    .computedLimit(QuotaSize.unlimited())
-                    .limitForScope(QuotaSize.unlimited(), scope)
-                    .build();
-            }
-
-            @Nested
-            class UnLimitedQuotaSizeGlobalScope {
-
-                private final String unLimitedQuotaSizeEventJsonGlobalScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":null,\"limits\":{\"Global\":null}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.Global));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaSizeEventJsonGlobalScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.Global));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaSizeEventJsonGlobalScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class UnLimitedQuotaSizeDomainScope {
-                private final String unLimitedQuotaSizeEventJsonDomainScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":null,\"limits\":{\"Domain\":null}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.Domain));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaSizeEventJsonDomainScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.Domain));
-
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaSizeEventJsonDomainScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-
-            @Nested
-            class UnLimitedQuotaSizeUserScope {
-                private final String unLimitedQuotaSizeEventJsonUserScope =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":null,\"limits\":{\"User\":null}}," +
-                        "\"user\":\"user\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void toJsonShouldSerializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.User));
-
-                    assertThatJson(EVENT_SERIALIZER.toJson(quotaEvent))
-                        .isEqualTo(unLimitedQuotaSizeEventJsonUserScope);
-                }
-
-                @Test
-                void fromJsonShouldDeserializeQuotaSize() {
-                    MailboxListener.QuotaUsageUpdatedEvent quotaEvent = quotaEventByQuotaSize(unLimitedQuotaSizeByScopes(Quota.Scope.User));
+    @Test
+    void fromJsonShouldThrowWhenSizeQuotaIsMissing() {
+        String quotaUsageUpdatedEvent =
+            "{" +
+                "\"QuotaUsageUpdatedEvent\":{" +
+                "\"quotaRoot\":\"foo\"," +
+                "\"time\":\"2018-11-13T12:00:55Z\"," +
+                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+                "\"user\":\"onlyUsername\"" +
+                "}" +
+                "}";
 
-                    assertThat(EVENT_SERIALIZER.fromJson(unLimitedQuotaSizeEventJsonUserScope).get())
-                        .isEqualTo(quotaEvent);
-                }
-            }
-        }
+        assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isInstanceOf(NoSuchElementException.class);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/0a16e7ca/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
new file mode 100644
index 0000000..88adaa6
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaCountTest.java
@@ -0,0 +1,205 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.event.json.DTOs;
+import org.apache.james.mailbox.model.Quota;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsString;
+import play.api.libs.json.Json;
+import scala.math.BigDecimal;
+
+class QuotaCountTest {
+    @Test
+    void quotaCountShouldBeWellSerialized() {
+        assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaCount.count(18)))
+            .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
+    }
+
+    @Test
+    void quotaCountShouldBeWellDeSerialized() {
+        assertThat(DTO_JSON_SERIALIZE.quotaCountReads().reads(new JsNumber(BigDecimal.valueOf(18))).get())
+            .isEqualTo(QuotaCount.count(18));
+    }
+
+    @Test
+    void quotaCountShouldBeWellSerializedWhenUnlimited() {
+        assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaCount.unlimited()))
+            .isEqualTo(JsNull$.MODULE$);
+    }
+
+    @Test
+    void quotaCountShouldBeWellDeSerializedWhenUnlimited() {
+        assertThat(DTO_JSON_SERIALIZE.quotaCountReads().reads(JsNull$.MODULE$).get())
+            .isEqualTo(QuotaCount.unlimited());
+    }
+
+    @Test
+    void quotaCountShouldReturnErrorWhenString() {
+        assertThat(DTO_JSON_SERIALIZE.quotaCountReads().reads(new JsString("18")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Nested
+    class LimitedQuotaCount {
+        private Quota<QuotaCount> limitedQuotaCountByScopes(Quota.Scope scope) {
+            return Quota.<QuotaCount>builder()
+                .used(QuotaCount.count(12))
+                .computedLimit(QuotaCount.count(100))
+                .limitForScope(QuotaCount.count(100), scope)
+                .build();
+        }
+
+        @Nested
+        class LimitedQuotaGlobalScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"Global\":100}}";
+            private final Quota<QuotaCount> quota = limitedQuotaCountByScopes(Quota.Scope.Global);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class LimitedQuotaDomainScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}";
+            private final Quota<QuotaCount> quota = limitedQuotaCountByScopes(Quota.Scope.Domain);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class LimitedQuotaUserScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"User\":100}}";
+            private final Quota<QuotaCount> quota = limitedQuotaCountByScopes(Quota.Scope.User);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+    }
+
+    @Nested
+    class UnLimitedQuotaCount {
+        private Quota<QuotaCount> unLimitedQuotaCountByScopes(Quota.Scope scope) {
+            return Quota.<QuotaCount>builder()
+                .used(QuotaCount.count(12))
+                .computedLimit(QuotaCount.unlimited())
+                .limitForScope(QuotaCount.unlimited(), scope)
+                .build();
+        }
+
+        @Nested
+        class UnLimitedQuotaGlobalScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"Global\":null}}";
+            private final Quota<QuotaCount> quota = unLimitedQuotaCountByScopes(Quota.Scope.Global);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class UnLimitedQuotaDomainScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"Domain\":null}}";
+            private final Quota<QuotaCount> quota = unLimitedQuotaCountByScopes(Quota.Scope.Domain);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class UnLimitedQuotaUserScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"User\":null}}";
+            private final Quota<QuotaCount> quota = unLimitedQuotaCountByScopes(Quota.Scope.User);
+
+            @Test
+            void toJsonShouldSerializeQuotaCount() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaCountWrites().writes(DTOs.Quota$.MODULE$.toScala(
+                    quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaCount() {
+                assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0a16e7ca/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaSizeTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaSizeTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaSizeTest.java
new file mode 100644
index 0000000..5940f13
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaSizeTest.java
@@ -0,0 +1,199 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.core.quota.QuotaSize;
+import org.apache.james.event.json.DTOs;
+import org.apache.james.mailbox.model.Quota;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsString;
+import play.api.libs.json.Json;
+import scala.math.BigDecimal;
+
+class QuotaSizeTest {
+    @Test
+    void quotaSizeShouldBeWellSerialized() {
+        assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaSize.size(18)))
+            .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
+    }
+
+    @Test
+    void quotaSizeShouldBeWellDeSerialized() {
+        assertThat(DTO_JSON_SERIALIZE.quotaSizeReads().reads(new JsNumber(BigDecimal.valueOf(18))).get())
+            .isEqualTo(QuotaSize.size(18));
+    }
+
+    @Test
+    void quotaSizeShouldBeWellSerializedWhenUnlimited() {
+        assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaSize.unlimited()))
+            .isEqualTo(JsNull$.MODULE$);
+    }
+
+    @Test
+    void quotaSizeShouldBeWellDeSerializedWhenUnlimited() {
+        assertThat(DTO_JSON_SERIALIZE.quotaSizeReads().reads(JsNull$.MODULE$).get())
+            .isEqualTo(QuotaSize.unlimited());
+    }
+
+    @Test
+    void quotaSizeShouldReturnErrorWhenString() {
+        assertThat(DTO_JSON_SERIALIZE.quotaSizeReads().reads(new JsString("18")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Nested
+    class LimitedQuotaSize {
+        private Quota<QuotaSize> limitedQuotaSizeByScopes(Quota.Scope scope) {
+            return Quota.<QuotaSize>builder()
+                .used(QuotaSize.size(12))
+                .computedLimit(QuotaSize.size(100))
+                .limitForScope(QuotaSize.size(100), scope)
+                .build();
+        }
+
+        @Nested
+        class LimitedQuotaGlobalScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"Global\":100}}";
+            private final Quota<QuotaSize> quota = limitedQuotaSizeByScopes(Quota.Scope.Global);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class LimitedQuotaDomainScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}";
+            private final Quota<QuotaSize> quota = limitedQuotaSizeByScopes(Quota.Scope.Domain);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class LimitedQuotaUserScope {
+            private final String json = "{\"used\":12,\"limit\":100,\"limits\":{\"User\":100}}";
+            private final Quota<QuotaSize> quota = limitedQuotaSizeByScopes(Quota.Scope.User);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+    }
+
+    @Nested
+    class UnLimitedQuotaSize {
+        private Quota<QuotaSize> unLimitedQuotaSizeByScopes(Quota.Scope scope) {
+            return Quota.<QuotaSize>builder()
+                .used(QuotaSize.size(12))
+                .computedLimit(QuotaSize.unlimited())
+                .limitForScope(QuotaSize.unlimited(), scope)
+                .build();
+        }
+
+        @Nested
+        class UnLimitedQuotaGlobalScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"Global\":null}}";
+            private final Quota<QuotaSize> quota = unLimitedQuotaSizeByScopes(Quota.Scope.Global);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class UnLimitedQuotaDomainScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"Domain\":null}}";
+            private final Quota<QuotaSize> quota = unLimitedQuotaSizeByScopes(Quota.Scope.Domain);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+
+        @Nested
+        class UnLimitedQuotaUserScope {
+            private final String json = "{\"used\":12,\"limit\":null,\"limits\":{\"User\":null}}";
+            private final Quota<QuotaSize> quota = unLimitedQuotaSizeByScopes(Quota.Scope.User);
+
+            @Test
+            void toJsonShouldSerializeQuotaSize() {
+                assertThatJson(DTO_JSON_SERIALIZE.quotaSizeWrites().writes(DTOs.Quota$.MODULE$.toScala(quota)).toString())
+                    .isEqualTo(json);
+            }
+
+            @Test
+            void fromJsonShouldDeserializeQuotaSize() {
+                assertThat(DTO_JSON_SERIALIZE.quotaSReads().reads(Json.parse(json)).get().toJava())
+                    .isEqualTo(quota);
+            }
+        }
+    }
+}


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


[37/47] james-project git commit: JAMES-2641 Remove MailboxEventDispatcher tests

Posted by bt...@apache.org.
JAMES-2641 Remove MailboxEventDispatcher tests

This class is going to be removed later in that PR


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

Branch: refs/heads/master
Commit: 8a21cb571ba553f89e731378668f33a659d6edbe
Parents: 305c321
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 11:22:43 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:46:01 2019 +0700

----------------------------------------------------------------------
 .../store/MailboxEventDispatcherTest.java       | 352 -------------------
 1 file changed, 352 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8a21cb57/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
deleted file mode 100644
index 24f5cab..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.store;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.Event;
-import org.apache.james.mailbox.FlagsBuilder;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSessionUtil;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.apache.james.mailbox.util.EventCollector;
-import org.assertj.core.api.Condition;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-public class MailboxEventDispatcherTest {
-    private static final MailboxSession.SessionId SESSION_ID = MailboxSession.SessionId.of(10);
-    private static final int MOD_SEQ = -1;
-    public static final Condition<Event> INSTANCE_OF_EVENT_FLAGS_UPDATED = new Condition<Event>() {
-        @Override
-        public boolean matches(Event event) {
-            return event instanceof MailboxListener.FlagsUpdated;
-        }
-    };
-    public static final TestId MAILBOX_ID = TestId.of(147L);
-    public static final int UID_VALIDITY = 145;
-
-    private MailboxEventDispatcher dispatcher;
-    private EventCollector collector;
-    private MessageResult result;
-    private Mailbox mailbox;
-
-    private MailboxSession session = MailboxSessionUtil.create("test", SESSION_ID);
-
-    @Before
-    public void setUp() throws Exception {
-        collector = new EventCollector();
-
-        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
-        mailboxListener.addGlobalListener(collector, session);
-        dispatcher = new MailboxEventDispatcher(mailboxListener);
-        result = mock(MessageResult.class);
-        mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, MAILBOX_ID);
-
-        when(result.getUid()).thenReturn(MessageUid.of(23));
-    }
-
-
-    @Test
-    public void testShouldReturnNoChangesWhenSystemFlagsUnchanged() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags(Flags.Flag.DELETED))
-                .oldFlags(new Flags(Flags.Flag.DELETED))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator()).isEmpty();
-    }
-
-    @Test
-    public void testShouldShowAnsweredAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(
-                UpdatedFlags.builder()
-                    .uid(result.getUid())
-                    .modSeq(MOD_SEQ)
-                    .newFlags(new Flags(Flags.Flag.ANSWERED))
-                    .oldFlags(new Flags())
-                    .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.ANSWERED);
-    }
-
-    @Test
-    public void testShouldShowAnsweredRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(
-                UpdatedFlags.builder()
-                    .uid(result.getUid())
-                    .modSeq(MOD_SEQ)
-                    .newFlags(new Flags(Flags.Flag.ANSWERED))
-                    .oldFlags(new Flags())
-                    .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.ANSWERED);
-    }
-
-    @Test
-    public void testShouldShowDeletedAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.DELETED))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.DELETED);
-    }
-
-    @Test
-    public void testShouldShowDeletedRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags(Flags.Flag.DELETED))
-                .oldFlags(new Flags())
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.DELETED);
-    }
-
-    @Test
-    public void testShouldShowDraftAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.DRAFT))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.DRAFT);
-    }
-
-    @Test
-    public void testShouldShowDraftRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.DRAFT))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.DRAFT);
-    }
-
-    @Test
-    public void testShouldShowFlaggedAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags(Flags.Flag.FLAGGED))
-                .oldFlags(new Flags())
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.FLAGGED);
-    }
-
-    @Test
-    public void testShouldShowFlaggedRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.FLAGGED))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.FLAGGED);
-    }
-
-    @Test
-    public void testShouldShowRecentAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags(Flags.Flag.RECENT))
-                .oldFlags(new Flags())
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.RECENT);
-    }
-
-    @Test
-    public void testShouldShowRecentRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.RECENT))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.RECENT);
-    }
-
-    @Test
-    public void testShouldShowSeenAdded() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags(Flags.Flag.SEEN))
-                .oldFlags(new Flags())
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.SEEN);
-    }
-
-    @Test
-    public void testShouldShowSeenRemoved() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(new Flags())
-                .oldFlags(new Flags(Flags.Flag.SEEN))
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-            .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.SEEN);
-    }
-
-    @Test
-    public void testShouldShowMixedChanges() {
-        dispatcher.flagsUpdated(session,
-            mailbox,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(result.getUid())
-                .modSeq(MOD_SEQ)
-                .newFlags(FlagsBuilder.builder()
-                    .add(Flags.Flag.ANSWERED, Flags.Flag.DRAFT, Flags.Flag.SEEN)
-                    .build())
-                .oldFlags(FlagsBuilder.builder()
-                    .add(Flags.Flag.DRAFT, Flags.Flag.RECENT)
-                    .build())
-                .build()));
-
-        assertThat(collector.getEvents()).hasSize(1)
-            .are(INSTANCE_OF_EVENT_FLAGS_UPDATED);
-        MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.getEvents()
-                .get(0);
-        assertThat(event.getUpdatedFlags().get(0).systemFlagIterator())
-            .containsOnly(Flags.Flag.SEEN, Flags.Flag.RECENT, Flags.Flag.ANSWERED);
-    }
-}


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


[06/47] james-project git commit: MAILBOX-359 Factorize tests for QuotaRoot ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for QuotaRoot ser-deserialization


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

Branch: refs/heads/master
Commit: d7910fcb001416800b401e8b6ba477652a36464c
Parents: 70a4fd5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 14:10:17 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../json/MailboxDeletionSerializationTest.java  | 93 +-------------------
 ...QuotaUsageUpdatedEventSerializationTest.java | 88 ------------------
 .../james/event/json/dtos/QuotaRootTest.java    | 92 +++++++++++++++++++
 3 files changed, 96 insertions(+), 177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d7910fcb/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index f0f9f66..1f76c5b 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -90,46 +90,6 @@ class MailboxDeletionSerializationTest {
     }
 
     @Nested
-    class EmptyQuotaRoot {
-        private final MailboxListener.MailboxDeletion emptyQuotaRootEvent = new MailboxListener.MailboxDeletion(
-                SESSION_ID,
-                USER,
-                MAILBOX_PATH,
-                QuotaRoot.quotaRoot("", Optional.empty()),
-                DELETED_MESSAGE_COUNT,
-                TOTAL_DELETED_SIZE,
-                MAILBOX_ID);
-        private final String nullUserMailboxEventJson =
-            "{" +
-            "  \"MailboxDeletion\":{" +
-            "    \"sessionId\":3652," +
-            "    \"user\":\"user\"," +
-            "    \"path\":{" +
-            "      \"namespace\":\"#private\"," +
-            "      \"user\":\"user\"," +
-            "      \"name\":\"mailboxName\"" +
-            "    }," +
-            "    \"quotaRoot\":\"\"," +
-            "    \"deletedMessageCount\":60," +
-            "    \"totalDeletedSize\":100," +
-            "    \"mailboxId\":\"789\"" +
-            "  }" +
-            "}";
-
-        @Test
-        void mailboxAddedShouldBeWellSerializedWhenEmptyQuotaRoot() {
-            assertThatJson(EVENT_SERIALIZER.toJson(emptyQuotaRootEvent))
-                .isEqualTo(nullUserMailboxEventJson);
-        }
-
-        @Test
-        void mailboxAddedShouldBeWellDeSerializedWhenEmptyQuotaRoot() {
-            assertThat(EVENT_SERIALIZER.fromJson(nullUserMailboxEventJson).get())
-                .isEqualTo(emptyQuotaRootEvent);
-        }
-    }
-
-    @Nested
     class NullQuotaCountInDeletedMessageCount {
         private final MailboxListener.MailboxDeletion unlimitedQuotaCountDeletedMessageEvent = new MailboxListener.MailboxDeletion(
                 SESSION_ID,
@@ -251,53 +211,10 @@ class MailboxDeletionSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnQuotaRoot {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingQuotaRoot() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenNullQuotaRoot() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":null," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenQuotaRootIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingQuotaRoot() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
                     "    \"sessionId\":3652," +
                     "    \"user\":\"user\"," +
@@ -306,14 +223,12 @@ class MailboxDeletionSerializationTest {
                     "      \"user\":\"user\"," +
                     "      \"name\":\"mailboxName\"" +
                     "    }," +
-                    "    \"quotaRoot\":123456," +
                     "    \"deletedMessageCount\":60," +
                     "    \"totalDeletedSize\":100," +
                     "    \"mailboxId\":\"789\"" +
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7910fcb/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index b76b53b..af95172 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -111,94 +111,6 @@ class QuotaUsageUpdatedEventSerializationTest {
         assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
             .isInstanceOf(NoSuchElementException.class);
     }
-
-    @Nested
-    class WitQuotaRoot {
-
-        @Nested
-        class WithNormalQuotaRoot {
-
-            @Test
-            void toJsonShouldReturnSerializedJsonQuotaRoot() {
-                assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_QUOTA_EVENT))
-                    .isEqualTo(DEFAULT_QUOTA_EVENT_JSON);
-            }
-
-            @Test
-            void fromJsonShouldDeserializeQuotaRootJson() {
-                assertThat(EVENT_SERIALIZER.fromJson(DEFAULT_QUOTA_EVENT_JSON).get())
-                    .isEqualTo(DEFAULT_QUOTA_EVENT);
-            }
-        }
-
-        @Nested
-        class WithEmptyQuotaRoot {
-            private final QuotaRoot emptyQuotaRoot = QuotaRoot.quotaRoot("", Optional.empty());
-            private final MailboxListener.QuotaUsageUpdatedEvent eventWithEmptyQuotaRoot =
-                new MailboxListener.QuotaUsageUpdatedEvent(
-                    USER,
-                    emptyQuotaRoot,
-                    QUOTA_COUNT,
-                    QUOTA_SIZE,
-                    INSTANT);
-            private final String quotaUsageUpdatedEvent =
-                "{" +
-                    "\"QuotaUsageUpdatedEvent\":{" +
-                    "\"quotaRoot\":\"\"," +
-                    "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                    "\"time\":\"2018-11-13T12:00:55Z\"," +
-                    "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                    "\"user\":\"user\"" +
-                    "}" +
-                "}";
-
-            @Test
-            void toJsonShouldSerializeWithEmptyQuotaRoot() {
-                assertThatJson(EVENT_SERIALIZER.toJson(eventWithEmptyQuotaRoot))
-                    .isEqualTo(quotaUsageUpdatedEvent);
-            }
-
-            @Test
-            void fromJsonShouldDeserializeWithEmptyQuotaRoot() {
-                assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                    .isEqualTo(eventWithEmptyQuotaRoot);
-            }
-        }
-
-        @Nested
-        class WithNullQuotaRoot {
-            private final MailboxListener.QuotaUsageUpdatedEvent eventWithNullQuotaRoot =
-                new MailboxListener.QuotaUsageUpdatedEvent(
-                    USER,
-                    null,
-                    QUOTA_COUNT,
-                    QUOTA_SIZE,
-                    INSTANT);
-
-            private final String quotaUsageUpdatedEvent =
-                "{" +
-                    "\"QuotaUsageUpdatedEvent\":{" +
-                    "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                    "\"time\":\"2018-11-13T12:00:55Z\"," +
-                    "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                    "\"user\":\"user\"" +
-                    "}" +
-                "}";
-
-            @Test
-            void toJsonShouldThrowWithNullQuotaRoot() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.toJson(eventWithNullQuotaRoot))
-                    .isInstanceOf(NullPointerException.class);
-            }
-
-            @Test
-            void fromJsonShouldThrowWithNullQuotaRoot() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-        }
-    }
-
     
     @Nested
     class WithQuotaCount {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7910fcb/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
new file mode 100644
index 0000000..53076a2
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
@@ -0,0 +1,92 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.core.Domain;
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class QuotaRootTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void quotaRootWithDomainShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld")))))
+            .isEqualTo(new JsString("bob@domain.tld"));
+    }
+
+    @Test
+    void quotaRootWithDomainShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob@domain.tld")))
+            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld"))), new JsPath(List.empty())));
+    }
+
+    @Test
+    void quotaRootShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob", Optional.empty())))
+            .isEqualTo(new JsString("bob"));
+    }
+
+    @Test
+    void quotaRootShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob")))
+            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("bob", Optional.empty()), new JsPath(List.empty())));
+    }
+
+    @Test
+    void emptyQuotaRootShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("", Optional.empty())))
+            .isEqualTo(new JsString(""));
+    }
+
+    @Test
+    void emptyQuotaRootShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("")))
+            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("", Optional.empty()), new JsPath(List.empty())));
+    }
+
+    @Test
+    void emptyQuotaRootShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.quotaRootReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void emptyQuotaRootShouldReturnErrorWhenNotString() {
+        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isInstanceOf(JsError.class);
+    }
+}


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


[26/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for MailboxAclUpdated event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for MailboxAclUpdated event


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

Branch: refs/heads/master
Commit: 098dbe44341d4d34099d1dd33dc6962a6ecb564e
Parents: 2c46d62
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 13:46:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 34 ++++++++++++++++----
 .../store/event/MailboxEventDispatcher.java     |  7 +++-
 2 files changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/098dbe44/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 0205560..de9ed6e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -168,6 +168,32 @@ public class EventFactory {
         }
     }
 
+    public static class MailboxAclUpdatedBuilder extends MailboxEventBuilder<MailboxAclUpdatedBuilder> {
+        private ACLDiff aclDiff;
+
+        public MailboxAclUpdatedBuilder aclDiff(ACLDiff aclDiff) {
+            this.aclDiff = aclDiff;
+            return this;
+        }
+
+        @Override
+        protected MailboxAclUpdatedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxListener.MailboxACLUpdated build() {
+            Preconditions.checkState(aclDiff != null, "Field `aclDiff` is compulsory");
+            mailboxEventChecks();
+
+            return new MailboxListener.MailboxACLUpdated(
+                sessionId,
+                user,
+                path,
+                aclDiff,
+                mailboxId);
+        }
+    }
+
     public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
         @Override
         protected MailboxAddedBuilder backReference() {
@@ -275,12 +301,8 @@ public class EventFactory {
         return new MailboxAddedBuilder();
     }
 
-    public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        return aclUpdated(session.getSessionId(), session.getUser(), mailboxPath, aclDiff, mailboxId);
-    }
-
-    public MailboxListener.MailboxACLUpdated aclUpdated(MailboxSession.SessionId sessionId, User user, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        return new MailboxListener.MailboxACLUpdated(sessionId, user, mailboxPath, aclDiff, mailboxId);
+    public MailboxAclUpdatedBuilder aclUpdated() {
+        return new MailboxAclUpdatedBuilder();
     }
 
     public MessageMoveEvent moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/098dbe44/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 122394f..da360d5 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -178,7 +178,12 @@ public class MailboxEventDispatcher {
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        event(eventFactory.aclUpdated(session, mailboxPath, aclDiff, mailboxId));
+        event(eventFactory.aclUpdated()
+            .mailboxSession(session)
+            .path(mailboxPath)
+            .mailboxId(mailboxId)
+            .aclDiff(aclDiff)
+            .build());
     }
 
     public void moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {


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


[46/47] james-project git commit: MAILBOX-367 EventBusContract should use real event pojo

Posted by bt...@apache.org.
MAILBOX-367 EventBusContract should use real event pojo

To avoid scala serialization error happens on mock event while running
rabbitmq eventbus


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

Branch: refs/heads/master
Commit: a15bd7053d351ff3210ca3fee6a155a4a4c1ae01
Parents: 0502ae1
Author: datph <dp...@linagora.com>
Authored: Mon Jan 7 10:24:59 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:47:47 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/events/EventBusContract.java  | 51 +++++++++++---------
 1 file changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a15bd705/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
index 236ee75..23743a5 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
@@ -38,6 +38,7 @@ import java.util.concurrent.CountDownLatch;
 import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
+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.TestId;
@@ -47,7 +48,11 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSortedMap;
 
 public interface EventBusContract {
-    MailboxListener.MailboxEvent event = mock(MailboxListener.MailboxEvent.class);
+    MailboxListener.MailboxEvent EVENT = new MailboxListener.MailboxAdded(
+        MailboxSession.SessionId.of(42),
+        User.fromUsername("user"),
+        new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", "mailboxName"),
+        TestId.of(18));
 
     class GroupA extends Group {}
 
@@ -73,7 +78,7 @@ public interface EventBusContract {
 
         eventBus().register(listener, new GroupA());
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -109,7 +114,7 @@ public interface EventBusContract {
 
         eventBus().register(listener, new GroupA());
 
-        assertThatCode(() -> eventBus().dispatch(event, NO_KEYS).block())
+        assertThatCode(() -> eventBus().dispatch(EVENT, NO_KEYS).block())
             .doesNotThrowAnyException();
     }
 
@@ -120,7 +125,7 @@ public interface EventBusContract {
 
         eventBus().register(listener, KEY_1);
 
-        assertThatCode(() -> eventBus().dispatch(event, NO_KEYS).block())
+        assertThatCode(() -> eventBus().dispatch(EVENT, NO_KEYS).block())
             .doesNotThrowAnyException();
     }
 
@@ -131,7 +136,7 @@ public interface EventBusContract {
         eventBus().register(listener, new GroupA());
         eventBus().register(listener2, new GroupB());
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
 
         verify(listener, times(1)).event(any());
         verify(listener2, times(1)).event(any());
@@ -144,7 +149,7 @@ public interface EventBusContract {
 
         registration.unregister();
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
         verifyZeroInteractions(listener);
     }
 
@@ -188,7 +193,7 @@ public interface EventBusContract {
         eventBus().register(listener, new GroupA()).unregister();
         eventBus().register(listener, new GroupA());
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -198,7 +203,7 @@ public interface EventBusContract {
         MailboxListener listener = newListener();
         eventBus().register(listener, KEY_1);
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
 
         verifyZeroInteractions(listener);
     }
@@ -208,7 +213,7 @@ public interface EventBusContract {
         MailboxListener listener = newListener();
         eventBus().register(listener, KEY_1);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_2)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_2)).block();
 
         verifyZeroInteractions(listener);
     }
@@ -218,7 +223,7 @@ public interface EventBusContract {
         MailboxListener listener = newListener();
         eventBus().register(listener, KEY_1);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -230,7 +235,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener2, KEY_2);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verify(listener, times(1)).event(any());
         verifyZeroInteractions(listener2);
@@ -243,7 +248,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener2, KEY_1);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verify(listener, times(1)).event(any());
         verify(listener2, times(1)).event(any());
@@ -255,7 +260,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener, KEY_1);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -266,7 +271,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener, KEY_1).unregister();
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verifyZeroInteractions(listener);
     }
@@ -278,7 +283,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1).unregister();
         registration.unregister();
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verifyZeroInteractions(listener);
     }
@@ -289,7 +294,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener, KEY_2).unregister();
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -310,7 +315,7 @@ public interface EventBusContract {
         MailboxListener listener = newListener();
         eventBus().register(listener, KEY_1);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1, KEY_2)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1, KEY_2)).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -321,7 +326,7 @@ public interface EventBusContract {
         eventBus().register(listener, KEY_1);
         eventBus().register(listener, KEY_2);
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1, KEY_2)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1, KEY_2)).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -331,7 +336,7 @@ public interface EventBusContract {
         MailboxListener listener = newListener();
         eventBus().register(listener, KEY_1).unregister();
 
-        eventBus().dispatch(event, ImmutableSet.of(KEY_1)).block();
+        eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block();
 
         verifyZeroInteractions(listener);
     }
@@ -342,7 +347,7 @@ public interface EventBusContract {
 
         eventBus().register(listener, new GroupA());
 
-        eventBus().dispatch(event, NO_KEYS).block();
+        eventBus().dispatch(EVENT, NO_KEYS).block();
 
         verify(listener, times(1)).event(any());
     }
@@ -355,12 +360,12 @@ public interface EventBusContract {
         doAnswer(invocation -> {
             latch.await();
             return null;
-        }).when(listener).event(event);
+        }).when(listener).event(EVENT);
 
         assertTimeout(Duration.ofSeconds(2),
             () -> {
-                eventBus().dispatch(event, NO_KEYS).block();
+                eventBus().dispatch(EVENT, NO_KEYS).block();
                 latch.countDown();
             });
     }
-}
+}
\ No newline at end of file


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


[23/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for FlagsUpdated event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for FlagsUpdated event


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

Branch: refs/heads/master
Commit: 886ad168872a4cc894c45fa4cb1e0b5b40e1c182
Parents: 8550ce9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 11:51:43 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java |  87 ++++++++++----
 .../store/event/MailboxEventDispatcher.java     |   8 +-
 .../base/MailboxEventAnalyserTest.java          | 120 +++++++++----------
 3 files changed, 130 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/886ad168/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index 13c6f9d..e87f967 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -20,7 +20,6 @@
 package org.apache.james.mailbox.store.event;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 
@@ -41,57 +40,103 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
 
 public class EventFactory {
-    public static class MailboxAddedBuilder {
-        private MailboxPath path;
-        private MailboxId mailboxId;
-        private User user;
-        private MailboxSession.SessionId sessionId;
+    public abstract static class MailboxEventBuilder<T extends MailboxEventBuilder> {
+        protected MailboxPath path;
+        protected MailboxId mailboxId;
+        protected User user;
+        protected MailboxSession.SessionId sessionId;
 
-        public MailboxAddedBuilder mailbox(Mailbox mailbox) {
+        abstract T backReference();
+
+        public T mailbox(Mailbox mailbox) {
             path(mailbox.generateAssociatedPath());
             mailboxId(mailbox.getMailboxId());
-            return this;
+            return backReference();
         }
 
-        public MailboxAddedBuilder mailboxSession(MailboxSession mailboxSession) {
+        public T mailboxSession(MailboxSession mailboxSession) {
             user(mailboxSession.getUser());
             sessionId(mailboxSession.getSessionId());
-            return this;
+            return backReference();
         }
 
-        public MailboxAddedBuilder mailboxId(MailboxId mailboxId) {
+        public T mailboxId(MailboxId mailboxId) {
             this.mailboxId = mailboxId;
-            return this;
+            return backReference();
         }
 
-        public MailboxAddedBuilder path(MailboxPath path) {
+        public T path(MailboxPath path) {
             this.path = path;
-            return this;
+            return backReference();
         }
 
-        public MailboxAddedBuilder user(User user) {
+        public T user(User user) {
             this.user = user;
-            return this;
+            return backReference();
         }
 
-        public MailboxAddedBuilder sessionId(MailboxSession.SessionId sessionId) {
+        public T sessionId(MailboxSession.SessionId sessionId) {
             this.sessionId = sessionId;
-            return this;
+            return backReference();
         }
 
-        public MailboxListener.MailboxAdded build() {
+        void mailboxEventChecks() {
             Preconditions.checkState(user != null, "Field `user` is compulsory");
             Preconditions.checkState(mailboxId != null, "Field `mailboxId` is compulsory");
             Preconditions.checkState(path != null, "Field `path` is compulsory");
             Preconditions.checkState(sessionId != null, "Field `sessionId` is compulsory");
+        }
+    }
+
+    public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
+        @Override
+        MailboxAddedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxListener.MailboxAdded build() {
+            mailboxEventChecks();
 
             return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId);
         }
     }
 
+    public static class FlagsUpdatedBuilder extends MailboxEventBuilder<FlagsUpdatedBuilder> {
+        private final ImmutableList.Builder<UpdatedFlags> updatedFlags;
+
+        public FlagsUpdatedBuilder() {
+            updatedFlags = ImmutableList.builder();
+        }
+
+        public FlagsUpdatedBuilder updatedFags(Iterable<UpdatedFlags> updatedFlags) {
+            this.updatedFlags.addAll(updatedFlags);
+            return this;
+        }
+
+        public FlagsUpdatedBuilder updatedFags(UpdatedFlags updatedFlags) {
+            this.updatedFlags.add(updatedFlags);
+            return this;
+        }
+
+        @Override
+        FlagsUpdatedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxListener.FlagsUpdated build() {
+            mailboxEventChecks();
+
+            ImmutableList<UpdatedFlags> updatedFlags = this.updatedFlags.build();
+
+            return new MailboxListener.FlagsUpdated(sessionId, user, path, mailboxId, updatedFlags);
+        }
+    }
+
     public MailboxListener.Added added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         return added(session.getSessionId(), session.getUser(), uids, mailbox);
     }
@@ -108,8 +153,8 @@ public class EventFactory {
         return new MailboxListener.Expunged(sessionId, user, mailbox.generateAssociatedPath(), mailbox.getMailboxId(), uids);
     }
 
-    public MailboxListener.FlagsUpdated flagsUpdated(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        return new MailboxListener.FlagsUpdated(session.getSessionId(), session.getUser(), mailbox.generateAssociatedPath(), mailbox.getMailboxId(), uflags);
+    public FlagsUpdatedBuilder flagsUpdated() {
+        return new FlagsUpdatedBuilder();
     }
 
     public MailboxListener.MailboxRenamed mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/886ad168/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index fa0b0bc..aabd204 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -125,7 +125,11 @@ public class MailboxEventDispatcher {
      * registered MailboxListener will get triggered then
      */
     public void flagsUpdated(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        event(eventFactory.flagsUpdated(session, mailbox, uflags));
+        event(eventFactory.flagsUpdated()
+            .mailbox(mailbox)
+            .mailboxSession(session)
+            .updatedFags(uflags)
+            .build());
     }
 
     public void flagsUpdated(MailboxSession session, Mailbox mailbox, UpdatedFlags uflags) {
@@ -153,7 +157,7 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        listener.event(eventFactory.mailboxAdded()
+        event(eventFactory.mailboxAdded()
             .mailbox(mailbox)
             .mailboxSession(session)
             .build());

http://git-wip-us.apache.org/repos/asf/james-project/blob/886ad168/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 1dc277a..9581044 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -56,6 +56,25 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSortedMap;
 
 public class MailboxEventAnalyserTest {
+    private static final MessageUid UID = MessageUid.of(900);
+    private static final UpdatedFlags ADD_RECENT_UPDATED_FLAGS = UpdatedFlags.builder()
+        .uid(UID)
+        .modSeq(-1)
+        .oldFlags(new Flags())
+        .newFlags(new Flags(Flags.Flag.RECENT))
+        .build();
+    private static final UpdatedFlags ADD_ANSWERED_UPDATED_FLAGS = UpdatedFlags.builder()
+        .uid(UID)
+        .modSeq(-1)
+        .oldFlags(new Flags())
+        .newFlags(new Flags(Flags.Flag.ANSWERED))
+        .build();
+    private static final UpdatedFlags NOOP_UPDATED_FLAGS = UpdatedFlags.builder()
+        .uid(UID)
+        .modSeq(-1)
+        .oldFlags(new Flags())
+        .newFlags(new Flags())
+        .build();
 
     public static class SingleMessageResultIterator implements MessageResultIterator {
         private final MessageResult messageResult;
@@ -169,15 +188,12 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldNotSetUidWhenNoSystemFlagChange() {
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(MessageUid.of(90))
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags())
-                .build()));
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(NOOP_UPDATED_FLAGS)
+            .build();
+
         testee.event(update);
 
         assertThat(testee.flagUpdateUids()).isEmpty();
@@ -185,36 +201,27 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldSetUidWhenSystemFlagChange() {
-        MessageUid uid = MessageUid.of(900);
-        
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            OTHER_MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(uid)
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags(Flags.Flag.ANSWERED))
-                .build()));
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(OTHER_MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .build();
+
         testee.event(update);
 
-       assertThat(testee.flagUpdateUids().iterator()).containsExactly(uid);
+       assertThat(testee.flagUpdateUids().iterator()).containsExactly(UID);
     }
 
     @Test
     public void testShouldClearFlagUidsUponReset() {
-        MessageUid uid = MessageUid.of(900);
         SelectedMailboxImpl analyser = this.testee;
-        
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(uid)
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags(Flags.Flag.ANSWERED))
-                .build()));
+
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .build();
+
         analyser.event(update);
         analyser.event(update);
         analyser.deselect();
@@ -224,35 +231,27 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() {
-        MessageUid uid = MessageUid.of(900);
-
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            OTHER_MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(uid)
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags(Flags.Flag.ANSWERED))
-                .build()));
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(OTHER_MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .build();
+
         testee.event(update);
         testee.setSilentFlagChanges(true);
         testee.event(update);
 
-        assertThat(testee.flagUpdateUids().iterator()).containsExactly(uid);
+        assertThat(testee.flagUpdateUids().iterator()).containsExactly(UID);
     }
 
     @Test
     public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode() {
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(MessageUid.of(345))
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags())
-                .build()));
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(NOOP_UPDATED_FLAGS)
+            .build();
+
         testee.event(update);
         testee.setSilentFlagChanges(true);
         testee.event(update);
@@ -262,15 +261,12 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() {
-        MailboxListener.FlagsUpdated update = eventFactory.flagsUpdated(
-            MAILBOX_SESSION,
-            DEFAULT_MAILBOX,
-            ImmutableList.of(UpdatedFlags.builder()
-                .uid(MessageUid.of(886))
-                .modSeq(-1)
-                .oldFlags(new Flags())
-                .newFlags(new Flags(Flags.Flag.RECENT))
-                .build()));
+        MailboxListener.FlagsUpdated update = new EventFactory().flagsUpdated()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(DEFAULT_MAILBOX)
+            .updatedFags(ADD_RECENT_UPDATED_FLAGS)
+            .build();
+
         testee.event(update);
 
         assertThat(testee.flagUpdateUids().iterator()).isEmpty();


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


[42/47] james-project git commit: JAMES-2641 Remove MailboxEventDispatcher

Posted by bt...@apache.org.
JAMES-2641 Remove MailboxEventDispatcher

Let's emmit on the Delegating listener


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

Branch: refs/heads/master
Commit: 31ed391c7b4594b102ab74bc76eca31bd80ae95e
Parents: 9cdf4ba
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 11:55:18 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:46:33 2019 +0700

----------------------------------------------------------------------
 .../cassandra/CassandraMailboxManager.java      |  7 +--
 .../cassandra/CassandraMessageManager.java      |  8 ++--
 .../CassandraCombinationManagerTest.java        |  5 +--
 .../CassandraCombinationManagerTestSystem.java  |  6 +--
 .../CassandraMailboxManagerProvider.java        |  9 ++--
 ...CassandraMessageIdManagerSideEffectTest.java |  6 +--
 .../CassandraMessageIdManagerStorageTest.java   |  5 +--
 .../CassandraMessageIdManagerTestSystem.java    | 10 ++---
 .../cassandra/CassandraTestSystemFixture.java   | 11 +++--
 .../CassandraMailboxManagerAttachmentTest.java  |  8 ++--
 .../ElasticSearchIntegrationTest.java           |  2 +-
 .../james/mailbox/jpa/JPAMailboxManager.java    |  4 +-
 .../james/mailbox/jpa/JPAMessageManager.java    |  6 +--
 .../jpa/openjpa/OpenJPAMailboxManager.java      |  6 +--
 .../jpa/openjpa/OpenJPAMessageManager.java      |  6 +--
 .../resources/META-INF/spring/mailbox-jpa.xml   |  5 +--
 .../mailbox/jpa/JpaMailboxManagerProvider.java  |  6 +--
 .../search/LuceneMessageSearchIndexTest.java    |  2 +-
 .../META-INF/spring/mailbox-maildir.xml         |  5 +--
 .../maildir/MaildirMailboxManagerProvider.java  |  7 +--
 .../inmemory/InMemoryMailboxManager.java        |  8 ++--
 .../inmemory/InMemoryMessageManager.java        |  6 +--
 .../META-INF/spring/mailbox-memory.xml          |  7 ++-
 .../InMemoryMailboxManagerAttachmentTest.java   |  8 ++--
 .../manager/InMemoryIntegrationResources.java   | 13 ++----
 .../InMemoryMessageIdManagerSideEffectTest.java | 12 +++--
 .../search/SimpleMessageSearchIndexTest.java    |  2 +-
 .../main/resources/META-INF/spring/quota.xml    |  2 +-
 .../META-INF/spring/spring-mailbox.xml          |  6 +--
 .../mailbox/store/StoreMailboxManager.java      | 23 +++-------
 .../mailbox/store/StoreMessageIdManager.java    | 18 ++++----
 .../mailbox/store/StoreMessageManager.java      | 46 ++++++--------------
 .../james/mailbox/store/StoreRightManager.java  | 12 ++---
 .../store/event/MailboxEventDispatcher.java     | 41 -----------------
 .../quota/ListeningCurrentQuotaUpdater.java     | 12 ++---
 .../AbstractMessageIdManagerSideEffectTest.java |  6 +--
 .../store/MessageIdManagerTestSystem.java       |  2 +-
 .../mailbox/store/StoreMailboxManagerTest.java  |  6 +--
 .../mailbox/store/StoreRightManagerTest.java    |  9 ++--
 .../quota/ListeningCurrentQuotaUpdaterTest.java |  4 +-
 .../cassandra/host/CassandraHostSystem.java     |  8 ++--
 .../inmemory/host/InMemoryHostSystem.java       |  2 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |  9 ++--
 .../host/LuceneSearchHostSystem.java            |  7 +--
 .../maildir/host/MaildirHostSystem.java         |  7 +--
 .../modules/mailbox/CassandraMailboxModule.java |  2 -
 .../modules/mailbox/MemoryMailboxModule.java    |  2 -
 .../META-INF/org/apache/james/spring-server.xml |  4 --
 48 files changed, 134 insertions(+), 274 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
index 09c4c31..f963706 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -61,8 +60,7 @@ public class CassandraMailboxManager extends StoreMailboxManager {
     @Inject
     public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, Authorizator authorizator,
                                    MailboxPathLocker locker, MessageParser messageParser,
-                                   MessageId.Factory messageIdFactory,
-                                   MailboxEventDispatcher mailboxEventDispatcher, DelegatingMailboxListener delegatingMailboxListener,
+                                   MessageId.Factory messageIdFactory, DelegatingMailboxListener delegatingMailboxListener,
                                    StoreMailboxAnnotationManager annotationManager, StoreRightManager storeRightManager) {
         super(mapperFactory,
             authenticator,
@@ -71,7 +69,6 @@ public class CassandraMailboxManager extends StoreMailboxManager {
             messageParser,
             messageIdFactory,
             annotationManager,
-            mailboxEventDispatcher,
             delegatingMailboxListener,
             storeRightManager);
         this.locker = locker;
@@ -105,7 +102,7 @@ public class CassandraMailboxManager extends StoreMailboxManager {
     protected StoreMessageManager createMessageManager(Mailbox mailboxRow, MailboxSession session) {
         return new CassandraMessageManager(mapperFactory,
             getMessageSearchIndex(),
-            getEventDispatcher(),
+            getDelegationListener(),
             this.locker,
             mailboxRow,
             getQuotaManager(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
index fe00a3a..11b46c9 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
@@ -33,7 +33,7 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.BatchSizes;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -50,11 +50,11 @@ public class CassandraMessageManager extends StoreMessageManager {
     private CassandraMailboxSessionMapperFactory mapperFactory;
 
     public CassandraMessageManager(CassandraMailboxSessionMapperFactory mapperFactory, MessageSearchIndex index,
-                                   MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, QuotaManager quotaManager,
+                                   DelegatingMailboxListener delegatingMailboxListener, MailboxPathLocker locker, Mailbox mailbox, QuotaManager quotaManager,
                                    QuotaRootResolver quotaRootResolver, MessageParser messageParser, MessageId.Factory messageIdFactory,
                                    BatchSizes batchSizes,
                                    StoreRightManager storeRightManager) {
-        super(CassandraMailboxManager.MESSAGE_CAPABILITIES, mapperFactory, index, dispatcher, locker, mailbox,
+        super(CassandraMailboxManager.MESSAGE_CAPABILITIES, mapperFactory, index, delegatingMailboxListener, locker, mailbox,
             quotaManager, quotaRootResolver, messageParser, messageIdFactory, batchSizes, storeRightManager);
 
         this.mapperFactory = mapperFactory;
@@ -71,7 +71,7 @@ public class CassandraMessageManager extends StoreMessageManager {
     }
 
     @Override
-    protected void storeAttachment(final MailboxMessage message, final List<MessageAttachment> messageAttachments, final MailboxSession session) throws MailboxException {
+    protected void storeAttachment(MailboxMessage message, List<MessageAttachment> messageAttachments, MailboxSession session) throws MailboxException {
         mapperFactory.getAttachmentMapper(session)
             .storeAttachmentsForMessage(
                 messageAttachments.stream()

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
index b2d0850..65cc240 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java
@@ -25,7 +25,6 @@ import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule;
 import org.apache.james.mailbox.store.AbstractCombinationManagerTest;
 import org.apache.james.mailbox.store.CombinationManagerTestSystem;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -62,9 +61,7 @@ public class CassandraCombinationManagerTest extends AbstractCombinationManagerT
     
     @Override
     public CombinationManagerTestSystem createTestingData() throws Exception {
-        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(mailboxListener);
-        return CassandraCombinationManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), mailboxEventDispatcher);
+        return CassandraCombinationManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), new DefaultDelegatingMailboxListener());
     }
     
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTestSystem.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTestSystem.java
index 373dc4d..9e1430c 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTestSystem.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTestSystem.java
@@ -28,7 +28,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.CombinationManagerTestSystem;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
 public class CassandraCombinationManagerTestSystem extends CombinationManagerTestSystem {
@@ -36,10 +36,10 @@ public class CassandraCombinationManagerTestSystem extends CombinationManagerTes
     private final CassandraMailboxSessionMapperFactory mapperFactory;
     private final CassandraMailboxManager cassandraMailboxManager;
 
-    public static CombinationManagerTestSystem createTestingData(CassandraCluster cassandra, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
+    public static CombinationManagerTestSystem createTestingData(CassandraCluster cassandra, QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) throws Exception {
         CassandraMailboxSessionMapperFactory mapperFactory = CassandraTestSystemFixture.createMapperFactory(cassandra);
 
-        return new CassandraCombinationManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, dispatcher),
+        return new CassandraCombinationManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, delegatingMailboxListener),
             mapperFactory,
             CassandraTestSystemFixture.createMailboxManager(mapperFactory));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
index 8f66335..8656080 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
@@ -38,7 +38,6 @@ import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
@@ -62,8 +61,7 @@ public class CassandraMailboxManagerProvider {
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
         MessageParser messageParser = new MessageParser();
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, aclResolver, groupMembershipResolver, delegatingMailboxListener);
 
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
@@ -71,8 +69,7 @@ public class CassandraMailboxManagerProvider {
             LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
 
         CassandraMailboxManager manager = new CassandraMailboxManager(mapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-            messageParser, messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener,
-            annotationManager, storeRightManager);
+            messageParser, messageIdFactory, delegatingMailboxListener, annotationManager, storeRightManager);
 
         CassandraPerUserMaxQuotaManager maxQuotaManager = new CassandraPerUserMaxQuotaManager(new CassandraPerUserMaxQuotaDao(session),
             new CassandraPerDomainMaxQuotaDao(session),
@@ -81,7 +78,7 @@ public class CassandraMailboxManagerProvider {
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaUpdater, maxQuotaManager);
         QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(manager, mapperFactory);
 
-        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaUpdater, quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
+        ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaUpdater, quotaRootResolver, delegatingMailboxListener, storeQuotaManager);
         manager.setQuotaManager(storeQuotaManager);
         manager.setQuotaUpdater(quotaUpdater);
         manager.setQuotaRootResolver(quotaRootResolver);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java
index 8553355..72ce1b4 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java
@@ -25,7 +25,7 @@ import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.AbstractMessageIdManagerSideEffectTest;
 import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -60,7 +60,7 @@ public class CassandraMessageIdManagerSideEffectTest extends AbstractMessageIdMa
     }
 
     @Override
-    protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
-        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, quotaManager, dispatcher);
+    protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) throws Exception {
+        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, quotaManager, delegatingMailboxListener);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
index 6b9a519..8133113 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java
@@ -25,7 +25,6 @@ import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule;
 import org.apache.james.mailbox.store.AbstractMessageIdManagerStorageTest;
 import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -62,8 +61,6 @@ public class CassandraMessageIdManagerStorageTest extends AbstractMessageIdManag
     
     @Override
     protected MessageIdManagerTestSystem createTestingData() throws Exception {
-        DefaultDelegatingMailboxListener mailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(mailboxListener);
-        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), mailboxEventDispatcher);
+        return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), new DefaultDelegatingMailboxListener());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
index 31eefc2..34e6236 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerTestSystem.java
@@ -24,16 +24,16 @@ import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.quota.CurrentQuotaManager;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
 import org.apache.james.mailbox.store.quota.StoreCurrentQuotaManager;
 
 public class CassandraMessageIdManagerTestSystem {
 
-    public static MessageIdManagerTestSystem createTestingData(CassandraCluster cassandra, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
+    public static MessageIdManagerTestSystem createTestingData(CassandraCluster cassandra, QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) throws Exception {
         CassandraMailboxSessionMapperFactory mapperFactory = CassandraTestSystemFixture.createMapperFactory(cassandra);
 
-        return new MessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, dispatcher),
+        return new MessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, delegatingMailboxListener),
             new CassandraMessageId.Factory(),
             mapperFactory,
             CassandraTestSystemFixture.createMailboxManager(mapperFactory)) {
@@ -46,9 +46,9 @@ public class CassandraMessageIdManagerTestSystem {
         CassandraMailboxManager mailboxManager = CassandraTestSystemFixture.createMailboxManager(mapperFactory);
         ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(
             (StoreCurrentQuotaManager) currentQuotaManager,
-            mailboxManager.getQuotaRootResolver(), mailboxManager.getEventDispatcher(), quotaManager);
+            mailboxManager.getQuotaRootResolver(), mailboxManager.getDelegationListener(), quotaManager);
         mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, mailboxManager.createSystemSession("System"));
-        return new MessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, mailboxManager.getEventDispatcher()),
+        return new MessageIdManagerTestSystem(CassandraTestSystemFixture.createMessageIdManager(mapperFactory, quotaManager, mailboxManager.getDelegationListener()),
             new CassandraMessageId.Factory(),
             mapperFactory,
             mailboxManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
index 6e70274..916029a 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
@@ -40,7 +40,7 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.StoreQuotaManager;
@@ -60,24 +60,23 @@ public class CassandraTestSystemFixture {
 
     public static CassandraMailboxManager createMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory) throws Exception {
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), delegatingMailboxListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mapperFactory, storeRightManager);
 
         CassandraMailboxManager cassandraMailboxManager = new CassandraMailboxManager(mapperFactory, mock(Authenticator.class), mock(Authorizator.class),
             new NoMailboxPathLocker(), new MessageParser(), new CassandraMessageId.Factory(),
-            mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
+            delegatingMailboxListener, annotationManager, storeRightManager);
         cassandraMailboxManager.init();
 
         return cassandraMailboxManager;
     }
 
-    public static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMapperFactory mapperFactory, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception {
+    public static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMapperFactory mapperFactory, QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) throws Exception {
         CassandraMailboxManager mailboxManager = createMailboxManager(mapperFactory);
         return new StoreMessageIdManager(
             mailboxManager,
             mapperFactory,
-            dispatcher,
+            delegatingMailboxListener,
             new CassandraMessageId.Factory(),
             quotaManager,
             new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
index d850be4..be88f00 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
@@ -39,7 +39,6 @@ import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
@@ -88,20 +87,19 @@ public class CassandraMailboxManagerAttachmentTest extends AbstractMailboxManage
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingMailboxListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), delegatingMailboxListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
 
         mailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory,
             noAuthenticator, noAuthorizator, new NoMailboxPathLocker(), new MessageParser(),
-            messageIdFactory, mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
+            messageIdFactory, delegatingMailboxListener, annotationManager, storeRightManager);
         mailboxManager.init();
         MessageParser failingMessageParser = mock(MessageParser.class);
         when(failingMessageParser.retrieveAttachments(any()))
             .thenThrow(new RuntimeException("Message parser set to fail"));
         parseFailingMailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator,
             new NoMailboxPathLocker(), failingMessageParser, messageIdFactory,
-            mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
+            delegatingMailboxListener, annotationManager, storeRightManager);
         parseFailingMailboxManager.init();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index bb8b1bf..f31e363 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -120,7 +120,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getDelegationListener(),
             storeMailboxManager.getMessageIdFactory(),
             storeMailboxManager.getQuotaManager(),
             storeMailboxManager.getQuotaRootResolver());

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
index c3f7399..d8e9759 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
@@ -33,7 +33,6 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.transaction.Mapper;
@@ -55,12 +54,11 @@ public abstract class JPAMailboxManager extends StoreMailboxManager {
                              MessageParser messageParser,
                              MessageId.Factory messageIdFactory,
                              DelegatingMailboxListener delegatingMailboxListener,
-                             MailboxEventDispatcher mailboxEventDispatcher,
                              StoreMailboxAnnotationManager annotationManager,
                              StoreRightManager storeRightManager) {
         super(mailboxSessionMapperFactory, authenticator, authorizator, locker,
             messageParser, messageIdFactory, annotationManager,
-            mailboxEventDispatcher, delegatingMailboxListener, storeRightManager);
+            delegatingMailboxListener, storeRightManager);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
index bdfcb91..e718f95 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
@@ -37,7 +37,7 @@ import org.apache.james.mailbox.store.BatchSizes;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -51,7 +51,7 @@ public class JPAMessageManager extends StoreMessageManager {
     
     public JPAMessageManager(MailboxSessionMapperFactory mapperFactory,
                              MessageSearchIndex index,
-                             MailboxEventDispatcher dispatcher,
+                             DelegatingMailboxListener delegatingMailboxListener,
                              MailboxPathLocker locker,
                              Mailbox mailbox,
                              QuotaManager quotaManager,
@@ -61,7 +61,7 @@ public class JPAMessageManager extends StoreMessageManager {
                              BatchSizes batchSizes,
                              StoreRightManager storeRightManager) {
 
-        super(JPAMailboxManager.DEFAULT_NO_MESSAGE_CAPABILITIES, mapperFactory, index, dispatcher, locker, mailbox,
+        super(JPAMailboxManager.DEFAULT_NO_MESSAGE_CAPABILITIES, mapperFactory, index, delegatingMailboxListener, locker, mailbox,
             quotaManager, quotaRootResolver, messageParser, messageIdFactory, batchSizes, storeRightManager);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
index 8dfedfe..2d637f4 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
@@ -33,7 +33,6 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 
@@ -50,11 +49,10 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
                                  MessageParser messageParser,
                                  MessageId.Factory messageIdFactory,
                                  DelegatingMailboxListener delegatingMailboxListener,
-                                 MailboxEventDispatcher mailboxEventDispatcher,
                                  StoreMailboxAnnotationManager annotationManager,
                                  StoreRightManager storeRightManager) {
         super(mapperFactory, authenticator, authorizator, new JVMMailboxPathLocker(), messageParser,
-            messageIdFactory, delegatingMailboxListener, mailboxEventDispatcher, annotationManager, storeRightManager);
+            messageIdFactory, delegatingMailboxListener, annotationManager, storeRightManager);
     }
 
     protected AdvancedFeature getAdvancedFeature() {
@@ -65,7 +63,7 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
     protected StoreMessageManager createMessageManager(Mailbox mailboxRow, MailboxSession session) {
         return new OpenJPAMessageManager(getMapperFactory(),
             getMessageSearchIndex(),
-            getEventDispatcher(),
+            getDelegationListener(),
             getLocker(),
             mailboxRow,
             getAdvancedFeature(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
index d5ce35c..2e96d5c 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
@@ -38,7 +38,7 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.BatchSizes;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -59,13 +59,13 @@ public class OpenJPAMessageManager extends JPAMessageManager {
     }
 
     public OpenJPAMessageManager(MailboxSessionMapperFactory mapperFactory,
-                                 MessageSearchIndex index, MailboxEventDispatcher dispatcher,
+                                 MessageSearchIndex index, DelegatingMailboxListener delegatingMailboxListener,
                                  MailboxPathLocker locker, Mailbox mailbox, AdvancedFeature f,
                                  QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser,
                                  MessageId.Factory messageIdFactory, BatchSizes batchSizes,
                                  StoreRightManager storeRightManager) {
 
-        super(mapperFactory,  index, dispatcher, locker, mailbox, quotaManager, quotaRootResolver,
+        super(mapperFactory,  index, delegatingMailboxListener, locker, mailbox, quotaManager, quotaRootResolver,
             messageParser, messageIdFactory, batchSizes, storeRightManager);
         this.feature = f;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml b/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
index cb0f321..6c0901f 100644
--- a/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
+++ b/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
@@ -39,9 +39,8 @@
         <constructor-arg index="3" ref="messageParser"/>
         <constructor-arg index="4" ref="messageIdFactory"/>
         <constructor-arg index="5" ref="delegating-listener"/>
-        <constructor-arg index="6" ref="dispatcher"/>
-        <constructor-arg index="7" ref="storeMailboxAnnotationManager"/>
-        <constructor-arg index="8" ref="storeRightManager" />
+        <constructor-arg index="6" ref="storeMailboxAnnotationManager"/>
+        <constructor-arg index="7" ref="storeRightManager" />
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>
         <property name="quotaUpdater" ref="quotaUpdater"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
index 76555dc..c66a734 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JpaMailboxManagerProvider.java
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 
@@ -57,13 +56,12 @@ public class JpaMailboxManagerProvider {
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver, delegatingListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mf, storeRightManager,
             LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
         OpenJPAMailboxManager openJPAMailboxManager = new OpenJPAMailboxManager(mf, noAuthenticator, noAuthorizator,
             messageParser, new DefaultMessageId.Factory(),
-            delegatingListener, mailboxEventDispatcher, annotationManager,
+            delegatingListener, annotationManager,
             storeRightManager);
 
         try {

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index 45b5093..ac4ac1e 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -43,7 +43,7 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getDelegationListener(),
             storeMailboxManager.getMessageIdFactory(),
             storeMailboxManager.getQuotaManager(),
             storeMailboxManager.getQuotaRootResolver());

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml b/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
index ca75508..eb364f3 100644
--- a/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
+++ b/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
@@ -42,9 +42,8 @@
         <constructor-arg index="4" ref="messageParser"/>
         <constructor-arg index="5" ref="messageIdFactory" />
         <constructor-arg index="6" ref="storeMailboxAnnotationManager" />
-        <constructor-arg index="7" ref="dispatcher" />
-        <constructor-arg index="8" ref="delegating-listener" />
-        <constructor-arg index="9" ref="storeRightManager" />
+        <constructor-arg index="7" ref="delegating-listener" />
+        <constructor-arg index="8" ref="storeRightManager" />
 <!--         <property name="messageSearchIndex" ref="lazyIndex"/> -->
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
index 8b632bd..2d5165c 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerProvider.java
@@ -34,7 +34,6 @@ import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.rules.TemporaryFolder;
@@ -52,16 +51,14 @@ public class MaildirMailboxManagerProvider {
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
         MessageParser messageParser = new MessageParser();
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mf, aclResolver, groupMembershipResolver, delegatingListener);
 
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
 
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mf, storeRightManager);
         StoreMailboxManager manager = new StoreMailboxManager(mf, noAuthenticator, noAuthorizator, new JVMMailboxPathLocker(),
-            messageParser, new DefaultMessageId.Factory(), annotationManager,
-            mailboxEventDispatcher, delegatingListener, storeRightManager);
+            messageParser, new DefaultMessageId.Factory(), annotationManager, delegatingListener, storeRightManager);
         manager.init();
 
         return manager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
index 3d27c79..821e4e3 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
@@ -34,7 +34,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
@@ -51,13 +50,12 @@ public class InMemoryMailboxManager extends StoreMailboxManager {
 
     @Inject
     public InMemoryMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, Authorizator authorizator,
-                                  MailboxPathLocker locker, MessageParser messageParser, MessageId.Factory messageIdFactory, MailboxEventDispatcher dispatcher,
+                                  MailboxPathLocker locker, MessageParser messageParser, MessageId.Factory messageIdFactory,
                                   DelegatingMailboxListener delegatingMailboxListener,
                                   StoreMailboxAnnotationManager annotationManager,
                                   StoreRightManager storeRightManager) {
         super(mailboxSessionMapperFactory, authenticator, authorizator, locker, messageParser, messageIdFactory,
-            annotationManager, dispatcher,
-            delegatingMailboxListener, storeRightManager);
+            annotationManager, delegatingMailboxListener, storeRightManager);
     }
 
     @Override
@@ -80,7 +78,7 @@ public class InMemoryMailboxManager extends StoreMailboxManager {
     protected StoreMessageManager createMessageManager(Mailbox mailbox, MailboxSession session) {
         return new InMemoryMessageManager(getMapperFactory(),
             getMessageSearchIndex(),
-            getEventDispatcher(),
+            getDelegationListener(),
             getLocker(),
             mailbox,
             getQuotaManager(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
index 354f343..e2ef5cf 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
@@ -15,7 +15,7 @@ import org.apache.james.mailbox.store.BatchSizes;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -29,7 +29,7 @@ public class InMemoryMessageManager extends StoreMessageManager {
 
     public InMemoryMessageManager(MailboxSessionMapperFactory mapperFactory,
                                   MessageSearchIndex index,
-                                  MailboxEventDispatcher dispatcher,
+                                  DelegatingMailboxListener delegatingMailboxListener,
                                   MailboxPathLocker locker,
                                   Mailbox mailbox,
                                   QuotaManager quotaManager,
@@ -39,7 +39,7 @@ public class InMemoryMessageManager extends StoreMessageManager {
                                   BatchSizes batchSizes,
                                   StoreRightManager storeRightManager) {
 
-        super(InMemoryMailboxManager.MESSAGE_CAPABILITIES, mapperFactory, index, dispatcher, locker, mailbox, quotaManager, quotaRootResolver,
+        super(InMemoryMailboxManager.MESSAGE_CAPABILITIES, mapperFactory, index, delegatingMailboxListener, locker, mailbox, quotaManager, quotaRootResolver,
             messageParser, messageIdFactory, batchSizes, storeRightManager);
         this.mapperFactory = (InMemoryMailboxSessionMapperFactory) mapperFactory;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml b/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
index 7857d0f..db25210 100644
--- a/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
+++ b/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
@@ -38,10 +38,9 @@
         <constructor-arg index="3" ref="memory-locker"/>
         <constructor-arg index="4" ref="messageParser"/>
         <constructor-arg index="5" ref="messageIdFactory" />
-        <constructor-arg index="6" ref="dispatcher" />
-        <constructor-arg index="7" ref="delegating-listener" />
-        <constructor-arg index="8" ref="storeMailboxAnnotationManager" />
-        <constructor-arg index="9" ref="storeRightManager" />
+        <constructor-arg index="6" ref="delegating-listener" />
+        <constructor-arg index="7" ref="storeMailboxAnnotationManager" />
+        <constructor-arg index="8" ref="storeRightManager" />
 <!--         <property name="messageSearchIndex" ref="lazyIndex"/> -->
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
index 51f993d..8217e54 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
@@ -40,7 +40,6 @@ import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.Before;
@@ -59,21 +58,20 @@ public class InMemoryMailboxManagerAttachmentTest extends AbstractMailboxManager
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
         MessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
         GroupMembershipResolver groupMembershipResolver = null;
         UnionMailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, aclResolver, groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, aclResolver, groupMembershipResolver, delegatingListener);
 
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
         mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-                new MessageParser(), messageIdFactory, mailboxEventDispatcher, delegatingListener, annotationManager, storeRightManager);
+                new MessageParser(), messageIdFactory, delegatingListener, annotationManager, storeRightManager);
         mailboxManager.init();
         MessageParser failingMessageParser = mock(MessageParser.class);
         when(failingMessageParser.retrieveAttachments(any(InputStream.class)))
             .thenThrow(new RuntimeException("Message parser set to fail"));
         parseFailingMailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, noAuthorizator, new NoMailboxPathLocker(),
-            failingMessageParser, messageIdFactory, mailboxEventDispatcher, delegatingListener, annotationManager, storeRightManager);
+            failingMessageParser, messageIdFactory, delegatingListener, annotationManager, storeRightManager);
         parseFailingMailboxManager.init();
         super.setUp();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 4255f82..829ef92 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -48,7 +48,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
@@ -141,9 +140,8 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
         fakeAuthenticator.addUser(ManagerTestResources.OTHER_USER, ManagerTestResources.OTHER_USER_PASS);
         InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
         StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(),
-            groupMembershipResolver, mailboxEventDispatcher);
+            groupMembershipResolver, delegatingListener);
         StoreMailboxAnnotationManager annotationManager = annotationManagerBiFunction
             .apply(storeRightManager, mailboxSessionMapperFactory);
 
@@ -154,7 +152,6 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             new JVMMailboxPathLocker(),
             new MessageParser(),
             new InMemoryMessageId.Factory(),
-            mailboxEventDispatcher,
             delegatingListener,
             annotationManager,
             storeRightManager);
@@ -179,8 +176,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
                                                     Authenticator authenticator, Authorizator authorizator) throws MailboxException {
         InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), groupMembershipResolver, mailboxEventDispatcher);
+        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory, new UnionMailboxACLResolver(), groupMembershipResolver, delegatingListener);
         StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory, storeRightManager);
 
         StoreMailboxManager manager = new InMemoryMailboxManager(
@@ -190,7 +186,6 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             new NoMailboxPathLocker(),
             new MessageParser(),
             new InMemoryMessageId.Factory(),
-            mailboxEventDispatcher,
             delegatingListener,
             annotationManager,
             storeRightManager);
@@ -207,7 +202,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
         return new StoreMessageIdManager(
             mailboxManager,
             mailboxManager.getMapperFactory(),
-            mailboxManager.getEventDispatcher(),
+            mailboxManager.getDelegationListener(),
             factory,
             mailboxManager.getQuotaManager(),
             mailboxManager.getQuotaRootResolver());
@@ -221,7 +216,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
         InMemoryCurrentQuotaManager currentQuotaManager = createCurrentQuotaManager(mailboxManager);
 
         StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager);
-        ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getEventDispatcher(), quotaManager);
+        ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, mailboxManager.getDelegationListener(), quotaManager);
         mailboxManager.setQuotaManager(quotaManager);
         mailboxManager.addGlobalListener(listeningCurrentQuotaUpdater, null);
         return quotaManager;

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
index feba1f4..329181d 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
@@ -34,8 +34,7 @@ import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
 import org.junit.Before;
@@ -49,7 +48,7 @@ public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdMan
     }
 
     @Override
-    protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, MailboxEventDispatcher dispatcher) {
+    protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, DelegatingMailboxListener delegatingMailboxListener) {
         InMemoryMailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
 
         FakeAuthenticator fakeAuthenticator = new FakeAuthenticator();
@@ -57,7 +56,7 @@ public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdMan
         fakeAuthenticator.addUser(ManagerTestResources.OTHER_USER, ManagerTestResources.OTHER_USER_PASS);
         FakeAuthorizator fakeAuthorizator = FakeAuthorizator.defaultReject();
 
-        StoreRightManager rightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), dispatcher);
+        StoreRightManager rightManager = new StoreRightManager(mapperFactory, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), delegatingMailboxListener);
         JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
         InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
         InMemoryMailboxManager mailboxManager = new InMemoryMailboxManager(mapperFactory,
@@ -66,14 +65,13 @@ public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdMan
             locker,
             new MessageParser(),
             messageIdFactory,
-            dispatcher,
-            new DefaultDelegatingMailboxListener(),
+            delegatingMailboxListener,
             new StoreMailboxAnnotationManager(mapperFactory, rightManager),
             rightManager);
         StoreMessageIdManager messageIdManager = new StoreMessageIdManager(
             mailboxManager,
             mapperFactory,
-            dispatcher,
+            delegatingMailboxListener,
             messageIdFactory,
             quotaManager,
             new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index 437e292..3691e39 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -44,7 +44,7 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,
             storeMailboxManager.getMapperFactory(),
-            storeMailboxManager.getEventDispatcher(),
+            storeMailboxManager.getDelegationListener(),
             storeMailboxManager.getMessageIdFactory(),
             storeMailboxManager.getQuotaManager(),
             storeMailboxManager.getQuotaRootResolver());

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
index faae187..a284b14 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
@@ -54,7 +54,7 @@
     <bean id="eventQuotaUpdater" class="org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater" lazy-init="true">
         <constructor-arg index="0" ref="currentQuotaManager"/>
         <constructor-arg index="1" ref="quotaRootResolver"/>
-        <constructor-arg index="2" ref="dispatcher"/>
+        <constructor-arg index="2" ref="delegating-listener"/>
         <constructor-arg index="3" ref="storeQuotaManager"/>
     </bean>
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
index eecd37c..b7ae58a 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
@@ -63,13 +63,9 @@
         <constructor-arg index="0" ref="messageMapperFactory" />
         <constructor-arg index="1" ref="aclResolver" />
         <constructor-arg index="2" ref="groupMembershipResolver" />
-        <constructor-arg index="3" ref="dispatcher" />
+        <constructor-arg index="3" ref="delegating-listener" />
     </bean>
 
     <alias name="default-delegating-listener" alias="delegating-listener"/>
 
-    <bean id="dispatcher" class="org.apache.james.mailbox.store.event.MailboxEventDispatcher">
-        <constructor-arg index="0" ref="delegating-listener"/>
-    </bean>
-
 </beans>

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index c281068..310fa05 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -71,7 +71,6 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -110,7 +109,6 @@ public class StoreMailboxManager implements MailboxManager {
     public static final char SQL_WILDCARD_CHAR = '%';
     public static final EnumSet<MessageCapabilities> DEFAULT_NO_MESSAGE_CAPABILITIES = EnumSet.noneOf(MessageCapabilities.class);
 
-    private final MailboxEventDispatcher dispatcher;
     private final DelegatingMailboxListener delegatingListener;
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
 
@@ -148,10 +146,8 @@ public class StoreMailboxManager implements MailboxManager {
     public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, Authorizator authorizator,
                                MailboxPathLocker locker, MessageParser messageParser,
                                MessageId.Factory messageIdFactory, MailboxAnnotationManager annotationManager,
-                               MailboxEventDispatcher mailboxEventDispatcher,
                                DelegatingMailboxListener delegatingListener, StoreRightManager storeRightManager) {
         Preconditions.checkNotNull(delegatingListener);
-        Preconditions.checkNotNull(mailboxEventDispatcher);
         Preconditions.checkNotNull(mailboxSessionMapperFactory);
 
         this.annotationManager = annotationManager;
@@ -162,7 +158,6 @@ public class StoreMailboxManager implements MailboxManager {
         this.messageParser = messageParser;
         this.messageIdFactory = messageIdFactory;
         this.delegatingListener = delegatingListener;
-        this.dispatcher = mailboxEventDispatcher;
         this.storeRightManager = storeRightManager;
     }
 
@@ -290,14 +285,6 @@ public class StoreMailboxManager implements MailboxManager {
         return quotaManager;
     }
 
-    /**
-     * Return the {@link MailboxEventDispatcher} used by thei {@link MailboxManager}
-     *
-     * @return dispatcher
-     */
-    public MailboxEventDispatcher getEventDispatcher() {
-        return dispatcher;
-    }
 
     /**
      * Return the {@link MailboxSessionMapperFactory} used by this {@link MailboxManager}
@@ -430,7 +417,7 @@ public class StoreMailboxManager implements MailboxManager {
      * @return storeMailbox
      */
     protected StoreMessageManager createMessageManager(Mailbox mailbox, MailboxSession session) throws MailboxException {
-        return new StoreMessageManager(DEFAULT_NO_MESSAGE_CAPABILITIES, getMapperFactory(), getMessageSearchIndex(), getEventDispatcher(),
+        return new StoreMessageManager(DEFAULT_NO_MESSAGE_CAPABILITIES, getMapperFactory(), getMessageSearchIndex(), getDelegationListener(),
                 getLocker(), mailbox, getQuotaManager(),
                 getQuotaRootResolver(), getMessageParser(), getMessageIdFactory(), getBatchSizes(),
             getStoreRightManager());
@@ -525,7 +512,7 @@ public class StoreMailboxManager implements MailboxManager {
                         try {
                             mapper.execute(Mapper.toTransaction(() -> mailboxIds.add(mapper.save(m))));
                             // notify listeners
-                            dispatcher.event(EventFactory.mailboxAdded()
+                            delegatingListener.event(EventFactory.mailboxAdded()
                                 .mailboxSession(mailboxSession)
                                 .mailbox(m)
                                 .build());
@@ -572,7 +559,7 @@ public class StoreMailboxManager implements MailboxManager {
             // mailbox once we remove it
             SimpleMailbox m = new SimpleMailbox(mailbox);
             mailboxMapper.delete(mailbox);
-            dispatcher.event(EventFactory.mailboxDeleted()
+            delegatingListener.event(EventFactory.mailboxDeleted()
                 .mailboxSession(session)
                 .mailbox(mailbox)
                 .quotaRoot(quotaRoot)
@@ -617,7 +604,7 @@ public class StoreMailboxManager implements MailboxManager {
         mailbox.setName(to.getName());
         mapper.save(mailbox);
 
-        dispatcher.event(EventFactory.mailboxRenamed()
+        delegatingListener.event(EventFactory.mailboxRenamed()
             .mailboxSession(session)
             .mailboxId(mailbox.getMailboxId())
             .oldPath(from)
@@ -634,7 +621,7 @@ public class StoreMailboxManager implements MailboxManager {
                 MailboxPath fromPath = new MailboxPath(children, subOriginalName);
                 sub.setName(subNewName);
                 mapper.save(sub);
-                dispatcher.event(EventFactory.mailboxRenamed()
+                delegatingListener.event(EventFactory.mailboxRenamed()
                     .mailboxSession(session)
                     .mailboxId(sub.getMailboxId())
                     .oldPath(fromPath)

http://git-wip-us.apache.org/repos/asf/james-project/blob/31ed391c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 8554380..7e01114 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -51,8 +51,8 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -101,18 +101,18 @@ public class StoreMessageIdManager implements MessageIdManager {
 
     private final MailboxManager mailboxManager;
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
-    private final MailboxEventDispatcher dispatcher;
+    private final DelegatingMailboxListener delegatingMailboxListener;
     private final MessageId.Factory messageIdFactory;
     private final QuotaManager quotaManager;
     private final QuotaRootResolver quotaRootResolver;
 
     @Inject
     public StoreMessageIdManager(MailboxManager mailboxManager, MailboxSessionMapperFactory mailboxSessionMapperFactory,
-                                 MailboxEventDispatcher dispatcher, MessageId.Factory messageIdFactory,
+                                 DelegatingMailboxListener delegatingMailboxListener, MessageId.Factory messageIdFactory,
                                  QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) {
         this.mailboxManager = mailboxManager;
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
-        this.dispatcher = dispatcher;
+        this.delegatingMailboxListener = delegatingMailboxListener;
         this.messageIdFactory = messageIdFactory;
         this.quotaManager = quotaManager;
         this.quotaRootResolver = quotaRootResolver;
@@ -218,7 +218,7 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
         for (MetadataWithMailboxId metadataWithMailboxId : metadataWithMailbox) {
-            dispatcher.event(EventFactory.expunged()
+            delegatingMailboxListener.event(EventFactory.expunged()
                 .mailboxSession(mailboxSession)
                 .mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId))
                 .addMetaData(metadataWithMailboxId.messageMetaData)
@@ -285,7 +285,7 @@ public class StoreMessageIdManager implements MessageIdManager {
         addMessageToMailboxes(mailboxMessage, messageMoves.addedMailboxIds(), mailboxSession);
         removeMessageFromMailboxes(mailboxMessage, messageMoves.removedMailboxIds(), mailboxSession);
 
-        dispatcher.event(EventFactory.moved()
+        delegatingMailboxListener.event(EventFactory.moved()
             .session(mailboxSession)
             .messageMoves(messageMoves)
             .messageId(mailboxMessage.getMessageId())
@@ -299,7 +299,7 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         for (MailboxId mailboxId: mailboxesToRemove) {
             messageIdMapper.delete(message.getMessageId(), mailboxesToRemove);
-            dispatcher.event(EventFactory.expunged()
+            delegatingMailboxListener.event(EventFactory.expunged()
                 .mailboxSession(mailboxSession)
                 .mailbox(mailboxMapper.findMailboxById(mailboxId))
                 .addMetaData(eventPayload)
@@ -315,7 +315,7 @@ public class StoreMessageIdManager implements MessageIdManager {
         if (updatedFlags.flagsChanged()) {
             Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
 
-            dispatcher.event(EventFactory.flagsUpdated()
+            delegatingMailboxListener.event(EventFactory.flagsUpdated()
                 .mailboxSession(mailboxSession)
                 .mailbox(mailbox)
                 .updatedFlag(updatedFlags)
@@ -381,7 +381,7 @@ public class StoreMessageIdManager implements MessageIdManager {
                     .build();
             save(mailboxSession, messageIdMapper, copy);
 
-            dispatcher.event(EventFactory.added()
+            delegatingMailboxListener.event(EventFactory.added()
                 .mailboxSession(mailboxSession)
                 .mailbox(mailboxMapper.findMailboxById(mailboxId))
                 .addMessage(copy)


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


[05/47] james-project git commit: MAILBOX-359 Factorize tests for User ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for User ser-deserialization


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

Branch: refs/heads/master
Commit: 21eff0689931e3c454d2dfbc91b82473ee80c440
Parents: 8ca8a33
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 13:11:31 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      |  71 +-------
 .../event/json/ExpungedSerializationTest.java   |  71 +-------
 .../json/FlagsUpdatedSerializationTest.java     |  75 +--------
 ...MailboxACLUpdatedEventSerializationTest.java |  54 +------
 .../json/MailboxAddedSerializationTest.java     |  34 ----
 .../json/MailboxDeletionSerializationTest.java  |  53 +-----
 .../json/MailboxRenamedSerializationTest.java   |  60 +------
 .../json/MessageMoveEventSerializationTest.java |  84 ----------
 ...QuotaUsageUpdatedEventSerializationTest.java | 161 +++++--------------
 .../james/event/json/dtos/SessionIdTest.java    |   4 +-
 .../apache/james/event/json/dtos/UserTest.java  |  90 +++++++++++
 11 files changed, 156 insertions(+), 601 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index 82afcd2..a299389 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -539,12 +539,10 @@ class AddedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnUser {
-            @Test
-            void addedShouldThrowWhenMissingUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void addedShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Added\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -568,67 +566,6 @@ class AddedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenUserIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": 596" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void addedShouldThrowWhenUserIsNotWellFormatted() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Added\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"added\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user@user@anotherUser\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 85987f5..3d60dab 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -538,12 +538,10 @@ class ExpungedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnUser {
-            @Test
-            void expungedShouldThrowWhenMissingUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void expungedShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"Expunged\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -567,67 +565,6 @@ class ExpungedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenUserIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": 596" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void expungedShouldThrowWhenUserIsNotWellFormatted() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"Expunged\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"expunged\": {" +
-                    "      \"123456\": {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"flags\": {" +
-                    "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
-                    "          \"userFlags\":[\"User Custom Flag\"]}," +
-                    "        \"size\": 45,  " +
-                    "        \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
-                    "        \"messageId\": \"42\"" +
-                    "      }" +
-                    "    }," +
-                    "    \"sessionId\": 42," +
-                    "    \"user\": \"user@user@anotherUser\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 76fdba3..091a259 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -464,12 +464,10 @@ class FlagsUpdatedSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnUser {
-            @Test
-            void flagsUpdatedShouldThrowWhenMissingUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void flagsUpdatedShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"FlagsUpdated\": {" +
                     "    \"path\": {" +
                     "      \"namespace\": \"#private\"," +
@@ -495,71 +493,6 @@ class FlagsUpdatedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenUserIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"sessionId\": 42," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": 4569" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void flagsUpdatedShouldThrowWhenUserIsNotWellFormatted() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"FlagsUpdated\": {" +
-                    "    \"path\": {" +
-                    "      \"namespace\": \"#private\"," +
-                    "      \"user\": \"user\"," +
-                    "      \"name\": \"mailboxName\"" +
-                    "    }," +
-                    "    \"mailboxId\": \"18\"," +
-                    "    \"sessionId\": 42," +
-                    "    \"updatedFlags\": [" +
-                    "      {" +
-                    "        \"uid\": 123456," +
-                    "        \"modSeq\": 35," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                    "      }," +
-                    "      {" +
-                    "        \"uid\": 654321," +
-                    "        \"modSeq\": 36," +
-                    "        \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
-                    "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
-                    "      }" +
-                    "    ]," +
-                    "    \"user\": \"user@user@anotherUser\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index da5b509..45f7605 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -290,13 +290,10 @@ class MailboxACLUpdatedEventSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnUser {
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenMissingUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxACLUpdatedShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxACLUpdated\":{" +
                     "    \"mailboxPath\":{" +
                     "       \"namespace\":\"#private\"," +
@@ -309,48 +306,7 @@ class MailboxACLUpdatedEventSerializationTest {
                     "    \"sessionId\":6" +
                     "   }" +
                     "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":12345" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxACLUpdatedShouldThrowWhenUserIsNotWellFormatted() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxACLUpdated\":{" +
-                    "    \"mailboxPath\":{" +
-                    "       \"namespace\":\"#private\"," +
-                    "       \"name\":\"mailboxName\"" +
-                    "      }," +
-                    "    \"aclDiff\":{" +
-                    "       \"oldACL\":{}," +
-                    "       \"newACL\":{\"$any\":\"ar\"}}," +
-                    "    \"mailboxId\":\"23\"," +
-                    "    \"sessionId\":6," +
-                    "    \"user\":\"user@domain@secondDomain\"" +
-                    "   }" +
-                    "}").get())
-                    .isInstanceOf(IllegalArgumentException.class);
-            }
+                .isInstanceOf(NoSuchElementException.class);
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index f880328..c491c9f 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -326,39 +326,5 @@ class MailboxAddedSerializationTest {
                 "}").get())
                 .isInstanceOf(NumberFormatException.class);
         }
-
-        @Test
-        void fromJsonShouldRejectLongUser() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":15," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void fromJsonShouldRejectNullUser() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":null," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index 4c92630..e0ae086 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -297,35 +297,12 @@ class MailboxDeletionSerializationTest {
                 .isInstanceOf(NoSuchElementException.class);
         }
 
-        @Nested
-        class DeserializationErrorOnUser {
-            @Test
-            void mailboxAddedShouldThrowWhenMissingUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenUserIsNotAString() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxAddedShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxDeletion\":{" +
                     "    \"sessionId\":3652," +
-                    "    \"user\":5489515," +
                     "    \"path\":{" +
                     "      \"namespace\":\"#private\"," +
                     "      \"user\":\"user\"," +
@@ -338,28 +315,6 @@ class MailboxDeletionSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxAddedShouldThrowWhenUserIsNotWellFormatted() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
-                    "  \"MailboxDeletion\":{" +
-                    "    \"sessionId\":3652," +
-                    "    \"user\":\"user@domain@secondDomain\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"mailboxName\"" +
-                    "    }," +
-                    "    \"quotaRoot\":\"user@domain\"," +
-                    "    \"deletedMessageCount\":60," +
-                    "    \"totalDeletedSize\":100," +
-                    "    \"mailboxId\":\"789\"" +
-                    "  }" +
-                    "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-            }
         }
 
         @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index e5ffc7e..b19b20c 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -284,13 +284,10 @@ class MailboxRenamedSerializationTest {
 
     @Nested
     class DeserializationErrors {
-
-        @Nested
-        class DeserializationErrorOnUser {
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenNullUser() {
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                    "{" +
+        @Test
+        void mailboxRenamedDeSerializeShouldThrowWhenMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                "{" +
                     "  \"MailboxRenamed\":{" +
                     "    \"sessionId\":123456789," +
                     "    \"path\":{" +
@@ -307,55 +304,6 @@ class MailboxRenamedSerializationTest {
                     "  }" +
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenEmptyUser() {
-                String eventWithEmptyUser =
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithEmptyUser).get())
-                    .isInstanceOf(IllegalArgumentException.class);
-            }
-
-            @Test
-            void mailboxRenamedDeSerializeShouldThrowWhenBadUser() {
-                String eventWithBadUser =
-                    "{" +
-                    "  \"MailboxRenamed\":{" +
-                    "    \"sessionId\":123456789," +
-                    "    \"user\":\"user@user@user\"," +
-                    "    \"path\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"oldMailboxName\"" +
-                    "     }," +
-                    "    \"mailboxId\":\"123456\"," +
-                    "    \"newPath\":{" +
-                    "      \"namespace\":\"#private\"," +
-                    "      \"user\":\"user\"," +
-                    "      \"name\":\"newMailboxName\"" +
-                    "     }" +
-                    "  }" +
-                    "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithBadUser).get())
-                    .isInstanceOf(IllegalArgumentException.class);
-            }
         }
 
         @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
index f3008dc..6e09af1 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
@@ -70,39 +70,6 @@ class MessageMoveEventSerializationTest {
     @Nested
     class ValidPayloads {
         @Nested
-        class NoVirtualHosting {
-            private final Event event = MessageMoveEvent.builder()
-                .user(User.fromUsername("bob"))
-                .messageId(TestMessageId.of(42))
-                .messageMoves(
-                    MessageMoves.builder()
-                        .previousMailboxIds(TestId.of(18), TestId.of(24))
-                        .targetMailboxIds(TestId.of(36))
-                        .build())
-                .build();
-            private final String json = "{" +
-                "  \"MessageMoveEvent\": {" +
-                "    \"user\": \"bob\"," +
-                "    \"previousMailboxIds\": [\"18\", \"24\"]," +
-                "    \"targetMailboxIds\": [\"36\"]," +
-                "    \"messageIds\": [\"42\"]" +
-                "  }" +
-                "}";
-
-            @Test
-            void messageMoveEventShouldBeWellSerialized() {
-                assertThatJson(EVENT_SERIALIZER.toJson(event))
-                    .isEqualTo(json);
-            }
-
-            @Test
-            void messageMoveEventShouldBeWellDeSerialized() {
-                assertThat(EVENT_SERIALIZER.fromJson(json).get())
-                    .isEqualTo(event);
-            }
-        }
-
-        @Nested
         class EmptyTargetMailboxIds {
             private final Event event = MessageMoveEvent.builder()
                 .user(User.fromUsername("bob"))
@@ -201,57 +168,6 @@ class MessageMoveEventSerializationTest {
 
     @Nested
     class InvalidPayloads {
-        @Test
-        void emptyUserShouldBeRejected() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MessageMoveEvent\": {" +
-                "    \"user\": \"\"," +
-                "    \"previousMailboxIds\": [\"18\", \"24\"]," +
-                "    \"targetMailboxIds\": [\"36\"]," +
-                "    \"messageIds\": [\"42\"]" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-        }
-
-        @Test
-        void basUsersShouldBeRejected() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MessageMoveEvent\": {" +
-                "    \"user\": \"bob@domain.tld@bad\"," +
-                "    \"previousMailboxIds\": [\"18\", \"24\"]," +
-                "    \"targetMailboxIds\": [\"36\"]," +
-                "    \"messageIds\": [\"42\"]" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(IllegalArgumentException.class);
-        }
-
-        @Test
-        void nonStringUserShouldBeRejected() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MessageMoveEvent\": {" +
-                "    \"user\": 42," +
-                "    \"previousMailboxIds\": [\"18\", \"24\"]," +
-                "    \"targetMailboxIds\": [\"36\"]," +
-                "    \"messageIds\": [\"42\"]" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
-        void nullUserShouldBeRejected() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MessageMoveEvent\": {" +
-                "    \"user\": null," +
-                "    \"previousMailboxIds\": [\"18\", \"24\"]," +
-                "    \"targetMailboxIds\": [\"36\"]," +
-                "    \"messageIds\": [\"42\"]" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
 
         @Test
         void nullPreviousMailboxIdsShouldBeRejected() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index 9b940fb..b76b53b 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -67,132 +67,49 @@ class QuotaUsageUpdatedEventSerializationTest {
 
     private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
 
-    @Nested
-    class WithUser {
-
-        @Nested
-        class WithValidUser {
-
-            @Nested
-            class WithUserContainsOnlyUsername {
-
-                private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent(
-                    User.fromUsername("onlyUsername"),
-                    QUOTA_ROOT,
-                    QUOTA_COUNT,
-                    QUOTA_SIZE,
-                    INSTANT);
-                private final String quotaUsageUpdatedEvent =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"onlyUsername\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void fromJsonShouldReturnQuotaEvent() {
-                    assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                        .isEqualTo(eventWithUserContainsUsername);
-                }
-
-                @Test
-                void toJsonShouldReturnQuotaEventJson() {
-                    assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsername))
-                        .isEqualTo(quotaUsageUpdatedEvent);
-                }
-            }
-
-            @Nested
-            class WithUserContainsUsernameAndDomain {
-
-                private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsernameAndDomain = new MailboxListener.QuotaUsageUpdatedEvent(
-                    User.fromUsername("user@domain"),
-                    QUOTA_ROOT,
-                    QUOTA_COUNT,
-                    QUOTA_SIZE,
-                    INSTANT);
-                private final String quotaUsageUpdatedEvent =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"user@domain\"" +
-                        "}" +
-                    "}";
-
-                @Test
-                void fromJsonShouldReturnQuotaEvent() {
-                    assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                        .isEqualTo(eventWithUserContainsUsernameAndDomain);
-                }
-
-                @Test
-                void toJsonShouldReturnQuotaEventJson() {
-                    assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsernameAndDomain))
-                        .isEqualTo(quotaUsageUpdatedEvent);
-                }
-            }
-        }
-
-        @Nested
-        class WithInvalidUser {
-
-            @Test
-            void fromJsonShouldThrowWhenEmptyUser() {
-                String quotaUsageUpdatedEvent =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"\"" +
-                        "}" +
-                    "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent))
-                    .isInstanceOf(IllegalArgumentException.class);
-            }
-
+    private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent(
+        User.fromUsername("onlyUsername"),
+        QUOTA_ROOT,
+        QUOTA_COUNT,
+        QUOTA_SIZE,
+        INSTANT);
+    private final String quotaUsageUpdatedEvent =
+        "{" +
+            "\"QuotaUsageUpdatedEvent\":{" +
+            "\"quotaRoot\":\"foo\"," +
+            "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+            "\"time\":\"2018-11-13T12:00:55Z\"," +
+            "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+            "\"user\":\"onlyUsername\"" +
+            "}" +
+            "}";
 
-            @Test
-            void fromJsonShouldThrowResultWhenUserIsNull() {
-                String quotaUsageUpdatedEvent =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
-                        "}" +
-                    "}";
+    @Test
+    void fromJsonShouldReturnQuotaEvent() {
+        assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isEqualTo(eventWithUserContainsUsername);
+    }
 
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
-                    .isInstanceOf(NoSuchElementException.class);
-            }
+    @Test
+    void toJsonShouldReturnQuotaEventJson() {
+        assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsername))
+            .isEqualTo(quotaUsageUpdatedEvent);
+    }
 
-            @Test
-            void fromJsonShouldThrowWhenUserIsInvalid() {
-                String quotaUsageUpdatedEvent =
-                    "{" +
-                        "\"QuotaUsageUpdatedEvent\":{" +
-                        "\"quotaRoot\":\"foo\"," +
-                        "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
-                        "\"time\":\"2018-11-13T12:00:55Z\"," +
-                        "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
-                        "\"user\":\"@domain\"" +
-                        "}" +
-                    "}";
-                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent))
-                    .isInstanceOf(IllegalArgumentException.class);
-            }
-        }
+    @Test
+    void fromJsonShouldThrowResultWhenUserIsMissing() {
+        String quotaUsageUpdatedEvent =
+            "{" +
+                "\"QuotaUsageUpdatedEvent\":{" +
+                "\"quotaRoot\":\"foo\"," +
+                "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+                "\"time\":\"2018-11-13T12:00:55Z\"," +
+                "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
+                "}" +
+                "}";
 
+        assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+            .isInstanceOf(NoSuchElementException.class);
     }
 
     @Nested

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
index 49ad7eb..11e3eed 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
@@ -41,8 +41,8 @@ class SessionIdTest {
 
     @Test
     void sessionIdShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)).toString())
-            .isEqualTo("18");
+        assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)))
+            .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
new file mode 100644
index 0000000..25d277e
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
@@ -0,0 +1,90 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.core.User;
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.JsNull$;
+import play.api.libs.json.JsNumber;
+import play.api.libs.json.JsPath;
+import play.api.libs.json.JsString;
+import play.api.libs.json.JsSuccess;
+import scala.collection.immutable.List;
+import scala.math.BigDecimal;
+
+class UserTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void userShouldBeWellSerialized() {
+        assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob")))
+            .isEqualTo(new JsString("bob"));
+    }
+
+    @Test
+    void userShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob")))
+            .isEqualTo(new JsSuccess<>(User.fromUsername("bob"), new JsPath(List.empty())));
+    }
+
+    @Test
+    void userShouldBeWellSerializedWhenVirtualHosting() {
+        assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob@domain")))
+            .isEqualTo(new JsString("bob@domain"));
+    }
+
+    @Test
+    void userShouldBeWellDeSerializedWhenVirtualHosting() {
+        assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob@domain")))
+            .isEqualTo(new JsSuccess<>(User.fromUsername("bob@domain"), new JsPath(List.empty())));
+    }
+
+    @Test
+    void userDeserializationShouldReturnErrorWhenNumber() {
+        assertThat(JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void userDeserializationShouldReturnErrorWhenNull() {
+        assertThat(JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void userDeserializationShouldThrowWhenBadUsername() {
+        assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad")))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void userDeserializationShouldThrowWhenEmpty() {
+        assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("")))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+}


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


[31/47] james-project git commit: MAILBOX-364 MailboxEvent builders should use staged builders

Posted by bt...@apache.org.
MAILBOX-364 MailboxEvent builders should use staged builders

We can leverage stage sharing through generics. Note that also uncouple stages from
each others (to define stage 1, I don't need to know stage 2, only the builder method defining the
stage chain needs that) which is a very nice benefit!

Note that alternative choices are implemented using default methods.


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

Branch: refs/heads/master
Commit: 7097446f95c933ce0508a3d200b097b50e246268
Parents: def6258
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Jan 3 11:42:16 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:41:11 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 421 ++++++++++---------
 .../store/event/MailboxEventDispatcher.java     |  16 +-
 .../event/MailboxAnnotationListenerTest.java    |   6 +-
 .../base/MailboxEventAnalyserTest.java          |  12 +-
 .../processor/base/SelectedMailboxImplTest.java |   2 +-
 5 files changed, 247 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7097446f/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index c581816..5695c6f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -41,291 +41,328 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSortedMap;
 
 public class EventFactory {
-    public abstract static class MailboxEventBuilder<T extends MailboxEventBuilder> {
-        protected MailboxPath path;
-        protected MailboxId mailboxId;
-        protected User user;
-        protected MailboxSession.SessionId sessionId;
-
-        protected abstract T backReference();
-
-        public T mailbox(Mailbox mailbox) {
-            path(mailbox.generateAssociatedPath());
-            mailboxId(mailbox.getMailboxId());
-            return backReference();
-        }
+    @FunctionalInterface
+    public interface RequireUser<T> {
+        T user(User user);
+    }
 
-        public T mailboxSession(MailboxSession mailboxSession) {
-            user(mailboxSession.getUser());
-            sessionId(mailboxSession.getSessionId());
-            return backReference();
-        }
+    @FunctionalInterface
+    public interface RequireSessionId<T> {
+        T sessionId(MailboxSession.SessionId sessionId);
+    }
 
-        public T mailboxId(MailboxId mailboxId) {
-            this.mailboxId = mailboxId;
-            return backReference();
+    @FunctionalInterface
+    public interface RequireSession<T> extends RequireUser<RequireSessionId<T>> {
+        default T mailboxSession(MailboxSession session) {
+            return user(session.getUser())
+                .sessionId(session.getSessionId());
         }
+    }
 
-        public T path(MailboxPath path) {
-            this.path = path;
-            return backReference();
-        }
+    @FunctionalInterface
+    public interface RequireMailboxId<T> {
+        T mailboxId(MailboxId mailboxId);
+    }
 
-        public T user(User user) {
-            this.user = user;
-            return backReference();
-        }
+    @FunctionalInterface
+    public interface RequirePath<T> {
+        T mailboxPath(MailboxPath path);
+    }
 
-        public T sessionId(MailboxSession.SessionId sessionId) {
-            this.sessionId = sessionId;
-            return backReference();
+    @FunctionalInterface
+    public interface RequireMailbox<T> extends RequireMailboxId<RequirePath<T>> {
+        default T mailbox(Mailbox mailbox) {
+            return mailboxId(mailbox.getMailboxId())
+                .mailboxPath(mailbox.generateAssociatedPath());
         }
+    }
 
-        protected void mailboxEventChecks() {
-            Preconditions.checkState(user != null, "Field `user` is compulsory");
-            Preconditions.checkState(mailboxId != null, "Field `mailboxId` is compulsory");
-            Preconditions.checkState(path != null, "Field `path` is compulsory");
-            Preconditions.checkState(sessionId != null, "Field `sessionId` is compulsory");
-        }
+    @FunctionalInterface
+    public interface RequireNewPath<T> {
+        T newPath(MailboxPath path);
     }
 
-    public abstract static class MessageMetaDataEventBuilder<T extends MessageMetaDataEventBuilder> extends MailboxEventBuilder<T> {
-        protected final ImmutableList.Builder<MessageMetaData> metaData;
+    @FunctionalInterface
+    public interface RequireOldPath<T> {
+        T oldPath(MailboxPath path);
+    }
+
+    @FunctionalInterface
+    public interface RequireMetadata<T> {
+        T metaData(ImmutableSortedMap<MessageUid, MessageMetaData> metaData);
 
-        protected MessageMetaDataEventBuilder() {
-            metaData = ImmutableList.builder();
+        default T addMetaData(MessageMetaData metaData) {
+            return metaData(ImmutableSortedMap.of(metaData.getUid(), metaData));
         }
 
-        protected abstract T backReference();
+        default T addMessage(MailboxMessage message) {
+            return addMetaData(message.metaData());
+        }
 
-        public T addMessage(MailboxMessage message) {
-            this.addMetaData(message.metaData());
-            return backReference();
+        default T addMetaData(Iterable<MessageMetaData> metaData) {
+            return metaData(ImmutableList.copyOf(metaData)
+                .stream()
+                .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid)));
         }
 
-        public T addMessages(Iterable<MailboxMessage> messages) {
-            this.addMetaData(ImmutableList.copyOf(messages)
+        default T addMessages(Iterable<MailboxMessage> messages) {
+            return metaData(ImmutableList.copyOf(messages)
                 .stream()
                 .map(MailboxMessage::metaData)
-                .collect(Guavate.toImmutableList()));
-            return backReference();
+                .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid)));
         }
+    }
 
-        public T addMetaData(MessageMetaData metaData) {
-            this.metaData.add(metaData);
-            return backReference();
-        }
+    @FunctionalInterface
+    public interface RequireAclDiff<T> {
+        T aclDiff(ACLDiff aclDiff);
+    }
+
+    @FunctionalInterface
+    public interface RequireUpdatedFlags<T> {
+        T updatedFlags(ImmutableList<UpdatedFlags> updatedFlags);
 
-        public T addMetaData(Iterable<MessageMetaData> metaData) {
-            this.metaData.addAll(metaData);
-            return backReference();
+        default T updatedFlags(Iterable<UpdatedFlags> updatedFlags) {
+            return updatedFlags(ImmutableList.copyOf(updatedFlags));
         }
 
-        protected ImmutableSortedMap<MessageUid, MessageMetaData> metaDataAsMap() {
-            return metaData.build()
-                .stream()
-                .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid));
+        default T updatedFlag(UpdatedFlags updatedFlags) {
+            return updatedFlags(ImmutableList.of(updatedFlags));
         }
     }
 
-    public static class AddedBuilder extends MessageMetaDataEventBuilder<AddedBuilder> {
-        @Override
-        protected AddedBuilder backReference() {
-            return this;
-        }
+    @FunctionalInterface
+    public interface RequireQuotaRoot<T> {
+        T quotaRoot(QuotaRoot quotaRoot);
+    }
 
-        public MailboxListener.Added build() {
-            mailboxEventChecks();
-
-            return new MailboxListener.Added(
-                sessionId,
-                user,
-                path,
-                mailboxId,
-                metaDataAsMap());
-        }
+    @FunctionalInterface
+    public interface RequireQuotaCount<T> {
+        T quotaCount(QuotaCount quotaCount);
     }
 
-    public static class ExpungedBuilder extends MessageMetaDataEventBuilder<ExpungedBuilder> {
-        @Override
-        protected ExpungedBuilder backReference() {
-            return this;
+    @FunctionalInterface
+    public interface RequireQuotaSize<T> {
+        T quotaSize(QuotaSize quotaSize);
+    }
+
+    @FunctionalInterface
+    public interface RequireMailboxEvent<T> extends RequireSession<RequireMailbox<T>> {}
+
+    public static class MailboxAddedFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+
+        MailboxAddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
         }
 
-        public MailboxListener.Expunged build() {
-            mailboxEventChecks();
-            
-            return new MailboxListener.Expunged(
-                sessionId,
-                user,
-                path,
-                mailboxId,
-                metaDataAsMap());
+        public MailboxListener.MailboxAdded build() {
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+
+            return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId);
         }
     }
 
-    public static class MailboxAclUpdatedBuilder extends MailboxEventBuilder<MailboxAclUpdatedBuilder> {
-        private ACLDiff aclDiff;
+    public static class AddedFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData;
 
-        public MailboxAclUpdatedBuilder aclDiff(ACLDiff aclDiff) {
-            this.aclDiff = aclDiff;
-            return this;
+        AddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableSortedMap<MessageUid, MessageMetaData> metaData) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
+            this.metaData = metaData;
         }
 
-        @Override
-        protected MailboxAclUpdatedBuilder backReference() {
-            return this;
-        }
+        public MailboxListener.Added build() {
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+            Preconditions.checkNotNull(metaData);
 
-        public MailboxListener.MailboxACLUpdated build() {
-            Preconditions.checkState(aclDiff != null, "Field `aclDiff` is compulsory");
-            mailboxEventChecks();
-
-            return new MailboxListener.MailboxACLUpdated(
-                sessionId,
-                user,
-                path,
-                aclDiff,
-                mailboxId);
+            return new MailboxListener.Added(sessionId, user, path, mailboxId, metaData);
         }
     }
 
-    public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
-        @Override
-        protected MailboxAddedBuilder backReference() {
-            return this;
+    public static class ExpungedFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData;
+
+        ExpungedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableSortedMap<MessageUid, MessageMetaData> metaData) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
+            this.metaData = metaData;
         }
 
-        public MailboxListener.MailboxAdded build() {
-            mailboxEventChecks();
+        public MailboxListener.Expunged build() {
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+            Preconditions.checkNotNull(metaData);
 
-            return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId);
+            return new MailboxListener.Expunged(sessionId, user, path, mailboxId, metaData);
         }
     }
 
-    public static class MailboxDeletionBuilder extends MailboxEventBuilder<MailboxDeletionBuilder> {
-        private QuotaRoot quotaRoot;
-        private QuotaCount deletedMessageCount;
-        private QuotaSize totalDeletedSize;
+    public static class MailboxAclUpdatedFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final ACLDiff aclDiff;
 
-        @Override
-        protected MailboxDeletionBuilder backReference() {
-            return this;
+        MailboxAclUpdatedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ACLDiff aclDiff) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
+            this.aclDiff = aclDiff;
         }
 
-        public MailboxDeletionBuilder quotaRoot(QuotaRoot quotaRoot) {
-            this.quotaRoot = quotaRoot;
-            return this;
-        }
+        public MailboxListener.MailboxACLUpdated build() {
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+            Preconditions.checkNotNull(aclDiff);
 
-        public MailboxDeletionBuilder deletedMessageCount(QuotaCount deletedMessageCount) {
-            this.deletedMessageCount = deletedMessageCount;
-            return this;
+            return new MailboxListener.MailboxACLUpdated(sessionId, user, path, aclDiff, mailboxId);
         }
+    }
 
-        public MailboxDeletionBuilder totalDeletedSize(QuotaSize totalDeletedSize) {
+    public static class MailboxDeletionFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final QuotaRoot quotaRoot;
+        private final QuotaCount deletedMessageCount;
+        private final QuotaSize totalDeletedSize;
+
+        MailboxDeletionFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
+            this.quotaRoot = quotaRoot;
+            this.deletedMessageCount = deletedMessageCount;
             this.totalDeletedSize = totalDeletedSize;
-            return this;
         }
 
         public MailboxListener.MailboxDeletion build() {
-            mailboxEventChecks();
-            Preconditions.checkState(quotaRoot != null, "Field `quotaRoot` is compulsory");
-            Preconditions.checkState(deletedMessageCount != null, "Field `deletedMessageCount` is compulsory");
-            Preconditions.checkState(totalDeletedSize != null, "Field `totalDeletedSize` is compulsory");
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+            Preconditions.checkNotNull(quotaRoot);
+            Preconditions.checkNotNull(deletedMessageCount);
+            Preconditions.checkNotNull(totalDeletedSize);
 
             return new MailboxListener.MailboxDeletion(sessionId, user, path, quotaRoot, deletedMessageCount, totalDeletedSize, mailboxId);
         }
     }
 
-    public static class MailboxRenamedBuilder extends MailboxEventBuilder<MailboxRenamedBuilder> {
-        private MailboxPath newPath;
+    public static class MailboxRenamedFinalStage {
+        private final MailboxPath oldPath;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final MailboxPath newPath;
 
-        @Override
-        protected MailboxRenamedBuilder backReference() {
-            return this;
-        }
-
-        public MailboxRenamedBuilder newPath(MailboxPath newPath) {
+        MailboxRenamedFinalStage(MailboxPath oldPath, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, MailboxPath newPath) {
+            this.oldPath = oldPath;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
             this.newPath = newPath;
-            return this;
         }
 
-        public MailboxRenamedBuilder oldPath(MailboxPath oldPath) {
-            this.path = oldPath;
-            return this;
-        }
 
         public MailboxListener.MailboxRenamed build() {
-            mailboxEventChecks();
-            Preconditions.checkState(path != null, "Field `newPath` is compulsory");
-
-            return new MailboxListener.MailboxRenamed(
-                sessionId,
-                user,
-                path,
-                mailboxId,
-                newPath);
-        }
-    }
-
-    public static class FlagsUpdatedBuilder extends MailboxEventBuilder<FlagsUpdatedBuilder> {
-        private final ImmutableList.Builder<UpdatedFlags> updatedFlags;
+            Preconditions.checkNotNull(oldPath);
+            Preconditions.checkNotNull(newPath);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
 
-        public FlagsUpdatedBuilder() {
-            updatedFlags = ImmutableList.builder();
+            return new MailboxListener.MailboxRenamed(sessionId, user, oldPath, mailboxId, newPath);
         }
+    }
 
-        public FlagsUpdatedBuilder updatedFags(Iterable<UpdatedFlags> updatedFlags) {
-            this.updatedFlags.addAll(updatedFlags);
-            return this;
-        }
+    public static class FlagsUpdatedFinalStage {
+        private final MailboxPath path;
+        private final MailboxId mailboxId;
+        private final User user;
+        private final MailboxSession.SessionId sessionId;
+        private final ImmutableList<UpdatedFlags> updatedFlags;
 
-        public FlagsUpdatedBuilder updatedFags(UpdatedFlags updatedFlags) {
-            this.updatedFlags.add(updatedFlags);
-            return this;
+        FlagsUpdatedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableList<UpdatedFlags> updatedFlags) {
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.user = user;
+            this.sessionId = sessionId;
+            this.updatedFlags = updatedFlags;
         }
 
-        @Override
-        protected FlagsUpdatedBuilder backReference() {
-            return this;
-        }
 
         public MailboxListener.FlagsUpdated build() {
-            mailboxEventChecks();
-
-            ImmutableList<UpdatedFlags> updatedFlags = this.updatedFlags.build();
+            Preconditions.checkNotNull(path);
+            Preconditions.checkNotNull(mailboxId);
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(sessionId);
+            Preconditions.checkNotNull(updatedFlags);
 
             return new MailboxListener.FlagsUpdated(sessionId, user, path, mailboxId, updatedFlags);
         }
     }
 
-    public static AddedBuilder added() {
-        return new AddedBuilder();
+    public static RequireMailboxEvent<RequireMetadata<AddedFinalStage>> added() {
+        return user -> sessionId -> mailboxId -> path -> metaData -> new AddedFinalStage(path, mailboxId, user, sessionId, metaData);
     }
 
-    public static ExpungedBuilder expunged() {
-        return new ExpungedBuilder();
+    public static RequireMailboxEvent<RequireMetadata<ExpungedFinalStage>> expunged() {
+        return user -> sessionId -> mailboxId -> path -> metaData -> new ExpungedFinalStage(path, mailboxId, user, sessionId, metaData);
     }
 
-    public static FlagsUpdatedBuilder flagsUpdated() {
-        return new FlagsUpdatedBuilder();
+    public static RequireMailboxEvent<RequireUpdatedFlags<FlagsUpdatedFinalStage>> flagsUpdated() {
+        return user -> sessionId -> mailboxId -> path -> updatedFlags -> new FlagsUpdatedFinalStage(path, mailboxId, user, sessionId, updatedFlags);
     }
 
-    public static MailboxRenamedBuilder mailboxRenamed() {
-        return new MailboxRenamedBuilder();
+    public static RequireSession<RequireMailboxId<RequireOldPath<RequireNewPath<MailboxRenamedFinalStage>>>> mailboxRenamed() {
+        return user -> sessionId -> mailboxId -> oldPath -> newPath -> new MailboxRenamedFinalStage(oldPath, mailboxId, user, sessionId, newPath);
     }
 
-    public static MailboxDeletionBuilder mailboxDeleted() {
-        return new MailboxDeletionBuilder();
+    public static  RequireMailboxEvent<RequireQuotaRoot<RequireQuotaCount<RequireQuotaSize<MailboxDeletionFinalStage>>>> mailboxDeleted() {
+        return user -> sessionId -> mailboxId -> path -> quotaRoot -> quotaCount -> quotaSize -> new MailboxDeletionFinalStage(
+            path, mailboxId, user, sessionId, quotaRoot, quotaCount, quotaSize);
     }
 
-    public static MailboxAddedBuilder mailboxAdded() {
-        return new MailboxAddedBuilder();
+    public static RequireMailboxEvent<MailboxAddedFinalStage> mailboxAdded() {
+        return user -> sessionId -> mailboxId -> path -> new MailboxAddedFinalStage(path, mailboxId, user, sessionId);
     }
 
-    public static MailboxAclUpdatedBuilder aclUpdated() {
-        return new MailboxAclUpdatedBuilder();
+    public static RequireMailboxEvent<RequireAclDiff<MailboxAclUpdatedFinalStage>> aclUpdated() {
+        return user -> sessionId -> mailboxId -> path -> aclDiff -> new MailboxAclUpdatedFinalStage(path, mailboxId, user, sessionId, aclDiff);
     }
 
     public static MessageMoveEvent.Builder moved() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/7097446f/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index 5de959c..c82bb13 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -71,8 +71,8 @@ public class MailboxEventDispatcher {
      */
     public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         event(EventFactory.added()
-            .mailbox(mailbox)
             .mailboxSession(session)
+            .mailbox(mailbox)
             .addMetaData(uids.values())
             .build());
     }
@@ -102,8 +102,8 @@ public class MailboxEventDispatcher {
      */
     public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
         event(EventFactory.expunged()
-            .mailbox(mailbox)
             .mailboxSession(session)
+            .mailbox(mailbox)
             .addMetaData(uids.values())
             .build());
     }
@@ -121,9 +121,9 @@ public class MailboxEventDispatcher {
      */
     public void flagsUpdated(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> uflags) {
         event(EventFactory.flagsUpdated()
-            .mailbox(mailbox)
             .mailboxSession(session)
-            .updatedFags(uflags)
+            .mailbox(mailbox)
+            .updatedFlags(uflags)
             .build());
     }
 
@@ -153,8 +153,8 @@ public class MailboxEventDispatcher {
             .mailboxSession(session)
             .mailbox(mailbox)
             .quotaRoot(quotaRoot)
-            .deletedMessageCount(deletedMessageCount)
-            .totalDeletedSize(totalDeletedSize)
+            .quotaCount(deletedMessageCount)
+            .quotaSize(totalDeletedSize)
             .build());
     }
 
@@ -164,16 +164,16 @@ public class MailboxEventDispatcher {
      */
     public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
         event(EventFactory.mailboxAdded()
-            .mailbox(mailbox)
             .mailboxSession(session)
+            .mailbox(mailbox)
             .build());
     }
 
     public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
         event(EventFactory.aclUpdated()
             .mailboxSession(session)
-            .path(mailboxPath)
             .mailboxId(mailboxId)
+            .mailboxPath(mailboxPath)
             .aclDiff(aclDiff)
             .build());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7097446f/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index fe8eaf1..1b55fb5 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -80,10 +80,10 @@ public class MailboxAnnotationListenerTest {
         deleteEvent = EventFactory.mailboxDeleted()
             .mailboxSession(mailboxSession)
             .mailboxId(mailboxId)
-            .path(MailboxPath.forUser("user", "name"))
+            .mailboxPath(MailboxPath.forUser("user", "name"))
             .quotaRoot(QuotaRoot.quotaRoot("root", Optional.empty()))
-            .deletedMessageCount(QuotaCount.count(123))
-            .totalDeletedSize(QuotaSize.size(456))
+            .quotaCount(QuotaCount.count(123))
+            .quotaSize(QuotaSize.size(456))
             .build();
 
         when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))

http://git-wip-us.apache.org/repos/asf/james-project/blob/7097446f/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 9115010..ef3934c 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -183,7 +183,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(NOOP_UPDATED_FLAGS)
+            .updatedFlag(NOOP_UPDATED_FLAGS)
             .build();
 
         testee.event(update);
@@ -196,7 +196,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(OTHER_MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS)
             .build();
 
         testee.event(update);
@@ -211,7 +211,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS)
             .build();
 
         analyser.event(update);
@@ -226,7 +226,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(OTHER_MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(ADD_ANSWERED_UPDATED_FLAGS)
+            .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS)
             .build();
 
         testee.event(update);
@@ -241,7 +241,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(NOOP_UPDATED_FLAGS)
+            .updatedFlag(NOOP_UPDATED_FLAGS)
             .build();
 
         testee.event(update);
@@ -256,7 +256,7 @@ public class MailboxEventAnalyserTest {
         MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated()
             .mailboxSession(MAILBOX_SESSION)
             .mailbox(DEFAULT_MAILBOX)
-            .updatedFags(ADD_RECENT_UPDATED_FLAGS)
+            .updatedFlag(ADD_RECENT_UPDATED_FLAGS)
             .build();
 
         testee.event(update);

http://git-wip-us.apache.org/repos/asf/james-project/blob/7097446f/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 2622c4b..2e13921 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -164,9 +164,9 @@ public class SelectedMailboxImplTest {
 
     private void emitEvent(MailboxListener mailboxListener) {
         mailboxListener.event(EventFactory.added()
+            .mailboxSession(MailboxSessionUtil.create("user"))
             .mailbox(mailbox)
             .addMetaData(new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()))
-            .mailboxSession(MailboxSessionUtil.create("user"))
             .build());
     }
 }


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


[20/47] james-project git commit: MAILBOX-359 MaildirMailboxMapper should return the mailboxId on persisted mailboxes

Posted by bt...@apache.org.
MAILBOX-359 MaildirMailboxMapper should return the mailboxId on persisted 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/def6258e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/def6258e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/def6258e

Branch: refs/heads/master
Commit: def6258ebe8491c4caeafcac0b3c51e655e366a2
Parents: 1371fad
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 20 13:14:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/def6258e/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index 173aba6..abf51f7 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -231,6 +231,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
             try {
                 folder.setUidValidity(mailbox.getUidValidity());
                 folder.setMailboxId(maildirId);
+                mailbox.setMailboxId(maildirId);
             } catch (IOException ioe) {
                 throw new MailboxException("Failed to save Mailbox " + mailbox, ioe);
 


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


[14/47] james-project git commit: MAILBOX-359 Use a fixture for the serializers

Posted by bt...@apache.org.
MAILBOX-359 Use a fixture for the serializers


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

Branch: refs/heads/master
Commit: 38ebe82603cb19909f1c1e074c34e963b513ad34
Parents: 19710d4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 16:06:21 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:20 2019 +0700

----------------------------------------------------------------------
 .../event/json/AddedSerializationTest.java      |  3 +-
 .../event/json/ExpungedSerializationTest.java   |  3 +-
 .../json/FlagsUpdatedSerializationTest.java     |  4 +-
 ...MailboxACLUpdatedEventSerializationTest.java | 89 +-------------------
 .../json/MailboxAddedSerializationTest.java     |  7 +-
 .../json/MailboxDeletionSerializationTest.java  |  4 +-
 .../json/MailboxRenamedSerializationTest.java   |  4 +-
 .../json/MessageMoveEventSerializationTest.java |  3 +-
 ...QuotaUsageUpdatedEventSerializationTest.java |  6 +-
 .../james/event/json/SerializerFixture.java     | 28 ++++++
 .../james/event/json/dtos/ACLDiffTest.java      | 55 ++++++++----
 .../apache/james/event/json/dtos/FlagsTest.java | 56 ++++++------
 .../james/event/json/dtos/MailboxIdTest.java    | 20 ++---
 .../james/event/json/dtos/MailboxPathTest.java  | 31 +++----
 .../james/event/json/dtos/MessageIdTest.java    | 17 ++--
 .../event/json/dtos/MessageMetaDataTest.java    | 44 +++++-----
 .../james/event/json/dtos/MessageUidTest.java   | 16 ++--
 .../james/event/json/dtos/QuotaRootTest.java    | 31 +++----
 .../james/event/json/dtos/SessionIdTest.java    | 19 ++---
 .../james/event/json/dtos/UpdatedFlagsTest.java | 16 ++--
 .../apache/james/event/json/dtos/UserTest.java  | 29 +++----
 21 files changed, 191 insertions(+), 294 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
index 327d5ba..7760523 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -92,8 +93,6 @@ class AddedSerializationTest {
         "  }" +
         "}";
 
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void addedShouldBeWellSerialized() {
         assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_ADDED_EVENT))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
index 0e46b59..85e0365 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -92,8 +93,6 @@ class ExpungedSerializationTest {
         "  }" +
         "}";
 
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void expungedShouldBeWellSerialized() {
         assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_EXPUNGED_EVENT))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 0fee8a15..941a5de 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -37,7 +38,6 @@ 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.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
@@ -120,8 +120,6 @@ class FlagsUpdatedSerializationTest {
         "  }" +
         "}";
 
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void flagsUpdatedShouldBeWellSerialized() {
         assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_EVENT))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index a4cefb3..8feb069 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -33,7 +34,6 @@ import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
@@ -42,7 +42,6 @@ class MailboxACLUpdatedEventSerializationTest {
     private static final User USER = User.fromUsername("user");
     private static final MailboxACL.EntryKey ENTRY_KEY = org.apache.james.mailbox.model.MailboxACL.EntryKey.createGroupEntryKey("any", false);
     private static final MailboxACL.Rfc4314Rights RIGHTS = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer, MailboxACL.Right.Read);
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
     private static final MailboxACL MAILBOX_ACL = new MailboxACL(
         new MailboxACL.Entry(ENTRY_KEY, RIGHTS),
         new MailboxACL.Entry(MailboxACL.EntryKey.createUserEntryKey("alice", true),
@@ -84,92 +83,6 @@ class MailboxACLUpdatedEventSerializationTest {
     }
 
     @Nested
-    class EmptyRightInMailboxACL {
-
-        private final String jsonNullRight =
-            "{" +
-            "  \"MailboxACLUpdated\":{" +
-            "    \"mailboxPath\":{" +
-            "       \"namespace\":\"#private\"," +
-            "       \"user\":\"bob\"," +
-            "       \"name\":\"mailboxName\"" +
-            "      }," +
-            "    \"aclDiff\":{" +
-            "       \"oldACL\":{\"$any\":\"\"}," +
-            "       \"newACL\":{}}," +
-            "    \"mailboxId\":\"23\"," +
-            "    \"sessionId\":6," +
-            "    \"user\":\"user\"" +
-            "   }" +
-            "}";
-
-        private final MailboxACL mailboxACL = new MailboxACL(
-                new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights()));
-
-        private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated(
-                MailboxSession.SessionId.of(6),
-                USER,
-                new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
-                ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY),
-                TestId.of(23));
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() {
-            assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated))
-                .isEqualTo(jsonNullRight);
-        }
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
-            assertThat(EVENT_SERIALIZER.fromJson(jsonNullRight).get())
-                .isEqualTo(mailboxACLUpdated);
-        }
-    }
-
-    @Nested
-    class DoubleRightInMailboxACL {
-
-        private final String jsonDoubleRight =
-            "{" +
-            "  \"MailboxACLUpdated\":{" +
-            "    \"mailboxPath\":{" +
-            "       \"namespace\":\"#private\"," +
-            "       \"user\":\"bob\"," +
-            "       \"name\":\"mailboxName\"" +
-            "      }," +
-            "    \"aclDiff\":{" +
-            "       \"oldACL\":{\"$any\":\"aa\"}," +
-            "       \"newACL\":{}}," +
-            "    \"mailboxId\":\"23\"," +
-            "    \"sessionId\":6," +
-            "    \"user\":\"user\"" +
-            "   }" +
-            "}";
-
-        private final MailboxACL mailboxACL = new MailboxACL(
-            new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer)));
-
-        private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated(
-            MailboxSession.SessionId.of(6),
-            USER,
-            new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
-            ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY),
-            TestId.of(23));
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() {
-            assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated))
-                .isNotEqualTo(jsonDoubleRight);
-        }
-
-        @Test
-        void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
-            assertThat(EVENT_SERIALIZER.fromJson(jsonDoubleRight).get())
-                .isEqualTo(mailboxACLUpdated);
-        }
-    }
-
-    @Nested
     class DeserializationErrors {
         @Test
         void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index 51c87e7..d8e58b1 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -31,22 +32,16 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 class MailboxAddedSerializationTest {
-
     private static final User USER = User.fromUsername("user");
-
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     private static final MailboxListener.MailboxAdded EVENT_1 = new MailboxListener.MailboxAdded(
         MailboxSession.SessionId.of(42),
         USER,
         new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
         TestId.of(18));
-
     private static final String JSON_1 = "{" +
         "  \"MailboxAdded\":{" +
         "    \"mailboxPath\":{" +

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index 1f76c5b..313dc33 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -36,7 +37,6 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
@@ -75,8 +75,6 @@ class MailboxDeletionSerializationTest {
         "  }" +
         "}";
 
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void mailboxAddedShouldBeWellSerialized() {
         assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_MAILBOX_DELETION_EVENT))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index 1989186..de65db2 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -32,7 +33,6 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
@@ -71,8 +71,6 @@ class MailboxRenamedSerializationTest {
             "  }" +
             "}";
 
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void mailboxRenamedShouldBeWellSerialized() {
         assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_MAILBOX_RENAMED_EVENT))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
index 6e09af1..8110215 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -35,8 +36,6 @@ import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 class MessageMoveEventSerializationTest {
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     private static final Event EVENT = MessageMoveEvent.builder()
         .user(User.fromUsername("bob@domain.tld"))
         .messageId(TestMessageId.of(42))

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index f0cbe7f..0e97545 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -33,8 +34,6 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
@@ -51,9 +50,6 @@ class QuotaUsageUpdatedEventSerializationTest {
         .computedLimit(QuotaSize.size(10000))
         .build();
     private static final Instant INSTANT = Instant.parse("2018-11-13T12:00:55Z");
-
-    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
-
     private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent(
         User.fromUsername("onlyUsername"),
         QUOTA_ROOT,

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java
new file mode 100644
index 0000000..5d9bcaf
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json;
+
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+
+public interface SerializerFixture {
+    JsonSerialize DTO_JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+    EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
index 8288261..e0aca09 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java
@@ -19,15 +19,18 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
+import org.apache.james.mailbox.acl.ACLDiff;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
+import com.google.common.collect.ImmutableMap;
+
 import play.api.libs.json.JsError;
 import play.api.libs.json.JsNull$;
 import play.api.libs.json.JsNumber;
@@ -36,18 +39,38 @@ import play.api.libs.json.Json;
 import scala.math.BigDecimal;
 
 class ACLDiffTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void deSerializeShouldThrowWhenNewACLIsMissing() {
-        assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
             "{\"oldACL\":{}}")))
             .isInstanceOf(JsError.class);
     }
 
     @Test
+    void deSerializeShouldAcceptDoubleRight() {
+        assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+            "{\"oldACL\":{\"$any\":\"aa\"},\"newACL\":{}}"))
+            .get().toJava())
+            .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of(
+                new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false),
+                new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer))),
+                new MailboxACL()));
+    }
+
+    @Test
+    void deSerializeShouldAcceptEmptyRight() {
+        assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+            "{\"oldACL\":{\"$any\":\"\"},\"newACL\":{}}"))
+            .get().toJava())
+            .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of(
+                new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false),
+                new MailboxACL.Rfc4314Rights())),
+                new MailboxACL()));
+    }
+
+    @Test
     void deSerializeShouldThrowWhenOldACLIsMissing() {
-        assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse(
             "{\"newACL\":{}}")))
             .isInstanceOf(JsError.class);
     }
@@ -56,31 +79,31 @@ class ACLDiffTest {
     class EntryKeyTest {
         @Test
         void deSerializeShouldThrowWhenNotIncludedNameInEntryKey() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$")))
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$")))
                 .isInstanceOf(IllegalStateException.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenNameInEntryKeyIsEmpty() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("")))
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("")))
                 .isInstanceOf(IllegalArgumentException.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenNameInEntryKeyIsNotWellFormatted() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-")))
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-")))
                 .isInstanceOf(StringIndexOutOfBoundsException.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenNameInEntryKeyIsNull() {
-            assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$))
+            assertThat(DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$))
                 .isInstanceOf(JsError.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenNameInEntryKeyIsNotString() {
-            assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            assertThat(DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18))))
                 .isInstanceOf(JsError.class);
         }
     }
@@ -89,19 +112,19 @@ class ACLDiffTest {
     class RightTest {
         @Test
         void deSerializeShouldThrowWhenUnsupportedRightInNewACL() {
-            assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsString("\"unsupported\"")))
-                .isInstanceOf(JsError.class);
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclRightsReads().reads(new JsString("\"unsupported\"")))
+                .isInstanceOf(UnsupportedRightException.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenNull() {
-            assertThat(JSON_SERIALIZE.aclDiffReads().reads(JsNull$.MODULE$))
+            assertThat(DTO_JSON_SERIALIZE.aclRightsReads().reads(JsNull$.MODULE$))
                 .isInstanceOf(JsError.class);
         }
 
         @Test
         void deSerializeShouldThrowWhenRightIsNotString() {
-            assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+            assertThat(DTO_JSON_SERIALIZE.aclRightsReads().reads(new JsNumber(BigDecimal.valueOf(18))))
                 .isInstanceOf(JsError.class);
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
index a41c245..9e70b7d 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.event.json.dtos;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -28,19 +29,14 @@ import java.util.NoSuchElementException;
 import javax.mail.Flags;
 
 import org.apache.james.event.json.DTOs;
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.Json;
 
 class FlagsTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void emptyFlagsShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags()))
             .toString())
             .isEqualTo("{\"systemFlags\":[],\"userFlags\":[]}");
@@ -48,7 +44,7 @@ class FlagsTest {
 
     @Test
     void answeredShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.ANSWERED)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}");
@@ -56,7 +52,7 @@ class FlagsTest {
 
     @Test
     void deletedShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.DELETED)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}");
@@ -64,7 +60,7 @@ class FlagsTest {
 
     @Test
     void draftShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.DRAFT)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}");
@@ -72,7 +68,7 @@ class FlagsTest {
 
     @Test
     void flaggedShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.FLAGGED)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}");
@@ -80,7 +76,7 @@ class FlagsTest {
 
     @Test
     void recentShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.RECENT)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}");
@@ -88,7 +84,7 @@ class FlagsTest {
 
     @Test
     void seenShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags(Flags.Flag.SEEN)))
             .toString())
             .isEqualTo("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}");
@@ -96,7 +92,7 @@ class FlagsTest {
 
     @Test
     void userFlagShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
+        assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags(
             new Flags("user flag")))
             .toString())
             .isEqualTo("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}");
@@ -105,7 +101,7 @@ class FlagsTest {
     @Test
     void emptyFlagsShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags());
     }
@@ -113,7 +109,7 @@ class FlagsTest {
     @Test
     void answeredShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.ANSWERED));
     }
@@ -121,7 +117,7 @@ class FlagsTest {
     @Test
     void deletedShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.DELETED));
     }
@@ -129,7 +125,7 @@ class FlagsTest {
     @Test
     void draftShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.DRAFT));
     }
@@ -137,7 +133,7 @@ class FlagsTest {
     @Test
     void flaggedShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.FLAGGED));
     }
@@ -145,7 +141,7 @@ class FlagsTest {
     @Test
     void recentShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.RECENT));
     }
@@ -153,7 +149,7 @@ class FlagsTest {
     @Test
     void seenShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}"))
                 .get()))
             .isEqualTo(new Flags(Flags.Flag.SEEN));
     }
@@ -161,7 +157,7 @@ class FlagsTest {
     @Test
     void userFlagShouldBeWellDeSerialized() {
         assertThat(DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}"))
                 .get()))
             .isEqualTo(new Flags("user flag"));
     }
@@ -169,7 +165,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenUnknownSystemFlag() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"unknown\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"unknown\"],\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -177,7 +173,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenBadCaseSystemFlag() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"AnSwErEd\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"AnSwErEd\"],\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -185,7 +181,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenNullSystemFlag() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":null,\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":null,\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -193,7 +189,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenSystemFlagContainsNullElements() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[null,\"Draft\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[null,\"Draft\"],\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -201,7 +197,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenSystemFlagContainsNotStringElements() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[42,\"Draft\"],\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[42,\"Draft\"],\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -209,7 +205,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenUserFlagsContainsNullElements() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[null, \"a\"]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[null, \"a\"]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -217,7 +213,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenUserFlagsContainsNonStringElements() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -225,7 +221,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenNoUserFlags() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }
@@ -233,7 +229,7 @@ class FlagsTest {
     @Test
     void deserializeShouldThrowWhenNoSystemFlags() {
         assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags(
-            JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}"))
+            DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}"))
                 .get()))
             .isInstanceOf(NoSuchElementException.class);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
index d54505c..aa4a436 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
@@ -19,53 +19,47 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.james.event.json.JsonSerialize;
 import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
 import play.api.libs.json.JsNull$;
 import play.api.libs.json.JsNumber;
-import play.api.libs.json.JsPath;
 import play.api.libs.json.JsString;
-import play.api.libs.json.JsSuccess;
-import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class MailboxIdTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void mailboxIdShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.mailboxIdWrites().writes(TestId.of(18)))
+        assertThat(DTO_JSON_SERIALIZE.mailboxIdWrites().writes(TestId.of(18)))
             .isEqualTo(new JsString("18"));
     }
 
     @Test
     void mailboxIdShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsString("18")))
-            .isEqualTo(new JsSuccess<>(TestId.of(18), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsString("18")).get())
+            .isEqualTo(TestId.of(18));
     }
 
     @Test
     void mailboxIdDeserializationShouldReturnErrorWhenNumber() {
-        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+        assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void mailboxIdDeserializationShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void mailboxIdDeserializationShouldThrowWhenInvalid() {
-        assertThatThrownBy(() -> JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid")))
+        assertThatThrownBy(() -> DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid")))
             .isInstanceOf(IllegalArgumentException.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
index 613f5a9..a47e582 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
@@ -20,14 +20,12 @@
 package org.apache.james.event.json.dtos;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.event.json.DTOs;
-import org.apache.james.event.json.JsonSerialize;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
@@ -36,11 +34,10 @@ import play.api.libs.json.Json;
 class MailboxPathTest {
     private static final String MAILBOX_NAME = "mailboxName";
     private static final MailboxPath MAILBOX_PATH = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME);
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
 
     @Test
     void mailboxPathShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(MAILBOX_PATH)).toString())
+        assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(MAILBOX_PATH)).toString())
             .isEqualTo(
                 "{" +
                 "  \"namespace\":\"#private\"," +
@@ -51,7 +48,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathWithNullUserShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
+        assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
             new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))).toString())
             .isEqualTo(
                 "{" +
@@ -62,7 +59,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathWithEmptyNamespaceShouldBeWellSerialized() {
-        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
+        assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
             new MailboxPath("", "user", MAILBOX_NAME))).toString())
             .isEqualTo(
                 "{" +
@@ -74,7 +71,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathWithShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":\"user\"," +
             "  \"name\":\"mailboxName\"" +
@@ -85,7 +82,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathWithNullUserShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":null," +
             "  \"name\":\"mailboxName\"" +
@@ -96,7 +93,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathWithNoUserShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"name\":\"mailboxName\"" +
             "}")).get())
@@ -106,7 +103,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenNoNamespace() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"user\":\"user\"," +
             "  \"name\":\"mailboxName\"" +
             "}"))
@@ -116,7 +113,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenNullNamespace() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":null," +
             "  \"user\":\"user\"," +
             "  \"name\":\"mailboxName\"" +
@@ -127,7 +124,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenLongNamespace() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":18," +
             "  \"user\":\"user\"," +
             "  \"name\":\"mailboxName\"" +
@@ -137,7 +134,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenLongUser() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":42," +
             "  \"name\":\"mailboxName\"" +
@@ -147,7 +144,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenMissingMailboxName() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":\"user\"" +
             "}")))
@@ -156,7 +153,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenNullMailboxName() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":\"user\"," +
             "  \"name\":null" +
@@ -166,7 +163,7 @@ class MailboxPathTest {
 
     @Test
     void mailboxPathDeserializationShouldFailWhenLongMailboxName() {
-        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+        assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
             "  \"namespace\":\"#private\"," +
             "  \"user\":\"user\"," +
             "  \"name\":42" +

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
index 21426fa..ef2c241 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java
@@ -19,11 +19,10 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
@@ -37,35 +36,33 @@ import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class MessageIdTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void messageIdShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.messageIdWrites().writes(TestMessageId.of(18)))
+        assertThat(DTO_JSON_SERIALIZE.messageIdWrites().writes(TestMessageId.of(18)))
             .isEqualTo(new JsString("18"));
     }
 
     @Test
     void messageIdShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsString("18")))
-            .isEqualTo(new JsSuccess<>(TestMessageId.of(18), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(new JsString("18")).get())
+            .isEqualTo(TestMessageId.of(18));
     }
 
     @Test
     void messageIdDeserializationShouldReturnErrorWhenNumber() {
-        assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+        assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void messageIdDeserializationShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void messageIdDeserializationShouldThrowWhenInvalid() {
-        assertThatThrownBy(() -> JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid")))
+        assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid")))
             .isInstanceOf(IllegalArgumentException.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
index b8169b5..d351ac6 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java
@@ -19,28 +19,24 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.time.Instant;
 import java.util.NoSuchElementException;
 
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.Json;
 
 class MessageMetaDataTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Nested
     class StructureTest {
         @Test
         void deserializeShouldThrowWhenNoFlags() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": 35," +
                     "        \"size\": 45,  " +
@@ -53,7 +49,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenNoUid() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"modSeq\": 35," +
                     "        \"flags\": {" +
                     "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
@@ -68,7 +64,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenNoModSeq() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"flags\": {" +
                     "          \"systemFlags\":[\"Answered\",\"Draft\"], " +
@@ -83,7 +79,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenNoSize() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": 35," +
                     "        \"flags\": {" +
@@ -98,7 +94,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenNoInternalDate() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": 35," +
                     "        \"flags\": {" +
@@ -113,7 +109,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenNoMessageId() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": 35," +
                     "        \"flags\": {" +
@@ -131,7 +127,7 @@ class MessageMetaDataTest {
     class ModSeqTest {
         @Test
         void deserializeShouldThrowWhenNullModSeq() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": null," +
                     "        \"flags\": {" +
@@ -147,7 +143,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenStringModSeq() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"modSeq\": \"42\"," +
                     "        \"flags\": {" +
@@ -166,7 +162,7 @@ class MessageMetaDataTest {
     class SizeTest {
         @Test
         void deserializeShouldThrowWhenNullSize() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": null," +
                     "        \"flags\": {" +
@@ -182,7 +178,7 @@ class MessageMetaDataTest {
 
         @Test
         void deserializeShouldThrowWhenStringSize() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": \"42\"," +
                     "        \"flags\": {" +
@@ -201,7 +197,7 @@ class MessageMetaDataTest {
     class DeserializationErrorOnInternalDate {
         @Test
         void deSerializeShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -217,7 +213,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateContainsOnlyDate() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -233,7 +229,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateIsMissingHourPart() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -249,7 +245,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateIsMissingTimeZone() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -265,7 +261,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateIsMissingHours() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -281,7 +277,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateIsEmpty() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -297,7 +293,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldThrowWhenInternalDateIsNull() {
-            assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -313,7 +309,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldParseValidISOInstants() {
-            assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThat(DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +
@@ -330,7 +326,7 @@ class MessageMetaDataTest {
 
         @Test
         void deSerializeShouldParseWhenInternalDateIsMissingMilliSeconds() {
-            assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
+            assertThat(DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" +
                     "        \"uid\": 123456," +
                     "        \"size\": 42," +
                     "        \"flags\": {" +

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
index 55f2a25..e6a2ce3 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java
@@ -19,12 +19,10 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.event.json.JsonSerialize;
 import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
@@ -37,29 +35,27 @@ import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class MessageUidTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void messageUidShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18)))
+        assertThat(DTO_JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18)))
             .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
     }
 
     @Test
     void messageUidShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18))))
-            .isEqualTo(new JsSuccess<>(MessageUid.of(18), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18))).get())
+            .isEqualTo(MessageUid.of(18));
     }
 
     @Test
     void messageUidShouldReturnErrorWhenString() {
-        assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsString("18")))
+        assertThat(DTO_JSON_SERIALIZE.messageUidReads().reads(new JsString("18")))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void messageUidShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
index 53076a2..4ba88b4 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java
@@ -19,74 +19,67 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Optional;
 
 import org.apache.james.core.Domain;
-import org.apache.james.event.json.JsonSerialize;
 import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
 import play.api.libs.json.JsNull$;
 import play.api.libs.json.JsNumber;
-import play.api.libs.json.JsPath;
 import play.api.libs.json.JsString;
-import play.api.libs.json.JsSuccess;
-import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class QuotaRootTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void quotaRootWithDomainShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld")))))
+        assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld")))))
             .isEqualTo(new JsString("bob@domain.tld"));
     }
 
     @Test
     void quotaRootWithDomainShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob@domain.tld")))
-            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld"))), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob@domain.tld")).get())
+            .isEqualTo(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld"))));
     }
 
     @Test
     void quotaRootShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob", Optional.empty())))
+        assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob", Optional.empty())))
             .isEqualTo(new JsString("bob"));
     }
 
     @Test
     void quotaRootShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob")))
-            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("bob", Optional.empty()), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob")).get())
+            .isEqualTo(QuotaRoot.quotaRoot("bob", Optional.empty()));
     }
 
     @Test
     void emptyQuotaRootShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("", Optional.empty())))
+        assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("", Optional.empty())))
             .isEqualTo(new JsString(""));
     }
 
     @Test
     void emptyQuotaRootShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("")))
-            .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("", Optional.empty()), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("")).get())
+            .isEqualTo(QuotaRoot.quotaRoot("", Optional.empty()));
     }
 
     @Test
     void emptyQuotaRootShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.quotaRootReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void emptyQuotaRootShouldReturnErrorWhenNotString() {
-        assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+        assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18))))
             .isInstanceOf(JsError.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
index 11e3eed..d0ec1ab 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
@@ -19,47 +19,40 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.event.json.JsonSerialize;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
 import play.api.libs.json.JsNull$;
 import play.api.libs.json.JsNumber;
-import play.api.libs.json.JsPath;
 import play.api.libs.json.JsString;
-import play.api.libs.json.JsSuccess;
-import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class SessionIdTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void sessionIdShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)))
+        assertThat(DTO_JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)))
             .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
     }
 
     @Test
     void sessionIdShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
-            .isEqualTo(new JsSuccess<>(MailboxSession.SessionId.of(18), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18))).get())
+            .isEqualTo(MailboxSession.SessionId.of(18));
     }
 
     @Test
     void sessionIdShouldReturnErrorWhenString() {
-        assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsString("18")))
+        assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(new JsString("18")))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void sessionIdShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.sessionIdReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
index 31eda91..e9f91a3 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
@@ -19,22 +19,18 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
 import play.api.libs.json.Json;
 
 class UpdatedFlagsTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void flagsUpdatedShouldThrowWhenMoqSeqIsAString() {
-        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
             "      {" +
                 "        \"uid\": 123456," +
                 "        \"modSeq\": \"35\"," +
@@ -46,7 +42,7 @@ class UpdatedFlagsTest {
 
     @Test
     void flagsUpdatedShouldThrowWhenMoqSeqIsNull() {
-        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
             "      {" +
                 "        \"uid\": 123456," +
                 "        \"modSeq\": null," +
@@ -58,7 +54,7 @@ class UpdatedFlagsTest {
 
     @Test
     void flagsUpdatedShouldThrowWhenMoqSeqIsNotAnInteger() {
-        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
             "      {" +
                 "        \"uid\": 123456," +
                 "        \"modSeq\": 35.2567454," +
@@ -70,7 +66,7 @@ class UpdatedFlagsTest {
 
     @Test
     void flagsUpdatedShouldThrowWhenOldFlagIsMissing() {
-        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
             "      {" +
                 "        \"uid\": 123456," +
                 "        \"modSeq\": 35," +
@@ -81,7 +77,7 @@ class UpdatedFlagsTest {
 
     @Test
     void flagsUpdatedShouldThrowWhenNewFlagIsMissing() {
-        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+        assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
             "      {" +
                 "        \"uid\": 123456," +
                 "        \"modSeq\": 35," +

http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
index 25d277e..2e1d69e 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
@@ -19,72 +19,65 @@
 
 package org.apache.james.event.json.dtos;
 
+import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.User;
-import org.apache.james.event.json.JsonSerialize;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
 
 import play.api.libs.json.JsError;
 import play.api.libs.json.JsNull$;
 import play.api.libs.json.JsNumber;
-import play.api.libs.json.JsPath;
 import play.api.libs.json.JsString;
-import play.api.libs.json.JsSuccess;
-import scala.collection.immutable.List;
 import scala.math.BigDecimal;
 
 class UserTest {
-    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
-
     @Test
     void userShouldBeWellSerialized() {
-        assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob")))
+        assertThat(DTO_JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob")))
             .isEqualTo(new JsString("bob"));
     }
 
     @Test
     void userShouldBeWellDeSerialized() {
-        assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob")))
-            .isEqualTo(new JsSuccess<>(User.fromUsername("bob"), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob")).get())
+            .isEqualTo(User.fromUsername("bob"));
     }
 
     @Test
     void userShouldBeWellSerializedWhenVirtualHosting() {
-        assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob@domain")))
+        assertThat(DTO_JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob@domain")))
             .isEqualTo(new JsString("bob@domain"));
     }
 
     @Test
     void userShouldBeWellDeSerializedWhenVirtualHosting() {
-        assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob@domain")))
-            .isEqualTo(new JsSuccess<>(User.fromUsername("bob@domain"), new JsPath(List.empty())));
+        assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob@domain")).get())
+            .isEqualTo(User.fromUsername("bob@domain"));
     }
 
     @Test
     void userDeserializationShouldReturnErrorWhenNumber() {
-        assertThat(JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+        assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18))))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void userDeserializationShouldReturnErrorWhenNull() {
-        assertThat(JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$))
+        assertThat(DTO_JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$))
             .isInstanceOf(JsError.class);
     }
 
     @Test
     void userDeserializationShouldThrowWhenBadUsername() {
-        assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad")))
+        assertThatThrownBy(() -> DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad")))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     void userDeserializationShouldThrowWhenEmpty() {
-        assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("")))
+        assertThatThrownBy(() -> DTO_JSON_SERIALIZE.userReads().reads(new JsString("")))
             .isInstanceOf(IllegalArgumentException.class);
     }
 }


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


[21/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for Added event

Posted by bt...@apache.org.
MAILBOX-364 EventFactory should expose a builder for Added event


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

Branch: refs/heads/master
Commit: e829c8edacc3839992bef750774cccdd08ee4378
Parents: 7ceb951
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 13:31:29 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../spamassassin/SpamAssassinListenerTest.java  | 22 ++++---
 .../james/mailbox/store/event/EventFactory.java | 63 +++++++++++++++++---
 .../store/event/MailboxEventDispatcher.java     |  6 +-
 .../base/MailboxEventAnalyserTest.java          | 22 +++----
 .../processor/base/SelectedMailboxImplTest.java | 14 ++---
 5 files changed, 85 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e829c8ed/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 0496ac5..ff0db16 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -37,7 +37,6 @@ import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageMoveEvent;
-import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
@@ -58,14 +57,10 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableSortedMap;
-
 public class SpamAssassinListenerTest {
-
     public static final String USER = "user";
     private static final MailboxSession MAILBOX_SESSION = MailboxSessionUtil.create(USER);
     private static final int UID_VALIDITY = 43;
-    private static final MessageUid UID = MessageUid.of(45);
     private static final TestMessageId MESSAGE_ID = TestMessageId.of(45);
 
     private SpamAssassin spamAssassin;
@@ -237,9 +232,11 @@ public class SpamAssassinListenerTest {
     public void eventShouldCallSpamAssassinHamLearningWhenTheMessageIsAddedInInbox() throws Exception {
         SimpleMailboxMessage message = createMessage(inbox);
 
-        ImmutableSortedMap<MessageUid, MessageMetaData> sortedMap = ImmutableSortedMap.of(UID, message.metaData());
-        MailboxListener.Added addedEvent = new EventFactory().added(
-                MAILBOX_SESSION, sortedMap, inbox);
+        MailboxListener.Added addedEvent = new EventFactory().added()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(inbox)
+            .addMessage(message)
+            .build();
 
         listener.event(addedEvent);
 
@@ -250,10 +247,11 @@ public class SpamAssassinListenerTest {
     public void eventShouldNotCallSpamAssassinHamLearningWhenTheMessageIsAddedInAMailboxOtherThanInbox() throws Exception {
         SimpleMailboxMessage message = createMessage(mailbox1);
 
-        MailboxListener.Added addedEvent = new EventFactory().added(
-            MAILBOX_SESSION,
-            ImmutableSortedMap.of(UID, message.metaData()),
-            mailbox1);
+        MailboxListener.Added addedEvent = new EventFactory().added()
+            .mailboxSession(MAILBOX_SESSION)
+            .mailbox(mailbox1)
+            .addMessage(message)
+            .build();
 
         listener.event(addedEvent);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e829c8ed/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index a05e561..cd8a38c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.store.event;
 
 import java.util.Collection;
 import java.util.Map;
-import java.util.SortedMap;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -39,6 +38,7 @@ import org.apache.james.mailbox.model.MessageMoves;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
@@ -93,6 +93,59 @@ public class EventFactory {
         }
     }
 
+    public abstract static class MessageMetaDataEventBuilder<T extends MessageMetaDataEventBuilder> extends MailboxEventBuilder<T> {
+        protected final ImmutableList.Builder<MessageMetaData> metaData;
+
+        protected MessageMetaDataEventBuilder() {
+            metaData = ImmutableList.builder();
+        }
+
+        protected abstract T backReference();
+
+        public T addMessage(MailboxMessage message) {
+            this.addMetaData(message.metaData());
+            return backReference();
+        }
+
+        public T addMessages(Iterable<MailboxMessage> messages) {
+            this.addMetaData(ImmutableList.copyOf(messages)
+                .stream()
+                .map(MailboxMessage::metaData)
+                .collect(Guavate.toImmutableList()));
+            return backReference();
+        }
+
+        public T addMetaData(MessageMetaData metaData) {
+            this.metaData.add(metaData);
+            return backReference();
+        }
+
+        public T addMetaData(Iterable<MessageMetaData> metaData) {
+            this.metaData.addAll(metaData);
+            return backReference();
+        }
+    }
+
+    public static class AddedBuilder extends MessageMetaDataEventBuilder<AddedBuilder> {
+        @Override
+        protected AddedBuilder backReference() {
+            return this;
+        }
+
+        public MailboxListener.Added build() {
+            mailboxEventChecks();
+
+            return new MailboxListener.Added(
+                sessionId,
+                user,
+                path,
+                mailboxId,
+                metaData.build()
+                    .stream()
+                    .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid)));
+        }
+    }
+
     public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
         @Override
         protected MailboxAddedBuilder backReference() {
@@ -172,12 +225,8 @@ public class EventFactory {
         }
     }
 
-    public MailboxListener.Added added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return added(session.getSessionId(), session.getUser(), uids, mailbox);
-    }
-
-    public MailboxListener.Added added(MailboxSession.SessionId sessionId, User user, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        return new MailboxListener.Added(sessionId, user, mailbox.generateAssociatedPath(), mailbox.getMailboxId(), uids);
+    public AddedBuilder added() {
+        return new AddedBuilder();
     }
 
     public MailboxListener.Expunged expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/e829c8ed/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index ca4076f..6684b8a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -83,7 +83,11 @@ public class MailboxEventDispatcher {
      * @param mailbox The mailbox
      */
     public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(eventFactory.added(session, uids, mailbox));
+        event(eventFactory.added()
+            .mailbox(mailbox)
+            .mailboxSession(session)
+            .addMetaData(uids.values())
+            .build());
     }
 
     public void added(MailboxSession session, Mailbox mailbox, MailboxMessage mailboxMessage) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/e829c8ed/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 9581044..165ff04 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -53,7 +53,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSortedMap;
 
 public class MailboxEventAnalyserTest {
     private static final MessageUid UID = MessageUid.of(900);
@@ -107,7 +106,6 @@ public class MailboxEventAnalyserTest {
         }
     }
 
-
     private static final MessageUid MESSAGE_UID = MessageUid.of(1);
     private static final MailboxSession MAILBOX_SESSION = MailboxSessionUtil.create("user");
     private static final MailboxSession OTHER_MAILBOX_SESSION = MailboxSessionUtil.create("user");
@@ -116,6 +114,11 @@ public class MailboxEventAnalyserTest {
     private static final TestId MAILBOX_ID = TestId.of(36);
     private static final int UID_VALIDITY = 1024;
     private static final SimpleMailbox DEFAULT_MAILBOX = new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY, MAILBOX_ID);
+    private static final MailboxListener.Added ADDED = new EventFactory().added()
+        .mailboxSession(MAILBOX_SESSION)
+        .mailbox(DEFAULT_MAILBOX)
+        .addMetaData(new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId()))
+        .build();
 
     private SelectedMailboxImpl testee;
     private EventFactory eventFactory;
@@ -164,23 +167,14 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldBeNoSizeChangeOnAdded() {
-        MailboxListener.Added mailboxAdded = eventFactory.added(
-            MAILBOX_SESSION,
-            ImmutableSortedMap.of(MessageUid.of(11),
-                new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
-            DEFAULT_MAILBOX);
-        testee.event(mailboxAdded);
+        testee.event(ADDED);
+
         assertThat(testee.isSizeChanged()).isTrue();
     }
 
     @Test
     public void testShouldNoSizeChangeAfterReset() {
-        MailboxListener.Added mailboxAdded = eventFactory.added(
-            MAILBOX_SESSION,
-            ImmutableSortedMap.of(MessageUid.of(11),
-                new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
-            DEFAULT_MAILBOX);
-        testee.event(mailboxAdded);
+        testee.event(ADDED);
         testee.resetEvents();
 
         assertThat(testee.isSizeChanged()).isFalse();

http://git-wip-us.apache.org/repos/asf/james-project/blob/e829c8ed/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 437c41f..86a5023 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -26,10 +26,8 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.security.SecureRandom;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.TreeMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
@@ -37,12 +35,12 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.mail.Flags;
 
-import org.apache.james.core.User;
 import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -165,10 +163,10 @@ public class SelectedMailboxImplTest {
     }
 
     private void emitEvent(MailboxListener mailboxListener) {
-        SecureRandom random = new SecureRandom();
-        TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
-        result.put(EMITTED_EVENT_UID, new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
-        mailboxListener.event(new EventFactory().added(MailboxSession.SessionId.of(random.nextLong()),
-            mock(User.class), result, mailbox));
+        mailboxListener.event(new EventFactory().added()
+            .mailbox(mailbox)
+            .addMetaData(new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()))
+            .mailboxSession(MailboxSessionUtil.create("user"))
+            .build());
     }
 }


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


[03/47] james-project git commit: MAILBOX-359 Factorize tests for UpdatedFlags ser-deserialization

Posted by bt...@apache.org.
MAILBOX-359 Factorize tests for UpdatedFlags ser-deserialization


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

Branch: refs/heads/master
Commit: b458e40508df877d7d87724073a6f2ba6f380e0d
Parents: 5383b12
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 15:34:47 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700

----------------------------------------------------------------------
 .../json/FlagsUpdatedSerializationTest.java     | 143 -------------------
 .../james/event/json/dtos/UpdatedFlagsTest.java |  92 ++++++++++++
 2 files changed, 92 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b458e405/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 12874ee..0fee8a15 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -296,148 +296,5 @@ class FlagsUpdatedSerializationTest {
                     "}").get())
                 .isInstanceOf(NoSuchElementException.class);
         }
-
-        @Nested
-        class DeserializationErrorOnUpdatedFlags {
-            @Nested
-            class DeserializationErrorOnMoqSeq {
-
-                @Test
-                void flagsUpdatedShouldThrowWhenMoqSeqIsAString() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenMoqSeqIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": null," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-
-                @Test
-                void flagsUpdatedShouldThrowWhenMoqSeqIsNotALongNumber() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": 35.2567454," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnOldFlags {
-                @Test
-                void flagsUpdatedShouldThrowWhenOldFlagsIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"oldFlags\": null," +
-                        "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-
-            @Nested
-            class DeserializationErrorOnNewFlags {
-                @Test
-                void flagsUpdatedShouldThrowWhenNewFlagsIsNull() {
-                    assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
-                        "{" +
-                        "  \"FlagsUpdated\": {" +
-                        "    \"path\": {" +
-                        "      \"namespace\": 482," +
-                        "      \"user\": \"user\"," +
-                        "      \"name\": \"mailboxName\"" +
-                        "    }," +
-                        "    \"mailboxId\": \"18\"," +
-                        "    \"sessionId\": 42," +
-                        "    \"updatedFlags\": [" +
-                        "      {" +
-                        "        \"uid\": 123456," +
-                        "        \"modSeq\": \"35\"," +
-                        "        \"newFlags\": null," +
-                        "        \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
-                        "      }" +
-                        "    ]," +
-                        "    \"user\": \"user\"" +
-                        "  }" +
-                        "}").get())
-                    .isInstanceOf(NoSuchElementException.class);
-                }
-            }
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b458e405/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
new file mode 100644
index 0000000..31eda91
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
@@ -0,0 +1,92 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.Json;
+
+class UpdatedFlagsTest {
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void flagsUpdatedShouldThrowWhenMoqSeqIsAString() {
+        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+            "      {" +
+                "        \"uid\": 123456," +
+                "        \"modSeq\": \"35\"," +
+                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+                "      }")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void flagsUpdatedShouldThrowWhenMoqSeqIsNull() {
+        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+            "      {" +
+                "        \"uid\": 123456," +
+                "        \"modSeq\": null," +
+                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+                "      }")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void flagsUpdatedShouldThrowWhenMoqSeqIsNotAnInteger() {
+        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+            "      {" +
+                "        \"uid\": 123456," +
+                "        \"modSeq\": 35.2567454," +
+                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+                "      }")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void flagsUpdatedShouldThrowWhenOldFlagIsMissing() {
+        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+            "      {" +
+                "        \"uid\": 123456," +
+                "        \"modSeq\": 35," +
+                "        \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+                "      }")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void flagsUpdatedShouldThrowWhenNewFlagIsMissing() {
+        assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+            "      {" +
+                "        \"uid\": 123456," +
+                "        \"modSeq\": 35," +
+                "        \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}" +
+                "      }")))
+            .isInstanceOf(JsError.class);
+    }
+}


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


[17/47] james-project git commit: MAILBOX-359 Remove a unused method

Posted by bt...@apache.org.
MAILBOX-359 Remove a unused method


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

Branch: refs/heads/master
Commit: 7776d2af983b7209ccf663e773b032c39c969a6c
Parents: 6f8cb22
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 18:00:53 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:39:52 2019 +0700

----------------------------------------------------------------------
 .../scala/org/apache/james/event/json/EventSerializer.scala     | 5 -----
 1 file changed, 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7776d2af/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 6daf248..3d63c76 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -115,11 +115,6 @@ private object ScalaConverter {
     aclDiff = ACLDiff.fromJava(event.getAclDiff),
     mailboxId = event.getMailboxId)
 
-  private def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): DTOs.Quota[T] = DTOs.Quota(
-    used = java.getUsed,
-    limit = java.getLimit,
-    limits = java.getLimitByScope.asScala.toMap)
-
   private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
     mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
     mailboxId = event.getMailboxId,


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


[07/47] james-project git commit: MAILBOX-359 Factorize tests for MailboxPath ser-deserialization

Posted by bt...@apache.org.
http://git-wip-us.apache.org/repos/asf/james-project/blob/70a4fd59/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
new file mode 100644
index 0000000..613f5a9
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java
@@ -0,0 +1,177 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.event.json.dtos;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.event.json.DTOs;
+import org.apache.james.event.json.JsonSerialize;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.junit.jupiter.api.Test;
+
+import play.api.libs.json.JsError;
+import play.api.libs.json.Json;
+
+class MailboxPathTest {
+    private static final String MAILBOX_NAME = "mailboxName";
+    private static final MailboxPath MAILBOX_PATH = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME);
+    private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+    @Test
+    void mailboxPathShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(MAILBOX_PATH)).toString())
+            .isEqualTo(
+                "{" +
+                "  \"namespace\":\"#private\"," +
+                "  \"user\":\"user\"," +
+                "  \"name\":\"mailboxName\"" +
+                "}");
+    }
+
+    @Test
+    void mailboxPathWithNullUserShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
+            new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))).toString())
+            .isEqualTo(
+                "{" +
+                "  \"namespace\":\"#private\"," +
+                "  \"name\":\"mailboxName\"" +
+                "}");
+    }
+
+    @Test
+    void mailboxPathWithEmptyNamespaceShouldBeWellSerialized() {
+        assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(
+            new MailboxPath("", "user", MAILBOX_NAME))).toString())
+            .isEqualTo(
+                "{" +
+                "  \"namespace\":\"#private\"," +
+                "  \"user\":\"user\"," +
+                "  \"name\":\"mailboxName\"" +
+                "}");
+    }
+
+    @Test
+    void mailboxPathWithShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":\"user\"," +
+            "  \"name\":\"mailboxName\"" +
+            "}")).get())
+            .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava(
+                new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME)));
+    }
+
+    @Test
+    void mailboxPathWithNullUserShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":null," +
+            "  \"name\":\"mailboxName\"" +
+            "}")).get())
+            .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava(
+                new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME)));
+    }
+
+    @Test
+    void mailboxPathWithNoUserShouldBeWellDeSerialized() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"name\":\"mailboxName\"" +
+            "}")).get())
+            .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava(
+                new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME)));
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenNoNamespace() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"user\":\"user\"," +
+            "  \"name\":\"mailboxName\"" +
+            "}"))
+            .get().toJava())
+            .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME));
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenNullNamespace() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":null," +
+            "  \"user\":\"user\"," +
+            "  \"name\":\"mailboxName\"" +
+            "}"))
+            .get().toJava())
+            .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME));
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenLongNamespace() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":18," +
+            "  \"user\":\"user\"," +
+            "  \"name\":\"mailboxName\"" +
+            "}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenLongUser() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":42," +
+            "  \"name\":\"mailboxName\"" +
+            "}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenMissingMailboxName() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":\"user\"" +
+            "}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenNullMailboxName() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":\"user\"," +
+            "  \"name\":null" +
+            "}")))
+            .isInstanceOf(JsError.class);
+    }
+
+    @Test
+    void mailboxPathDeserializationShouldFailWhenLongMailboxName() {
+        assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" +
+            "  \"namespace\":\"#private\"," +
+            "  \"user\":\"user\"," +
+            "  \"name\":42" +
+            "}")))
+            .isInstanceOf(JsError.class);
+    }
+
+}


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


[39/47] james-project git commit: JAMES-2641 Remove MailboxEventDispatcher extra methods

Posted by bt...@apache.org.
JAMES-2641 Remove MailboxEventDispatcher extra methods

Callers should use directly the builders and call the `event` method

This transform the MailboxEventDispatcher into a useless wrapper around
the delegatingMailboxListener that is now easier to remove.


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

Branch: refs/heads/master
Commit: 185810d05bdea16ada99d4e5f5f94b18c546b87c
Parents: b4d9035
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Jan 7 11:26:31 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:46:02 2019 +0700

----------------------------------------------------------------------
 .../mailbox/store/StoreMailboxManager.java      |  28 +++-
 .../mailbox/store/StoreMessageIdManager.java    |  35 ++++-
 .../mailbox/store/StoreMessageManager.java      |  80 +++++++---
 .../james/mailbox/store/StoreRightManager.java  |  13 +-
 .../james/mailbox/store/event/EventFactory.java |  17 +-
 .../store/event/MailboxEventDispatcher.java     | 157 +------------------
 .../quota/ListeningCurrentQuotaUpdater.java     |  28 ++--
 .../store/MessageIdManagerTestSystem.java       |   7 +-
 8 files changed, 156 insertions(+), 209 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index f86b20b..c281068 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -69,6 +69,7 @@ import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
@@ -524,7 +525,10 @@ public class StoreMailboxManager implements MailboxManager {
                         try {
                             mapper.execute(Mapper.toTransaction(() -> mailboxIds.add(mapper.save(m))));
                             // notify listeners
-                            dispatcher.mailboxAdded(mailboxSession, m);
+                            dispatcher.event(EventFactory.mailboxAdded()
+                                .mailboxSession(mailboxSession)
+                                .mailbox(m)
+                                .build());
                         } catch (MailboxExistsException e) {
                             LOGGER.info("{} mailbox was created concurrently", m.generateAssociatedPath());
                         }
@@ -568,7 +572,13 @@ public class StoreMailboxManager implements MailboxManager {
             // mailbox once we remove it
             SimpleMailbox m = new SimpleMailbox(mailbox);
             mailboxMapper.delete(mailbox);
-            dispatcher.mailboxDeleted(session, mailbox, quotaRoot, QuotaCount.count(messageCount), QuotaSize.size(totalSize));
+            dispatcher.event(EventFactory.mailboxDeleted()
+                .mailboxSession(session)
+                .mailbox(mailbox)
+                .quotaRoot(quotaRoot)
+                .quotaCount(QuotaCount.count(messageCount))
+                .quotaSize(QuotaSize.size(totalSize))
+                .build());
             return m;
         });
 
@@ -607,7 +617,12 @@ public class StoreMailboxManager implements MailboxManager {
         mailbox.setName(to.getName());
         mapper.save(mailbox);
 
-        dispatcher.mailboxRenamed(session, from, mailbox);
+        dispatcher.event(EventFactory.mailboxRenamed()
+            .mailboxSession(session)
+            .mailboxId(mailbox.getMailboxId())
+            .oldPath(from)
+            .newPath(to)
+            .build());
 
         // rename submailboxes
         MailboxPath children = new MailboxPath(from.getNamespace(), from.getUser(), from.getName() + getDelimiter() + "%");
@@ -619,7 +634,12 @@ public class StoreMailboxManager implements MailboxManager {
                 MailboxPath fromPath = new MailboxPath(children, subOriginalName);
                 sub.setName(subNewName);
                 mapper.save(sub);
-                dispatcher.mailboxRenamed(session, fromPath, sub);
+                dispatcher.event(EventFactory.mailboxRenamed()
+                    .mailboxSession(session)
+                    .mailboxId(sub.getMailboxId())
+                    .oldPath(fromPath)
+                    .newPath(sub.generateAssociatedPath())
+                    .build());
 
                 LOGGER.debug("Rename mailbox sub-mailbox {} to {}", subOriginalName, subNewName);
             }

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index ff93e53..8554380 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -51,6 +51,7 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
@@ -217,8 +218,11 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
         for (MetadataWithMailboxId metadataWithMailboxId : metadataWithMailbox) {
-            dispatcher.expunged(mailboxSession, metadataWithMailboxId.messageMetaData,
-                mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId));
+            dispatcher.event(EventFactory.expunged()
+                .mailboxSession(mailboxSession)
+                .mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId))
+                .addMetaData(metadataWithMailboxId.messageMetaData)
+                .build());
         }
     }
 
@@ -280,7 +284,12 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         addMessageToMailboxes(mailboxMessage, messageMoves.addedMailboxIds(), mailboxSession);
         removeMessageFromMailboxes(mailboxMessage, messageMoves.removedMailboxIds(), mailboxSession);
-        dispatcher.moved(mailboxSession, messageMoves, ImmutableList.of(mailboxMessage.getMessageId()));
+
+        dispatcher.event(EventFactory.moved()
+            .session(mailboxSession)
+            .messageMoves(messageMoves)
+            .messageId(mailboxMessage.getMessageId())
+            .build());
     }
 
     private void removeMessageFromMailboxes(MailboxMessage message, Set<MailboxId> mailboxesToRemove, MailboxSession mailboxSession) throws MailboxException {
@@ -290,7 +299,11 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         for (MailboxId mailboxId: mailboxesToRemove) {
             messageIdMapper.delete(message.getMessageId(), mailboxesToRemove);
-            dispatcher.expunged(mailboxSession, eventPayload, mailboxMapper.findMailboxById(mailboxId));
+            dispatcher.event(EventFactory.expunged()
+                .mailboxSession(mailboxSession)
+                .mailbox(mailboxMapper.findMailboxById(mailboxId))
+                .addMetaData(eventPayload)
+                .build());
         }
     }
 
@@ -301,7 +314,12 @@ public class StoreMessageIdManager implements MessageIdManager {
     private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, UpdatedFlags updatedFlags) throws MailboxException {
         if (updatedFlags.flagsChanged()) {
             Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-            dispatcher.flagsUpdated(mailboxSession, mailbox, updatedFlags);
+
+            dispatcher.event(EventFactory.flagsUpdated()
+                .mailboxSession(mailboxSession)
+                .mailbox(mailbox)
+                .updatedFlag(updatedFlags)
+                .build());
         }
     }
 
@@ -362,7 +380,12 @@ public class StoreMessageIdManager implements MessageIdManager {
                             .build())
                     .build();
             save(mailboxSession, messageIdMapper, copy);
-            dispatcher.added(mailboxSession, mailboxMapper.findMailboxById(mailboxId), copy);
+
+            dispatcher.event(EventFactory.added()
+                .mailboxSession(mailboxSession)
+                .mailbox(mailboxMapper.findMailboxById(mailboxId))
+                .addMessage(copy)
+                .build());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 36cb3e8..6ec668d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -65,6 +65,7 @@ import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
@@ -86,10 +87,13 @@ import org.apache.james.mime4j.stream.MimeTokenStream;
 import org.apache.james.mime4j.stream.RecursionMode;
 import org.apache.james.util.BodyOffsetInputStream;
 import org.apache.james.util.IteratorWrapper;
+import org.apache.james.util.streams.Iterators;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSortedMap;
 
 /**
  * Base class for {@link org.apache.james.mailbox.MessageManager}
@@ -272,7 +276,11 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         }
         Map<MessageUid, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession);
 
-        dispatcher.expunged(mailboxSession, uids, getMailboxEntity());
+        dispatcher.event(EventFactory.expunged()
+            .mailboxSession(mailboxSession)
+            .mailbox(getMailboxEntity())
+            .metaData(ImmutableSortedMap.copyOf(uids))
+            .build());
         return uids.keySet().iterator();
     }
 
@@ -414,7 +422,11 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
                         Mailbox mailbox = getMailboxEntity();
                         MailboxMessage copy = copyMessage(message);
-                        dispatcher.added(mailboxSession, mailbox, copy);
+                        dispatcher.event(EventFactory.added()
+                            .mailboxSession(mailboxSession)
+                            .mailbox(mailbox)
+                            .addMessage(copy)
+                            .build());
                         return new ComposedMessageId(mailbox.getMailboxId(), data.getMessageId(), data.getUid());
                     }, true);
                 }
@@ -563,25 +575,23 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         if (!isWriteable(mailboxSession)) {
             throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());
         }
-        final SortedMap<MessageUid, Flags> newFlagsByUid = new TreeMap<>();
 
         trimFlags(flags, mailboxSession);
 
-        final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession);
+        MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession);
 
         Iterator<UpdatedFlags> it = messageMapper.execute(() -> messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(flags, flagsUpdateMode), set));
+        List<UpdatedFlags> updatedFlags = Iterators.toStream(it).collect(Guavate.toImmutableList());
 
-        final SortedMap<MessageUid, UpdatedFlags> uFlags = new TreeMap<>();
-
-        while (it.hasNext()) {
-            UpdatedFlags flag = it.next();
-            newFlagsByUid.put(flag.getUid(), flag.getNewFlags());
-            uFlags.put(flag.getUid(), flag);
-        }
-
-        dispatcher.flagsUpdated(mailboxSession, getMailboxEntity(), new ArrayList<>(uFlags.values()));
+        dispatcher.event(EventFactory.flagsUpdated()
+            .mailboxSession(mailboxSession)
+            .mailbox(getMailboxEntity())
+            .updatedFlags(updatedFlags)
+            .build());
 
-        return newFlagsByUid;
+        return updatedFlags.stream().collect(Guavate.toImmutableMap(
+            UpdatedFlags::getUid,
+            UpdatedFlags::getNewFlags));
     }
 
     /**
@@ -735,13 +745,21 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         for (MailboxMessage message : originalRows.getEntriesSeen()) {
             messageIds.add(message.getMessageId());
         }
-        dispatcher.added(session, copiedUids, to.getMailboxEntity());
-        dispatcher.moved(session,
-            MessageMoves.builder()
+
+        dispatcher.event(EventFactory.added()
+            .mailboxSession(session)
+            .mailbox(to.getMailboxEntity())
+            .metaData(copiedUids)
+            .build());
+        dispatcher.event(EventFactory.moved()
+            .session(session)
+            .messageMoves(MessageMoves.builder()
                 .previousMailboxIds(getMailboxEntity().getMailboxId())
                 .targetMailboxIds(to.getMailboxEntity().getMailboxId(), getMailboxEntity().getMailboxId())
-                .build(),
-            messageIds.build());
+                .build())
+            .messageId(messageIds.build())
+            .build());
+
         return copiedUids;
     }
 
@@ -755,14 +773,26 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         for (MailboxMessage message : originalRows.getEntriesSeen()) {
             messageIds.add(message.getMessageId());
         }
-        dispatcher.added(session, moveUids, to.getMailboxEntity());
-        dispatcher.expunged(session, collectMetadata(moveResult.getOriginalMessages()), getMailboxEntity());
-        dispatcher.moved(session,
-            MessageMoves.builder()
+
+        dispatcher.event(EventFactory.added()
+            .mailboxSession(session)
+            .mailbox(to.getMailboxEntity())
+            .metaData(moveUids)
+            .build());
+        dispatcher.event(EventFactory.expunged()
+            .mailboxSession(session)
+            .mailbox(getMailboxEntity())
+            .addMetaData(moveResult.getOriginalMessages())
+            .build());
+        dispatcher.event(EventFactory.moved()
+            .messageMoves(MessageMoves.builder()
                 .previousMailboxIds(getMailboxEntity().getMailboxId())
                 .targetMailboxIds(to.getMailboxEntity().getMailboxId())
-                .build(),
-            messageIds.build());
+                .build())
+            .messageId(messageIds.build())
+            .session(session)
+            .build());
+
         return moveUids;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index b97793f..df0924c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -43,6 +43,7 @@ import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -138,7 +139,11 @@ public class StoreRightManager implements RightManager {
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
         ACLDiff aclDiff = mapper.updateACL(mailbox, mailboxACLCommand);
 
-        dispatcher.aclUpdated(session, mailboxPath, aclDiff, mailbox.getMailboxId());
+        dispatcher.event(EventFactory.aclUpdated()
+            .mailboxSession(session)
+            .mailbox(mailbox)
+            .aclDiff(aclDiff)
+            .build());
     }
 
     private void assertSharesBelongsToUserDomain(String user, ACLCommand mailboxACLCommand) throws DifferentDomainException {
@@ -216,7 +221,11 @@ public class StoreRightManager implements RightManager {
     private void setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
         ACLDiff aclDiff = mapper.setACL(mailbox, mailboxACL);
 
-        dispatcher.aclUpdated(session, mailbox.generateAssociatedPath(), aclDiff, mailbox.getMailboxId());
+        dispatcher.event(EventFactory.aclUpdated()
+            .mailboxSession(session)
+            .mailbox(mailbox)
+            .aclDiff(aclDiff)
+            .build());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index e4a96e8..6dd75a9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -20,6 +20,9 @@
 package org.apache.james.mailbox.store.event;
 
 import java.time.Instant;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -92,7 +95,7 @@ public class EventFactory {
 
     @FunctionalInterface
     public interface RequireMetadata<T> {
-        T metaData(ImmutableSortedMap<MessageUid, MessageMetaData> metaData);
+        T metaData(SortedMap<MessageUid, MessageMetaData> metaData);
 
         default T addMetaData(MessageMetaData metaData) {
             return metaData(ImmutableSortedMap.of(metaData.getUid(), metaData));
@@ -108,6 +111,10 @@ public class EventFactory {
                 .collect(Guavate.toImmutableSortedMap(MessageMetaData::getUid)));
         }
 
+        default T addMetaData(Iterator<MessageMetaData> metaData) {
+            return addMetaData(ImmutableList.copyOf(metaData));
+        }
+
         default T addMessages(Iterable<MailboxMessage> messages) {
             return metaData(ImmutableList.copyOf(messages)
                 .stream()
@@ -197,12 +204,12 @@ public class EventFactory {
         private final MailboxSession.SessionId sessionId;
         private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData;
 
-        AddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableSortedMap<MessageUid, MessageMetaData> metaData) {
+        AddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) {
             this.path = path;
             this.mailboxId = mailboxId;
             this.user = user;
             this.sessionId = sessionId;
-            this.metaData = metaData;
+            this.metaData = ImmutableSortedMap.copyOf(metaData);
         }
 
         public MailboxListener.Added build() {
@@ -223,12 +230,12 @@ public class EventFactory {
         private final MailboxSession.SessionId sessionId;
         private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData;
 
-        ExpungedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableSortedMap<MessageUid, MessageMetaData> metaData) {
+        ExpungedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) {
             this.path = path;
             this.mailboxId = mailboxId;
             this.user = user;
             this.sessionId = sessionId;
-            this.metaData = metaData;
+            this.metaData = ImmutableSortedMap.copyOf(metaData);
         }
 
         public MailboxListener.Expunged build() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index c82bb13..d3d02ea 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -19,36 +19,10 @@
 
 package org.apache.james.mailbox.store.event;
 
-import java.time.Instant;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-
 import javax.inject.Inject;
 
-import org.apache.james.core.User;
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.MessageMoves;
-import org.apache.james.mailbox.model.Quota;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSortedMap;
 
 /**
  * Helper class to dispatch {@link org.apache.james.mailbox.Event}'s to registerend MailboxListener
@@ -60,136 +34,7 @@ public class MailboxEventDispatcher {
     public MailboxEventDispatcher(DelegatingMailboxListener delegatingMailboxListener) {
         this.listener = delegatingMailboxListener;
     }
-
-    /**
-     * Should get called when a new message was added to a Mailbox. All
-     * registered MailboxListener will get triggered then
-     *
-     * @param session The mailbox session
-     * @param uids Sorted map with uids and message meta data
-     * @param mailbox The mailbox
-     */
-    public void added(MailboxSession session, SortedMap<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(EventFactory.added()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .addMetaData(uids.values())
-            .build());
-    }
-
-    public void added(MailboxSession session, Mailbox mailbox, MailboxMessage mailboxMessage) {
-        MessageMetaData messageMetaData = mailboxMessage.metaData();
-        SortedMap<MessageUid, MessageMetaData> metaDataMap = ImmutableSortedMap.<MessageUid, MessageMetaData>naturalOrder()
-                .put(messageMetaData.getUid(), messageMetaData)
-                .build();
-        added(session, metaDataMap, mailbox);
-    }
-
-    public void added(MailboxSession session, MessageMetaData messageMetaData, Mailbox mailbox) {
-        SortedMap<MessageUid, MessageMetaData> metaDataMap = ImmutableSortedMap.<MessageUid, MessageMetaData>naturalOrder()
-            .put(messageMetaData.getUid(), messageMetaData)
-            .build();
-        added(session, metaDataMap, mailbox);
-    }
-
-    /**
-     * Should get called when a message was expunged from a Mailbox. All
-     * registered MailboxListener will get triggered then
-     *
-     * @param session The mailbox session
-     * @param uids Sorted map with uids and message meta data
-     * @param mailbox The mailbox
-     */
-    public void expunged(MailboxSession session,  Map<MessageUid, MessageMetaData> uids, Mailbox mailbox) {
-        event(EventFactory.expunged()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .addMetaData(uids.values())
-            .build());
-    }
-
-    public void expunged(MailboxSession session,  MessageMetaData messageMetaData, Mailbox mailbox) {
-        Map<MessageUid, MessageMetaData> metaDataMap = ImmutableMap.<MessageUid, MessageMetaData>builder()
-            .put(messageMetaData.getUid(), messageMetaData)
-            .build();
-        expunged(session, metaDataMap, mailbox);
-    }
-
-    /**
-     * Should get called when the message flags were update in a Mailbox. All
-     * registered MailboxListener will get triggered then
-     */
-    public void flagsUpdated(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> uflags) {
-        event(EventFactory.flagsUpdated()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .updatedFlags(uflags)
-            .build());
-    }
-
-    public void flagsUpdated(MailboxSession session, Mailbox mailbox, UpdatedFlags uflags) {
-        flagsUpdated(session, mailbox, ImmutableList.of(uflags));
-    }
-
-    /**
-     * Should get called when a Mailbox was renamed. All registered
-     * MailboxListener will get triggered then
-     */
-    public void mailboxRenamed(MailboxSession session, MailboxPath from, Mailbox to) {
-        event(EventFactory.mailboxRenamed()
-            .mailboxSession(session)
-            .mailboxId(to.getMailboxId())
-            .oldPath(from)
-            .newPath(to.generateAssociatedPath())
-            .build());
-    }
-
-    /**
-     * Should get called when a Mailbox was deleted. All registered
-     * MailboxListener will get triggered then
-     */
-    public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        event(EventFactory.mailboxDeleted()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .quotaRoot(quotaRoot)
-            .quotaCount(deletedMessageCount)
-            .quotaSize(totalDeletedSize)
-            .build());
-    }
-
-    /**
-     * Should get called when a Mailbox was added. All registered
-     * MailboxListener will get triggered then
-     */
-    public void mailboxAdded(MailboxSession session, Mailbox mailbox) {
-        event(EventFactory.mailboxAdded()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .build());
-    }
-
-    public void aclUpdated(MailboxSession session, MailboxPath mailboxPath, ACLDiff aclDiff, MailboxId mailboxId) {
-        event(EventFactory.aclUpdated()
-            .mailboxSession(session)
-            .mailboxId(mailboxId)
-            .mailboxPath(mailboxPath)
-            .aclDiff(aclDiff)
-            .build());
-    }
-
-    public void moved(MailboxSession session, MessageMoves messageMoves, Collection<MessageId> messageIds) {
-        event(EventFactory.moved()
-            .session(session)
-            .messageMoves(messageMoves)
-            .messageId(messageIds)
-            .build());
-    }
-
-    public void quota(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota) {
-        event(new MailboxListener.QuotaUsageUpdatedEvent(user, quotaRoot, countQuota, sizeQuota, Instant.now()));
-    }
-
+    
     public void event(Event event) {
         listener.event(event);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index a3519b8..baa33fe 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.store.quota;
 
+import java.time.Instant;
 import java.util.Collection;
 
 import javax.inject.Inject;
@@ -29,6 +30,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,11 +89,14 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(
-            expunged.getUser(),
-            quotaRoot,
-            quotaManager.getMessageQuota(quotaRoot),
-            quotaManager.getStorageQuota(quotaRoot));
+        dispatcher.event(
+            EventFactory.quotaUpdated()
+                .user(expunged.getUser())
+                .quotaRoot(quotaRoot)
+                .quotaCount(quotaManager.getMessageQuota(quotaRoot))
+                .quotaSize(quotaManager.getStorageQuota(quotaRoot))
+                .instant(Instant.now())
+                .build());
     }
 
     private void handleAddedEvent(Added added, QuotaRoot quotaRoot) throws MailboxException {
@@ -105,11 +110,14 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(
-            added.getUser(),
-            quotaRoot,
-            quotaManager.getMessageQuota(quotaRoot),
-            quotaManager.getStorageQuota(quotaRoot));
+        dispatcher.event(
+            EventFactory.quotaUpdated()
+                .user(added.getUser())
+                .quotaRoot(quotaRoot)
+                .quotaCount(quotaManager.getMessageQuota(quotaRoot))
+                .quotaSize(quotaManager.getStorageQuota(quotaRoot))
+                .instant(Instant.now())
+                .build());
     }
 
     private void handleMailboxDeletionEvent(MailboxDeletion mailboxDeletionEvent) throws MailboxException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/185810d0/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index f195e92..0e549fe 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -81,7 +82,11 @@ public class MessageIdManagerTestSystem {
             Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
             MailboxMessage message = createMessage(mailboxId, flags, messageId, uid);
             mapperFactory.getMessageMapper(mailboxSession).add(mailbox, message);
-            mailboxManager.getEventDispatcher().added(mailboxSession, message.metaData(), mailbox);
+            mailboxManager.getEventDispatcher().event(EventFactory.added()
+                .mailboxSession(mailboxSession)
+                .mailbox(mailbox)
+                .addMessage(message)
+                .build());
             return messageId;
         } catch (Exception e) {
             throw new RuntimeException(e);


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


[35/47] james-project git commit: JAMES-2636 Remove serial UID from ErrorMappingException

Posted by bt...@apache.org.
JAMES-2636 Remove serial UID from ErrorMappingException


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

Branch: refs/heads/master
Commit: 305c321de80329c358527407a81e6286806a2b44
Parents: 4e2bd7f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Jan 4 10:07:23 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:45:33 2019 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/rrt/api/RecipientRewriteTable.java  | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/305c321d/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index bbcece6..7efc0bd 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -35,8 +35,6 @@ import com.google.common.base.Preconditions;
  */
 public interface RecipientRewriteTable {
     class ErrorMappingException extends Exception {
-        private static final long serialVersionUID = 2348752938798L;
-
         public ErrorMappingException(String string) {
             super(string);
         }


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