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 ad...@apache.org on 2017/11/13 15:27:38 UTC

[1/8] james-project git commit: PROTOCOLS-117 Rework MailboxPath equals

Repository: james-project
Updated Branches:
  refs/heads/master 9047b4bab -> 3aa1732b3


PROTOCOLS-117 Rework MailboxPath equals


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

Branch: refs/heads/master
Commit: 3757e5e713722737a653b7624995939c77756c8b
Parents: 6a6e74c
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 8 09:23:30 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:23:06 2017 +0100

----------------------------------------------------------------------
 .../apache/james/mailbox/model/MailboxPath.java | 52 +++++---------------
 .../james/mailbox/model/MailboxPathTest.java    |  9 ++++
 2 files changed, 22 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3757e5e7/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
index 42de9a4..1f4f2f9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.model;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 import org.apache.james.mailbox.MailboxSession;
@@ -135,50 +136,23 @@ public class MailboxPath {
         return asString();
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
-    public boolean equals(Object mailboxPath) {
-        if (this == mailboxPath)
-            return true;
-
-        if (!(mailboxPath instanceof MailboxPath))
-            return false;
-        MailboxPath mp = (MailboxPath) mailboxPath;
-        if (namespace == null) {
-            if (mp.getNamespace() != null)
-                return false;
-        } else if (!namespace.equals(mp.getNamespace()))
-            return false;
-        if (user == null) {
-            if (mp.getUser() != null)
-                return false;
-        } else if (!user.equals(mp.getUser()))
-            return false;
-        if (name == null) {
-            if (mp.getName() != null)
-                return false;
-        } else if (!name.equals(mp.getName()))
-            return false;
-        return true;
+    public final boolean equals(Object o) {
+        if (o instanceof MailboxPath) {
+            MailboxPath that = (MailboxPath) o;
+
+            return Objects.equals(this.namespace, that.namespace)
+                && Objects.equals(this.user, that.user)
+                && Objects.equals(this.name, that.name);
+        }
+        return false;
     }
 
     @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        if (getName() != null)
-            result = PRIME * result + getName().hashCode();
-        if (getUser() != null)
-            result = PRIME * result + getUser().hashCode();
-        if (getNamespace() != null)
-            result = PRIME * result + getNamespace().hashCode();
-        return result;
+    public final int hashCode() {
+        return Objects.hash(namespace, user, name);
     }
-    
+
     /**
      * Return the full name of the {@link MailboxPath}, which is constructed via the {@link #namespace} and {@link #name}
      * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3757e5e7/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
index d51608f..2761658 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
@@ -24,9 +24,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.Test;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+
 public class MailboxPathTest {
 
     @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(MailboxPath.class)
+            .allFieldsShouldBeUsed()
+            .verify();
+    }
+
+    @Test
     public void getHierarchyLevelsShouldBeOrdered() {
         assertThat(MailboxPath.forUser("user", "inbox.folder.subfolder")
             .getHierarchyLevels('.'))


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


[8/8] james-project git commit: PROTOCOLS-117 Case issues in StoreManagerTests

Posted by ad...@apache.org.
PROTOCOLS-117 Case issues in StoreManagerTests


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

Branch: refs/heads/master
Commit: 3aa1732b3b823185edfae549f8db55a9002f6e29
Parents: 14a6930
Author: benwa <bt...@linagora.com>
Authored: Thu Nov 9 10:07:18 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:25:59 2017 +0100

----------------------------------------------------------------------
 .../org/apache/james/mailbox/store/StoreRightManagerTest.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3aa1732b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index 5ebe23b..78ce9e6 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -90,7 +90,7 @@ public class StoreRightManagerTest {
     }
 
     @Test
-    public void hasRightShouldReturnTrueWhenTheUserDoesnotOwnTheMailboxButHaveTheCorrectRightOnIt() throws MailboxException {
+    public void hasRightShouldReturnTrueWhenTheUserDoesNotOwnTheMailboxButHaveTheCorrectRightOnIt() throws MailboxException {
         Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
         mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write)));
 
@@ -99,7 +99,7 @@ public class StoreRightManagerTest {
     }
 
     @Test
-    public void hasRightShouldReturnTrueWhenTheUserDoesnotOwnTheMailboxButHasAtLeastTheCorrectRightOnIt() throws MailboxException {
+    public void hasRightShouldReturnTrueWhenTheUserDoesNotOwnTheMailboxButHasAtLeastTheCorrectRightOnIt() throws MailboxException {
         Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
         mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write, Right.Lookup)));
 


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


[7/8] james-project git commit: PROTOCOLS-117 Correct StoreManagerTests

Posted by ad...@apache.org.
PROTOCOLS-117 Correct StoreManagerTests


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

Branch: refs/heads/master
Commit: 14a6930f1a56f574ffd27e9488e971b10041208d
Parents: 2b4626f
Author: benwa <bt...@linagora.com>
Authored: Thu Nov 9 10:06:58 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:25:59 2017 +0100

----------------------------------------------------------------------
 .../org/apache/james/mailbox/store/StoreRightManagerTest.java    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/14a6930f/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index 9d765d5..5ebe23b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -47,7 +47,6 @@ import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class StoreRightManagerTest {
@@ -82,13 +81,12 @@ public class StoreRightManagerTest {
             .isInstanceOf(MailboxNotFoundException.class);
     }
 
-    @Ignore("PROTOCOLS-117 Will be solved in next commit")
     @Test
     public void hasRightShouldReturnTrueWhenTheUserOwnTheMailbox() throws MailboxException {
         Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(ALICE, MailboxConstants.INBOX), UID_VALIDITY);
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
-            .isFalse();
+            .isTrue();
     }
 
     @Test


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


[6/8] james-project git commit: PROTOCOLS-117 MailboxPath sanitizing should be handled by MailboxPath

Posted by ad...@apache.org.
PROTOCOLS-117 MailboxPath sanitizing should be handled by MailboxPath


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

Branch: refs/heads/master
Commit: 7e8aaea41677ff280065719d1e0d9ae2507ea8ee
Parents: 3757e5e
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 8 16:35:40 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:25:59 2017 +0100

----------------------------------------------------------------------
 .../apache/james/mailbox/model/MailboxPath.java | 16 ++++++
 .../james/mailbox/model/MailboxPathTest.java    | 56 ++++++++++++++++++++
 .../mailbox/store/StoreMailboxManager.java      | 14 +----
 3 files changed, 73 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7e8aaea4/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
index 1f4f2f9..02daf0b 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
@@ -127,6 +127,22 @@ public class MailboxPath {
         return levels;
     }
 
+    public MailboxPath sanitize(char delimiter) {
+        if (name == null) {
+            return this;
+        }
+        if (name.endsWith(String.valueOf(delimiter))) {
+            int length = name.length();
+            String sanitizedName = name.substring(0, length - 1);
+            return new MailboxPath(
+                namespace,
+                user,
+                sanitizedName);
+        }
+        return this;
+    }
+
+
     public String asString() {
         return namespace + ":" + user + ":" + name;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e8aaea4/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
index 2761658..5292690 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
@@ -68,4 +68,60 @@ public class MailboxPathTest {
             .containsExactly(
                 MailboxPath.forUser("user", null));
     }
+
+    @Test
+    public void sanitizeShouldNotThrowOnNullMailboxName() {
+        assertThat(MailboxPath.forUser("user", null)
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", null));
+    }
+
+    @Test
+    public void sanitizeShouldReturnEmptyWhenEmpty() {
+        assertThat(MailboxPath.forUser("user", "")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", ""));
+    }
+
+    @Test
+    public void sanitizeShouldRemoveMaximumOneTrailingDelimiterWhenAlone() {
+        assertThat(MailboxPath.forUser("user", ".")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", ""));
+    }
+
+    @Test
+    public void sanitizeShouldPreserveHeadingDelimiter() {
+        assertThat(MailboxPath.forUser("user", ".a")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", ".a"));
+    }
+
+    @Test
+    public void sanitizeShouldRemoveTrailingDelimiter() {
+        assertThat(MailboxPath.forUser("user", "a.")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", "a"));
+    }
+
+    @Test
+    public void sanitizeShouldRemoveMaximumOneTrailingDelimiter() {
+        assertThat(MailboxPath.forUser("user", "a..")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", "a."));
+    }
+
+    @Test
+    public void sanitizeShouldPreserveRedundantDelimiters() {
+        assertThat(MailboxPath.forUser("user", "a..a")
+            .sanitize('.'))
+            .isEqualTo(
+                MailboxPath.forUser("user", "a..a"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7e8aaea4/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 7664f84..5f499aa 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -490,7 +490,7 @@ public class StoreMailboxManager implements MailboxManager {
         if (mailboxPath.getName().isEmpty()) {
             LOGGER.warn("Ignoring mailbox with empty name");
         } else {
-            MailboxPath sanitizedMailboxPath = sanitizeMailboxPath(mailboxPath);
+            MailboxPath sanitizedMailboxPath = mailboxPath.sanitize(mailboxSession.getPathDelimiter());
             if (mailboxExists(sanitizedMailboxPath, mailboxSession))
                 throw new MailboxExistsException(sanitizedMailboxPath.asString());
             // Create parents first
@@ -519,18 +519,6 @@ public class StoreMailboxManager implements MailboxManager {
         return Optional.empty();
     }
 
-    private MailboxPath sanitizeMailboxPath(MailboxPath mailboxPath) {
-        if (mailboxPath.getName().endsWith(String.valueOf(getDelimiter()))) {
-            int length = mailboxPath.getName().length();
-            String sanitizedName = mailboxPath.getName().substring(0, length - 1);
-            return new MailboxPath(
-                mailboxPath.getNamespace(),
-                mailboxPath.getUser(),
-                sanitizedName);
-        }
-        return mailboxPath;
-    }
-
     @Override
     public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException {
         LOGGER.info("deleteMailbox " + mailboxPath);


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


[2/8] james-project git commit: PROTOCOLS-117 MailboxPath should be immutable

Posted by ad...@apache.org.
PROTOCOLS-117 MailboxPath should be immutable


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

Branch: refs/heads/master
Commit: 6a6e74cf0f869c3f69bbb82991fd703bb0f1c42b
Parents: 5218473
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 8 10:04:41 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:23:06 2017 +0100

----------------------------------------------------------------------
 .../apache/james/mailbox/model/MailboxPath.java | 28 ++---------------
 .../hbase/mail/HBaseMailboxMapperTest.java      | 20 ++++++++----
 .../mailbox/store/StoreMailboxManager.java      | 32 +++++++++++++-------
 3 files changed, 38 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6a6e74cf/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
index ea5e760..42de9a4 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
@@ -49,9 +49,9 @@ public class MailboxPath {
         return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxName);
     }
 
-    private String namespace;
-    private String user;
-    private String name;
+    private final String namespace;
+    private final String user;
+    private final String name;
     
     public MailboxPath(String namespace, String user, String name) {
         this.namespace = Optional.ofNullable(namespace)
@@ -79,13 +79,6 @@ public class MailboxPath {
     }
 
     /**
-     * Set the namespace this mailbox is in
-     */
-    public void setNamespace(String namespace) {
-        this.namespace = namespace;
-    }
-
-    /**
      * Get the name of the user who owns the mailbox. This can be null e.g. for
      * shared mailboxes.
      * 
@@ -96,13 +89,6 @@ public class MailboxPath {
     }
 
     /**
-     * Set the name of the user who owns the mailbox.
-     */
-    public void setUser(String user) {
-        this.user = user;
-    }
-
-    /**
      * Get the name of the mailbox. This is the pure name without user or
      * namespace, so this is what a user would see in his client.
      * 
@@ -113,14 +99,6 @@ public class MailboxPath {
     }
 
     /**
-     * Set the name of the mailbox. This is the pure name without user or
-     * namespace, so this is what a user would see in his client.
-     */
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    /**
      * Return a list of MailboxPath representing the hierarchy levels of this
      * MailboxPath. E.g. INBOX.main.sub would yield
      * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a6e74cf/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java
index 078824c..dca113b 100644
--- a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java
+++ b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapperTest.java
@@ -160,18 +160,26 @@ public class HBaseMailboxMapperTest {
         MailboxPath newPath;
 
         for (int i = start; i < end; i++) {
-            newPath = new MailboxPath(path);
-            newPath.setName(i + newPath.getName() + " " + i);
-            // test for paths with null user
-            if (i % 2 == 0) {
-                newPath.setUser(null);
-            }
+            newPath = new MailboxPath(path.getNamespace(),
+                computeUserName(path.getUser(), i),
+                computeMailboxName(path.getName(), i));
             addMailbox(new HBaseMailbox(newPath, 1234));
         }
         result = mapper.findMailboxWithPathLike(path);
         assertEquals(end - start + 1, result.size());
     }
 
+    private String computeUserName(String user, int i) {
+        if (i % 2 == 0) {
+            return null;
+        }
+        return user;
+    }
+
+    private String computeMailboxName(String name, int i) {
+        return i + name + " " + i;
+    }
+
     /**
      * Test of list method, of class HBaseMailboxMapper.
      */

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a6e74cf/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index b4f6433..7664f84 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -484,27 +484,25 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
-    public Optional<MailboxId> createMailbox(MailboxPath mailboxPath, final MailboxSession mailboxSession)
+    public Optional<MailboxId> createMailbox(MailboxPath mailboxPath, MailboxSession mailboxSession)
             throws MailboxException {
         LOGGER.debug("createMailbox " + mailboxPath);
-        final int length = mailboxPath.getName().length();
-        if (length == 0) {
+        if (mailboxPath.getName().isEmpty()) {
             LOGGER.warn("Ignoring mailbox with empty name");
         } else {
-            if (mailboxPath.getName().charAt(length - 1) == getDelimiter())
-                mailboxPath.setName(mailboxPath.getName().substring(0, length - 1));
-            if (mailboxExists(mailboxPath, mailboxSession))
-                throw new MailboxExistsException(mailboxPath.toString());
+            MailboxPath sanitizedMailboxPath = sanitizeMailboxPath(mailboxPath);
+            if (mailboxExists(sanitizedMailboxPath, mailboxSession))
+                throw new MailboxExistsException(sanitizedMailboxPath.asString());
             // Create parents first
             // If any creation fails then the mailbox will not be created
             // TODO: transaction
-            final List<MailboxId> mailboxIds = new ArrayList<>();
-            for (final MailboxPath mailbox : mailboxPath.getHierarchyLevels(getDelimiter()))
+            List<MailboxId> mailboxIds = new ArrayList<>();
+            for (MailboxPath mailbox : sanitizedMailboxPath.getHierarchyLevels(getDelimiter()))
 
                 locker.executeWithLock(mailboxSession, mailbox, (LockAwareExecution<Void>) () -> {
                     if (!mailboxExists(mailbox, mailboxSession)) {
-                        final Mailbox m = doCreateMailbox(mailbox, mailboxSession);
-                        final MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
+                        Mailbox m = doCreateMailbox(mailbox, mailboxSession);
+                        MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
                         mapper.execute(Mapper.toTransaction(() -> mailboxIds.add(mapper.save(m))));
 
                         // notify listeners
@@ -521,6 +519,18 @@ public class StoreMailboxManager implements MailboxManager {
         return Optional.empty();
     }
 
+    private MailboxPath sanitizeMailboxPath(MailboxPath mailboxPath) {
+        if (mailboxPath.getName().endsWith(String.valueOf(getDelimiter()))) {
+            int length = mailboxPath.getName().length();
+            String sanitizedName = mailboxPath.getName().substring(0, length - 1);
+            return new MailboxPath(
+                mailboxPath.getNamespace(),
+                mailboxPath.getUser(),
+                sanitizedName);
+        }
+        return mailboxPath;
+    }
+
     @Override
     public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException {
         LOGGER.info("deleteMailbox " + mailboxPath);


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


[5/8] james-project git commit: PROTOCOLS-117 Rewrite StoreManagerTests without mock

Posted by ad...@apache.org.
PROTOCOLS-117 Rewrite StoreManagerTests without mock


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

Branch: refs/heads/master
Commit: 2b4626fc7e689ba13f5e70a45cf177f6956ec613
Parents: 7e8aaea
Author: benwa <bt...@linagora.com>
Authored: Thu Nov 9 10:06:31 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:25:59 2017 +0100

----------------------------------------------------------------------
 .../mailbox/store/StoreRightManagerTest.java    | 85 ++++++++++----------
 1 file changed, 42 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2b4626fc/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index 265bfe8..9d765d5 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -30,8 +30,6 @@ import static org.mockito.Mockito.when;
 
 import javax.mail.Flags;
 
-import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.DifferentDomainException;
@@ -43,25 +41,21 @@ import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
 import org.apache.james.mailbox.model.MailboxACL.Right;
+import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Before;
-import org.junit.Rule;
+import org.junit.Ignore;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class StoreRightManagerTest {
 
-    public static final long UID_VALIDITY = 3421l;
+    private static final long UID_VALIDITY = 3421L;
     private StoreRightManager storeRightManager;
-    private MailboxACLResolver mailboxAclResolver;
-    private GroupMembershipResolver groupMembershipResolver;
     private MockMailboxSession aliceSession;
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
     private MailboxMapper mockedMailboxMapper;
 
     @Before
@@ -69,29 +63,29 @@ public class StoreRightManagerTest {
         aliceSession = new MockMailboxSession(MailboxFixture.ALICE);
         MailboxSessionMapperFactory mockedMapperFactory = mock(MailboxSessionMapperFactory.class);
         mockedMailboxMapper = mock(MailboxMapper.class);
-        mailboxAclResolver = new UnionMailboxACLResolver();
-        groupMembershipResolver = new SimpleGroupMembershipResolver();
         when(mockedMapperFactory.getMailboxMapper(aliceSession))
             .thenReturn(mockedMailboxMapper);
+
         storeRightManager = new StoreRightManager(mockedMapperFactory,
-                                                  mailboxAclResolver,
-                                                  groupMembershipResolver);
+            new UnionMailboxACLResolver(),
+            new SimpleGroupMembershipResolver());
     }
 
     @Test
     public void hasRightShouldThrowMailboxNotFoundExceptionWhenMailboxDoesNotExist() throws MailboxException {
-        expectedException.expect(MailboxNotFoundException.class);
-
         MailboxPath mailboxPath = MailboxPath.forUser(MailboxFixture.ALICE, "unexisting mailbox");
         when(mockedMailboxMapper.findMailboxByPath(mailboxPath))
             .thenThrow(new MailboxNotFoundException(""));
-        storeRightManager.hasRight(mailboxPath, Right.Read, aliceSession);
+
+        assertThatThrownBy(() ->
+            storeRightManager.hasRight(mailboxPath, Right.Read, aliceSession))
+            .isInstanceOf(MailboxNotFoundException.class);
     }
 
+    @Ignore("PROTOCOLS-117 Will be solved in next commit")
     @Test
     public void hasRightShouldReturnTrueWhenTheUserOwnTheMailbox() throws MailboxException {
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getUser()).thenReturn(MailboxFixture.ALICE);
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(ALICE, MailboxConstants.INBOX), UID_VALIDITY);
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
             .isFalse();
@@ -99,9 +93,8 @@ public class StoreRightManagerTest {
 
     @Test
     public void hasRightShouldReturnTrueWhenTheUserDoesnotOwnTheMailboxButHaveTheCorrectRightOnIt() throws MailboxException {
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getUser()).thenReturn(MailboxFixture.BOB);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write)));
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
             .isTrue();
@@ -109,9 +102,8 @@ public class StoreRightManagerTest {
 
     @Test
     public void hasRightShouldReturnTrueWhenTheUserDoesnotOwnTheMailboxButHasAtLeastTheCorrectRightOnIt() throws MailboxException {
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getUser()).thenReturn(MailboxFixture.BOB);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write, Right.Lookup)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write, Right.Lookup)));
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
             .isTrue();
@@ -119,8 +111,7 @@ public class StoreRightManagerTest {
 
     @Test
     public void hasRightShouldReturnFalseWhenTheUserDoesNotOwnTheMailboxAndHasNoRightOnIt() throws MailboxException {
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getUser()).thenReturn(MailboxFixture.BOB);
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
             .isFalse();
@@ -128,71 +119,79 @@ public class StoreRightManagerTest {
 
     @Test
     public void isReadWriteShouldReturnTrueWhenUserHasInsertRightOnMailbox() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Insert)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Insert)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isTrue();
     }
 
     @Test
     public void isReadWriteShouldReturnTrueWhenUserHasPerformExpungeRightOnMailbox() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.PerformExpunge)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.PerformExpunge)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isTrue();
     }
 
     @Test
     public void isReadWriteShouldReturnTrueWhenUserHasDeleteMessagesRightOnMailboxAndFlagsContainDeletedFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags(Flags.Flag.DELETED);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.DeleteMessages)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.DeleteMessages)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isTrue();
     }
 
     @Test
     public void isReadWriteShouldReturnFalseWhenUserHasDeleteMessagesRightOnMailboxButFlagsDoesNotContainDeletedFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.DeleteMessages)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.DeleteMessages)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isFalse();
     }
 
     @Test
     public void isReadWriteShouldReturnTrueWhenUserHasWriteSeenFlagRightOnMailboxAndFlagsContainSeenFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags(Flags.Flag.SEEN);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.WriteSeenFlag)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.WriteSeenFlag)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isTrue();
     }
 
     @Test
     public void isReadWriteShouldReturnFalseWhenUserHasWriteSeenFlagRightOnMailboxAndFlagsDoesNotContainSeenFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.WriteSeenFlag)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.WriteSeenFlag)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isFalse();
     }
 
     @Test
     public void isReadWriteShouldReturnTrueWhenUserHasWriteRightOnMailboxAndFlagsContainAnsweredFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags(Flags.Flag.ANSWERED);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Write)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags))
             .isTrue();
     }
 
     @Test
     public void isReadWriteShouldReturnFalseWhenUserDoesNotHaveInsertOrPerformExpungeRightOnMailboxAndNullFlag() throws Exception {
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getACL()).thenReturn(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Administer)));
+        Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY);
+        mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE, Right.Administer)));
+
         assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, new Flags()))
             .isFalse();
     }
