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:31 UTC

[15/18] james-project git commit: MAILBOX-359 MailboxAdded serialization

MAILBOX-359 MailboxAdded 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/9e47d6eb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9e47d6eb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9e47d6eb

Branch: refs/heads/master
Commit: 9e47d6eb71cb8d1fa0bfb44bc20ddc115d8e43cc
Parents: ed838fa
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 13 11:20:22 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Dec 14 17:13:32 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   |  26 +-
 .../james/mailbox/MailboxListenerTest.java      |  31 ++
 .../james/event/json/EventSerializer.scala      |  54 ++-
 .../json/MailboxAddedSerializationTest.java     | 391 +++++++++++++++++++
 4 files changed, 488 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9e47d6eb/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 2f13389..9c89b8e 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
@@ -137,10 +137,10 @@ public interface MailboxListener {
      * A mailbox event.
      */
     abstract class MailboxEvent implements Event {
-        private final MailboxPath path;
-        private final MailboxId mailboxId;
-        private final User user;
-        private final MailboxSession.SessionId sessionId;
+        protected final MailboxPath path;
+        protected final MailboxId mailboxId;
+        protected final User user;
+        protected final MailboxSession.SessionId sessionId;
 
         public MailboxEvent(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             this.user = user;
@@ -226,6 +226,24 @@ public interface MailboxListener {
         public MailboxAdded(MailboxSession.SessionId sessionId, User user, MailboxPath path, MailboxId mailboxId) {
             super(sessionId, user, path, mailboxId);
         }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof MailboxAdded) {
+                MailboxAdded that = (MailboxAdded) 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);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(sessionId, user, path, mailboxId);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e47d6eb/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
new file mode 100644
index 0000000..bcad8b3
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class MailboxListenerTest {
+    @Test
+    void mailboxAddedShouldMatchBeanContract() {
+        EqualsVerifier.forClass(MailboxListener.MailboxAdded.class).verify();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e47d6eb/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 79d73da..9e4c182 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,8 +25,9 @@ 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.{QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
-import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, Quota => JavaQuota}
+import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, 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}
 import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsString, JsSuccess, Json, OFormat, Reads, Writes}
 
@@ -38,6 +39,17 @@ private sealed trait Event {
 
 private object DTO {
 
+  object MailboxPath {
+    def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = DTO.MailboxPath(
+      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 Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
     def toJava: JavaQuota[T] =
       JavaQuota.builder[T]
@@ -49,10 +61,11 @@ private object DTO {
 
   case class QuotaUsageUpdatedEvent(user: User, quotaRoot: QuotaRoot, countQuota: Quota[QuotaCount],
                                     sizeQuota: Quota[QuotaSize], time: Instant) extends Event {
-    def getQuotaRoot: QuotaRoot = quotaRoot
+    override def toJava: JavaEvent = new JavaQuotaUsageUpdatedEvent(user, quotaRoot, countQuota.toJava, sizeQuota.toJava, time)
+  }
 
-    override def toJava: JavaEvent =
-      new JavaQuotaUsageUpdatedEvent(user, getQuotaRoot, countQuota.toJava, sizeQuota.toJava, time)
+  case class MailboxAdded(mailboxPath: MailboxPath, mailboxId: MailboxId, user: User, sessionId: SessionId) extends Event {
+    override def toJava: JavaEvent = new JavaMailboxAdded(sessionId, user, mailboxPath.toJava, mailboxId)
   }
 }
 
@@ -63,11 +76,22 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
   implicit val quotaScopeWrites: Writes[JavaQuota.Scope] = value => JsString(value.name)
   implicit val quotaCountWrites: Writes[DTO.Quota[QuotaCount]] = Json.writes[DTO.Quota[QuotaCount]]
   implicit val quotaSizeWrites: Writes[DTO.Quota[QuotaSize]] = Json.writes[DTO.Quota[QuotaSize]]
+  implicit val mailboxPathWrites: Writes[DTO.MailboxPath] = Json.writes[DTO.MailboxPath]
+  implicit val mailboxIdWrites: Writes[MailboxId] = value => JsString(value.serialize())
+  implicit val sessionIdWrites: Writes[SessionId] = value => JsNumber(value.getValue)
 
   implicit val userReads: Reads[User] = {
     case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
     case _ => JsError()
   }
+  implicit val mailboxIdReads: Reads[MailboxId] = {
+    case JsString(serializedMailboxId) => JsSuccess(mailboxIdFactory.fromString(serializedMailboxId))
+    case _ => JsError()
+  }
+  implicit val sessionIdReads: Reads[SessionId] = {
+    case JsNumber(id) => JsSuccess(SessionId.of(id.longValue()))
+    case _ => JsError()
+  }
   implicit val quotaRootReads: Reads[QuotaRoot] = {
     case JsString(quotaRoot) => JsSuccess(QuotaRoot.quotaRoot(quotaRoot, Optional.empty[Domain]))
     case _ => JsError()
@@ -99,6 +123,7 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
 
   implicit val quotaCReads: Reads[DTO.Quota[QuotaCount]] = Json.reads[DTO.Quota[QuotaCount]]
   implicit val quotaSReads: Reads[DTO.Quota[QuotaSize]] = Json.reads[DTO.Quota[QuotaSize]]
+  implicit val mailboxPathReads: Reads[DTO.MailboxPath] = Json.reads[DTO.MailboxPath]
 
   implicit val eventOFormat: OFormat[Event] = derived.oformat()
 
@@ -109,24 +134,33 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
 
 class EventSerializer(mailboxIdFactory: MailboxId.Factory) {
 
-  private def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): DTO.Quota[T] =
-    DTO.Quota(used = java.getUsed, limit = java.getLimit, limits = java.getLimitByScope.asScala.toMap)
+  private def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): DTO.Quota[T] = DTO.Quota(
+    used = java.getUsed,
+    limit = java.getLimit,
+    limits = java.getLimitByScope.asScala.toMap)
 
-  private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent =
-    DTO.QuotaUsageUpdatedEvent(
+  private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
       user = event.getUser,
       quotaRoot = event.getQuotaRoot,
       countQuota = toScala(event.getCountQuota),
       sizeQuota = toScala(event.getSizeQuota),
       time = event.getInstant)
 
+  private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
+      mailboxPath = DTO.MailboxPath.fromJava(event.getMailboxPath),
+      mailboxId = event.getMailboxId,
+      user = event.getUser,
+      sessionId = event.getSessionId)
+
   def toJson(event: JavaEvent): String = event match {
     case e: JavaQuotaUsageUpdatedEvent => new JsonSerialize(mailboxIdFactory).toJson(toScala(e))
+    case e: JavaMailboxAdded => new JsonSerialize(mailboxIdFactory).toJson(toScala(e))
     case _ => throw new RuntimeException("no encoder found")
   }
 
   def fromJson(json: String): JsResult[JavaEvent] = {
-    new JsonSerialize(mailboxIdFactory).fromJson(json)
+    new JsonSerialize(mailboxIdFactory)
+      .fromJson(json)
       .map(event => event.toJava)
   }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9e47d6eb/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
new file mode 100644
index 0000000..8e8bfb0
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -0,0 +1,391 @@
+/****************************************************************
+ * 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.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.NoSuchElementException;
+
+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.MailboxPath;
+import org.apache.james.mailbox.model.TestId;
+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());
+
+    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\":{" +
+        "      \"namespace\":\"#private\"," +
+        "      \"user\":\"bob\"," +
+        "      \"name\":\"mailboxName\"" +
+        "     }," +
+        "     \"mailboxId\":\"18\"," +
+        "     \"user\":\"user\"," +
+        "     \"sessionId\":42" +
+        "  }" +
+        "}";
+
+    @Test
+    void mailboxAddedShouldBeWellSerialized() {
+        assertThatJson(EVENT_SERIALIZER.toJson(EVENT_1))
+            .isEqualTo(JSON_1);
+    }
+
+    @Test
+    void mailboxAddedShouldBeWellDeSerialized() {
+        assertThat(EVENT_SERIALIZER.fromJson(JSON_1).get())
+            .isEqualTo(EVENT_1);
+    }
+
+    @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 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\":{" +
+                "    \"mailboxPath\":{" +
+                "      \"namespace\":\"#private\"," +
+                "      \"user\":\"bob\"" +
+                "     }," +
+                "     \"mailboxId\":\"18\"," +
+                "     \"user\":\"user\"," +
+                "     \"sessionId\":18" +
+                "  }" +
+                "}").get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void fromJsonShouldRejectMissingNamespace() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
+                "  \"MailboxAdded\":{" +
+                "    \"mailboxPath\":{" +
+                "      \"user\":\"bob\"," +
+                "      \"name\":\"mailboxName\"" +
+                "     }," +
+                "     \"mailboxId\":\"18\"," +
+                "     \"user\":\"user\"," +
+                "     \"sessionId\":18" +
+                "  }" +
+                "}").get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void fromJsonShouldRejectMissingMailboxId() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
+                "  \"MailboxAdded\":{" +
+                "    \"mailboxPath\":{" +
+                "      \"namespace\":\"#private\"," +
+                "      \"user\":\"bob\"," +
+                "      \"name\":\"mailboxName\"" +
+                "     }," +
+                "     \"user\":\"user\"," +
+                "     \"sessionId\":18" +
+                "  }" +
+                "}").get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void fromJsonShouldRejectMissingUser() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
+                "  \"MailboxAdded\":{" +
+                "    \"mailboxPath\":{" +
+                "      \"namespace\":\"#private\"," +
+                "      \"user\":\"bob\"," +
+                "      \"name\":\"mailboxName\"" +
+                "     }," +
+                "     \"mailboxId\":\"18\"," +
+                "     \"sessionId\":18" +
+                "  }" +
+                "}").get())
+                .isInstanceOf(NoSuchElementException.class);
+        }
+
+        @Test
+        void fromJsonShouldRejectMissingMailboxPath() {
+            assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
+                "  \"MailboxAdded\":{" +
+                "     \"mailboxId\":\"18\"," +
+                "     \"user\":\"user\"," +
+                "     \"sessionId\":18" +
+                "  }" +
+                "}").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 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\":{" +
+                "    \"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);
+        }
+
+        @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);
+        }
+
+        @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);
+        }
+    }
+}


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