james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [18/19] james-project git commit: JAMES-2616 putting User into MailboxEvent, create a DummyMailboxSession to avoid compilation error
Date Fri, 07 Dec 2018 01:10:41 GMT
JAMES-2616 putting User into MailboxEvent, create a DummyMailboxSession to avoid compilation
error

And duplicate Constructor for each MailboxEvent impl to expose constructors
with user.


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

Branch: refs/heads/master
Commit: 6ae22a22fe58ee4aaa555a38e62a128a7309c4e7
Parents: b90fcba
Author: tran tien duc <dtran@linagora.com>
Authored: Fri Nov 30 14:00:06 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 131 ++++++++++++++++++-
 .../event/AsynchronousEventDeliveryTest.java    |   3 +-
 .../DefaultDelegatingMailboxListenerTest.java   |  20 +--
 .../event/MailboxAnnotationListenerTest.java    |   2 +-
 .../store/event/MixedEventDeliveryTest.java     |   7 +-
 .../event/SynchronousEventDeliveryTest.java     |   3 +-
 6 files changed, 148 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/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 b38de49..02c5856 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
@@ -21,8 +21,11 @@ package org.apache.james.mailbox;
 
 import java.io.Serializable;
 import java.time.Instant;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 
 import org.apache.james.core.User;
 import org.apache.james.core.quota.QuotaCount;
@@ -91,6 +94,11 @@ public interface MailboxListener {
             throw new UnsupportedOperationException("this method will be removed");
         }
 
+        @Override
+        public User getUser() {
+            return user;
+        }
+
         public Quota<QuotaCount> getCountQuota() {
             return countQuota;
         }