@@ -203,7 +202,7 @@ public class StoreRightManagerTest {
             .apply(MailboxACL.command().rights(Right.Read, Right.Write).forUser(BOB).asAddition())
             .apply(MailboxACL.command().rights(Right.Read, Right.Write, Right.Administer).forUser(CEDRIC).asAddition());
         MailboxACL actual = StoreRightManager.filteredForSession(
-            new SimpleMailbox(INBOX_ALICE, UID_VALIDITY), acl, new MockMailboxSession(ALICE));
+            new SimpleMailbox(INBOX_ALICE, UID_VALIDITY), acl, aliceSession);
         assertThat(actual).isEqualTo(acl);
     }
 


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


[4/8] james-project git commit: PROTOCOLS-117 MailboxPath creation SHOULD NOT be dynamic

Posted by ad...@apache.org.
PROTOCOLS-117 MailboxPath creation SHOULD NOT be dynamic


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

Branch: refs/heads/master
Commit: 48d7caf604ca9090ba9253689b4b5b5f5d5c356c
Parents: 9047b4b
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 8 16:42:42 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:23:06 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/model/MailboxPath.java    | 3 +--
 .../james/mailbox/maildir/mail/MaildirMailboxMapper.java    | 2 +-
 .../org/apache/james/imap/processor/CopyProcessorTest.java  | 9 +++------
 .../org/apache/james/imap/processor/MoveProcessorTest.java  | 9 +++------
 .../james/transport/mailets/delivery/MailboxAppender.java   | 4 ++--
 .../james/jmap/DefaultMailboxesProvisioningFilter.java      | 2 +-
 .../james/jmap/methods/SetMailboxesCreationProcessor.java   | 6 ++++--
 .../james/jmap/methods/SetMailboxesUpdateProcessor.java     | 6 +++---
 .../apache/james/webadmin/service/UserMailboxesService.java | 2 +-
 9 files changed, 19 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
