You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/08 08:00:31 UTC

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

MAILBOX-359 Factorize tests for MessageUid ser-deserialization


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

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

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


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

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

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

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


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