You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rc...@apache.org on 2020/07/17 10:24:09 UTC

[james-project] branch master updated (0967b65 -> 8da802e)

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

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 0967b65  [RELEASE] git-commit-id-plugin should not fail when no git directory
     new f78a914  [Refactoring] Migrate MailboxCopierTest to JUnit5
     new e8d9def  [Refactoring] Migrate JpaMigratorTest to JUnit5
     new 7475d71  [Refactoring] Migrate PDFTextExtractorTest to JUnit5
     new 95fd894  [Refactoring] Migrate SpringMailboxTest to JUnit5
     new 8cbc671  JAMES-3098 add tests for mailbox/get with properties filtering
     new 9b1c388  JAMES-3098 filter properties from response
     new a8b7894  JAMES-3098 return error if invalid property requested
     new c338d0f  [REFACTORING] Remove unused method argument
     new 8da802e  JAMES-3309 Avoid a NPE in FetchProcessor when SelectedMailbox is unselected

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../mailbox/store/search/PDFTextExtractorTest.java |  20 +-
 .../james/mailbox/spring/SpringMailboxTest.java    |  16 +-
 .../mailbox/tools/copier/MailboxCopierTest.java    |  21 +-
 .../tools/jpa/migrator/JpaMigratorTest.java        |  20 +-
 .../james/imap/processor/fetch/FetchProcessor.java |  11 +-
 .../imap/processor/fetch/FetchResponseBuilder.java |  22 +-
 .../contract/MailboxGetMethodContract.scala        | 381 +++++++++++++++++++++
 .../org/apache/james/jmap/json/Serializer.scala    |  19 +-
 .../scala/org/apache/james/jmap/mail/Mailbox.scala |  25 +-
 .../org/apache/james/jmap/mail/MailboxGet.scala    |   5 +-
 .../james/jmap/method/MailboxGetMethod.scala       |  34 +-
 .../org/apache/james/jmap/model/Invocation.scala   |  20 ++
 .../jmap/json/MailboxGetSerializationTest.scala    |   4 +-
 .../james/jmap/json/MailboxSerializationTest.scala |   3 +-
 14 files changed, 510 insertions(+), 91 deletions(-)


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


[james-project] 09/09: JAMES-3309 Avoid a NPE in FetchProcessor when SelectedMailbox is unselected

Posted by rc...@apache.org.
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 8da802ebbb0d6a721529127572da7a88e2f2903b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jul 16 12:20:47 2020 +0700

    JAMES-3309 Avoid a NPE in FetchProcessor when SelectedMailbox is unselected
    
    It turns out ImapSession::getSelectedMailbox can return null when the mailbox is deselected.
    
    Furthermore, data races can occurs upon selected mailbox switches.
    
    In FetchReponseBuilder we need to rely on the mailbox selected when the command was first issued.
---
 .../james/imap/processor/fetch/FetchProcessor.java |  7 +++++--
 .../imap/processor/fetch/FetchResponseBuilder.java | 22 ++++++++--------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index 4500155..f60bc02 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -32,6 +32,7 @@ import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.api.process.SelectedMailbox;
 import org.apache.james.imap.message.request.FetchRequest;
 import org.apache.james.imap.message.response.FetchResponse;
 import org.apache.james.imap.processor.AbstractMailboxProcessor;