index 92afdf2..ea5e760 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java
@@ -39,7 +39,7 @@ public class MailboxPath {
      * @return inbox
      */
     public static MailboxPath inbox(MailboxSession session) {
-        return new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), MailboxConstants.INBOX);
+        return MailboxPath.forUser(session.getUser().getUserName(), MailboxConstants.INBOX);
     }
 
     /**
@@ -47,7 +47,6 @@ public class MailboxPath {
      */
     public static MailboxPath forUser(String username, String mailboxName) {
         return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxName);
-
     }
 
     private String namespace;

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index fe0348a..16ed62a 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -314,7 +314,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
             }
             
             // Special case for INBOX: Let's use the user's folder.
-            MailboxPath inboxMailboxPath = new MailboxPath(session.getPersonalSpace(), userName, MailboxConstants.INBOX);
+            MailboxPath inboxMailboxPath = MailboxPath.forUser(userName, MailboxConstants.INBOX);
             mailboxList.add(maildirStore.loadMailbox(session, inboxMailboxPath));
             
             // List all INBOX sub folders.

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
index 5c0f875..eb61e67 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
+
 import java.util.Optional;
 
 import org.apache.james.imap.api.ImapCommand;
@@ -48,11 +49,11 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.store.MailboxMetaData;
 import org.apache.james.metrics.api.NoopMetricFactory;
