This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 7b4e8d2b6a54d7bf0814f62d193f10e1e58a6223 Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Mon Mar 11 11:17:17 2019 +0700 JAMES-2666 add unit test for each group deserialization --- mailbox/caching/pom.xml | 9 ++++-- .../CacheInvalidatingMailboxListenerTest.java | 33 ++++++++++++++++++++++ .../MailboxOperationLoggingListenerTest.java | 33 ++++++++++++++++++++++ ...asticSearchListeningMessageSearchIndexTest.java | 8 ++++++ .../james/mailbox/events/RabbitMQEventBusTest.java | 7 +++++ .../QuotaThresholdCrossingListenerTest.java | 33 ++++++++++++++++++++++ .../ElasticSearchQuotaMailboxListenerTest.java | 7 +++++ .../spamassassin/SpamAssassinListenerTest.java | 7 +++++ .../store/event/MailboxAnnotationListenerTest.java | 8 ++++++ .../quota/ListeningCurrentQuotaUpdaterTest.java | 8 ++++++ .../store/search/LazyMessageSearchIndexTest.java | 33 ++++++++++++++++++++++ .../mailbox/MailboxListenersLoaderImplTest.java | 6 ++++ .../event/PropagateLookupRightListenerTest.java | 7 +++++ 13 files changed, 197 insertions(+), 2 deletions(-) diff --git a/mailbox/caching/pom.xml b/mailbox/caching/pom.xml index 486cfd0..dc39f84 100644 --- a/mailbox/caching/pom.xml +++ b/mailbox/caching/pom.xml @@ -50,8 +50,13 @@ <artifactId>guava</artifactId> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/mailbox/caching/src/test/java/org/apache/james/mailbox/caching/CacheInvalidatingMailboxListenerTest.java b/mailbox/caching/src/test/java/org/apache/james/mailbox/caching/CacheInvalidatingMailboxListenerTest.java new file mode 100644 index 0000000..db725b1 --- /dev/null +++ b/mailbox/caching/src/test/java/org/apache/james/mailbox/caching/CacheInvalidatingMailboxListenerTest.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.caching; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.events.Group; +import org.junit.jupiter.api.Test; + +class CacheInvalidatingMailboxListenerTest { + @Test + void deserializeCacheInvalidatingMailboxListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.caching.CacheInvalidatingMailboxListener$CacheInvalidatingMailboxListenerGroup")) + .isEqualTo(new CacheInvalidatingMailboxListener.CacheInvalidatingMailboxListenerGroup()); + } +} \ No newline at end of file diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListenerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListenerTest.java new file mode 100644 index 0000000..45adb03 --- /dev/null +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListenerTest.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.cassandra; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.events.Group; +import org.junit.jupiter.api.Test; + +class MailboxOperationLoggingListenerTest { + @Test + void deserializeMailboxOperationLoggingListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.cassandra.MailboxOperationLoggingListener$MailboxOperationLoggingListenerGroup")) + .isEqualTo(new MailboxOperationLoggingListener.MailboxOperationLoggingListenerGroup()); + } +} \ No newline at end of file diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java index 0dc602f..e6510eb 100644 --- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java +++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.mailbox.elasticsearch.events; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; @@ -41,6 +42,7 @@ import org.apache.james.mailbox.MailboxSessionUtil; import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson; import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.model.TestId; import org.apache.james.mailbox.model.UpdatedFlags; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; @@ -92,6 +94,12 @@ public class ElasticSearchListeningMessageSearchIndexTest { mailbox = mock(Mailbox.class); when(mailbox.getMailboxId()).thenReturn(MAILBOX_ID); } + + @Test + public void deserializeElasticSearchListeningMessageSearchIndexGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex$ElasticSearchListeningMessageSearchIndexGroup")) + .isEqualTo(new ElasticSearchListeningMessageSearchIndex.ElasticSearchListeningMessageSearchIndexGroup()); + } @Test public void addShouldIndex() throws Exception { diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java index f9d922d..7d70ea5 100644 --- a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java +++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java @@ -59,6 +59,7 @@ import org.apache.james.mailbox.events.EventBusTestFixture.GroupA; import org.apache.james.mailbox.events.EventBusTestFixture.MailboxListenerCountingSuccessfulExecution; import org.apache.james.mailbox.model.TestId; import org.apache.james.mailbox.model.TestMessageId; +import org.apache.james.mailbox.util.EventCollector; import org.apache.james.metrics.api.NoopMetricFactory; import org.apache.james.util.concurrency.ConcurrentTestRunner; import org.junit.jupiter.api.AfterEach; @@ -157,6 +158,12 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract, } @Test + void deserializeEventCollectorGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.util.EventCollector$EventCollectorGroup")) + .isEqualTo(new EventCollector.EventCollectorGroup()); + } + + @Test void registerGroupShouldCreateRetryExchange() throws Exception { MailboxListener listener = newListener(); EventBusTestFixture.GroupA registeredGroup = new EventBusTestFixture.GroupA(); diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListenerTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListenerTest.java new file mode 100644 index 0000000..6b76fd5 --- /dev/null +++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListenerTest.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.quota.mailing.listeners; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.events.Group; +import org.junit.jupiter.api.Test; + +class QuotaThresholdCrossingListenerTest { + @Test + void deserializeQuotaThresholdCrossingListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.quota.mailing.listeners.QuotaThresholdCrossingListener$QuotaThresholdCrossingListenerGroup")) + .isEqualTo(new QuotaThresholdCrossingListener.QuotaThresholdCrossingListenerGroup()); + } +} \ No newline at end of file diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java index a037668..bd01ab8 100644 --- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java +++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java @@ -34,6 +34,7 @@ import org.apache.james.backends.es.ElasticSearchIndexer; import org.apache.james.backends.es.EmbeddedElasticSearch; import org.apache.james.backends.es.utils.TestingClientProvider; import org.apache.james.mailbox.events.Event; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.quota.QuotaFixture.Counts; import org.apache.james.mailbox.quota.QuotaFixture.Sizes; import org.apache.james.mailbox.store.event.EventFactory; @@ -79,6 +80,12 @@ public class ElasticSearchQuotaMailboxListenerTest { } @Test + public void deserializeElasticSearchQuotaMailboxListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.quota.search.elasticsearch.events.ElasticSearchQuotaMailboxListener$ElasticSearchQuotaMailboxListenerGroup")) + .isEqualTo(new ElasticSearchQuotaMailboxListener.ElasticSearchQuotaMailboxListenerGroup()); + } + + @Test public void eventShouldDoNothingWhenNoQuotaEvent() throws Exception { quotaMailboxListener.event(DUMB_EVENT); diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java index f269a43..8bcbf3c 100644 --- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java +++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java @@ -36,6 +36,7 @@ import org.apache.james.mailbox.DefaultMailboxes; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSessionUtil; import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.events.MailboxListener; import org.apache.james.mailbox.events.MessageMoveEvent; import org.apache.james.mailbox.exception.MailboxException; @@ -99,6 +100,12 @@ public class SpamAssassinListenerTest { } @Test + public void deserializeSpamAssassinListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.spamassassin.SpamAssassinListener$SpamAssassinListenerGroup")) + .isEqualTo(new SpamAssassinListener.SpamAssassinListenerGroup()); + } + + @Test public void isEventOnSpamMailboxShouldReturnFalseWhenMessageIsMovedToANonSpamMailbox() { MessageMoveEvent messageMoveEvent = MessageMoveEvent.builder() .session(MAILBOX_SESSION) 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 22160cd..c189ff5 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 @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.mailbox.store.event; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -34,6 +35,7 @@ import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSessionUtil; import org.apache.james.mailbox.events.Event; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.events.MailboxListener; import org.apache.james.mailbox.model.MailboxAnnotation; import org.apache.james.mailbox.model.MailboxAnnotationKey; @@ -95,6 +97,12 @@ public class MailboxAnnotationListenerTest { } @Test + public void deserializeMailboxAnnotationListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.store.event.MailboxAnnotationListener$MailboxAnnotationListenerGroup")) + .isEqualTo(new MailboxAnnotationListener.MailboxAnnotationListenerGroup()); + } + + @Test public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() throws Exception { MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); listener.event(event); 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 5367381..1ab9ee1 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,6 +19,7 @@ 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.ArgumentMatchers.anySet; import static org.mockito.ArgumentMatchers.eq; @@ -39,6 +40,7 @@ import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.events.Event; import org.apache.james.mailbox.events.EventBus; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.events.MailboxListener; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MessageMetaData; @@ -77,6 +79,12 @@ public class ListeningCurrentQuotaUpdaterTest { } @Test + public void deserializeListeningCurrentQuotaUpdaterGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater$ListeningCurrentQuotaUpdaterGroup")) + .isEqualTo(new ListeningCurrentQuotaUpdater.ListeningCurrentQuotaUpdaterGroup()); + } + + @Test public void addedEventShouldIncreaseCurrentQuotaValues() throws Exception { MailboxListener.Added added = mock(MailboxListener.Added.class); when(added.getMailboxId()).thenReturn(MAILBOX_ID); diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndexTest.java new file mode 100644 index 0000000..21f7d09 --- /dev/null +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndexTest.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.search; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.events.Group; +import org.junit.jupiter.api.Test; + +class LazyMessageSearchIndexTest { + @Test + void deserializeLazyMessageSearchIndexGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.mailbox.store.search.LazyMessageSearchIndex$LazyMessageSearchIndexGroup")) + .isEqualTo(new LazyMessageSearchIndex.LazyMessageSearchIndexGroup()); + } +} \ No newline at end of file diff --git a/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java b/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java index 722b603..9ca87b4 100644 --- a/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java +++ b/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java @@ -62,6 +62,12 @@ class MailboxListenersLoaderImplTest { } @Test + void deserializeNoopMailboxListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.modules.mailbox.NoopMailboxListener$NoopMailboxListenerGroup")) + .isEqualTo(new NoopMailboxListener.NoopMailboxListenerGroup()); + } + + @Test void createListenerShouldThrowWhenClassCantBeLoaded() { ListenerConfiguration configuration = ListenerConfiguration.forClass("MyUnknownClass"); diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java index 8edb7d9..d38b37d 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java @@ -26,6 +26,7 @@ import org.apache.james.mailbox.MailboxSessionUtil; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.acl.GroupMembershipResolver; import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; +import org.apache.james.mailbox.events.Group; import org.apache.james.mailbox.events.MailboxListener; import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.mailbox.model.MailboxACL; @@ -93,6 +94,12 @@ public class PropagateLookupRightListenerTest { } @Test + public void deserializePropagateLookupRightListenerGroup() throws Exception { + assertThat(Group.deserialize("org.apache.james.jmap.event.PropagateLookupRightListener$PropagateLookupRightListenerGroup")) + .isEqualTo(new PropagateLookupRightListener.PropagateLookupRightListenerGroup()); + } + + @Test public void getExecutionModeShouldReturnAsynchronous() throws Exception { assertThat(testee.getExecutionMode()).isEqualTo(MailboxListener.ExecutionMode.SYNCHRONOUS); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org