chibenwa commented on a change in pull request #752:
URL: https://github.com/apache/james-project/pull/752#discussion_r753986522



##########
File path: 
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/IdentitySetContract.scala
##########
@@ -0,0 +1,618 @@
+/****************************************************************
+ * 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`, requestSpecification}
+import io.restassured.http.ContentType.JSON
+import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.GuiceJamesServer
+import org.apache.james.jmap.core.ResponseObject.SESSION_STATE
+import org.apache.james.jmap.core.UuidState.INSTANCE
+import org.apache.james.jmap.http.UserCredential
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
BOB, BOB_PASSWORD, DOMAIN, authScheme, baseRequestSpecBuilder}
+import org.apache.james.utils.DataProbeImpl
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+trait IdentitySetContract {
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN.asString)
+      .addDomain("domain-alias.tld")
+      .addUser(BOB.asString, BOB_PASSWORD)
+
+    requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .build
+  }
+
+  @Test
+  def setIdentityShouldSucceed(): Unit = {
+    val request =
+      s"""{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                             "create": {
+         |                                     "4f29": {
+         |                                             "name": "Bob",
+         |                                             "email": 
"[email protected]",
+         |                                             "replyTo": [{
+         |                                                     "name": "Alice",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "bcc": [{
+         |                                                     "name": "David",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "textSignature": "Some 
text signature",
+         |                                             "htmlSignature": 
"<p>Some html signature</p>"
+         |                                     }
+         |                             }
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    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)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s"""{
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "${INSTANCE.serialize}",
+           |   "created": {
+           |           "4f29": {
+           |
+           |           }
+           |   }
+           |}""".stripMargin)
+  }
+
+  @Test
+  def 
setIdentityWithSomePropertiesOmittedShouldSucceedAndReturnDefaultValues(): Unit 
= {
+    val request =
+      s"""{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                             "create": {
+         |                                     "4f29": {
+         |                                             "email": 
"[email protected]"
+         |                                     }
+         |                             }
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    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)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s"""{
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "${INSTANCE.serialize}",
+           |   "created": {
+           |           "4f29": {
+           |                   "name": "",
+           |                   "textSignature": "",
+           |                   "htmlSignature": ""
+           |           }
+           |   }
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldCreatedSeveralValidCreationRequest(): Unit = {
+    val request: String =
+      """{
+        |      "using": ["urn:ietf:params:jmap:core"],
+        |      "methodCalls": [
+        |              [
+        |                      "Identity/set",
+        |                      {
+        |                              "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+        |                              "create": {
+        |                                      "4f28": {
+        |                                              "name": "Identity1",
+        |                                              "email": 
"[email protected]",
+        |                                              "replyTo": [{
+        |                                                      "name": "Alice",
+        |                                                      "email": 
"[email protected]"
+        |                                              }],
+        |                                              "bcc": [{
+        |                                                      "name": "David",
+        |                                                      "email": 
"[email protected]"
+        |                                              }],
+        |                                              "textSignature": "Some 
text signature",
+        |                                              "htmlSignature": 
"<p>Some html signature</p>"
+        |                                      },
+        |                                      "4f29": {
+        |                                              "name": "Identity2",
+        |                                              "email": 
"[email protected]",
+        |                                              "replyTo": null,
+        |                                              "bcc": null,
+        |                                              "textSignature": "Some 
text signature",
+        |                                              "htmlSignature": 
"<p>Some html signature</p>"
+        |                                      }
+        |                              }
+        |                      },
+        |                      "c1"
+        |              ]
+        |      ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s""" {
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "created": {
+           |           "4f28": {
+           |
+           |           },
+           |           "4f29": {
+           |
+           |           }
+           |   }
+           | }""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldReturnForbiddenFromErrorWhenForbiddenEmailProperty(): 
Unit = {
+    val request: String =
+      """{
+        |      "using": ["urn:ietf:params:jmap:core"],
+        |      "methodCalls": [
+        |              [
+        |                      "Identity/set",
+        |                      {
+        |                              "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+        |                              "create": {
+        |                                      "4f28": {
+        |                                              "name": "valid send 
from identity",
+        |                                              "email": 
"[email protected]"
+        |                                      },
+        |                                      "4f29": {
+        |                                              "name": "forbidden send 
from identity",
+        |                                              "email": 
"[email protected]"
+        |                                      }
+        |                              }
+        |                      },
+        |                      "c1"
+        |              ]
+        |      ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s""" {
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "created": {
+           |           "4f28": {
+           |                   "textSignature": "",
+           |                   "htmlSignature": ""
+           |           }
+           |   },
+           |   "notCreated": [
+           |           [
+           |                   "4f29",
+           |                   {
+           |                           "type": "forbiddenFrom",
+           |                           "description": "Can not send from 
[email protected]"
+           |                   }
+           |           ]
+           |   ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldSucceedWhenValidEmailProperty(server: 
GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl]).addUserAliasMapping("bob-alias", 
"domain.tld", "[email protected]")
+
+    val request: String =
+      """{
+        |      "using": ["urn:ietf:params:jmap:core"],
+        |      "methodCalls": [
+        |              [
+        |                      "Identity/set",
+        |                      {
+        |                              "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+        |                              "create": {
+        |                                      "4f28": {
+        |                                              "name": "valid send 
from identity",
+        |                                              "email": 
"[email protected]"
+        |                                      },
+        |                                      "4f29": {
+        |                                              "name": "valid send 
from identity",
+        |                                              "email": 
"[email protected]"
+        |                                      }
+        |                              }
+        |                      },
+        |                      "c1"
+        |              ]
+        |      ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .body(request)
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s""" {
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "created": {
+           |           "4f28": {
+           |                   "textSignature": "",
+           |                   "htmlSignature": ""
+           |           },
+           |           "4f29": {
+           |                   "textSignature": "",
+           |                   "htmlSignature": ""
+           |           }
+           |   }
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldFailWhenEmailPropertyIsMissing(): Unit = {
+    val request =
+      s"""{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                             "create": {
+         |                                     "4f29": {
+         |                                             "name": "Bob",
+         |                                             "replyTo": [{
+         |                                                     "name": "Alice",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "bcc": [{
+         |                                                     "name": "David",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "textSignature": "Some 
text signature",
+         |                                             "htmlSignature": 
"<p>Some html signature</p>"
+         |                                     }
+         |                             }
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    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)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s"""{
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "notCreated": [
+           |           [
+           |                   "4f29",
+           |                   {
+           |                           "type": "invalidArguments",
+           |                           "description": "Missing '/email' 
property in Identity object"
+           |                   }
+           |           ]
+           |   ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldFailWhenEmailPropertyIsNull(): Unit = {
+    val request =
+      s"""{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                             "create": {
+         |                                     "4f29": {
+         |                                             "name": "Bob",
+         |                                             "email": null,
+         |                                             "replyTo": [{
+         |                                                     "name": "Alice",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "bcc": [{
+         |                                                     "name": "David",
+         |                                                     "email": 
"[email protected]"
+         |                                             }],
+         |                                             "textSignature": "Some 
text signature",
+         |                                             "htmlSignature": 
"<p>Some html signature</p>"
+         |                                     }
+         |                             }
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    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)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s"""{
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "notCreated": [
+           |           [
+           |                   "4f29",
+           |                   {
+           |                           "type": "invalidArguments",
+           |                           "description": "'/email' property in 
Identity object is not valid: mail address needs to be represented with a 
JsString"
+           |                   }
+           |           ]
+           |   ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldNotCreatedWhenCreationRequestHasServerSetProperty(): 
Unit = {
+    val request =
+      s"""{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+         |                             "create": {
+         |                                     "4f29": {
+         |                                             "id": "someId",
+         |            "mayDelete": false,
+         |                                             "email": 
"[email protected]"
+         |                                     }
+         |                             }
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    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)
+      .inPath("methodResponses[0][1]")
+      .isEqualTo(
+        s"""{
+           |   "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+           |   "newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
+           |   "notCreated": [
+           |           [
+           |                   "4f29",
+           |                   {
+           |                           "type": "invalidArguments",
+           |                           "description": "Some server-set 
properties were specified",
+           |                           "properties": [
+           |                                   "id",
+           |                                   "mayDelete"
+           |                           ]
+           |                   }
+           |           ]
+           |   ]
+           |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldFailWhenWrongAccountId(): Unit = {
+    val request =
+      s"""
+         |{
+         |     "using": ["urn:ietf:params:jmap:core"],
+         |     "methodCalls": [
+         |             [
+         |                     "Identity/set",
+         |                     {
+         |                             "accountId": "unknownAccountId",
+         |                             "create": {}
+         |                     },
+         |                     "c1"
+         |             ]
+         |     ]
+         |}""".stripMargin
+
+    val response =  `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .log().ifValidationFails()
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response).isEqualTo(
+      s"""{
+         |  "sessionState": "${SESSION_STATE.value}",
+         |  "methodResponses": [
+         |    ["error", {
+         |      "type": "accountNotFound"
+         |    }, "c1"]
+         |  ]
+         |}""".stripMargin)
+  }
+
+  @Test
+  def setIdentityShouldFailWhenMissingCapability(): Unit = {
+    val request: String =
+      """{
+        |      "using": [],
+        |      "methodCalls": [
+        |              [
+        |                      "Identity/set",
+        |                      {
+        |                              "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+        |                              "create": {
+        |                                      "4f29": {
+        |                                              "email": 
"[email protected]"
+        |                                      }
+        |                              }
+        |                      },
+        |                      "c1"
+        |              ]
+        |      ]
+        |}""".stripMargin
+
+    val response: String = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .contentType(JSON)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .isEqualTo(
+        s"""{
+           |    "sessionState": "${SESSION_STATE.value}",
+           |    "methodResponses": [
+           |        [
+           |            "error",
+           |            {
+           |                "type": "unknownMethod",
+           |                "description": "Missing capability(ies): 
urn:ietf:params:jmap:core"
+           |            },
+           |            "c1"
+           |        ]
+           |    ]
+           |}""".stripMargin)
+  }
+
+}

Review comment:
       This test `Identity/set create af29 + Identity/get #af29` is not 
implemented as far as I can see




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to