james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/19] james-project git commit: JAMES-2616 replace getSession() in ListeningCurrentQuotaUpdater
Date Fri, 07 Dec 2018 01:10:28 GMT
JAMES-2616 replace getSession() in ListeningCurrentQuotaUpdater


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

Branch: refs/heads/master
Commit: 9ac7d7ae03e622baad9861d95db785a625a18d55
Parents: 543284e
Author: tran tien duc <dtran@linagora.com>
Authored: Fri Nov 30 11:42:17 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Dec 7 07:52:50 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 13 ++++----
 .../james/mailbox/quota/QuotaRootResolver.java  |  2 +-
 .../CassandraMailboxManagerProvider.java        |  2 +-
 .../cassandra/CassandraTestSystemFixture.java   |  5 +--
 .../manager/InMemoryIntegrationResources.java   |  2 +-
 .../InMemoryMessageIdManagerSideEffectTest.java |  2 +-
 .../main/resources/META-INF/spring/quota.xml    |  3 +-
 .../mailbox/store/StoreMailboxManager.java      |  2 +-
 .../store/event/MailboxEventDispatcher.java     |  5 +--
 .../quota/DefaultUserQuotaRootResolver.java     | 10 ++++--
 .../quota/ListeningCurrentQuotaUpdater.java     |  8 ++---
 .../quota/DefaultUserQuotaRootResolverTest.java | 21 +++++++-----
 .../quota/ListeningCurrentQuotaUpdaterTest.java | 35 ++++++++++----------
 .../cassandra/host/CassandraHostSystem.java     |  2 +-
 .../host/ElasticSearchHostSystem.java           |  2 +-
 .../inmemory/host/InMemoryHostSystem.java       |  2 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |  2 +-
 .../host/LuceneSearchHostSystem.java            |  4 +--
 .../maildir/host/MaildirHostSystem.java         |  4 +--
 .../transport/matchers/IsOverQuotaTest.java     |  2 +-
 20 files changed, 69 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 5e52828..b38de49 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -24,6 +24,7 @@ import java.time.Instant;
 import java.util.List;
 import java.util.Objects;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.acl.ACLDiff;
