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 433162e9405555d85f45f7a93c51652ccf8c1bc7
Author: Benoit Tellier <[email protected]>
AuthorDate: Wed Nov 11 11:54:56 2020 +0700

    JAMES-3413 Email/set updateValidation message should pass on distributed 
james
---
 .../distributed/DistributedEmailSetMethodTest.java |  5 ++
 .../rfc8621/contract/EmailGetMethodContract.scala  |  4 +-
 .../rfc8621/contract/EmailSetMethodContract.scala  | 60 +++++++++++-----------
 .../rfc8621/memory/MemoryEmailSetMethodTest.java   |  5 ++
 .../jmap/method/EmailSetUpdatePerformer.scala      |  2 +-
 5 files changed, 44 insertions(+), 32 deletions(-)

diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailSetMethodTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailSetMethodTest.java
index 20a16f1..ec07ea6 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailSetMethodTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedEmailSetMethodTest.java
@@ -62,4 +62,9 @@ public class DistributedEmailSetMethodTest implements 
EmailSetMethodContract {
     public MessageId randomMessageId() {
         return MESSAGE_ID_FACTORY.of(UUIDs.timeBased());
     }
+
+    @Override
+    public String invalidMessageIdMessage(String invalid) {
+        return String.format("Invalid UUID string: %s", invalid);
+    }
 }
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
index 20a1800..347c4ea 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
@@ -2417,7 +2417,7 @@ trait EmailGetMethodContract {
          |                        "threadId": "${messageId.serialize}",
          |                        "size": 2695,
          |                        "keywords": {},
-         |                        "blobId": "1",
+         |                        "blobId": "${messageId.serialize}",
          |                        "mailboxIds": {"${mailboxId.serialize}": 
true},
          |                        "id": "${messageId.serialize}",
          |                        "receivedAt": "2014-10-30T14:12:00Z",
@@ -5885,7 +5885,7 @@ trait EmailGetMethodContract {
       .inPath("methodResponses[0][1].list[0]")
       .isEqualTo(
         s"""{
-           |    "id": "1",
+           |    "id": "${messageId.serialize}",
            |    "header:Bcc:asRaw": " \\"user3\\" [email protected]",
            |    "header:MessageId:asRaw": null,
            |    "header:ReplyTo:asRaw": " \\"user1\\" [email protected]",
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
index af77d0b..8bd5a9e 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala
@@ -71,6 +71,8 @@ trait EmailSetMethodContract {
 
   def randomMessageId: MessageId
 
+  def invalidMessageIdMessage(invalid: String): String
+
   @Test
   def shouldResetKeywords(server: GuiceJamesServer): Unit = {
     val message: Message = Fixture.createTestMessage
@@ -426,9 +428,9 @@ trait EmailSetMethodContract {
     assertThatJson(response)
       .inPath(s"methodResponses[0][1].notUpdated.${messageId.serialize}")
       .isEqualTo(
-        """|{
+        s"""|{
           |   "type":"invalidPatch",
-          |   "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(keyword value can only be 
true),ArraySeq()))))),ArraySeq()))))"
+          |   "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(keyword value can only be 
true),ArraySeq()))))),ArraySeq()))))"
           |}""".stripMargin)
   }
 
@@ -962,7 +964,7 @@ trait EmailSetMethodContract {
       .inPath("methodResponses[0][1].notCreated.aaaaaa")
       .isEqualTo(
         s"""{
-          |  "description": 
"List((/mailboxIds,List(JsonValidationError(List(For input string: 
\\"invalid\\"),ArraySeq()))))",
+          |  "description": 
"List((/mailboxIds,List(JsonValidationError(List(${invalidMessageIdMessage("invalid")}),ArraySeq()))))",
           |  "type": "invalidArguments"
           |}""".stripMargin)
   }
@@ -3310,7 +3312,7 @@ trait EmailSetMethodContract {
       .isEqualTo(
         """|{
            |   "type":"invalidPatch",
-           |   "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(FlagName must not be null or empty, must 
have length form 1-255,must not contain characters with hex from '\\u0000' to 
'\\u00019' or {'(' ')' '{' ']' '%' '*' '\"' '\\'} 
),ArraySeq()))))),ArraySeq()))))"
+           |   "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(FlagName must not be null or empty, must 
have length form 1-255,must not contain characters with hex from '\\u0000' to 
'\\u00019' or {'(' ')' '{' ']' '%' '*' '\"' '\\'} 
),ArraySeq()))))),ArraySeq()))))"
            |}""".stripMargin)
   }
 
@@ -3366,7 +3368,7 @@ trait EmailSetMethodContract {
         s"""{
            |  "${messageId.serialize}":{
            |      "type":"invalidPatch",
-           |      "description":"Message 1 update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(Does not allow to update 'Deleted' or 
'Recent' flag),ArraySeq()))))),ArraySeq()))))"}
+           |      "description":"Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords is invalid: 
List((,List(JsonValidationError(List(Does not allow to update 'Deleted' or 
'Recent' flag),ArraySeq()))))),ArraySeq()))))"}
            |  }
            |}"""
           .stripMargin)
@@ -3507,10 +3509,10 @@ trait EmailSetMethodContract {
 
     assertThatJson(response)
      .inPath("methodResponses[0][1].notUpdated")
-     .isEqualTo("""{
+     .isEqualTo(s"""{
         | "invalid": {
         |     "type":"invalidPatch",
-        |     "description":"Message invalid update is invalid: For input 
string: \"invalid\""
+        |     "description":"Message update is invalid: 
${invalidMessageIdMessage("invalid")}"
         | }
         |}""".stripMargin)
   }
@@ -4122,7 +4124,7 @@ trait EmailSetMethodContract {
       .isEqualTo(s"""{
           |  "${messageId.serialize}": {
           |     "type": "invalidPatch",
-          |     "description": "Message 1 update is invalid: Partial update 
and reset specified for keywords"
+          |     "description": "Message update is invalid: Partial update and 
reset specified for keywords"
           |   }
           |}
       """.stripMargin)
@@ -4172,7 +4174,7 @@ trait EmailSetMethodContract {
       .isEqualTo(
         """|{
            |   "type":"invalidPatch",
-           |   "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(keywords/mus*c is an invalid entry in an 
Email/set update patch: FlagName must not be null or empty, must have length 
form 1-255,must not contain characters with hex from '\\u0000' to '\\u00019' or 
{'(' ')' '{' ']' '%' '*' '\"' '\\'} ),ArraySeq()))))"}"
+           |   "description": "Message update is invalid: 
List((,List(JsonValidationError(List(keywords/mus*c is an invalid entry in an 
Email/set update patch: FlagName must not be null or empty, must have length 
form 1-255,must not contain characters with hex from '\\u0000' to '\\u00019' or 
{'(' ')' '{' ']' '%' '*' '\"' '\\'} ),ArraySeq()))))"}"
            |}""".stripMargin)
   }
 
@@ -4219,9 +4221,9 @@ trait EmailSetMethodContract {
     assertThatJson(response)
       .inPath(s"methodResponses[0][1].notUpdated.${messageId.serialize}")
       .isEqualTo(
-        """|{
+        s"""|{
           |   "type":"invalidPatch",
-          |   "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords/movie is 
invalid: Keywords partial updates requires a JsBoolean(true) (set) or a JsNull 
(unset)),ArraySeq()))))"
+          |   "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with keywords/movie is 
invalid: Keywords partial updates requires a JsBoolean(true) (set) or a JsNull 
(unset)),ArraySeq()))))"
           |}""".stripMargin)
   }
 