@@ -159,6 +160,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
     }
 
     private void processMessageRangeForFlags(ImapSession session, MessageManager mailbox, FetchData fetch, MailboxSession mailboxSession, Responder responder, FetchResponseBuilder builder, MessageRange range) {
+        SelectedMailbox selected = session.getSelected();
         Iterator<ComposedMessageIdWithMetaData> results = Flux.from(mailbox.listMessagesMetadata(range, mailboxSession))
             .filter(ids -> !fetch.contains(Item.MODSEQ) || ids.getModSeq().asLong() > fetch.getChangedSince())
             .toStream()
@@ -168,7 +170,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
             ComposedMessageIdWithMetaData result = results.next();
 
             try {
-                final FetchResponse response = builder.build(fetch, result, mailbox, session);
+                final FetchResponse response = builder.build(fetch, result, mailbox, selected, mailboxSession);
                 responder.respond(response);
             } catch (MessageRangeException e) {
                 // we can't for whatever reason find the message so
@@ -186,6 +188,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
 
     private void processMessageRange(ImapSession session, MessageManager mailbox, FetchData fetch, MailboxSession mailboxSession, Responder responder, FetchResponseBuilder builder, FetchGroup resultToFetch, MessageRange range) throws MailboxException {
         MessageResultIterator messages = mailbox.getMessages(range, resultToFetch, mailboxSession);
+        SelectedMailbox selected = session.getSelected();
         while (messages.hasNext()) {
             final MessageResult result = messages.next();
 
@@ -195,7 +198,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
             }
 
             try {
-                final FetchResponse response = builder.build(fetch, result, mailbox, session);
+                final FetchResponse response = builder.build(fetch, result, mailbox, selected, mailboxSession);
                 responder.respond(response);
             } catch (MessageRangeException e) {
                 // we can't for whatever reason find the message so
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index 3674f68..fc26dd6 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -37,7 +37,6 @@ import org.apache.james.imap.api.message.BodyFetchElement;
 import org.apache.james.imap.api.message.FetchData;
 import org.apache.james.imap.api.message.FetchData.Item;
 import org.apache.james.imap.api.message.SectionType;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
 import org.apache.james.imap.message.response.FetchResponse;
 import org.apache.james.mailbox.MailboxSession;
@@ -101,23 +100,20 @@ public final class FetchResponseBuilder {
         return new FetchResponse(msn, flags, uid, modSeq, internalDate, size, envelope, body, bodystructure, elements);
     }
 
-    public FetchResponse build(FetchData fetch, MessageResult result, MessageManager mailbox, ImapSession session) throws MessageRangeException, MailboxException {
-        final SelectedMailbox selected = session.getSelected();
+    public FetchResponse build(FetchData fetch, MessageResult result, MessageManager mailbox, SelectedMailbox selectedMailbox, MailboxSession mailboxSession) throws MessageRangeException, MailboxException {
         final MessageUid resultUid = result.getUid();
-        return selected.msn(resultUid).fold(() -> {
+        return selectedMailbox.msn(resultUid).fold(() -> {
             throw new MessageRangeException("No such message found with uid " + resultUid);
         }, msn -> {
 
             reset(msn);
             // setMsn(resultMsn);
 
+            // FLAGS response
             // Check if this fetch will cause the "SEEN" flag to be set on this
             // message. If so, update the flags, and ensure that a flags response is
             // included in the response.
-            final MailboxSession mailboxSession = session.getMailboxSession();
-
-            // FLAGS response
-            addFlags(fetch, mailbox, selected, resultUid, mailboxSession, result.getFlags());
+            addFlags(fetch, mailbox, selectedMailbox, resultUid, mailboxSession, result.getFlags());
 
             // INTERNALDATE response
             if (fetch.contains(Item.INTERNAL_DATE)) {
@@ -208,22 +204,20 @@ public final class FetchResponseBuilder {
         }
     }
 
-    public FetchResponse build(FetchData fetch, ComposedMessageIdWithMetaData result, MessageManager mailbox, ImapSession session) throws MessageRangeException, MailboxException {
-        final SelectedMailbox selected = session.getSelected();
+    public FetchResponse build(FetchData fetch, ComposedMessageIdWithMetaData result, MessageManager mailbox, SelectedMailbox selectedMailbox, MailboxSession mailboxSession) throws MessageRangeException, MailboxException {
         final MessageUid resultUid = result.getComposedMessageId().getUid();
-        return selected.msn(resultUid).fold(() -> {
+        return selectedMailbox.msn(resultUid).fold(() -> {
             throw new MessageRangeException("No such message found with uid " + resultUid);
         }, msn -> {
 
             reset(msn);
             // setMsn(resultMsn);
 
+            // FLAGS response
             // Check if this fetch will cause the "SEEN" flag to be set on this
             // message. If so, update the flags, and ensure that a flags response is
             // included in the response.
-            final MailboxSession mailboxSession = session.getMailboxSession();
-            // FLAGS response
-            addFlags(fetch, mailbox, selected, resultUid, mailboxSession, result.getFlags());
+            addFlags(fetch, mailbox, selectedMailbox, resultUid, mailboxSession, result.getFlags());
             // UID response
             addUid(fetch, resultUid);
 


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


[james-project] 07/09: JAMES-3098 return error if invalid property requested

Posted by rc...@apache.org.
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 a8b7894ae047a7a6458404659b4bbf955efe422a
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Thu Jul 16 12:01:28 2020 +0200

    JAMES-3098 return error if invalid property requested
---
 .../contract/MailboxGetMethodContract.scala        |  5 ++--
 .../org/apache/james/jmap/mail/MailboxGet.scala    |  5 +++-
 .../james/jmap/method/MailboxGetMethod.scala       | 34 ++++++++++++++--------
 .../org/apache/james/jmap/model/Invocation.scala   | 20 +++++++++++++
 4 files changed, 48 insertions(+), 16 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/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 40471f3..6a255a2 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, Disabled, Tag, Test}
+import org.junit.jupiter.api.{BeforeEach, Tag, Test}
 
 object MailboxGetMethodContract {
   private val ARGUMENTS: String = "methodResponses[0][1]"
@@ -680,7 +680,6 @@ trait MailboxGetMethodContract {
          |}""".stripMargin)
   }
 
-  @Disabled("TODO")
   @Test
   def getMailboxesShouldNotIncludeNamespaceIfSharesCapabilityIsUsedAndNamespaceIsNotRequested(server: GuiceJamesServer): Unit = {
     val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
@@ -743,7 +742,7 @@ trait MailboxGetMethodContract {
          |  "methodResponses": [[
          |   "error", {
          |     "type": "invalidArguments",
-         |     "description": "The following properties [invalidProperty] do not exist"
+         |     "description": "The following properties [invalidProperty] do not exist."
          |},
          |    "c1"]]
          |}""".stripMargin)
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 5d9b971..613d418 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
@@ -26,7 +26,10 @@ import org.apache.james.mailbox.model.MailboxId
 
 case class Ids(value: List[MailboxId])
 
-case class Properties(value: List[NonEmptyString])
+case class Properties(value: List[NonEmptyString]) {
+  def asSetOfString: Set[String] = value.map(_.toString()).toSet
+}
+
 
 case class MailboxGetRequest(accountId: AccountId,
                              ids: Option[Ids],
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
index b48e7a6..2423978 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
@@ -26,7 +26,7 @@ import org.apache.james.jmap.mail._
 import org.apache.james.jmap.model.CapabilityIdentifier.CapabilityIdentifier
 import org.apache.james.jmap.model.Invocation.{Arguments, MethodName}
 import org.apache.james.jmap.model.State.INSTANCE
-import org.apache.james.jmap.model.{Invocation, MailboxFactory}
+import org.apache.james.jmap.model.{ErrorCode, Invocation, MailboxFactory}
 import org.apache.james.jmap.utils.quotas.{QuotaLoader, QuotaLoaderWithPreloadedDefaultFactory}
 import org.apache.james.mailbox.exception.MailboxNotFoundException
 import org.apache.james.mailbox.model.search.MailboxQuery
@@ -57,17 +57,27 @@ class MailboxGetMethod @Inject() (serializer: Serializer,
   override def process(capabilities: Set[CapabilityIdentifier], invocation: Invocation, mailboxSession: MailboxSession): Publisher[Invocation] = {
     metricFactory.decoratePublisherWithTimerMetricLogP99(JMAP_RFC8621_PREFIX + methodName.value,
       asMailboxGetRequest(invocation.arguments)
-        .flatMap(mailboxGetRequest => getMailboxes(mailboxGetRequest, mailboxSession)
-          .reduce(MailboxGetResults(Set.empty, NotFound(Set.empty)), (result1: MailboxGetResults, result2: MailboxGetResults) => result1.merge(result2))
-          .map(mailboxes => MailboxGetResponse(
-            accountId = mailboxGetRequest.accountId,
-            state = INSTANCE,
-            list = mailboxes.mailboxes.toList.sortBy(_.sortOrder),
-            notFound = mailboxes.notFound))
-          .map(mailboxGetResponse => Invocation(
-            methodName = methodName,
-            arguments = Arguments(serializer.serialize(mailboxGetResponse, mailboxGetRequest.properties, capabilities).as[JsObject]),
-            methodCallId = invocation.methodCallId))))
+        .flatMap(mailboxGetRequest => {
+          mailboxGetRequest.properties match {
+            case Some(properties) if !properties.asSetOfString.subsetOf(Mailbox.allProperties) =>
+              SMono.just(Invocation.error(errorCode = ErrorCode.InvalidArguments,
+                description = Some(s"The following properties [${properties.asSetOfString.diff(Mailbox.allProperties).mkString(", ")}] do not exist."),
+                methodCallId = invocation.methodCallId))
+            case _ => getMailboxes(mailboxGetRequest, mailboxSession)
+              .reduce(MailboxGetResults(Set.empty, NotFound(Set.empty)), (result1: MailboxGetResults, result2: MailboxGetResults) => result1.merge(result2))
+              .map(mailboxes => MailboxGetResponse(
+                accountId = mailboxGetRequest.accountId,
+                state = INSTANCE,
+                list = mailboxes.mailboxes.toList.sortBy(_.sortOrder),
+                notFound = mailboxes.notFound))
+              .map(mailboxGetResponse => Invocation(
+                methodName = methodName,
+                arguments = Arguments(serializer.serialize(mailboxGetResponse, mailboxGetRequest.properties, capabilities).as[JsObject]),
+                methodCallId = invocation.methodCallId))
+
+          }
+        }
+        ))
   }
 
   private def asMailboxGetRequest(arguments: Arguments): SMono[MailboxGetRequest] = {
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
index c46d95b..5e8ec02 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
@@ -18,6 +18,7 @@
  * ***************************************************************/
 package org.apache.james.jmap.model
 
+import eu.timepit.refined.auto._
 import eu.timepit.refined.types.string.NonEmptyString
 import org.apache.james.jmap.model.Invocation.{Arguments, MethodCallId, MethodName}
 import play.api.libs.json._
@@ -33,4 +34,23 @@ object Invocation {
   case class Arguments(value: JsObject) extends AnyVal
   case class MethodCallId(value: NonEmptyString)
 
+
+  def error(errorCode: ErrorCode, description: Option[String], methodCallId: MethodCallId): Invocation = {
+    Invocation(MethodName("error"),
+      Arguments(JsObject(Seq("type" -> JsString(errorCode.code), "description" -> JsString(description.getOrElse(errorCode.defaultDescription))))),
+      methodCallId)
+  }
+}
+
+sealed trait ErrorCode {
+  def code: String
+  def defaultDescription: String
+}
+
+object ErrorCode {
+  case object InvalidArguments extends ErrorCode {
+    override def code: String = "invalidArguments"
+
+    override def defaultDescription: String = "One of the arguments is of the wrong type or otherwise invalid, or a required argument is missing."
+  }
 }


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


[james-project] 06/09: JAMES-3098 filter properties from response

Posted by rc...@apache.org.
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 9b1c3888d5d6765b2aa8547c00a3e1c42b03aa5e
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Wed Jul 15 16:34:24 2020 +0200

    JAMES-3098 filter properties from response
---
 .../contract/MailboxGetMethodContract.scala        | 128 +++++++++++++++++++--
 .../org/apache/james/jmap/json/Serializer.scala    |  19 +--
 .../scala/org/apache/james/jmap/mail/Mailbox.scala |  25 +++-
 .../james/jmap/method/MailboxGetMethod.scala       |   2 +-
 .../jmap/json/MailboxGetSerializationTest.scala    |   4 +-
 .../james/jmap/json/MailboxSerializationTest.scala |   3 +-
 6 files changed, 149 insertions(+), 32 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/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 3f51a4b..40471f3 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
@@ -81,6 +81,21 @@ object MailboxGetMethodContract {
     |      "c1"]]
     |}""".stripMargin
 
+  private val GET_ALL_MAILBOXES_REQUEST_EMPTY_PROPERTIES: String =
+    """{
+    |  "using": [
+    |    "urn:ietf:params:jmap:core",
+    |    "urn:ietf:params:jmap:mail"],
+    |  "methodCalls": [[
+    |      "Mailbox/get",
+    |      {
+    |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+    |        "properties": [],
+    |        "ids": null
+    |      },
+    |      "c1"]]
+    |}""".stripMargin
+
   private val GET_ALL_MAILBOXES_REQUEST_NAME_AND_ID_PROPERTIES: String =
     """{
     |  "using": [
@@ -156,6 +171,22 @@ object MailboxGetMethodContract {
     |      "c1"]]
     |}""".stripMargin
 
+  private val GET_ALL_MAILBOXES_REQUEST_WITH_SHARES_WITH_ONLY_ID_NAME_AND_RIGHTS: String =
+    """{
+      |  "using": [
+      |    "urn:ietf:params:jmap:core",
+      |    "urn:ietf:params:jmap:mail",
+      |    "urn:apache:james:params:jmap:mail:shares"],
+      |  "methodCalls": [[
+      |      "Mailbox/get",
+      |      {
+      |        "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+      |        "properties": ["id", "name", "rights"],
+      |        "ids": null
+      |      },
+      |      "c1"]]
+      |}""".stripMargin
+
   private val GET_ALL_MAILBOXES_REQUEST_WITH_BOTH: String =
     """{
     |  "using": [
@@ -436,9 +467,9 @@ trait MailboxGetMethodContract {
     val response: String = `given`
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
       .body(GET_ALL_MAILBOXES_REQUEST)
-      .when
+    .when
       .post
-      .`then`
+    .`then`
       .statusCode(SC_OK)
       .contentType(JSON)
       .extract
@@ -491,9 +522,9 @@ trait MailboxGetMethodContract {
     val response: String = `given`
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
       .body(GET_ALL_MAILBOXES_REQUEST_NULL_PROPERTIES)
-      .when
+    .when
       .post
-      .`then`
+    .`then`
       .statusCode(SC_OK)
       .contentType(JSON)
       .extract
@@ -537,7 +568,42 @@ trait MailboxGetMethodContract {
          |}""".stripMargin)
   }
 
-  @Disabled("TODO")
+  @Test
+  def getMailboxesShouldReturnIdWhenNoPropertiesRequested(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_EMPTY_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}"
+         |        }
+         |      ],
+         |      "notFound": []
+         |    },
+         |    "c1"]]
+         |}""".stripMargin)
+  }
   @Test
   def getMailboxesShouldReturnOnlyNameAndIdWhenPropertiesRequested(server: GuiceJamesServer): Unit = {
     val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
@@ -547,9 +613,9 @@ trait MailboxGetMethodContract {
     val response: String = `given`
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
       .body(GET_ALL_MAILBOXES_REQUEST_NAME_AND_ID_PROPERTIES)
-      .when
+    .when
       .post
-      .`then`
+    .`then`
       .statusCode(SC_OK)
       .contentType(JSON)
       .extract
@@ -576,7 +642,6 @@ trait MailboxGetMethodContract {
          |}""".stripMargin)
   }
 
-  @Disabled("TODO")
   @Test
   def getMailboxesShouldAlwaysReturnIdEvenIfNotRequested(server: GuiceJamesServer): Unit = {
     val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
@@ -586,9 +651,9 @@ trait MailboxGetMethodContract {
     val response: String = `given`
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
       .body(GET_ALL_MAILBOXES_REQUEST_NAME_PROPERTIES)
-      .when
+    .when
       .post
-      .`then`
+    .`then`
       .statusCode(SC_OK)
       .contentType(JSON)
       .extract
@@ -617,6 +682,45 @@ trait MailboxGetMethodContract {
 
   @Disabled("TODO")
   @Test
+  def getMailboxesShouldNotIncludeNamespaceIfSharesCapabilityIsUsedAndNamespaceIsNotRequested(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_WITH_SHARES_WITH_ONLY_ID_NAME_AND_RIGHTS)
+    .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",
+         |          "rights": {}
+         |        }
+         |      ],
+         |      "notFound": []
+         |    },
+         |    "c1"]]
+         |}""".stripMargin)
+  }
+
+  @Test
   def getMailboxesShouldReturnInvalidArgumentsErrorWhenInvalidProperty(server: GuiceJamesServer): Unit = {
     server.getProbe(classOf[MailboxProbeImpl])
       .createMailbox(MailboxPath.forUser(BOB, "custom"))
@@ -624,9 +728,9 @@ trait MailboxGetMethodContract {
     val response: String = `given`
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
       .body(GET_ALL_MAILBOXES_REQUEST_INVALID_PROPERTIES)
-      .when
+    .when
       .post
-      .`then`
+    .`then`
       .statusCode(SC_OK)
       .contentType(JSON)
       .extract
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
index ad6b6b5..b31e0b5 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/Serializer.scala
@@ -201,8 +201,8 @@ class Serializer @Inject() (mailboxIdFactory: MailboxId.Factory) {
       })
     }
 
-  implicit def mailboxWrites(propertiesToHide: Set[String]): Writes[Mailbox] = Json.writes[Mailbox]
-    .transform((o: JsObject) => JsObject(o.fields.filterNot(entry => propertiesToHide.contains(entry._1))))
+  implicit def mailboxWrites(properties: Set[String]): Writes[Mailbox] = Json.writes[Mailbox]
+    .transform((o: JsObject) => JsObject(o.fields.filter(entry => properties.contains(entry._1))))
 
   private implicit val idsRead: Reads[Ids] = Json.valueReads[Ids]
   private implicit val propertiesRead: Reads[Properties] = Json.valueReads[Properties]
@@ -230,15 +230,8 @@ class Serializer @Inject() (mailboxIdFactory: MailboxId.Factory) {
       })
     }
 
-  private def mailboxWritesWithFilteredProperties(capabilities: Set[CapabilityIdentifier]): Writes[Mailbox] = {
-    val propertiesForCapabitilites: Map[CapabilityIdentifier, Set[String]] = Map(
-      CapabilityIdentifier.JAMES_QUOTA -> Set("quotas"),
-      CapabilityIdentifier.JAMES_SHARES -> Set("namespace", "rights")
-    )
-    val propertiesToHide = propertiesForCapabitilites.filterNot(entry => capabilities.contains(entry._1))
-      .flatMap(_._2)
-      .toSet
-    mailboxWrites(propertiesToHide)
+  private def mailboxWritesWithFilteredProperties(properties: Option[Properties], capabilities: Set[CapabilityIdentifier]): Writes[Mailbox] = {
+    mailboxWrites(Mailbox.propertiesFiltered(properties, capabilities))
   }
 
   private implicit def jsErrorWrites: Writes[JsError] = Json.writes[JsError]
@@ -253,8 +246,8 @@ class Serializer @Inject() (mailboxIdFactory: MailboxId.Factory) {
 
   def serialize(mailboxGetResponse: MailboxGetResponse)(implicit mailboxWrites: Writes[Mailbox]): JsValue = Json.toJson(mailboxGetResponse)
 
-  def serialize(mailboxGetResponse: MailboxGetResponse, capabilities: Set[CapabilityIdentifier]): JsValue = {
-    serialize(mailboxGetResponse)(mailboxWritesWithFilteredProperties(capabilities))
+  def serialize(mailboxGetResponse: MailboxGetResponse, properties: Option[Properties], capabilities: Set[CapabilityIdentifier]): JsValue = {
+    serialize(mailboxGetResponse)(mailboxWritesWithFilteredProperties(properties, capabilities))
   }
 
   def serialize(errors: JsError): JsValue = Json.toJson(errors)
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
index 9f3cd6a..23782bb 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Mailbox.scala
@@ -25,6 +25,8 @@ import eu.timepit.refined.auto._
 import eu.timepit.refined.collection.NonEmpty
 import org.apache.james.core.Username
 import org.apache.james.jmap.mail.MailboxName.MailboxName
+import org.apache.james.jmap.model.CapabilityIdentifier
+import org.apache.james.jmap.model.CapabilityIdentifier.CapabilityIdentifier
 import org.apache.james.jmap.model.UnsignedInt.UnsignedInt
 import org.apache.james.mailbox.Role
 import org.apache.james.mailbox.model.MailboxId
@@ -142,4 +144,25 @@ case class Mailbox(id: MailboxId,
   def hasRole(role: Role): Boolean = this.role.contains(role)
 
   val hasSystemRole: Boolean = role.exists(_.isSystemRole)
-}
\ No newline at end of file
+}
+
+object Mailbox {
+  def allProperties: Set[String] = Set("id", "name", "parentId", "role", "sortOrder", "totalEmails", "unreadEmails",
+    "totalThreads", "unreadThreads", "myRights", "isSubscribed", "namespace", "rights", "quotas")
+
+  def propertiesFiltered(requestedProperties: Option[Properties], allowedCapabilities : Set[CapabilityIdentifier]) : Set[String] = {
+    val propertiesForCapabilities: Map[CapabilityIdentifier, Set[String]] = Map(
+      CapabilityIdentifier.JAMES_QUOTA -> Set("quotas"),
+      CapabilityIdentifier.JAMES_SHARES -> Set("namespace", "rights")
+    )
+
+    val propertiesToHide = propertiesForCapabilities.filterNot(entry => allowedCapabilities.contains(entry._1))
+      .flatMap(_._2)
+      .toSet
+
+    requestedProperties match {
+      case None => allProperties -- propertiesToHide
+      case Some(requested) => (Set("id") ++ requested.value.map(_.toString()).toSet) -- propertiesToHide
+    }
+  }
+}
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
index 168b095..b48e7a6 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
@@ -66,7 +66,7 @@ class MailboxGetMethod @Inject() (serializer: Serializer,
             notFound = mailboxes.notFound))
           .map(mailboxGetResponse => Invocation(
             methodName = methodName,
-            arguments = Arguments(serializer.serialize(mailboxGetResponse, capabilities).as[JsObject]),
+            arguments = Arguments(serializer.serialize(mailboxGetResponse, mailboxGetRequest.properties, capabilities).as[JsObject]),
             methodCallId = invocation.methodCallId))))
   }
 
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
index c2da125..aa22699 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxGetSerializationTest.scala
@@ -42,8 +42,6 @@ object MailboxGetSerializationTest {
   private val MAILBOX_ID_2: MailboxId = FACTORY.fromString("2")
 
   private val PROPERTIES: Properties = Properties(List("name", "role"))
-
-  private val NO_PROPERTY_FILTERING: Set[String] = Set.empty
 }
 
 class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
@@ -207,7 +205,7 @@ class MailboxGetSerializationTest extends AnyWordSpec with Matchers {
           |}
           |""".stripMargin
 
-      assertThatJson(Json.stringify(SERIALIZER.serialize(actualValue)(SERIALIZER.mailboxWrites(NO_PROPERTY_FILTERING)))).isEqualTo(expectedJson)
+      assertThatJson(Json.stringify(SERIALIZER.serialize(actualValue)(SERIALIZER.mailboxWrites(Mailbox.allProperties)))).isEqualTo(expectedJson)
     }
   }
 }
diff --git a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
index 99455a6..c3a6a1a 100644
--- a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
+++ b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/MailboxSerializationTest.scala
@@ -130,8 +130,7 @@ class MailboxSerializationTest extends AnyWordSpec with Matchers {
           |}""".stripMargin
 
       val serializer = new Serializer(new TestId.Factory)
-      val noPropertyFiltering: Set[String] = Set.empty
-      assertThatJson(Json.stringify(serializer.serialize(MAILBOX)(serializer.mailboxWrites(noPropertyFiltering)))).isEqualTo(expectedJson)
+      assertThatJson(Json.stringify(serializer.serialize(MAILBOX)(serializer.mailboxWrites(Mailbox.allProperties)))).isEqualTo(expectedJson)
     }
   }
 }


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


[james-project] 08/09: [REFACTORING] Remove unused method argument

Posted by rc...@apache.org.
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 c338d0f281d848263955895b1644ed9bc41255b6
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jul 16 12:11:15 2020 +0700

    [REFACTORING] Remove unused method argument
---
 .../java/org/apache/james/imap/processor/fetch/FetchProcessor.java  | 6 +++---
 .../org/apache/james/imap/processor/fetch/FetchResponseBuilder.java | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index 901b472..4500155 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -152,7 +152,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
             if (fetch.isOnlyFlags()) {
                 processMessageRangeForFlags(session, mailbox, fetch, mailboxSession, responder, builder, range);
             } else {
-                processMessageRange(session, mailbox, fetch, useUids, mailboxSession, responder, builder, resultToFetch, range);
+                processMessageRange(session, mailbox, fetch, mailboxSession, responder, builder, resultToFetch, range);
             }
         }
 
@@ -184,7 +184,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
         }
     }
 
-    private void processMessageRange(ImapSession session, MessageManager mailbox, FetchData fetch, boolean useUids, MailboxSession mailboxSession, Responder responder, FetchResponseBuilder builder, FetchGroup resultToFetch, MessageRange range) throws MailboxException {
+    private void processMessageRange(ImapSession session, MessageManager mailbox, FetchData fetch, MailboxSession mailboxSession, Responder responder, FetchResponseBuilder builder, FetchGroup resultToFetch, MessageRange range) throws MailboxException {
         MessageResultIterator messages = mailbox.getMessages(range, resultToFetch, mailboxSession);
         while (messages.hasNext()) {
             final MessageResult result = messages.next();
@@ -195,7 +195,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
             }
 
             try {
-                final FetchResponse response = builder.build(fetch, result, mailbox, session, useUids);
+                final FetchResponse response = builder.build(fetch, result, mailbox, session);
                 responder.respond(response);
             } catch (MessageRangeException e) {
                 // we can't for whatever reason find the message so
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index 41a1d68..3674f68 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -101,7 +101,7 @@ public final class FetchResponseBuilder {
         return new FetchResponse(msn, flags, uid, modSeq, internalDate, size, envelope, body, bodystructure, elements);
     }
 
-    public FetchResponse build(FetchData fetch, MessageResult result, MessageManager mailbox, ImapSession session, boolean useUids) throws MessageRangeException, MailboxException {
+    public FetchResponse build(FetchData fetch, MessageResult result, MessageManager mailbox, ImapSession session) throws MessageRangeException, MailboxException {
         final SelectedMailbox selected = session.getSelected();
         final MessageUid resultUid = result.getUid();
         return selected.msn(resultUid).fold(() -> {


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


[james-project] 04/09: [Refactoring] Migrate SpringMailboxTest to JUnit5

Posted by rc...@apache.org.
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 95fd8943c0690fd69e54baf7acdf851ca52c3c73
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 17 11:08:01 2020 +0700

    [Refactoring] Migrate SpringMailboxTest to JUnit5
---
 .../apache/james/mailbox/spring/SpringMailboxTest.java   | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java b/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
index 81f3c31..0b9dfca 100644
--- a/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
+++ b/mailbox/spring/src/test/java/org/apache/james/mailbox/spring/SpringMailboxTest.java
@@ -20,23 +20,21 @@ package org.apache.james.mailbox.spring;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.IOException;
-
 import org.apache.james.mailbox.tools.copier.MailboxCopierImpl;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
-public class SpringMailboxTest {
+class SpringMailboxTest {
     
-    private static SpringMailbox springMailbox;
+    static SpringMailbox springMailbox;
     
-    @BeforeClass
-    public static void beforeClass() {
+    @BeforeAll
+    static void beforeClass() {
         springMailbox = new SpringMailbox();
     }
     
     @Test
-    public void testGetBean() throws IOException {
+    void testGetBean() {
         assertThat(springMailbox.getBean("authenticator").getClass().getName()).isEqualTo(AnonymousAuthenticator.class.getName());
         assertThat(springMailbox.getBean("mailboxcopier").getClass().getName()).isEqualTo(MailboxCopierImpl.class.getName());
     }


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


[james-project] 03/09: [Refactoring] Migrate PDFTextExtractorTest to JUnit5

Posted by rc...@apache.org.
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 7475d71b8f7b839c6d42ffa5a7c45c40fa434e9e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 17 11:04:29 2020 +0700

    [Refactoring] Migrate PDFTextExtractorTest to JUnit5
---
 .../mailbox/store/search/PDFTextExtractorTest.java   | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractorTest.java b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractorTest.java
index de4bac9..658bdcf 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractorTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/PDFTextExtractorTest.java
@@ -27,34 +27,34 @@ import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.james.mailbox.model.ContentType;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class PDFTextExtractorTest {
+class PDFTextExtractorTest {
 
-    private PDFTextExtractor testee;
+    PDFTextExtractor testee;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         testee = new PDFTextExtractor();
     }
 
     @Test
-    public void extractContentShouldThrowWhenNullInputStream() throws Exception {
+    void extractContentShouldThrowWhenNullInputStream() {
         assertThatThrownBy(() ->
             testee.extractContent(null, ContentType.of("any/any")))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void extractContentShouldThrowWhenNullContentType() throws Exception {
+    void extractContentShouldThrowWhenNullContentType() {
         InputStream inputStream = new ByteArrayInputStream("content".getBytes(StandardCharsets.UTF_8));
         assertThatThrownBy(() -> testee.extractContent(inputStream, null))
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void extractContentShouldExtractPlainText() throws Exception {
+    void extractContentShouldExtractPlainText() throws Exception {
         String content = "content";
         InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
 
@@ -64,7 +64,7 @@ public class PDFTextExtractorTest {
     }
 
     @Test
-    public void extractContentShouldExtractPDF() throws Exception {
+    void extractContentShouldExtractPDF() throws Exception {
         String content = "Little PDF\n";
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("pdf.pdf");
 


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


[james-project] 05/09: JAMES-3098 add tests for mailbox/get with properties filtering

Posted by rc...@apache.org.
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 <rk...@linagora.com>
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 01/09: [Refactoring] Migrate MailboxCopierTest to JUnit5

Posted by rc...@apache.org.
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 f78a9145d7f53bc323818680b8d96523b1c30cca
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 17 10:40:02 2020 +0700

    [Refactoring] Migrate MailboxCopierTest to JUnit5
---
 .../mailbox/tools/copier/MailboxCopierTest.java     | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java b/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
index 5efb540..57b0937 100644
--- a/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
+++ b/mailbox/tools/copier/src/test/java/org/apache/james/mailbox/tools/copier/MailboxCopierTest.java
@@ -33,8 +33,8 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.mock.DataProvisioner;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * Test class for the {@link MailboxCopierImpl} implementation.
@@ -43,33 +43,30 @@ import org.junit.Test;
  * Mailbox Manager.
  *
  */
-public class MailboxCopierTest {
+class MailboxCopierTest {
     /**
      * The instance for the test mailboxCopier.
      */
-    private MailboxCopierImpl mailboxCopier;
+    MailboxCopierImpl mailboxCopier;
 
     /**
      * The instance for the source Mailbox Manager.
      */
-    private MailboxManager srcMemMailboxManager;
+    MailboxManager srcMemMailboxManager;
 
     /**
      * The instance for the destination Mailbox Manager.
      */
-    private MailboxManager dstMemMailboxManager;
+    MailboxManager dstMemMailboxManager;
 
     /**
      * Setup the mailboxCopier and the source and destination
      * Mailbox Manager.
      *
      * We use a InMemoryMailboxManager implementation.
-     *
-     * @throws BadCredentialsException
-     * @throws MailboxException
      */
-    @Before
-    public void setup() throws BadCredentialsException, MailboxException {
+    @BeforeEach
+    void setup() {
         mailboxCopier = new MailboxCopierImpl();
 
         srcMemMailboxManager = newInMemoryMailboxManager();
@@ -89,7 +86,7 @@ public class MailboxCopierTest {
      * @throws IOException
      */
     @Test
-    public void testMailboxCopy() throws MailboxException, IOException {
+    void testMailboxCopy() throws MailboxException, IOException {
         DataProvisioner.feedMailboxManager(srcMemMailboxManager);
 
         assertMailboxManagerSize(srcMemMailboxManager, 1);


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


[james-project] 02/09: [Refactoring] Migrate JpaMigratorTest to JUnit5

Posted by rc...@apache.org.
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 e8d9defe149b8ce0583579d9d132e44ae51a9a17
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 17 10:42:34 2020 +0700

    [Refactoring] Migrate JpaMigratorTest to JUnit5
---
 .../mailbox/tools/jpa/migrator/JpaMigratorTest.java  | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java b/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
index cc8bb94..d8a6044 100644
--- a/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
+++ b/mailbox/tools/jpa-migrator/src/test/java/org/apache/james/mailbox/tools/jpa/migrator/JpaMigratorTest.java
@@ -18,38 +18,38 @@
  ****************************************************************/
 package org.apache.james.mailbox.tools.jpa.migrator;
 
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-@Ignore("This class needs to be reviewed")
-public class JpaMigratorTest {
+@Disabled("This class needs to be reviewed")
+class JpaMigratorTest {
     @Test
-    public void testImap165() throws Exception {
+    void testImap165() throws Exception {
         JpaMigrator.main(new String[]{"IMAP165"});
     }
 
     @Test
-    public void testImap168() throws Exception {
+    void testImap168() throws Exception {
         JpaMigrator.main(new String[]{"IMAP168"});
     }
 
     @Test
-    public void testImap172() throws Exception {
+    void testImap172() throws Exception {
         JpaMigrator.main(new String[]{"IMAP172"});
     }
 
     @Test
-    public void testImap176() throws Exception {
+    void testImap176() throws Exception {
         JpaMigrator.main(new String[]{"IMAP176"});
     }
 
     @Test
-    public void testImap180() throws Exception {
+    void testImap180() throws Exception {
         JpaMigrator.main(new String[]{"IMAP180"});
     }
 
     @Test
-    public void testImap184() throws Exception {
+    void testImap184() throws Exception {
         JpaMigrator.main(new String[]{"IMAP184"});
     }
 }


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