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 <btell...@linagora.com>
Authored: Mon Dec 24 12:59:52 2018 +0700
Committer: Benoit Tellier <btell...@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-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to