vttranlina commented on code in PR #2177:
URL: https://github.com/apache/james-project/pull/2177#discussion_r1560392833


##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/QuotaMailingTest.scala:
##########
@@ -0,0 +1,234 @@
+/****************************************************************
+ * 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 java.nio.charset.StandardCharsets
+import java.util
+import java.util.concurrent.TimeUnit
+
+import com.google.common.base.Strings
+import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured
+import io.restassured.RestAssured.`given`
+import io.restassured.builder.ResponseSpecBuilder
+import org.apache.http.HttpStatus.SC_OK
+import org.apache.james.GuiceJamesServer
+import org.apache.james.core.quota.QuotaSizeLimit
+import org.apache.james.jmap.http.UserCredential
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
ACCOUNT_ID, ANDRE, ANDRE_ACCOUNT_ID, ANDRE_PASSWORD, BOB, BOB_PASSWORD, DOMAIN, 
authScheme, baseRequestSpecBuilder}
+import org.apache.james.jmap.rfc8621.contract.QuotaMailingTest.andreDraftsPath
+import org.apache.james.junit.categories.BasicFeature
+import org.apache.james.mailbox.DefaultMailboxes
+import org.apache.james.mailbox.MessageManager.AppendCommand
+import org.apache.james.mailbox.model.{MailboxConstants, MailboxPath, 
MessageId}
+import org.apache.james.mime4j.dom.Message
+import org.apache.james.modules.{MailboxProbeImpl, QuotaProbesImpl}
+import org.apache.james.utils.DataProbeImpl
+import org.awaitility.Awaitility
+import org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS
+import org.hamcrest.Matchers.{containsString, hasItem}
+import org.junit.experimental.categories.Category
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import scala.jdk.CollectionConverters._
+
+object QuotaMailingTest {
+  private val andreDraftsPath = MailboxPath.forUser(ANDRE, 
DefaultMailboxes.DRAFTS)
+}
+
+trait QuotaMailingTest {
+  private lazy val slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS
+  private lazy val calmlyAwait = Awaitility.`with`
+    .pollInterval(slowPacedPollInterval)
+    .and.`with`.pollDelay(slowPacedPollInterval)
+    .await
+  private lazy val awaitAtMostTwoMinutes = calmlyAwait.atMost(2, 
TimeUnit.MINUTES)
+
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN.asString)
+      .addUser(BOB.asString, BOB_PASSWORD)
+      .addUser(ANDRE.asString, ANDRE_PASSWORD)
+
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, BOB.asString, 
DefaultMailboxes.INBOX)
+    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, 
ANDRE.asString, DefaultMailboxes.INBOX)
+
+    mailboxProbe.createMailbox(andreDraftsPath)
+
+    RestAssured.requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .build
+  }
+
+  @Category(Array(classOf[BasicFeature]))
+  @Test
+  def shouldSendANoticeWhenThresholdExceeded(server: GuiceJamesServer): Unit = 
{
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    quotaProbe.setMaxStorage(quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB)), 
QuotaSizeLimit.size(100 * 1000))
+
+    andreSendMailToBob(server)
+
+    // Bob receives a mail big enough to trigger a configured threshold
+    awaitAtMostTwoMinutes.until(() => listMessageIds().size == 2)
+
+    val ids: List[String] = listMessageIds().asScala.toList
+    val idString: String = concatMessageIds(ids)
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", 
"urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [[
+         |     "Email/get",
+         |     {
+         |       "accountId": "$ACCOUNT_ID",
+         |       "ids": [$idString]
+         |     },
+         |     "c1"]]
+         |}""".stripMargin
+
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post()
+    .`then`
+      .statusCode(SC_OK)
+      .log.ifValidationFails()
+      .body("methodResponses[0][1].list.subject",
+        hasItem("Warning: Your email usage just exceeded a configured 
threshold"))
+  }
+
+  @Test
+  def configurationShouldBeWellLoaded(server: GuiceJamesServer): Unit = {
+    val quotaProbe = server.getProbe(classOf[QuotaProbesImpl])
+    quotaProbe.setMaxStorage(quotaProbe.getQuotaRoot(MailboxPath.inbox(BOB)), 
QuotaSizeLimit.size(100 * 1000))
+
+    andreSendMailToBob(server)
+
+    // Bob receives a mail big enough to trigger a 10% configured threshold
+    awaitAtMostTwoMinutes.until(() => listMessageIds().size == 2)
+
+    andreSendMailToBob(server)
+
+    // Bob receives a mail big enough to trigger a 20% configured threshold
+    awaitAtMostTwoMinutes.until(() => listMessageIds().size == 4)
+    val ids: List[String] = listMessageIds().asScala.toList
+    val idString: String = concatMessageIds(ids)
+
+    val request =
+      s"""{
+         |  "using": ["urn:ietf:params:jmap:core","urn:ietf:params:jmap:mail", 
"urn:ietf:params:jmap:submission"],
+         |  "methodCalls": [[
+         |     "Email/get",
+         |     {
+         |       "accountId": "$ACCOUNT_ID",
+         |       "ids": [$idString]
+         |     },
+         |     "c1"]]
+         |}""".stripMargin
+
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(request)
+    .when
+      .post()
+    .`then`
+      .statusCode(SC_OK)
+      .log.ifValidationFails()
+      .body("methodResponses[0][1].list.preview",

Review Comment:
   Why duplicate check `"methodResponses[0][1].list.preview"` here?
   which one is correct?



##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/VacationIntegrationTest.scala:
##########
@@ -0,0 +1,447 @@
+/****************************************************************
+ * 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 java.nio.charset.StandardCharsets
+import java.util.concurrent.TimeUnit
+
+import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
+import io.restassured.RestAssured
+import io.restassured.RestAssured.`given`
+import io.restassured.builder.ResponseSpecBuilder
+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.core.Username
+import org.apache.james.jmap.JMAPTestingConstants.DOMAIN
+import org.apache.james.jmap.JmapGuiceProbe
+import org.apache.james.jmap.api.model.AccountId
+import org.apache.james.jmap.http.UserCredential
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
ACCOUNT_ID, ANDRE, ANDRE_ACCOUNT_ID, ANDRE_PASSWORD, BOB, BOB_PASSWORD, 
authScheme, baseRequestSpecBuilder}
+import 
org.apache.james.jmap.rfc8621.contract.VacationIntegrationTest.{andreDraftsPath,
 html_reason, original_message_text_body, reason}
+import org.apache.james.junit.categories.BasicFeature
+import org.apache.james.mailbox.DefaultMailboxes
+import org.apache.james.mailbox.MessageManager.AppendCommand
+import org.apache.james.mailbox.model.{MailboxConstants, MailboxId, 
MailboxPath, MessageId}
+import org.apache.james.mime4j.dom.Message
+import org.apache.james.modules.MailboxProbeImpl
+import org.apache.james.utils.DataProbeImpl
+import org.apache.james.vacation.api.VacationPatch
+import org.awaitility.Awaitility
+import org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS
+import org.junit.experimental.categories.Category
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+object VacationIntegrationTest {
+  private val reason = "Message explaining my wonderful vacations"
+  private val html_reason = "<b>" + reason + "</b>"
+  private val original_message_text_body = "Hello someone, and thank you for 
joining example.com!"
+  private val andreDraftsPath = MailboxPath.forUser(ANDRE, 
DefaultMailboxes.DRAFTS)
+}
+
+trait VacationIntegrationTest {
+  private lazy val slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS
+  private lazy val calmlyAwait = Awaitility.`with`
+    .pollInterval(slowPacedPollInterval)
+    .and.`with`.pollDelay(slowPacedPollInterval)
+    .await
+  private lazy val awaitAtMostTenSeconds = calmlyAwait.atMost(10, 
TimeUnit.SECONDS)
+
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN)
+      .addUser(BOB.asString, BOB_PASSWORD)
+      .addUser(ANDRE.asString, ANDRE_PASSWORD)
+
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
+    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, BOB.asString, 
DefaultMailboxes.SENT)
+    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, 
ANDRE.asString, DefaultMailboxes.SENT)
+
+    mailboxProbe.createMailbox(andreDraftsPath)
+
+    RestAssured.requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .build
+  }
+
+  @Category(Array(classOf[BasicFeature]))
+  @Test
+  def jmapVacationShouldGenerateAReplyWhenActive(server: GuiceJamesServer): 
Unit = {
+    /* Test scenario :
+      - bob sets a Vacation on its account
+      - andre [email protected] sends bob a mail
+      - bob should well receive this mail
+      - andre should well receive a notification about bob vacation
+    */
+
+    val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])