@@ -133,17 +141,95 @@ public interface MailboxListener {
      * A mailbox event.
      */
     abstract class MailboxEvent implements Event, Serializable {
+        public static class DummyMailboxSession implements MailboxSession {
+
+            @Override
+            public SessionType getType() {
+                return null;
+            }
+
+            @Override
+            public long getSessionId() {
+                return 0;
+            }
+
+            @Override
+            public boolean isOpen() {
+                return false;
+            }
+
+            @Override
+            public void close() {
+
+            }
+
+            @Override
+            public User getUser() {
+                return null;
+            }
+
+            @Override
+            public String getPersonalSpace() {
+                return null;
+            }
+
+            @Override
+            public String getOtherUsersSpace() {
+                return null;
+            }
+
+            @Override
+            public Collection<String> getSharedSpaces() {
+                return null;
+            }
+
+            @Override
+            public Map<Object, Object> getAttributes() {
+                return null;
+            }
+
+            @Override
+            public char getPathDelimiter() {
+                return 0;
+            }
+        }
+
         private final MailboxSession session;
         private final MailboxPath path;
         private final MailboxId mailboxId;
+        private final User user;
 
         public MailboxEvent(MailboxSession session, MailboxPath path, MailboxId mailboxId)
{
             this.session = session;
             this.path = path;
             this.mailboxId = mailboxId;
+            // To pass some tests, which pass null MailboxSession to the constructors
+            this.user = Optional.ofNullable(session)
+                .map(MailboxSession::getUser)
+                .map(MailboxSession.User::getCoreUser)
+                .orElse(null);
+        }
+
+        public MailboxEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            this.user = user;
+            this.path = path;
+            this.mailboxId = mailboxId;
+            this.session = new DummyMailboxSession();
         }
 
         /**
+         * Gets the {@link User} in which's context the {@link MailboxEvent}
+         * happened
+         *
+         * @return user
+         */
+        @Override
+        public User getUser() {
+            return user;
+        }
+
+
+        /**
          * Gets the {@link MailboxSession} in which's context the {@link MailboxEvent}
          * happened
          * 
@@ -195,6 +281,14 @@ public interface MailboxListener {
             this.totalDeletedSize = totalDeletedSize;
         }
 
+        public MailboxDeletion(User user, MailboxPath path, QuotaRoot quotaRoot, QuotaCount
deletedMessageCOunt, QuotaSize totalDeletedSize,
+                               MailboxId mailboxId) {
+            super(user, path, mailboxId);
+            this.quotaRoot = quotaRoot;
+            this.deletedMessageCOunt = deletedMessageCOunt;
+            this.totalDeletedSize = totalDeletedSize;
+        }
+
         public QuotaRoot getQuotaRoot() {
             return quotaRoot;
         }
@@ -220,6 +314,10 @@ public interface MailboxListener {
         public MailboxAdded(MailboxSession session, MailboxPath path, MailboxId mailboxId)
{
             super(session, path, mailboxId);
         }
+
+        public MailboxAdded(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
     }
 
     /**
@@ -235,6 +333,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MailboxRenamed(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Gets the new name for this mailbox.
          * 
@@ -256,6 +358,11 @@ public interface MailboxListener {
             this.aclDiff = aclDiff;
         }
 
+        public MailboxACLUpdated(User user, MailboxPath path, ACLDiff aclDiff, MailboxId
mailboxId) {
+            super(user, path, mailboxId);
+            this.aclDiff = aclDiff;
+        }
+
         public ACLDiff getAclDiff() {
             return aclDiff;
         }
@@ -276,6 +383,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MessageEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Gets the message UIDs for the subject of this event.
          * 
@@ -290,6 +401,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public MetaDataHoldingEvent(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the afected message
          *
@@ -309,7 +424,11 @@ public interface MailboxListener {
         public Expunged(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
-        
+
+        public Expunged(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the added message
          * 
@@ -333,6 +452,10 @@ public interface MailboxListener {
             super(session, path, mailboxId);
         }
 
+        public FlagsUpdated(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         public abstract List<UpdatedFlags> getUpdatedFlags();
     }
 
@@ -349,7 +472,11 @@ public interface MailboxListener {
         public Added(MailboxSession session, MailboxPath path, MailboxId mailboxId) {
             super(session, path, mailboxId);
         }
-        
+
+        public Added(User user, MailboxPath path, MailboxId mailboxId) {
+            super(user, path, mailboxId);
+        }
+
         /**
          * Return the flags which were set for the added message
          * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
index 7cd2176..44ffae0 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
@@ -53,7 +54,7 @@ public class AsynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() throws Exception {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null,
null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, null, null) {};
         asynchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener, timeout(ONE_MINUTE)).event(event);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
index c9a411a..7442a98 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
@@ -83,7 +83,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -92,7 +92,7 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH,
OTHER_MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -104,9 +104,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount deletedMessageCount = QuotaCount.count(123);
         QuotaSize totalDeletedSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null,
MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession)
null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null,
MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -118,9 +118,9 @@ public class DefaultDelegatingMailboxListenerTest {
         QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
         QuotaCount quotaCount = QuotaCount.count(123);
         QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null,
MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
+        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion((MailboxSession)
null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null,
OTHER_MAILBOX_PATH, MAILBOX_ID) {};
+        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent((MailboxSession)
null, OTHER_MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(secondEvent);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
@@ -130,7 +130,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldWork() {
         defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector,
null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).isEmpty();
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -140,7 +140,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
         defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector,
null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
@@ -150,7 +150,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForONCE() {
         defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).isEmpty();
@@ -160,7 +160,7 @@ public class DefaultDelegatingMailboxListenerTest {
     @Test
     public void removeGlobalListenerShouldWorkForEACH_NODE() {
         defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         defaultDelegatingMailboxListener.event(event);
         assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
         assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 2f77a8b..9a62834 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -95,7 +95,7 @@ public class MailboxAnnotationListenerTest {
 
     @Test
     public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH,
MAILBOX_ID) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, MAILBOX_PATH, MAILBOX_ID) {};
         listener.event(event);
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
index 7eecc59..c2cc095 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
@@ -29,6 +29,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.After;
 import org.junit.Before;
@@ -58,14 +59,14 @@ public class MixedEventDeliveryTest {
     @Test
     public void deliverShouldWorkOnSynchronousListeners() {
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null,
null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, null, null) {};
         mixedEventDelivery.deliver(listener, event);
         verify(listener).event(event);
     }
 
     @Test
     public void deliverShouldEventuallyDeliverOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null,
null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         mixedEventDelivery.deliver(listener, event);
         verify(listener, timeout(DELIVERY_DELAY * 10)).event(event);
@@ -73,7 +74,7 @@ public class MixedEventDeliveryTest {
 
     @Test(timeout = ONE_MINUTE)
     public void deliverShouldNotBlockOnAsynchronousListeners() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null,
null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, null, null) {};
         when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
         final CountDownLatch latch = new CountDownLatch(1);
         doAnswer(invocation -> {

http://git-wip-us.apache.org/repos/asf/james-project/blob/6ae22a22/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
index 2b3e90a..4a1ebda 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.junit.Before;
@@ -42,7 +43,7 @@ public class SynchronousEventDeliveryTest {
 
     @Test
     public void deliverShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null,
null) {};
+        MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent((MailboxSession)
null, null, null) {};
         synchronousEventDelivery.deliver(mailboxListener, event);
         verify(mailboxListener).event(event);
     }


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