@@ -4275,7 +4277,7 @@ trait EmailSetMethodContract {
         s"""{
            |  "${messageId.serialize}":{
            |      "type":"invalidPatch",
-           |      "description":"Message 1 update is invalid: 
List((,List(JsonValidationError(List(Does not allow to update 'Deleted' or 
'Recent' flag),ArraySeq()))))"}
+           |      "description":"Message update is invalid: 
List((,List(JsonValidationError(List(Does not allow to update 'Deleted' or 
'Recent' flag),ArraySeq()))))"}
            |  }
            |}"""
           .stripMargin)
@@ -4375,7 +4377,7 @@ trait EmailSetMethodContract {
          |        "notDestroyed": {
          |          "invalid": {
          |            "type": "invalidArguments",
-         |            "description": "invalid is not a messageId: For input 
string: \\"invalid\\""
+         |            "description": "invalid is not a messageId: 
${invalidMessageIdMessage("invalid")}"
          |          }
          |        }
          |      }, "c1"]]
@@ -4782,9 +4784,9 @@ trait EmailSetMethodContract {
       .inPath("methodResponses[0][1].notUpdated")
       .isEqualTo(
       s"""{
-         |  "1": {
+         |  "${messageId.serialize}": {
          |    "type": "invalidPatch",
-         |    "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(invalid is an invalid entry in an 
Email/set update patch),ArraySeq()))))"
+         |    "description": "Message update is invalid: 
List((,List(JsonValidationError(List(invalid is an invalid entry in an 
Email/set update patch),ArraySeq()))))"
          |  }
          |}""".stripMargin)
   }
