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 bt...@apache.org on 2019/01/17 06:50:18 UTC

[02/27] james-project git commit: JAMES-2641 Delete DefaultDelegatingMailboxListenerTest

JAMES-2641 Delete DefaultDelegatingMailboxListenerTest


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

Branch: refs/heads/master
Commit: 0947b1b300b731139212c0a821fa44520adfff5c
Parents: 1f390f4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Jan 10 10:05:52 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 10:23:40 2019 +0700

----------------------------------------------------------------------
 .../DefaultDelegatingMailboxListenerTest.java   | 196 -------------------
 1 file changed, 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0947b1b3/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
deleted file mode 100644
index 9490f63..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
+++ /dev/null
@@ -1,196 +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.event;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-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;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSessionUtil;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.util.EventCollector;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableSortedMap;
-
-public class DefaultDelegatingMailboxListenerTest {
-
-    private static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "user", "name");
-    private static final MailboxPath OTHER_MAILBOX_PATH = new MailboxPath("namespace", "other", "name");
-    private static final MailboxId MAILBOX_ID = TestId.of(100);
-    private static final MailboxId OTHER_MAILBOX_ID = TestId.of(42);
-
-    private DefaultDelegatingMailboxListener defaultDelegatingMailboxListener;
-    private EventCollector mailboxEventCollector;
-    private EventCollector eachNodeEventCollector;
-    private EventCollector onceEventCollector;
-
-    @Before
-    public void setUp() throws Exception {
-        mailboxEventCollector = new EventCollector(MailboxListener.ListenerType.MAILBOX);
-        eachNodeEventCollector = new EventCollector(MailboxListener.ListenerType.EACH_NODE);
-        onceEventCollector = new EventCollector(MailboxListener.ListenerType.ONCE);
-        defaultDelegatingMailboxListener = new DefaultDelegatingMailboxListener();
-        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxEventCollector, null);
-        defaultDelegatingMailboxListener.addGlobalListener(onceEventCollector, null);
-        defaultDelegatingMailboxListener.addGlobalListener(eachNodeEventCollector, null);
-    }
-
-    @Test(expected = MailboxException.class)
-    public void addListenerShouldThrowOnEACH_NODEListenerType() throws Exception {
-        MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.EACH_NODE);
-        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null);
-    }
-
-    @Test(expected = MailboxException.class)
-    public void addListenerShouldThrowOnONCEListenerType() throws Exception {
-        MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.ONCE);
-        defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null);
-    }
-
-    @Test(expected = MailboxException.class)
-    public void addGlobalListenerShouldThrowOnMAILBOXListenerType() throws Exception {
-        MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.MAILBOX);
-        defaultDelegatingMailboxListener.addGlobalListener(mailboxListener, null);
-    }
-
-    @Test
-    public void eventShouldWork() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event);
-    }
-
-    @Test
-    public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() {
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).isEmpty();
-        assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event);
-    }
-
-    @Test
-    public void mailboxDeletionShouldUnregisterMAILBOXListeners() {
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null);
-        QuotaCount deletedMessageCount = QuotaCount.count(123);
-        QuotaSize totalDeletedSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(secondEvent);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent);
-    }
-
-    @Test
-    public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() {
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null);
-        QuotaCount quotaCount = QuotaCount.count(123);
-        QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(secondEvent);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent);
-    }
-
-    @Test
-    public void removeListenerShouldWork() {
-        defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).isEmpty();
-        assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event);
-    }
-
-    @Test
-    public void removeListenerShouldNotRemoveAListenerFromADifferentPath() {
-        defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
-        assertThat(onceEventCollector.getEvents()).containsExactly(event);
-    }
-
-    @Test
-    public void removeGlobalListenerShouldWorkForONCE() {
-        defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).isEmpty();
-        assertThat(onceEventCollector.getEvents()).containsExactly(event);
-    }
-
-    @Test
-    public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception {
-        defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null);
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        defaultDelegatingMailboxListener.event(event);
-        assertThat(mailboxEventCollector.getEvents()).containsExactly(event);
-        assertThat(eachNodeEventCollector.getEvents()).containsExactly(event);
-        assertThat(onceEventCollector.getEvents()).isEmpty();
-    }
-
-    @Test
-    public void listenersErrorsShouldNotBePropageted() throws Exception {
-        MailboxSession session = MailboxSessionUtil.create("benwa");
-        MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(session.getSessionId(),
-            session.getUser(), MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
-        MailboxListener mockedListener = mock(MailboxListener.class);
-        when(mockedListener.getType()).thenReturn(MailboxListener.ListenerType.ONCE);
-        doThrow(new RuntimeException()).when(mockedListener).event(event);
-
-        defaultDelegatingMailboxListener.addGlobalListener(mockedListener, null);
-
-        defaultDelegatingMailboxListener.event(event);
-    }
-
-
-    @Test
-    public void listenersShouldReceiveEvents() {
-        MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random());
-
-        defaultDelegatingMailboxListener.event(noopEvent);
-
-        assertThat(onceEventCollector.getEvents()).isEmpty();
-    }
-
-}


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