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 2018/12/14 10:34:29 UTC

[13/18] james-project git commit: MAILBOX-359 MailboxDeletion Scala Event Serialization

MAILBOX-359 MailboxDeletion Scala Event Serialization


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

Branch: refs/heads/master
Commit: 9d42cc30aa9c2416b68689169ccaeba315a75fe8
Parents: 3b89930
Author: tran tien duc <dt...@linagora.com>
Authored: Thu Dec 13 18:09:55 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 14 17:13:32 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   |  29 +-
 .../james/mailbox/MailboxListenerTest.java      |   5 +
 .../james/event/json/EventSerializer.scala      |  25 +-
 .../json/MailboxAddedSerializationTest.java     |  68 +-
 .../json/MailboxDeletionSerializationTest.java  | 726 +++++++++++++++++++
 5 files changed, 814 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d42cc30/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 128e134..bbd5e4a 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -194,14 +194,14 @@ public interface MailboxListener {
      */
     class MailboxDeletion extends MailboxEvent {
         private final QuotaRoot quotaRoot;
-        private final QuotaCount deletedMessageCOunt;
+        private final QuotaCount deletedMessageCount;
         private final QuotaSize totalDeletedSize;
 
-        public MailboxDeletion(MailboxSession.SessionId sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize totalDeletedSize,
+        public MailboxDeletion(MailboxSession.SessionId sessionId, User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize,
                                MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
             this.quotaRoot = quotaRoot;
-            this.deletedMessageCOunt = deletedMessageCOunt;
+            this.deletedMessageCount = deletedMessageCount;
             this.totalDeletedSize = totalDeletedSize;
         }
 
@@ -210,12 +210,33 @@ public interface MailboxListener {
         }
 
         public QuotaCount getDeletedMessageCount() {
-            return deletedMessageCOunt;
+            return deletedMessageCount;
         }
 
         public QuotaSize getTotalDeletedSize() {
             return totalDeletedSize;
         }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof MailboxDeletion) {
+                MailboxDeletion that = (MailboxDeletion) o;
+
+                return Objects.equals(this.sessionId, that.sessionId)
+                    && Objects.equals(this.user, that.user)
+                    && Objects.equals(this.path, that.path)
+                    && Objects.equals(this.mailboxId, that.mailboxId)
+                    && Objects.equals(this.quotaRoot, that.quotaRoot)
+                    && Objects.equals(this.deletedMessageCount, that.deletedMessageCount)
+                    && Objects.equals(this.totalDeletedSize, that.totalDeletedSize);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(sessionId, user, path, mailboxId, quotaRoot, deletedMessageCount, totalDeletedSize);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d42cc30/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
index b3b3585..0e28d17 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
@@ -33,4 +33,9 @@ class MailboxListenerTest {
     void mailboxRenamedShouldMatchBeanContract() {
         EqualsVerifier.forClass(MailboxListener.MailboxRenamed.class).verify();
     }
+
+    @Test
+    void mailboxDeletionShouldMatchBeanContract() {
+        EqualsVerifier.forClass(MailboxListener.MailboxDeletion.class).verify();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d42cc30/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 5085640..9c89b58 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
@@ -25,7 +25,7 @@ import java.util.Optional
 import julienrf.json.derived
 import org.apache.james.core.quota.{QuotaCount, QuotaSize, QuotaValue}
 import org.apache.james.core.{Domain, User}
-import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
+import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, MailboxDeletion => JavaMailboxDeletion, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
 import org.apache.james.mailbox.MailboxSession.SessionId
 import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, MailboxPath => JavaMailboxPath, Quota => JavaQuota}
 import org.apache.james.mailbox.{Event => JavaEvent}
@@ -41,13 +41,13 @@ private object DTO {
 
   object MailboxPath {
     def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = DTO.MailboxPath(
-      javaMailboxPath.getNamespace,
+      Option(javaMailboxPath.getNamespace),
       Option(javaMailboxPath.getUser),
       javaMailboxPath.getName)
   }
 
-  case class MailboxPath(namespace: String, user: Option[String], name: String) {
-    def toJava: JavaMailboxPath = new JavaMailboxPath(namespace, user.orNull, name)
+  case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
+    def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
   }
 
   case class Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
@@ -71,6 +71,13 @@ private object DTO {
   case class MailboxRenamed(sessionId: SessionId, user: User, path: MailboxPath, mailboxId: MailboxId, newPath: MailboxPath) extends Event {
     override def toJava: JavaEvent = new JavaMailboxRenamed(sessionId, user, path.toJava, mailboxId, newPath.toJava)
   }
+
+  case class MailboxDeletion(sessionId: SessionId, user: User, path: MailboxPath, quotaRoot: QuotaRoot,
+                             deletedMessageCount: QuotaCount, totalDeletedSize: QuotaSize, mailboxId: MailboxId) extends Event {
+    override def toJava: JavaEvent = new JavaMailboxDeletion(sessionId, user, path.toJava, quotaRoot, deletedMessageCount,
+      totalDeletedSize,
+      mailboxId)
+  }
 }
 
 private object ScalaConverter {
@@ -99,10 +106,20 @@ private object ScalaConverter {
     mailboxId = event.getMailboxId,
     newPath = DTO.MailboxPath.fromJava(event.getNewPath))
 
+  private def toScala(event: JavaMailboxDeletion): DTO.MailboxDeletion = DTO.MailboxDeletion(
+    sessionId = event.getSessionId,
+    user = event.getUser,
+    quotaRoot = event.getQuotaRoot,
+    path = DTO.MailboxPath.fromJava(event.getMailboxPath),
+    deletedMessageCount = event.getDeletedMessageCount,
+    totalDeletedSize = event.getTotalDeletedSize,
+    mailboxId = event.getMailboxId)
+
   def toScala(javaEvent: JavaEvent): Event = javaEvent match {
     case e: JavaQuotaUsageUpdatedEvent => toScala(e)
     case e: JavaMailboxAdded => toScala(e)
     case e: JavaMailboxRenamed => toScala(e)
+    case e: JavaMailboxDeletion => toScala(e)
     case _ => throw new RuntimeException("no Scala convertion known")
   }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d42cc30/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 8e8bfb0..0c7b3ea 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
@@ -106,27 +106,49 @@ class MailboxAddedSerializationTest {
     }
 
     @Nested
-    class DeserializationErrors {
+    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 fromJsonShouldRejectNullSessionId() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
+        void mailboxAddedShouldBeWellDeSerializedWhenNullNameSpace() {
+            assertThat(EVENT_SERIALIZER.fromJson(
+                "{" +
                 "  \"MailboxAdded\":{" +
                 "    \"mailboxPath\":{" +
-                "      \"namespace\":\"#private\"," +
+                "      \"namespace\":null," +
                 "      \"user\":\"bob\"," +
                 "      \"name\":\"mailboxName\"" +
                 "     }," +
                 "     \"mailboxId\":\"18\"," +
                 "     \"user\":\"user\"," +
-                "     \"sessionId\":null" +
+                "     \"sessionId\":42" +
                 "  }" +
                 "}").get())
-                .isInstanceOf(NoSuchElementException.class);
+            .isEqualTo(EVENT_1);
         }
+    }
+
+    @Nested
+    class DeserializationErrors {
 
         @Test
-        void fromJsonShouldRejectStringSessionId() {
+        void fromJsonShouldRejectNullSessionId() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
                 "  \"MailboxAdded\":{" +
                 "    \"mailboxPath\":{" +
@@ -136,35 +158,36 @@ class MailboxAddedSerializationTest {
                 "     }," +
                 "     \"mailboxId\":\"18\"," +
                 "     \"user\":\"user\"," +
-                "     \"sessionId\":\"invalid\"" +
+                "     \"sessionId\":null" +
                 "  }" +
                 "}").get())
                 .isInstanceOf(NoSuchElementException.class);
         }
 
         @Test
-        void fromJsonShouldRejectMissingSessionId() {
+        void fromJsonShouldRejectStringSessionId() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
                 "  \"MailboxAdded\":{" +
                 "    \"mailboxPath\":{" +
                 "      \"namespace\":\"#private\"," +
-                "      \"user\":\"bob\"" +
+                "      \"user\":\"bob\"," +
+                "      \"name\":\"mailboxName\"" +
                 "     }," +
                 "     \"mailboxId\":\"18\"," +
                 "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
+                "     \"sessionId\":\"invalid\"" +
                 "  }" +
                 "}").get())
                 .isInstanceOf(NoSuchElementException.class);
         }
 
         @Test
-        void fromJsonShouldRejectMissingNamespace() {
+        void fromJsonShouldRejectMissingSessionId() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
                 "  \"MailboxAdded\":{" +
                 "    \"mailboxPath\":{" +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
+                "      \"namespace\":\"#private\"," +
+                "      \"user\":\"bob\"" +
                 "     }," +
                 "     \"mailboxId\":\"18\"," +
                 "     \"user\":\"user\"," +
@@ -236,23 +259,6 @@ class MailboxAddedSerializationTest {
         }
 
         @Test
-        void fromJsonShouldRejectNullNamespace() {
-            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
-                "  \"MailboxAdded\":{" +
-                "    \"mailboxPath\":{" +
-                "      \"namespace\":null," +
-                "      \"user\":\"bob\"," +
-                "      \"name\":\"mailboxName\"" +
-                "     }," +
-                "     \"mailboxId\":\"18\"," +
-                "     \"user\":\"user\"," +
-                "     \"sessionId\":18" +
-                "  }" +
-                "}").get())
-                .isInstanceOf(NoSuchElementException.class);
-        }
-
-        @Test
         void fromJsonShouldRejectLongUserInMailboxPath() {
             assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
                 "  \"MailboxAdded\":{" +

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d42cc30/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
new file mode 100644
index 0000000..bec317e
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -0,0 +1,726 @@
+/****************************************************************
+ * 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 static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+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;
+
+import java.util.NoSuchElementException;
+import java.util.Optional;
+
+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.MailboxListener;
+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.QuotaRoot;
+import org.apache.james.mailbox.model.TestId;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+class MailboxDeletionSerializationTest {
+
+    private static final MailboxSession.SessionId SESSION_ID = MailboxSession.SessionId.of(3652);
+    private static final User USER = User.fromUsername("user");
+    private static final MailboxPath MAILBOX_PATH = new MailboxPath(USER_NAMESPACE, USER.asString(), "mailboxName");
+    private static final MailboxId MAILBOX_ID = TestId.of(789);
+    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("user@domain", Optional.empty());
+    private static final QuotaCount DELETED_MESSAGE_COUNT = QuotaCount.count(60);
+    private static final QuotaSize TOTAL_DELETED_SIZE = QuotaSize.size(100);
+    private static final MailboxListener.MailboxDeletion DEFAULT_MAILBOX_DELETION_EVENT = new MailboxListener.MailboxDeletion(
+        SESSION_ID,
+        USER,
+        MAILBOX_PATH,
+        QUOTA_ROOT,
+        DELETED_MESSAGE_COUNT,
+        TOTAL_DELETED_SIZE,
+        MAILBOX_ID);
+
+    private static final String DEFAULT_EVEN_JSON =
+        "{" +
+        "  \"MailboxDeletion\":{" +
+        "    \"sessionId\":3652," +
+        "    \"user\":\"user\"," +
+        "    \"path\":{" +
+        "      \"namespace\":\"#private\"," +
+        "      \"user\":\"user\"," +
+        "      \"name\":\"mailboxName\"" +
+        "    }," +
+        "    \"quotaRoot\":\"user@domain\"," +
+        "    \"deletedMessageCount\":60," +
+        "    \"totalDeletedSize\":100," +
+        "    \"mailboxId\":\"789\"" +
+        "  }" +
+        "}";
+
+    private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory());
+
+    @Test
+    void mailboxAddedShouldBeWellSerialized() {
+        assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_MAILBOX_DELETION_EVENT))
+            .isEqualTo(DEFAULT_EVEN_JSON);
+    }
+
+    @Test
+    void mailboxAddedShouldBeWellDeSerialized() {
+        assertThat(EVENT_SERIALIZER.fromJson(DEFAULT_EVEN_JSON).get())
+            .isEqualTo(DEFAULT_MAILBOX_DELETION_EVENT);
+    }
+
+    @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,
+                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,
+                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 {
+
+        @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(
+                    "{" +
+                    "  \"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
+        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(
+                    "{" +
+                    "  \"MailboxDeletion\":{" +
+                    "    \"sessionId\":3652," +
+                    "    \"user\":5489515," +
+                    "    \"path\":{" +
+                    "      \"namespace\":\"#private\"," +
+                    "      \"user\":\"user\"," +
+                    "      \"name\":\"mailboxName\"" +
+                    "    }," +
+                    "    \"quotaRoot\":\"user@domain\"," +
+                    "    \"deletedMessageCount\":60," +
+                    "    \"totalDeletedSize\":100," +
+                    "    \"mailboxId\":\"789\"" +
+                    "  }" +
+                    "}").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
+        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(
+                    "{" +
+                    "  \"MailboxDeletion\":{" +
+                    "    \"sessionId\":3652," +
+                    "    \"user\":\"user\"," +
+                    "    \"path\":{" +
+                    "      \"namespace\":\"#private\"," +
+                    "      \"user\":\"user\"," +
+                    "      \"name\":\"mailboxName\"" +
+                    "    }," +
+                    "    \"quotaRoot\":123456," +
+                    "    \"deletedMessageCount\":60," +
+                    "    \"totalDeletedSize\":100," +
+                    "    \"mailboxId\":\"789\"" +
+                    "  }" +
+                    "}").get())
+                .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(
+                    "{" +
+                    "  \"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
+        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(
+                    "{" +
+                    "  \"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
+        class DeserializationErrorOnMailboxId {
+            @Test
+            void mailboxAddedShouldThrowWhenMissingMailboxId() {
+                assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+                    "{" +
+                    "  \"MailboxDeletion\":{" +
+                    "    \"sessionId\":3652," +
+                    "    \"user\":\"user\"," +
+                    "    \"path\":{" +
+                    "      \"namespace\":\"#private\"," +
+                    "      \"user\":\"user\"," +
+                    "      \"name\":\"mailboxName\"" +
+                    "    }," +
+                    "    \"quotaRoot\":\"user@domain\"," +
+                    "    \"deletedMessageCount\":60," +
+                    "    \"totalDeletedSize\":100" +
+                    "  }" +
+                    "}").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
+        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);
+                }
+            }
+        }
+    }
+}


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