@@ -4831,9 +4833,9 @@ trait EmailSetMethodContract {
       .inPath("methodResponses[0][1].notUpdated")
       .isEqualTo(
       s"""{
-         |  "1": {
+         |  "${messageId.serialize}": {
          |    "type": "invalidPatch",
-         |    "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(mailboxIds/invalid is an invalid entry in 
an Email/set update patch: For input string: \\"invalid\\"),ArraySeq()))))"
+         |    "description": "Message update is invalid: 
List((,List(JsonValidationError(List(mailboxIds/invalid is an invalid entry in 
an Email/set update patch: 
${invalidMessageIdMessage("invalid")}),ArraySeq()))))"
          |  }
          |}""".stripMargin)
   }
@@ -4880,9 +4882,9 @@ trait EmailSetMethodContract {
       .inPath("methodResponses[0][1].notUpdated")
       .isEqualTo(
       s"""{
-         |  "1": {
+         |  "${messageId.serialize}": {
          |    "type": "invalidPatch",
-         |    "description": "Message 1 update is invalid: 
List((,List(JsonValidationError(List(Value associated with mailboxIds/1 is 
invalid: MailboxId partial updates requires a JsBoolean(true) (set) or a JsNull 
(unset)),ArraySeq()))))"
+         |    "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with 
mailboxIds/${mailboxId1.serialize} is invalid: MailboxId partial updates 
requires a JsBoolean(true) (set) or a JsNull (unset)),ArraySeq()))))"
          |  }
          |}""".stripMargin)
   }
@@ -4932,9 +4934,9 @@ trait EmailSetMethodContract {
       .inPath("methodResponses[0][1].notUpdated")
       .isEqualTo(
       s"""{
-         |  "1": {
+         |  "${messageId.serialize}": {
          |    "type": "invalidPatch",
-         |    "description": "Message 1 update is invalid: Partial update and 
reset specified for mailboxIds"
+         |    "description": "Message update is invalid: Partial update and 
reset specified for mailboxIds"
          |  }
          |}""".stripMargin)
   }
@@ -4989,7 +4991,7 @@ trait EmailSetMethodContract {
          |        "notDestroyed": {
          |          "invalid": {
          |            "type": "invalidArguments",
-         |            "description": "invalid is not a messageId: For input 
string: \\"invalid\\""
+         |            "description": "invalid is not a messageId: 
${invalidMessageIdMessage("invalid")}"
          |          }
          |        }
          |      }, "c1"]
@@ -5224,9 +5226,9 @@ trait EmailSetMethodContract {
            |          "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
            |          "newState": "000001",
            |          "notUpdated": {
-           |            "1": {
+           |            "${messageId.serialize}": {
            |              "type": "notFound",
-           |              "description": "Cannot find message with messageId: 
1"
+           |              "description": "Cannot find message with messageId: 
${messageId.serialize}"
            |            }
            |          }
            |        }, "c1"]
@@ -5381,7 +5383,7 @@ trait EmailSetMethodContract {
            |        "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
            |        "newState": "000001",
            |        "notUpdated": {
-           |          "1": {
+           |          "${messageId.serialize}": {
            |            "type": "notFound",
            |            "description": "Mailbox not found"
            |          }
@@ -5692,7 +5694,7 @@ trait EmailSetMethodContract {
            |        "notUpdated": {
            |          "${messageId.serialize}": {
            |            "type": "invalidPatch",
-           |            "description": "Message ${messageId.serialize} update 
is invalid: List((,List(JsonValidationError(List(Value associated with 
mailboxIds is invalid: List((,List(JsonValidationError(List(For input string: 
\\"invalid\\"),ArraySeq()))))),ArraySeq()))))"
+           |            "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with mailboxIds is 
invalid: 
List((,List(JsonValidationError(List(${invalidMessageIdMessage("invalid")}),ArraySeq()))))),ArraySeq()))))"
            |          }
            |        }
            |      }, "c1"]
