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 2020/12/21 07:29:42 UTC
[james-project] 17/17: JAMES-3481 Move common JMAP methods to a
dedicated object
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 24dc4ec52ec2b57db0c6e145366389f95c3f1236
Author: LanKhuat <dl...@linagora.com>
AuthorDate: Thu Dec 17 16:50:18 2020 +0700
JAMES-3481 Move common JMAP methods to a dedicated object
---
.../james/jmap/rfc8621/contract/JmapRequests.scala | 159 +++++++++++++++++++++
.../contract/MailboxChangesMethodContract.scala | 152 ++------------------
2 files changed, 170 insertions(+), 141 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/JmapRequests.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/JmapRequests.scala
new file mode 100644
index 0000000..2ac3cee
--- /dev/null
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/JmapRequests.scala
@@ -0,0 +1,159 @@
+/****************************************************************
+ * 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.jmap.rfc8621.contract
+
+import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured.`given`
+import io.restassured.http.ContentType.JSON
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.jmap.rfc8621.contract.Fixture.ACCEPT_RFC8621_VERSION_HEADER
+import org.apache.james.mailbox.model.MessageId
+
+object JmapRequests {
+ def renameMailbox(mailboxId: String, name: String): Unit = {
+ val request =
+ s"""
+ |{
+ | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
+ | "methodCalls": [[
+ | "Mailbox/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "update": {
+ | "$mailboxId": {
+ | "name": "$name"
+ | }
+ | }
+ | }, "c1"]
+ | ]
+ |}
+ |""".stripMargin
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ }
+
+ def destroyMailbox(mailboxId: String): Unit = {
+ val request =
+ s"""
+ |{
+ | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
+ | "methodCalls": [[
+ | "Mailbox/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "destroy": ["$mailboxId"]
+ | }, "c1"]
+ | ]
+ |}
+ |""".stripMargin
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ }
+
+ def markEmailAsSeen(messageId: MessageId): Unit = {
+ val request = String.format(
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [
+ | ["Email/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "update": {
+ | "${messageId.serialize}": {
+ | "keywords": {
+ | "$$seen": true
+ | }
+ | }
+ | }
+ | }, "c1"]]
+ |}""".stripMargin)
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ }
+
+ def markEmailAsNotSeen(messageId: MessageId): Unit = {
+ val request = String.format(
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [
+ | ["Email/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "update": {
+ | "${messageId.serialize}": {
+ | "keywords/$$seen": null
+ | }
+ | }
+ | }, "c1"]]
+ |}""".stripMargin)
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ }
+
+ def destroyEmail(messageId: MessageId): Unit = {
+ val request = String.format(
+ s"""{
+ | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
+ | "methodCalls": [
+ | ["Email/set", {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "destroy": ["${messageId.serialize}"]
+ | }, "c1"]]
+ |}""".stripMargin)
+
+ `given`
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .body(request)
+ .when
+ .post
+ .`then`
+ .log().ifValidationFails()
+ .statusCode(SC_OK)
+ .contentType(JSON)
+ }
+}
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 c230dd5..36cdfad 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
@@ -154,7 +154,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, BOB)
- renameMailbox(mailboxId, "mailbox11")
+ JmapRequests.renameMailbox(mailboxId, "mailbox11")
val request =
s"""{
@@ -284,7 +284,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, BOB)
- markEmailAsSeen(messageId)
+ JmapRequests.markEmailAsSeen(messageId)
val request =
s"""{
@@ -352,7 +352,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, BOB)
- markEmailAsNotSeen(messageId)
+ JmapRequests.markEmailAsNotSeen(messageId)
val request =
s"""{
@@ -418,7 +418,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, BOB)
- destroyEmail(messageId)
+ JmapRequests.destroyEmail(messageId)
val request =
s"""{
@@ -551,7 +551,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- renameMailbox(mailboxId, "mailbox11")
+ JmapRequests.renameMailbox(mailboxId, "mailbox11")
val request =
s"""{
@@ -622,7 +622,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- markEmailAsSeen(messageId)
+ JmapRequests.markEmailAsSeen(messageId)
val request =
s"""{
@@ -692,7 +692,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- markEmailAsNotSeen(messageId)
+ JmapRequests.markEmailAsNotSeen(messageId)
val request =
s"""{
@@ -763,7 +763,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- destroyEmail(messageId)
+ JmapRequests.destroyEmail(messageId)
val request =
s"""{
@@ -834,7 +834,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- destroyEmail(messageId)
+ JmapRequests.destroyEmail(messageId)
val request =
s"""{
@@ -899,7 +899,7 @@ trait MailboxChangesMethodContract {
val oldState: State = storeReferenceState(server, ANDRE)
- destroyMailbox(mailboxId)
+ JmapRequests.destroyMailbox(mailboxId)
val request =
s"""{
@@ -1032,7 +1032,7 @@ trait MailboxChangesMethodContract {
val mailboxId2: String = mailboxProbe
.createMailbox(path2)
.serialize
- renameMailbox(mailboxId2, "mailbox22")
+ JmapRequests.renameMailbox(mailboxId2, "mailbox22")
server.getProbe(classOf[MailboxProbeImpl])
.deleteMailbox(path1.getNamespace, BOB.asString(), path1.getName)
@@ -1416,136 +1416,6 @@ trait MailboxChangesMethodContract {
|}""".stripMargin)
}
- private def renameMailbox(mailboxId: String, name: String): Unit = {
- val request =
- s"""
- |{
- | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
- | "methodCalls": [[
- | "Mailbox/set", {
- | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
- | "update": {
- | "$mailboxId": {
- | "name": "$name"
- | }
- | }
- | }, "c1"]
- | ]
- |}
- |""".stripMargin
-
- `given`
- .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
- .body(request)
- .when
- .post
- .`then`
- .log().ifValidationFails()
- .statusCode(SC_OK)
- .contentType(JSON)
- }
-
- private def destroyMailbox(mailboxId: String): Unit = {
- val request =
- s"""
- |{
- | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
- | "methodCalls": [[
- | "Mailbox/set", {
- | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
- | "destroy": ["$mailboxId"]
- | }, "c1"]
- | ]
- |}
- |""".stripMargin
-
- `given`
- .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
- .body(request)
- .when
- .post
- .`then`
- .log().ifValidationFails()
- .statusCode(SC_OK)
- .contentType(JSON)
- }
-
- private def markEmailAsSeen(messageId: MessageId): Unit = {
- val request = String.format(
- s"""{
- | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
- | "methodCalls": [
- | ["Email/set", {
- | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
- | "update": {
- | "${messageId.serialize}": {
- | "keywords": {
- | "$$seen": true
- | }
- | }
- | }
- | }, "c1"]]
- |}""".stripMargin)
-
- `given`
- .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
- .body(request)
- .when
- .post
- .`then`
- .log().ifValidationFails()
- .statusCode(SC_OK)
- .contentType(JSON)
- }
-
- private def markEmailAsNotSeen(messageId: MessageId): Unit = {
- val request = String.format(
- s"""{
- | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
- | "methodCalls": [
- | ["Email/set", {
- | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
- | "update": {
- | "${messageId.serialize}": {
- | "keywords/$$seen": null
- | }
- | }
- | }, "c1"]]
- |}""".stripMargin)
-
- `given`
- .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
- .body(request)
- .when
- .post
- .`then`
- .log().ifValidationFails()
- .statusCode(SC_OK)
- .contentType(JSON)
- }
-
- private def destroyEmail(messageId: MessageId): Unit = {
- val request = String.format(
- s"""{
- | "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
- | "methodCalls": [
- | ["Email/set", {
- | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
- | "destroy": ["${messageId.serialize}"]
- | }, "c1"]]
- |}""".stripMargin)
-
- `given`
- .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
- .body(request)
- .when
- .post
- .`then`
- .log().ifValidationFails()
- .statusCode(SC_OK)
- .contentType(JSON)
- }
-
private def storeReferenceState(server: GuiceJamesServer, username: Username): State = {
val state: State = stateFactory.generate()
val jmapGuiceProbe: JmapGuiceProbe = server.getProbe(classOf[JmapGuiceProbe])
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org