JAMES-2186 RFC4314Rights: Provide an easy method for rights exclusion

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

Branch: refs/heads/master
Commit: 154453af0b6c3b9c135000178e5b8d1ba605539a
Parents: 86d9aef
Author: benwa <btell...@linagora.com>
Authored: Wed Oct 18 13:33:55 2017 +0700
Committer: Matthieu Baechler <matth...@apache.org>
Committed: Fri Oct 20 12:34:51 2017 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/model/MailboxACL.java  |  5 ++
 .../james/mailbox/model/Rfc4314RightsTest.java  | 54 ++++++++++++++++++++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/154453af/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
index 1f7a5be..cf22364 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
@@ -170,6 +170,11 @@ public class MailboxACL {
      * MailboxACLRights are initialized.
      */
     public static class Rfc4314Rights {
+        public static Rfc4314Rights allExcept(Right... rights) throws 
UnsupportedRightException {
+            return MailboxACL.FULL_RIGHTS
+                .except(new Rfc4314Rights(rights));
+        }
+
         private static final char c_ObsoleteCreate = 'c';
         private static final char d_ObsoleteDelete = 'd';
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/154453af/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
index 0e58229..24e8c2b 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java
@@ -232,4 +232,58 @@ public class Rfc4314RightsTest {
     public void containsShouldReturnTrueWhenNonRightsPresent() throws 
UnsupportedRightException {
         assertThat(lprs.contains()).isTrue();
     }
+
+    @Test
+    public void allExceptShouldReturnFullWhenProvidedEmpty() throws 
UnsupportedRightException {
+        
assertThat(Rfc4314Rights.allExcept()).isEqualTo(MailboxACL.FULL_RIGHTS);
+    }
+
+    @Test
+    public void allExceptShouldReturnAllButProvidedRight() throws 
UnsupportedRightException {
+        assertThat(Rfc4314Rights.allExcept(Lookup))
+            .isEqualTo(new Rfc4314Rights(
+                DeleteMessages,
+                Insert,
+                Read,
+                Administer,
+                Write,
+                WriteSeenFlag,
+                PerformExpunge,
+                CreateMailbox,
+                Post,
+                DeleteMailbox));
+    }
+
+    @Test
+    public void allExceptShouldReturnAllButProvidedRights() throws 
UnsupportedRightException {
+        assertThat(Rfc4314Rights.allExcept(Lookup, Read))
+            .isEqualTo(new Rfc4314Rights(
+                DeleteMessages,
+                Insert,
+                Administer,
+                Write,
+                WriteSeenFlag,
+                PerformExpunge,
+                CreateMailbox,
+                Post,
+                DeleteMailbox));
+    }
+
+    @Test
+    public void allExceptShouldReturnEmptyWhenProvidedAllRights() throws 
UnsupportedRightException {
+        assertThat(
+            Rfc4314Rights.allExcept(
+                Lookup,
+                Read,
+                DeleteMessages,
+                Insert,
+                Administer,
+                Write,
+                WriteSeenFlag,
+                PerformExpunge,
+                CreateMailbox,
+                Post,
+                DeleteMailbox))
+            .isEqualTo(new Rfc4314Rights());
+    }
 }


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

Reply via email to