-
-import com.google.common.collect.Lists;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.Lists;
+
 public class CopyProcessorTest {
 
     public static final String TAG = "TAG";
@@ -83,7 +84,6 @@ public class CopyProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -122,7 +122,6 @@ public class CopyProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -160,7 +159,6 @@ public class CopyProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -192,7 +190,6 @@ public class CopyProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index aa8a754..7b45822 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
+
 import java.util.Optional;
 
 import org.apache.james.imap.api.ImapCommand;
@@ -51,11 +52,11 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.store.MailboxMetaData;
 import org.apache.james.metrics.api.NoopMetricFactory;
-
-import com.google.common.collect.Lists;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.Lists;
+
 public class MoveProcessorTest {
 
     public static final String TAG = "TAG";
@@ -100,7 +101,6 @@ public class MoveProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -141,7 +141,6 @@ public class MoveProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -180,7 +179,6 @@ public class MoveProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
@@ -212,7 +210,6 @@ public class MoveProcessorTest {
 
         MailboxSession.User user = mock(MailboxSession.User.class);
         when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getPersonalSpace()).thenReturn("");
         when(mockMailboxSession.getUser()).thenReturn(user);
         when(mockMailboxSession.getSessionId()).thenReturn(42L);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
index 2a931c1..50e80dd 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
@@ -25,7 +25,6 @@ import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.james.server.core.MimeMessageInputStream;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -33,6 +32,7 @@ import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.server.core.MimeMessageInputStream;
 
 import com.google.common.base.Strings;
 
@@ -65,7 +65,7 @@ public class MailboxAppender {
     private ComposedMessageId append(MimeMessage mail, String user, String folder, MailboxSession session) throws MessagingException {
         mailboxManager.startProcessingRequest(session);
         try {
-            MailboxPath mailboxPath = new MailboxPath(session.getPersonalSpace(), user, folder);
+            MailboxPath mailboxPath = MailboxPath.forUser(user, folder);
             return appendMessageToMailbox(mail, session, mailboxPath);
         } catch (MailboxException e) {
             throw new MessagingException("Unable to access mailbox.", e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
index 7738e6a..4b9857b 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
@@ -98,7 +98,7 @@ public class DefaultMailboxesProvisioningFilter implements Filter {
     }
 
     private Function<String, MailboxPath> toMailboxPath(MailboxSession session) {
-        return mailbox -> new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), mailbox);
+        return mailbox -> MailboxPath.forUser(session.getUser().getUserName(), mailbox);
     }
     
     private void createMailbox(MailboxPath mailboxPath, MailboxSession session) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
index 51b9c54..d9e4f1f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
@@ -20,9 +20,11 @@
 package org.apache.james.jmap.methods;
 
 import static org.apache.james.jmap.methods.Method.JMAP_PREFIX;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
+
 import javax.inject.Inject;
 
 import org.apache.james.jmap.exceptions.MailboxParentNotFoundException;
@@ -170,10 +172,10 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor {
                             .orElseThrow(() -> new MailboxParentNotFoundException(parentId))
                     ));
 
-            return new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), 
+            return MailboxPath.forUser(mailboxSession.getUser().getUserName(),
                     parentName + mailboxSession.getPathDelimiter() + mailboxRequest.getName());
         }
-        return new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), mailboxRequest.getName());
+        return MailboxPath.forUser(mailboxSession.getUser().getUserName(), mailboxRequest.getName());
     }
 
     private Optional<String> getMailboxNameFromId(MailboxCreationId creationId, MailboxSession mailboxSession) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 4d7a8fd..645182e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -235,9 +235,9 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
     private MailboxPath computeNewMailboxPath(Mailbox mailbox, MailboxPath originMailboxPath, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxException {
         Optional<MailboxId> parentId = updateRequest.getParentId();
         if (parentId == null) {
-            return new MailboxPath(mailboxSession.getPersonalSpace(), 
-                    mailboxSession.getUser().getUserName(), 
-                    updateRequest.getName().orElse(mailbox.getName()));
+            return MailboxPath.forUser(
+                mailboxSession.getUser().getUserName(),
+                updateRequest.getName().orElse(mailbox.getName()));
         }
 
         MailboxPath modifiedMailboxPath = updateRequest.getName()

http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
index 581d1e9..35e1860 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
@@ -122,7 +122,7 @@ public class UserMailboxesService {
     }
 
     private MailboxPath convertToMailboxPath(String username, String mailboxName, MailboxSession mailboxSession) {
-        return new MailboxPath(mailboxSession.getPersonalSpace(), username, mailboxName);
+        return MailboxPath.forUser(username, mailboxName);
     }
 
     private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession) throws MailboxException {


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


[3/8] james-project git commit: PROTOCOLS-117 Delete GroupFolderResolver

Posted by ad...@apache.org.
PROTOCOLS-117 Delete GroupFolderResolver


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

Branch: refs/heads/master
Commit: 5218473de5c1e74f150c6b8ebe46ff63fac7466f
Parents: 48d7caf
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 8 16:27:23 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Nov 13 16:23:06 2017 +0100

----------------------------------------------------------------------
 .../mailbox/store/GroupFolderResolver.java      | 41 -----------
 .../james/mailbox/store/StoreRightManager.java  | 11 ++-
 .../mailbox/store/GroupFolderResolverTest.java  | 75 --------------------
 3 files changed, 8 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5218473d/mailbox/store/src/main/java/org/apache/james/mailbox/store/GroupFolderResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/GroupFolderResolver.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/GroupFolderResolver.java
deleted file mode 100644
index 7be235d..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/GroupFolderResolver.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/****************************************************************
- * 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.mailbox.store;
-
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-
-public class GroupFolderResolver {
-    
-    private final MailboxSession mailboxSession;
-
-    public GroupFolderResolver(MailboxSession mailboxSession) {
-        this.mailboxSession = mailboxSession;
-    }
-
-    public boolean isGroupFolder(Mailbox mailbox) {
-        String namespace = mailbox.getNamespace();
-        return namespace == null || 
-                (!namespace.equals(mailboxSession.getPersonalSpace())
-                && !namespace.equals(MailboxConstants.USER_NAMESPACE)
-                && !namespace.equals(mailboxSession.getOtherUsersSpace()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/5218473d/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index e1796fb..38076df 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -50,6 +50,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 
 public class StoreRightManager implements RightManager {
+    public static final boolean GROUP_FOLDER = true;
 
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
     private final MailboxACLResolver aclResolver;
@@ -102,7 +103,7 @@ public class StoreRightManager implements RightManager {
                     groupMembershipResolver,
                     mailbox.getACL(),
                     mailbox.getUser(),
-                    new GroupFolderResolver(session).isGroupFolder(mailbox)))
+                    !GROUP_FOLDER))
                 .sneakyThrow())
             .orElse(MailboxACL.NO_RIGHTS);
     }
@@ -111,7 +112,11 @@ public class StoreRightManager implements RightManager {
     public Rfc4314Rights[] listRigths(MailboxPath mailboxPath, EntryKey key, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
-        return aclResolver.listRights(key, groupMembershipResolver, mailbox.getUser(), new GroupFolderResolver(session).isGroupFolder(mailbox));
+
+        return aclResolver.listRights(key,
+            groupMembershipResolver,
+            mailbox.getUser(),
+            !GROUP_FOLDER);
     }
 
     @Override
@@ -209,7 +214,7 @@ public class StoreRightManager implements RightManager {
     public MailboxACL getResolvedMailboxACL(Mailbox mailbox, MailboxSession mailboxSession) throws UnsupportedRightException {
         MailboxACL acl = aclResolver.applyGlobalACL(
             mailbox.getACL(),
-            new GroupFolderResolver(mailboxSession).isGroupFolder(mailbox));
+            !GROUP_FOLDER);
 
         return filteredForSession(mailbox, acl, mailboxSession);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5218473d/mailbox/store/src/test/java/org/apache/james/mailbox/store/GroupFolderResolverTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/GroupFolderResolverTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/GroupFolderResolverTest.java
deleted file mode 100644
index 2abbaa9..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/GroupFolderResolverTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************
- * 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.mailbox.store;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.james.mailbox.MailboxSession.SessionType;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.junit.Test;
-
-public class GroupFolderResolverTest {
-
-    private static final long UID_VALIDITY = 9999;
-    private List<Locale> localePreferences = null;
-    private List<String> sharedSpaces = null;
-    private char pathSeparator = ' ';
-    
-    @Test
-    public void isGroupFolderShouldReturnFalseWhenMailboxNamespaceIsNull() {
-        SimpleMailboxSession mailboxSession = new SimpleMailboxSession(1, "username", "password", localePreferences, sharedSpaces, null, pathSeparator, SessionType.User);
-        GroupFolderResolver testee =  new GroupFolderResolver(mailboxSession);
-        
-        SimpleMailbox mailbox = new SimpleMailbox(new MailboxPath(null, "user", "name"), UID_VALIDITY);
-        assertThat(testee.isGroupFolder(mailbox)).isFalse();
-    }
-    
-    @Test
-    public void isGroupFolderShouldReturnFalseWhenMailboxNamespaceEqualsToUserNamespace() {
-        SimpleMailboxSession mailboxSession = new SimpleMailboxSession(1, "username", "password", localePreferences, sharedSpaces, null, pathSeparator, SessionType.User);
-        GroupFolderResolver testee =  new GroupFolderResolver(mailboxSession);
-        
-        SimpleMailbox mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY);
-        assertThat(testee.isGroupFolder(mailbox)).isFalse();
-    }
-    
-    @Test
-    public void isGroupFolderShouldReturnFalseWhenMailboxNamespaceEqualsToOtherUsersNamespace() {
-        String otherUsersSpace = "other";
-        SimpleMailboxSession mailboxSession = new SimpleMailboxSession(1, "username", "password", localePreferences, sharedSpaces, otherUsersSpace, pathSeparator, SessionType.User);
-        GroupFolderResolver testee =  new GroupFolderResolver(mailboxSession);
-        
-        SimpleMailbox mailbox = new SimpleMailbox(new MailboxPath("other", "user", "name"), UID_VALIDITY);
-        assertThat(testee.isGroupFolder(mailbox)).isFalse();
-    }
-    
-    @Test
-    public void isGroupFolderShouldReturnTrueWhenMailboxNamespaceDoesntEqualToOtherUsersNamespace() {
-        String otherUsersSpace = "other";
-        SimpleMailboxSession mailboxSession = new SimpleMailboxSession(1, "username", "password", localePreferences, sharedSpaces, otherUsersSpace, pathSeparator, SessionType.User);
-        GroupFolderResolver testee =  new GroupFolderResolver(mailboxSession);
-        
-        SimpleMailbox mailbox = new SimpleMailbox(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        assertThat(testee.isGroupFolder(mailbox)).isTrue();
-    }
-}


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