@@ -5753,7 +5755,7 @@ trait EmailSetMethodContract {
            |        "notUpdated": {
            |          "${messageId.serialize}": {
            |            "type": "invalidPatch",
-           |            "description": "Message ${messageId.serialize} update 
is invalid: List((,List(JsonValidationError(List(Value associated with 
mailboxIds is invalid: List((,List(JsonValidationError(List(Expecting mailboxId 
value to be a boolean),ArraySeq()))))),ArraySeq()))))"
+           |            "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with mailboxIds is 
invalid: List((,List(JsonValidationError(List(Expecting mailboxId value to be a 
boolean),ArraySeq()))))),ArraySeq()))))"
            |          }
            |        }
            |      }, "c1"]
@@ -5814,7 +5816,7 @@ trait EmailSetMethodContract {
            |        "notUpdated": {
            |          "${messageId.serialize}": {
            |            "type": "invalidPatch",
-           |            "description": "Message ${messageId.serialize} update 
is invalid: List((,List(JsonValidationError(List(Value associated with 
mailboxIds is invalid: List((,List(JsonValidationError(List(Expecting mailboxId 
value to be a boolean),ArraySeq()))))),ArraySeq()))))"
+           |            "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with mailboxIds is 
invalid: List((,List(JsonValidationError(List(Expecting mailboxId value to be a 
boolean),ArraySeq()))))),ArraySeq()))))"
            |          }
            |        }
            |      }, "c1"]
@@ -5895,7 +5897,7 @@ trait EmailSetMethodContract {
            |        "notUpdated": {
            |          "${messageId2.serialize}": {
            |            "type": "invalidPatch",
-           |            "description": "Message ${messageId2.serialize} update 
is invalid: List((,List(JsonValidationError(List(Value associated with 
mailboxIds is invalid: List((,List(JsonValidationError(List(For input string: 
\\"invalid\\"),ArraySeq()))))),ArraySeq()))))"
+           |            "description": "Message update is invalid: 
List((,List(JsonValidationError(List(Value associated with mailboxIds is 
invalid: 
List((,List(JsonValidationError(List(${invalidMessageIdMessage("invalid")}),ArraySeq()))))),ArraySeq()))))"
            |          }
            |        }
            |      }, "c1"]
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryEmailSetMethodTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryEmailSetMethodTest.java
index cdf72f4..b67b80c 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryEmailSetMethodTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryEmailSetMethodTest.java
@@ -45,4 +45,9 @@ public class MemoryEmailSetMethodTest implements 
EmailSetMethodContract {
     public MessageId randomMessageId() {
         return 
InMemoryMessageId.of(ThreadLocalRandom.current().nextInt(100000) + 100);
     }
+
+    @Override
+    public String invalidMessageIdMessage(String invalid) {
+        return String.format("For input string: \\\"%s\\\"", invalid);
+    }
 }
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetUpdatePerformer.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetUpdatePerformer.scala
index 094f823..c5a71b9 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetUpdatePerformer.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSetUpdatePerformer.scala
@@ -46,7 +46,7 @@ object EmailSetUpdatePerformer {
   case class EmailUpdateSuccess(messageId: MessageId) extends EmailUpdateResult
   case class EmailUpdateFailure(unparsedMessageId: UnparsedMessageId, e: 
Throwable) extends EmailUpdateResult {
     def asMessageSetError: SetError = e match {
-      case e: IllegalArgumentException => 
SetError.invalidPatch(SetErrorDescription(s"Message $unparsedMessageId update 
is invalid: ${e.getMessage}"))
+      case e: IllegalArgumentException => 
SetError.invalidPatch(SetErrorDescription(s"Message update is invalid: 
${e.getMessage}"))
       case _: MailboxNotFoundException => 
SetError.notFound(SetErrorDescription(s"Mailbox not found"))
       case e: MessageNotFoundException => 
SetError.notFound(SetErrorDescription(s"Cannot find message with messageId: 
${e.messageId.serialize()}"))
       case _ => SetError.serverFail(SetErrorDescription(e.getMessage))


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to