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 rc...@apache.org on 2020/05/20 01:58:19 UTC

[james-project] 10/11: JAMES-3091 JsonAssert can't seem to evaluate correctly JsValue

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 691aae411b0170be99115ccee1b6b066caef33ad
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri May 15 11:19:02 2020 +0700

    JAMES-3091 JsonAssert can't seem to evaluate correctly JsValue
    
    When evaluating JsValue, JsonAssert seems to always say success, even if it should fail.
    Converting those values into String, could see that there was a serialization issue with MailboxNamespace and fix it
---
 .../src/main/scala/org/apache/james/jmap/json/Serializer.scala     | 7 ++++---
 .../org/apache/james/jmap/json/MailboxGetSerializationTest.scala   | 6 +++---
 .../org/apache/james/jmap/json/MailboxSerializationTest.scala      | 6 +++---
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
index 982ce1b..295e270 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
@@ -158,9 +158,10 @@ class Serializer(mailboxIdFactory: MailboxId.Factory) {
   private implicit val maySubmitWrites: Writes[MaySubmit] = Json.valueWrites[MaySubmit]
   private implicit val mailboxRightsWrites: Writes[MailboxRights] = Json.writes[MailboxRights]
 
-  private implicit val personalNamespaceWrites: Writes[PersonalNamespace] = namespace => JsString("Personal")
-  private implicit val delegatedNamespaceWrites: Writes[DelegatedNamespace] = namespace => JsString(s"Delegated[${namespace.owner.asString}]")
-  private implicit val mailboxNamespaceWrites: Writes[MailboxNamespace] = Json.writes[MailboxNamespace]
+  private implicit val mailboxNamespaceWrites: Writes[MailboxNamespace] = {
+    case personal: PersonalNamespace => JsString("Personal")
+    case delegated: DelegatedNamespace => JsString(s"Delegated[${delegated.owner.asString}]")
+  }
 
   private implicit val mailboxACLWrites: Writes[MailboxACL.Right] = right => JsString(right.asCharacter.toString)
 
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
index 44a1594..2449d6c 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
@@ -158,7 +158,7 @@ class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
         list = List(MAILBOX),
         notFound = NotFound(List(MAILBOX_ID_1, MAILBOX_ID_2)))
 
-      val expectedJson = Json.parse(
+      val expectedJson: String =
         """
           |{
           |  "accountId": "aHR0cHM6Ly93d3cuYmFzZTY0ZW5jb2RlLm9yZy8",
@@ -203,9 +203,9 @@ class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
           |  }],
           |  "notFound": ["1", "2"]
           |}
-          |""".stripMargin)
+          |""".stripMargin
 
-      assertThatJson(SERIALIZER.serialize(actualValue)).isEqualTo(expectedJson)
+      assertThatJson(Json.stringify(SERIALIZER.serialize(actualValue))).isEqualTo(expectedJson)
     }
   }
 }
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
index 23c643d..940d29a 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
@@ -89,7 +89,7 @@ class MailboxSerializationTest extends AnyWordSpec with Matchers {
   "Serialize Mailbox" should {
     "succeed " in {
 
-      val expectedJson = Json.parse(
+      val expectedJson: String =
         """{
           |  "id":"2",
           |  "name":"inbox",
@@ -127,9 +127,9 @@ class MailboxSerializationTest extends AnyWordSpec with Matchers {
           |      "Storage":{"used":19}
           |    }
           |  }
-          |}""".stripMargin)
+          |}""".stripMargin
 
-      assertThatJson(new Serializer(new TestId.Factory).serialize(MAILBOX)).isEqualTo(expectedJson)
+      assertThatJson(Json.stringify(new Serializer(new TestId.Factory).serialize(MAILBOX))).isEqualTo(expectedJson)
     }
   }
 }


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