JAMES-1715 Mailbox Role should tell if it's system or not

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

Branch: refs/heads/master
Commit: ee19df89d97b4a81c63aeda6079e308f5cccfc9b
Parents: 169e7bf
Author: Antoine Duprat <[email protected]>
Authored: Thu Mar 31 14:53:39 2016 +0200
Committer: Antoine Duprat <[email protected]>
Committed: Tue Apr 5 11:27:47 2016 +0200

----------------------------------------------------------------------
 .../apache/james/jmap/model/mailbox/Role.java   |  6 ++-
 .../james/jmap/model/mailbox/RoleTest.java      | 50 ++++++++++++++++++--
 2 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ee19df89/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 deaf90c..4c01a48 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
@@ -68,7 +68,11 @@ public class Role {
         }
         return Optional.empty();
     }
-    
+
+    public boolean isSystemRole() {
+        return ROLES.containsKey(name.toLowerCase(Locale.ENGLISH));
+    }
+
     @JsonValue
     public String serialize() {
         return name;

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee19df89/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
index e65bfa6..05c7928 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
@@ -20,12 +20,11 @@ package org.apache.james.jmap.model.mailbox;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.james.jmap.model.mailbox.Role;
-import org.junit.Test;
-
 import java.util.Locale;
 import java.util.Optional;
 
+import org.junit.Test;
+
 public class RoleTest {
 
     @Test
@@ -59,4 +58,49 @@ public class RoleTest {
         
assertThat(Role.from("x-client-specific-role")).isEqualTo(Optional.of(new 
Role("x-client-specific-role")));
     }
 
+    @Test
+    public void isSystemRoleShouldBeTrueWhenInbox() {
+        assertThat(Role.INBOX.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenArchive() {
+        assertThat(Role.ARCHIVE.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenDrafts() {
+        assertThat(Role.DRAFTS.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenOutbox() {
+        assertThat(Role.OUTBOX.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenSent() {
+        assertThat(Role.SENT.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenTrash() {
+        assertThat(Role.TRASH.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenSpam() {
+        assertThat(Role.SPAM.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeTrueWhenTemplates() {
+        assertThat(Role.TEMPLATES.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void isSystemRoleShouldBeFalseWhenUserDefinedRole() {
+        Role userRole = Role.from(Role.USER_DEFINED_ROLE_PREFIX + 
"myRole").get();
+        assertThat(userRole.isSystemRole()).isFalse();
+    }
 }
\ No newline at end of file


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

Reply via email to