You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/04/02 01:29:57 UTC

[james-project] 01/03: JAMES-3481 s/maxChanged/maxChanges/

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

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

commit b695254f24c7ef2bc4da762c0fcb7ea8d62f4156
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Mar 31 17:07:58 2021 +0700

    JAMES-3481 s/maxChanged/maxChanges/
---
 .../contract/MailboxChangesMethodContract.scala    | 77 ++++++++++++++++++++++
 .../org/apache/james/jmap/mail/MailboxGet.scala    |  2 +-
 .../james/jmap/method/MailboxChangesMethod.scala   |  6 +-
 3 files changed, 81 insertions(+), 4 deletions(-)

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/MailboxChangesMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
index e0a0aa1..f4cdb93 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxChangesMethodContract.scala
@@ -1277,6 +1277,83 @@ trait MailboxChangesMethodContract {
   }
 
   @Test
+  def maxChangesShouldBeTakenIntoAccount(server: GuiceJamesServer): Unit = {
+    val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl])
+
+    val provisioningState: State = provisionSystemMailboxes(server)
+
+    val mailboxId1: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox1"))
+      .serialize
+
+    val mailboxId2: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox2"))
+      .serialize
+
+    val mailboxId3: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox3"))
+      .serialize
+
+    val mailboxId4: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox4"))
+      .serialize
+
+    val mailboxId5: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox5"))
+      .serialize
+
+    val mailboxId6: String = mailboxProbe
+      .createMailbox(MailboxPath.forUser(BOB, "mailbox6"))
+      .serialize
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+         |  "methodCalls": [[
+         |    "Mailbox/changes",
+         |    {
+         |      "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |      "sinceState": "${provisioningState.getValue}",
+         |      "maxChanges": 38
+         |    },
+         |    "c1"]]
+         |}""".stripMargin
+
+    awaitAtMostTenSeconds.untilAsserted { () =>
+      val response = `given`
+        .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+        .body(request)
+      .when
+        .post
+      .`then`
+        .statusCode(SC_OK)
+        .contentType(JSON)
+        .extract
+        .body
+        .asString
+
+      assertThatJson(response)
+        .whenIgnoringPaths("methodResponses[0][1].newState")
+        .withOptions(new Options(IGNORING_ARRAY_ORDER))
+        .isEqualTo(
+          s"""{
+             |    "sessionState": "${SESSION_STATE.value}",
+             |    "methodResponses": [
+             |      [ "Mailbox/changes", {
+             |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+             |        "oldState": "${provisioningState.getValue}",
+             |        "hasMoreChanges": false,
+             |        "updatedProperties": null,
+             |        "created": ["$mailboxId1", "$mailboxId2", "$mailboxId3", "$mailboxId4", "$mailboxId5", "$mailboxId6"],
+             |        "updated": [],
+             |        "destroyed": []
+             |      }, "c1"]
+             |    ]
+             |}""".stripMargin)
+    }
+  }
+
+  @Test
   def mailboxChangesShouldFailWhenAccountIdNotFound(server: GuiceJamesServer): Unit = {
     val jmapGuiceProbe:JmapGuiceProbe = server.getProbe(classOf[JmapGuiceProbe])
     val oldState: State = jmapGuiceProbe.getLatestMailboxState(AccountId.fromUsername(BOB))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
index 7f9fd33..37bf418 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxGet.scala
@@ -75,7 +75,7 @@ case class HasMoreChanges(value: Boolean) extends AnyVal
 
 case class MailboxChangesRequest(accountId: AccountId,
                                  sinceState: State,
-                                 maxChanged: Option[Limit]) extends WithAccountId
+                                 maxChanges: Option[Limit]) extends WithAccountId
 
 case class MailboxChangesResponse(accountId: AccountId,
                                   oldState: State,
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
index 9fb7c6c..d96361b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxChangesMethod.scala
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.method
 
 import eu.timepit.refined.auto._
+import javax.inject.Inject
 import org.apache.james.jmap.api.change.{MailboxChangeRepository, MailboxChanges, State => JavaState}
 import org.apache.james.jmap.api.model.{AccountId => JavaAccountId}
 import org.apache.james.jmap.core.CapabilityIdentifier.{CapabilityIdentifier, JMAP_MAIL}
@@ -34,7 +35,6 @@ import org.apache.james.metrics.api.MetricFactory
 import play.api.libs.json.{JsError, JsSuccess}
 import reactor.core.scala.publisher.SMono
 
-import javax.inject.Inject
 import scala.jdk.CollectionConverters._
 import scala.jdk.OptionConverters._
 
@@ -54,9 +54,9 @@ class MailboxChangesMethod @Inject()(mailboxSerializer: MailboxSerializer,
       val accountId: JavaAccountId = JavaAccountId.fromUsername(mailboxSession.getUser)
       val state: JavaState = JavaState.of(request.sinceState.value)
       if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
-        mailboxChangeRepository.getSinceStateWithDelegation(accountId, state, request.maxChanged.toJava)
+        mailboxChangeRepository.getSinceStateWithDelegation(accountId, state, request.maxChanges.toJava)
       } else {
-        mailboxChangeRepository.getSinceState(accountId, state, request.maxChanged.toJava)
+        mailboxChangeRepository.getSinceState(accountId, state, request.maxChanges.toJava)
       }})
       .map(mailboxChanges => MailboxChangesResponse(
         accountId = request.accountId,

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