Review Comment:
   we can add the code bellow in `@BeforeEach`
   I see it repeat in each test
   
   ```
       val mailboxProbe = server.getProbe(classOf[MailboxProbeImpl])
       val bobInboxId = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, BOB.asString, 
DefaultMailboxes.INBOX)
       val andreInboxId = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ANDRE.asString, 
DefaultMailboxes.INBOX)
   ```



##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CorsHeaderAPITest.scala:
##########
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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
+import io.restassured.RestAssured.`given`
+import org.apache.james.GuiceJamesServer
+import org.apache.james.jmap.JMAPTestingConstants.DOMAIN
+import org.apache.james.jmap.http.UserCredential
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
ACCOUNT_ID, BOB, BOB_PASSWORD, authScheme, baseRequestSpecBuilder}
+import org.apache.james.utils.DataProbeImpl
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+trait CorsHeaderAPITest {
+  @BeforeEach
+  def setUp(server: GuiceJamesServer): Unit = {
+    server.getProbe(classOf[DataProbeImpl])
+      .fluent
+      .addDomain(DOMAIN)
+      .addUser(BOB.asString, BOB_PASSWORD)
+
+    RestAssured.requestSpecification = baseRequestSpecBuilder(server)
+      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .build
+  }
+
+  @Test
+  def apiShouldPositionCorsHeaders(): Unit =
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(s"""{
+               |  "using": [
+               |    "urn:ietf:params:jmap:core",
+               |    "urn:ietf:params:jmap:mail"],
+               |  "methodCalls": [[
+               |    "Mailbox/get",
+               |    {
+               |      "accountId": "$ACCOUNT_ID"
+               |    },
+               |    "c1"]]
+               |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .header("Access-Control-Allow-Origin", "*")
+      .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")

Review Comment:
   Do you think we should update `Access-Control-Allow-Methods` in jmap server?
   I think we just allows:
   - POST: Jmap, upload
   - GET: download
   - OPTIONS: for check cors
   No any use PUT and DELETE



-- 
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