@@ -71,14 +72,14 @@ public interface MailboxListener {
     }
 
     class QuotaUsageUpdatedEvent implements QuotaEvent, Serializable {
-        private final MailboxSession session;
+        private final User user;
         private final QuotaRoot quotaRoot;
         private final Quota<QuotaCount> countQuota;
         private final Quota<QuotaSize> sizeQuota;
         private final Instant instant;
 
-        public QuotaUsageUpdatedEvent(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount>
countQuota, Quota<QuotaSize> sizeQuota, Instant instant) {
-            this.session = session;
+        public QuotaUsageUpdatedEvent(User user, QuotaRoot quotaRoot, Quota<QuotaCount>
countQuota, Quota<QuotaSize> sizeQuota, Instant instant) {
+            this.user = user;
             this.quotaRoot = quotaRoot;
             this.countQuota = countQuota;
             this.sizeQuota = sizeQuota;
@@ -87,7 +88,7 @@ public interface MailboxListener {
 
         @Override
         public MailboxSession getSession() {
-            return session;
+            throw new UnsupportedOperationException("this method will be removed");
         }
 
         public Quota<QuotaCount> getCountQuota() {
@@ -112,7 +113,7 @@ public interface MailboxListener {
             if (o instanceof QuotaUsageUpdatedEvent) {
                 QuotaUsageUpdatedEvent that = (QuotaUsageUpdatedEvent) o;
 
-                return Objects.equals(this.session, that.session)
+                return Objects.equals(this.user, that.user)
                     && Objects.equals(this.quotaRoot, that.quotaRoot)
                     && Objects.equals(this.countQuota, that.countQuota)
                     && Objects.equals(this.sizeQuota, that.sizeQuota)
@@ -123,7 +124,7 @@ public interface MailboxListener {
 
         @Override
         public final int hashCode() {
-            return Objects.hash(session, quotaRoot, countQuota, sizeQuota, instant);
+            return Objects.hash(user, quotaRoot, countQuota, sizeQuota, instant);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
index 38aa4e6..6adff1e 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
@@ -38,7 +38,7 @@ public interface QuotaRootResolver {
      */
     QuotaRoot getQuotaRoot(MailboxPath mailboxPath) throws MailboxException;
 
-    QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException;
+    QuotaRoot getQuotaRoot(MailboxId mailboxId) throws MailboxException;
 
     QuotaRoot fromString(String serializedQuotaRoot) throws MailboxException;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
index 569def8..8f66335 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerProvider.java
@@ -79,7 +79,7 @@ public class CassandraMailboxManagerProvider {
             new CassandraGlobalMaxQuotaDao(session));
         CassandraCurrentQuotaManager currentQuotaUpdater = new CassandraCurrentQuotaManager(session);
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaUpdater,
maxQuotaManager);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(manager, mapperFactory);
 
         ListeningCurrentQuotaUpdater quotaUpdater = new ListeningCurrentQuotaUpdater(currentQuotaUpdater,
quotaRootResolver, mailboxEventDispatcher, storeQuotaManager);
         manager.setQuotaManager(storeQuotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
index f89c251..6e70274 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
@@ -73,13 +73,14 @@ public class CassandraTestSystemFixture {
     }
 
     public static StoreMessageIdManager createMessageIdManager(CassandraMailboxSessionMapperFactory
mapperFactory, QuotaManager quotaManager, MailboxEventDispatcher dispatcher) throws Exception
{
+        CassandraMailboxManager mailboxManager = createMailboxManager(mapperFactory);
         return new StoreMessageIdManager(
-            createMailboxManager(mapperFactory),
+            mailboxManager,
             mapperFactory,
             dispatcher,
             new CassandraMessageId.Factory(),
             quotaManager,
-            new DefaultUserQuotaRootResolver(mapperFactory));
+            new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));
     }
 
     public static MaxQuotaManager createMaxQuotaManager(CassandraCluster cassandra) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index e6d6ee8..4255f82 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -251,7 +251,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
     @Override
     public DefaultUserQuotaRootResolver createQuotaRootResolver(StoreMailboxManager mailboxManager)
{
         if (quotaRootResolver == null) {
-            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
         }
         return quotaRootResolver;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
index 43295bd..feba1f4 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java
@@ -76,7 +76,7 @@ public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdMan
             dispatcher,
             messageIdFactory,
             quotaManager,
-            new DefaultUserQuotaRootResolver(mapperFactory));
+            new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory));
         return new MessageIdManagerTestSystem(messageIdManager, messageIdFactory, mapperFactory,
mailboxManager);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
index a43f300..faae187 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/quota.xml
@@ -26,7 +26,8 @@
         <constructor-arg index="0" ref="entityManagerFactory" />
     </bean>
     <bean id="defaultQuotaRootResolver" class="org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver"
lazy-init="true">
-        <constructor-arg index="0" ref="messageMapperFactory"/>
+        <constructor-arg index="0" ref="mailboxmanager"/>
+        <constructor-arg index="1" ref="messageMapperFactory"/>
     </bean>
 
     <bean id="currentQuotaCalculator" class="org.apache.james.mailbox.store.quota.CurrentQuotaCalculator"
lazy-init="true">

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/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 63c30ef..a8fda79 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
@@ -236,7 +236,7 @@ public class StoreMailboxManager implements MailboxManager {
             quotaManager = new NoQuotaManager();
         }
         if (quotaRootResolver == null) {
-            quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxSessionMapperFactory);
+            quotaRootResolver = new DefaultUserQuotaRootResolver(this, mailboxSessionMapperFactory);
         }
         if (quotaUpdater != null && quotaUpdater instanceof MailboxListener) {
             this.addGlobalListener((MailboxListener) quotaUpdater, session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index d6eee58..206e8b7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -26,6 +26,7 @@ import java.util.SortedMap;
 
 import javax.inject.Inject;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.Event;
@@ -169,8 +170,8 @@ public class MailboxEventDispatcher {
         }
     }
 
-    public void quota(MailboxSession session, QuotaRoot quotaRoot, Quota<QuotaCount>
countQuota, Quota<QuotaSize> sizeQuota) {
-        listener.event(new MailboxListener.QuotaUsageUpdatedEvent(session, quotaRoot, countQuota,
sizeQuota, Instant.now()));
+    public void quota(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota,
Quota<QuotaSize> sizeQuota) {
+        listener.event(new MailboxListener.QuotaUsageUpdatedEvent(user, quotaRoot, countQuota,
sizeQuota, Instant.now()));
     }
 
     public void event(Event event) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
index 2340ff1..3d86e2d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
@@ -25,6 +25,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -43,10 +44,12 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver
{
 
     public static final String SEPARATOR = "&"; // Character illegal for mailbox naming
in regard of RFC 3501 section 5.1
 
+    private final MailboxManager mailboxManager;
     private final MailboxSessionMapperFactory factory;
 
     @Inject
-    public DefaultUserQuotaRootResolver(MailboxSessionMapperFactory factory) {
+    public DefaultUserQuotaRootResolver(MailboxManager mailboxManager, MailboxSessionMapperFactory
factory) {
+        this.mailboxManager = mailboxManager;
         this.factory = factory;
     }
 
@@ -69,9 +72,10 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver
{
     }
 
     @Override
-    public QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws
MailboxException {
+    public QuotaRoot getQuotaRoot(MailboxId mailboxId) throws MailboxException {
+        MailboxSession session = mailboxManager.createSystemSession("DefaultUserQuotaRootResolver");
         User user = User.fromUsername(
-            factory.getMailboxMapper(mailboxSession)
+            factory.getMailboxMapper(session)
                 .findMailboxById(mailboxId)
                 .generateAssociatedPath()
                 .getUser());

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 5f9da05..e8f4e54 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -60,11 +60,11 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener,
QuotaUpdat
         try {
             if (event instanceof Added) {
                 Added addedEvent = (Added) event;
-                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId(),
event.getSession());
+                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId());
                 handleAddedEvent(addedEvent, quotaRoot);
             } else if (event instanceof Expunged) {
                 Expunged expungedEvent = (Expunged) event;
-                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId(),
event.getSession());
+                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId());
                 handleExpungedEvent(expungedEvent, quotaRoot);
             } else if (event instanceof MailboxDeletion) {
                 MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
@@ -87,7 +87,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.decrease(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(expunged.getSession(),
+        dispatcher.quota(expunged.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));
@@ -104,7 +104,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener,
QuotaUpdat
         if (addedCount != 0 && addedSize != 0) {
             currentQuotaManager.increase(quotaRoot, addedCount, addedSize);
         }
-        dispatcher.quota(added.getSession(),
+        dispatcher.quota(added.getUser(),
             quotaRoot,
             quotaManager.getMessageQuota(quotaRoot),
             quotaManager.getStorageQuota(quotaRoot));

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
index f5f98ff..52ee7b3 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
@@ -20,11 +20,13 @@
 package org.apache.james.mailbox.store.quota;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.Optional;
 
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
@@ -41,7 +43,7 @@ import com.google.common.collect.Lists;
 
 public class DefaultUserQuotaRootResolverTest {
 
-    public static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
+    private static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
     public static final SimpleMailbox MAILBOX = new SimpleMailbox(MAILBOX_PATH, 10);
     private static final MailboxPath PATH_LIKE = MailboxPath.forUser("benwa", "%");
     private static final MailboxPath MAILBOX_PATH_2 = MailboxPath.forUser("benwa", "test");
@@ -55,8 +57,9 @@ public class DefaultUserQuotaRootResolverTest {
 
     @Before
     public void setUp() {
+        MailboxManager mailboxManager = mock(MailboxManager.class);
         mockedFactory = mock(MailboxSessionMapperFactory.class);
-        testee = new DefaultUserQuotaRootResolver(mockedFactory);
+        testee = new DefaultUserQuotaRootResolver(mailboxManager, mockedFactory);
     }
 
     @Test
@@ -90,18 +93,18 @@ public class DefaultUserQuotaRootResolverTest {
         assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, MAILBOX_SESSION)).containsOnly(MAILBOX_PATH,
MAILBOX_PATH_2);
     }
 
+    @Test(expected = MailboxException.class)
+    public void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times()
throws Exception {
+        testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa",
Optional.empty()), MAILBOX_SESSION);
+    }
+
     @Test
     public void getQuotaRootShouldReturnUserValueWhenCalledWithMailboxId() throws Exception
{
         MailboxMapper mockedMapper = mock(MailboxMapper.class);
-        when(mockedFactory.getMailboxMapper(MAILBOX_SESSION)).thenReturn(mockedMapper);
+        when(mockedFactory.getMailboxMapper(any())).thenReturn(mockedMapper);
         when(mockedMapper.findMailboxById(MAILBOX_ID)).thenReturn(MAILBOX);
 
-        assertThat(testee.getQuotaRoot(MAILBOX_ID, MAILBOX_SESSION)).isEqualTo(QUOTA_ROOT);
-    }
-
-    @Test(expected = MailboxException.class)
-    public void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times()
throws Exception {
-        testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa",
Optional.empty()), MAILBOX_SESSION);
+        assertThat(testee.getQuotaRoot(MAILBOX_ID)).isEqualTo(QUOTA_ROOT);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index a14dd30..241b62b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.mailbox.store.quota;
 
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -32,12 +31,11 @@ import java.util.Optional;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
@@ -55,8 +53,9 @@ public class ListeningCurrentQuotaUpdaterTest {
 
     private static final int SIZE = 45;
     private static final MailboxId MAILBOX_ID = TestId.of(42);
-    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", Optional.empty());
-    private static final MailboxSession MAILBOX_SESSION = new MockMailboxSession("benwa");
+    private static final String BENWA = "benwa";
+    private static final User USER_BENWA = User.fromUsername(BENWA);
+    private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot(BENWA, Optional.empty());
 
     private StoreCurrentQuotaManager mockedCurrentQuotaManager;
     private QuotaRootResolver mockedQuotaRootResolver;
@@ -73,12 +72,12 @@ public class ListeningCurrentQuotaUpdaterTest {
     @Test
     public void addedEventShouldIncreaseCurrentQuotaValues() throws Exception {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
+        when(added.getMailboxId()).thenReturn(MAILBOX_ID);
         when(added.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new
Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(added.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new
Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
-        when(added.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(added.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(added.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(added);
 
@@ -92,8 +91,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new
Flags(), SIZE, new Date(), new DefaultMessageId()));
         when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
         when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(expunged.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(expunged);
 
@@ -105,8 +104,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
         when(expunged.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
         when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(expunged.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(expunged);
 
@@ -118,8 +117,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
         when(added.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
         when(added.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(added.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(added.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(added);
 
@@ -133,8 +132,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(10));
         when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(5));
         when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(deletion.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(deletion);
 
@@ -148,8 +147,8 @@ public class ListeningCurrentQuotaUpdaterTest {
         when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(0));
         when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(0));
         when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
-        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+        when(deletion.getUser()).thenReturn(USER_BENWA);
+        when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
 
         testee.event(deletion);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index f40a588..6df19d7 100644
--- a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -92,7 +92,7 @@ public class CassandraHostSystem extends JamesImapHostSystem {
         mailboxManager = new CassandraMailboxManager(mapperFactory, authenticator, authorizator,
             new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory,
             mailboxEventDispatcher, delegatingMailboxListener, annotationManager, storeRightManager);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager,
mapperFactory);
 
         perUserMaxQuotaManager = new CassandraPerUserMaxQuotaManager(
             new CassandraPerUserMaxQuotaDao(session),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 4186ee9..058c0c9 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -123,7 +123,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
             DefaultImapProcessorFactory.createDefaultProcessor(this.mailboxManager,
                 new StoreSubscriptionManager(factory),
                 new NoQuotaManager(),
-                new DefaultUserQuotaRootResolver(factory),
+                new DefaultUserQuotaRootResolver(mailboxManager, factory),
                 new DefaultMetricFactory());
         configure(new DefaultImapDecoderFactory().buildImapDecoder(),
             new DefaultImapEncoderFactory().buildImapEncoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
index 2de23d3..3c36732 100644
--- a/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
+++ b/mpt/impl/imap-mailbox/inmemory/src/test/java/org/apache/james/mpt/imapmailbox/inmemory/host/InMemoryHostSystem.java
@@ -65,7 +65,7 @@ public class InMemoryHostSystem extends JamesImapHostSystem {
         super.beforeTest();
         this.mailboxManager = new InMemoryIntegrationResources()
             .createMailboxManager(new SimpleGroupMembershipResolver(), authenticator, authorizator);
-        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+        QuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager,
mailboxManager.getMapperFactory());
 
         perUserMaxQuotaManager = new InMemoryPerUserMaxQuotaManager();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
index 3c78b0a..c540145 100644
--- a/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
+++ b/mpt/impl/imap-mailbox/jpa/src/test/java/org/apache/james/mpt/imapmailbox/jpa/host/JPAHostSystem.java
@@ -104,7 +104,7 @@ public class JPAHostSystem extends JamesImapHostSystem {
             messageParser, new DefaultMessageId.Factory(), delegatingListener,
             mailboxEventDispatcher, annotationManager, storeRightManager);
 
-        DefaultUserQuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mapperFactory);
+        DefaultUserQuotaRootResolver quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager,
mapperFactory);
         JpaCurrentQuotaManager currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);
         maxQuotaManager = new JPAPerUserMaxQuotaManager(new JPAPerUserMaxQuotaDAO(entityManagerFactory));
         StoreQuotaManager storeQuotaManager = new StoreQuotaManager(currentQuotaManager,
maxQuotaManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index 6ebc72f..9161134 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -124,12 +124,12 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
 
             SubscriptionManager subscriptionManager = new StoreSubscriptionManager(mapperFactory);
 
-            final ImapProcessor defaultImapProcessorFactory =
+            ImapProcessor defaultImapProcessorFactory =
                 DefaultImapProcessorFactory.createDefaultProcessor(
                     mailboxManager,
                     subscriptionManager,
                     new NoQuotaManager(),
-                    new DefaultUserQuotaRootResolver(mapperFactory),
+                    new DefaultUserQuotaRootResolver(mailboxManager, mapperFactory),
                     new DefaultMetricFactory());
 
             configure(new DefaultImapDecoderFactory().buildImapDecoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
index 4587a5a..a55cf7b 100644
--- a/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
+++ b/mpt/impl/imap-mailbox/maildir/src/test/java/org/apache/james/mpt/imapmailbox/maildir/host/MaildirHostSystem.java
@@ -84,12 +84,12 @@ public class MaildirHostSystem extends JamesImapHostSystem {
             mailboxEventDispatcher, delegatingListener, storeRightManager);
         mailboxManager.init();
 
-        final ImapProcessor defaultImapProcessorFactory = 
+        ImapProcessor defaultImapProcessorFactory =
                 DefaultImapProcessorFactory.createDefaultProcessor(
                         mailboxManager, 
                         sm, 
                         new NoQuotaManager(), 
-                        new DefaultUserQuotaRootResolver(mailboxSessionMapperFactory),
+                        new DefaultUserQuotaRootResolver(mailboxManager, mailboxSessionMapperFactory),
                         new DefaultMetricFactory());
         configure(new DefaultImapDecoderFactory().buildImapDecoder(),
                 new DefaultImapEncoderFactory().buildImapEncoder(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ac7d7ae/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
index 25e021f..b25da39 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/IsOverQuotaTest.java
@@ -56,7 +56,7 @@ public class IsOverQuotaTest {
     public void setUp() throws Exception {
         mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver());
 
-        quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory());
+        quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager, mailboxManager.getMapperFactory());
         maxQuotaManager = new InMemoryPerUserMaxQuotaManager();
         CurrentQuotaCalculator quotaCalculator = new CurrentQuotaCalculator(mailboxManager.getMapperFactory(),
quotaRootResolver);
         InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(quotaCalculator,
mailboxManager);


---------------------------------------------------------------------
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