james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject james-project git commit: JAMES-1683 getMailboxes should return roles in lower case
Date Thu, 04 Feb 2016 13:09:35 GMT
Repository: james-project
Updated Branches:
  refs/heads/master ea3aa656f -> c1d028086


JAMES-1683 getMailboxes should return roles in lower case


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c1d02808
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c1d02808
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c1d02808

Branch: refs/heads/master
Commit: c1d028086d98a6169dffeca2dbdf066f36e5c12e
Parents: ea3aa65
Author: Laura Royet <lroyet@linagora.com>
Authored: Wed Feb 3 15:27:27 2016 +0100
Committer: Antoine Duprat <antduprat@gmail.com>
Committed: Thu Feb 4 14:09:01 2016 +0100

----------------------------------------------------------------------
 .../jmap/methods/GetMailboxesMethodTest.java    | 31 +++++++++++++---
 .../apache/james/jmap/model/mailbox/Role.java   |  3 ++
 .../jmap/methods/GetMailboxesMethodTest.java    | 39 ++++++++++++++++++++
 3 files changed, 68 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c1d02808/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index f4b25ee..3ed4ec2 100644
--- a/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -35,11 +35,6 @@ import java.util.Map;
 
 import javax.mail.Flags;
 
-import com.google.common.collect.ImmutableMap;
-import com.jayway.jsonpath.Configuration;
-import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.Option;
-import com.jayway.jsonpath.ParseContext;
 import org.apache.james.backends.cassandra.EmbeddedCassandra;
 import org.apache.james.jmap.JmapAuthentication;
 import org.apache.james.jmap.JmapServer;
@@ -54,6 +49,11 @@ import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 
 import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableMap;
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.Option;
+import com.jayway.jsonpath.ParseContext;
 import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.http.ContentType;
 
@@ -342,4 +342,25 @@ public abstract class GetMailboxesMethodTest {
                         ImmutableMap.of("name", "inbox", "sortOrder", 10));
     }
 
+    @Test
+    public void getMailboxesShouldReturnMailboxesWithRolesInLowerCase() throws Exception
{
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username,
"outbox");
+
+        String response = given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMailboxes\", {}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .content(startsWith("[[\"mailboxes\","))
+            .extract()
+            .asString();
+        
+        String firstMailboxPath = "$.[0].[1].list.[0]";
+        assertThat(jsonPath.parse(response).<String>read(firstMailboxPath + ".role")).isEqualTo("outbox");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c1d02808/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
index f389763..b173e23 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
@@ -21,6 +21,8 @@ package org.apache.james.jmap.model.mailbox;
 import java.util.Locale;
 import java.util.Optional;
 
+import com.fasterxml.jackson.annotation.JsonValue;
+
 public enum Role {
 
     INBOX("inbox"),
@@ -47,6 +49,7 @@ public enum Role {
         return Optional.empty();
     }
 
+    @JsonValue
     public String serialize() {
         return name;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c1d02808/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index 01f06ac..de12b71 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;
 import java.io.ByteArrayInputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 import javax.mail.Flags;
@@ -34,6 +35,7 @@ import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
 import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -338,4 +340,41 @@ public class GetMailboxesMethodTest {
                 .extracting(Mailbox::getUnreadMessages)
                 .containsExactly(2L);
     }
+
+    @Test
+    public void getMailboxesShouldReturnMailboxesWithRoles() throws Exception {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "INBOX"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "ARCHIVE"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "DRAFTS"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "OUTBOX"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "SENT"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "TRASH"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "SPAM"), mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "TEMPLATES"),
mailboxSession);
+        mailboxManager.createMailbox(new MailboxPath("#private", USERNAME, "WITHOUT ROLE"),
mailboxSession);
+        
+        GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
+                .build();
+
+        List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
clientId, mailboxSession).collect(Collectors.toList());
+
+        assertThat(getMailboxesResponse)
+                .hasSize(1)
+                .extracting(JmapResponse::getResponse)
+                .hasOnlyElementsOfType(GetMailboxesResponse.class)
+                .extracting(GetMailboxesResponse.class::cast)
+                .flatExtracting(GetMailboxesResponse::getList)
+                .extracting(Mailbox::getName, Mailbox::getRole)
+                .containsOnly(
+                        Tuple.tuple("INBOX", Optional.of(Role.INBOX)),
+                        Tuple.tuple("ARCHIVE", Optional.of(Role.ARCHIVE)),
+                        Tuple.tuple("DRAFTS", Optional.of(Role.DRAFTS)),
+                        Tuple.tuple("OUTBOX", Optional.of(Role.OUTBOX)),
+                        Tuple.tuple("SENT", Optional.of(Role.SENT)),
+                        Tuple.tuple("TRASH", Optional.of(Role.TRASH)),
+                        Tuple.tuple("SPAM", Optional.of(Role.SPAM)),
+                        Tuple.tuple("TEMPLATES", Optional.of(Role.TEMPLATES)),
+                        Tuple.tuple("WITHOUT ROLE", Optional.empty()));
+    }
 }


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


Mime
View raw message