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 8cbc6712c94d2948a53464b49e828853d87accfe Author: Rémi Kowalski <[email protected]> AuthorDate: Wed Jul 15 15:07:13 2020 +0200 JAMES-3098 add tests for mailbox/get with properties filtering --- .../contract/MailboxGetMethodContract.scala | 280 ++++++++++++++++++++- 1 file changed, 279 insertions(+), 1 deletion(-) 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/MailboxGetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala index e5e9b1f..3f51a4b 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala @@ -41,7 +41,7 @@ import org.apache.james.mime4j.dom.Message import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl, QuotaProbesImpl} import org.apache.james.utils.DataProbeImpl import org.hamcrest.Matchers._ -import org.junit.jupiter.api.{BeforeEach, Tag, Test} +import org.junit.jupiter.api.{BeforeEach, Disabled, Tag, Test} object MailboxGetMethodContract { private val ARGUMENTS: String = "methodResponses[0][1]" @@ -66,6 +66,66 @@ object MailboxGetMethodContract { | "c1"]] |}""".stripMargin + private val GET_ALL_MAILBOXES_REQUEST_NULL_PROPERTIES: String = + """{ + | "using": [ + | "urn:ietf:params:jmap:core", + | "urn:ietf:params:jmap:mail"], + | "methodCalls": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "properties": null, + | "ids": null + | }, + | "c1"]] + |}""".stripMargin + + private val GET_ALL_MAILBOXES_REQUEST_NAME_AND_ID_PROPERTIES: String = + """{ + | "using": [ + | "urn:ietf:params:jmap:core", + | "urn:ietf:params:jmap:mail"], + | "methodCalls": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "properties": ["id", "name"], + | "ids": null + | }, + | "c1"]] + |}""".stripMargin + + private val GET_ALL_MAILBOXES_REQUEST_NAME_PROPERTIES: String = + """{ + | "using": [ + | "urn:ietf:params:jmap:core", + | "urn:ietf:params:jmap:mail"], + | "methodCalls": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "properties": ["name"], + | "ids": null + | }, + | "c1"]] + |}""".stripMargin + + private val GET_ALL_MAILBOXES_REQUEST_INVALID_PROPERTIES: String = + """{ + | "using": [ + | "urn:ietf:params:jmap:core", + | "urn:ietf:params:jmap:mail"], + | "methodCalls": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "properties": ["invalidProperty"], + | "ids": null + | }, + | "c1"]] + |}""".stripMargin + private val GET_ALL_MAILBOXES_REQUEST_WITH_QUOTA: String = """{ | "using": [ @@ -368,6 +428,224 @@ trait MailboxGetMethodContract { } @Test + def getMailboxesShouldReturnAllPropertiesWhenNotSupplied(server: GuiceJamesServer): Unit = { + val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl]) + .createMailbox(MailboxPath.forUser(BOB, "custom")) + .serialize + + val response: String = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(GET_ALL_MAILBOXES_REQUEST) + .when + .post + .`then` + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "state": "000001", + | "list": [ + | { + | "id": "${mailboxId}", + | "name": "custom", + | "sortOrder": 1000, + | "totalEmails": 0, + | "unreadEmails": 0, + | "totalThreads": 0, + | "unreadThreads": 0, + | "myRights": { + | "mayReadItems": true, + | "mayAddItems": true, + | "mayRemoveItems": true, + | "maySetSeen": true, + | "maySetKeywords": true, + | "mayCreateChild": true, + | "mayRename": true, + | "mayDelete": true, + | "maySubmit": true + | }, + | "isSubscribed": false + | } + | ], + | "notFound": [] + | }, + | "c1"]] + |}""".stripMargin) + } + + @Test + def getMailboxesShouldReturnAllPropertiesWhenNull(server: GuiceJamesServer): Unit = { + val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl]) + .createMailbox(MailboxPath.forUser(BOB, "custom")) + .serialize + + val response: String = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(GET_ALL_MAILBOXES_REQUEST_NULL_PROPERTIES) + .when + .post + .`then` + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "state": "000001", + | "list": [ + | { + | "id": "${mailboxId}", + | "name": "custom", + | "sortOrder": 1000, + | "totalEmails": 0, + | "unreadEmails": 0, + | "totalThreads": 0, + | "unreadThreads": 0, + | "myRights": { + | "mayReadItems": true, + | "mayAddItems": true, + | "mayRemoveItems": true, + | "maySetSeen": true, + | "maySetKeywords": true, + | "mayCreateChild": true, + | "mayRename": true, + | "mayDelete": true, + | "maySubmit": true + | }, + | "isSubscribed": false + | } + | ], + | "notFound": [] + | }, + | "c1"]] + |}""".stripMargin) + } + + @Disabled("TODO") + @Test + def getMailboxesShouldReturnOnlyNameAndIdWhenPropertiesRequested(server: GuiceJamesServer): Unit = { + val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl]) + .createMailbox(MailboxPath.forUser(BOB, "custom")) + .serialize + + val response: String = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(GET_ALL_MAILBOXES_REQUEST_NAME_AND_ID_PROPERTIES) + .when + .post + .`then` + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "state": "000001", + | "list": [ + | { + | "id": "${mailboxId}", + | "name": "custom" + | } + | ], + | "notFound": [] + | }, + | "c1"]] + |}""".stripMargin) + } + + @Disabled("TODO") + @Test + def getMailboxesShouldAlwaysReturnIdEvenIfNotRequested(server: GuiceJamesServer): Unit = { + val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl]) + .createMailbox(MailboxPath.forUser(BOB, "custom")) + .serialize + + val response: String = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(GET_ALL_MAILBOXES_REQUEST_NAME_PROPERTIES) + .when + .post + .`then` + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "Mailbox/get", + | { + | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + | "state": "000001", + | "list": [ + | { + | "id": "${mailboxId}", + | "name": "custom" + | } + | ], + | "notFound": [] + | }, + | "c1"]] + |}""".stripMargin) + } + + @Disabled("TODO") + @Test + def getMailboxesShouldReturnInvalidArgumentsErrorWhenInvalidProperty(server: GuiceJamesServer): Unit = { + server.getProbe(classOf[MailboxProbeImpl]) + .createMailbox(MailboxPath.forUser(BOB, "custom")) + + val response: String = `given` + .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .body(GET_ALL_MAILBOXES_REQUEST_INVALID_PROPERTIES) + .when + .post + .`then` + .statusCode(SC_OK) + .contentType(JSON) + .extract + .body + .asString + + assertThatJson(response).isEqualTo( + s"""{ + | "sessionState": "75128aab4b1b", + | "methodResponses": [[ + | "error", { + | "type": "invalidArguments", + | "description": "The following properties [invalidProperty] do not exist" + |}, + | "c1"]] + |}""".stripMargin) + } + + @Test @Tag(CategoryTags.BASIC_FEATURE) def getMailboxesShouldReturnEmptyWhenNone(): Unit = { `given` --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
