james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [14/18] james-project git commit: JAMES-2553 Rewrite JamesCapabilitiesServerTest test in JUNIT 5
Date Thu, 04 Oct 2018 10:49:34 GMT
JAMES-2553 Rewrite JamesCapabilitiesServerTest test in JUNIT 5

Note that no message capability for attachment exists thus one test made no sens, and was
passing because of a bad mockito usage.


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

Branch: refs/heads/master
Commit: c001475dd3c977c09d2f27050a782a13ed4892cb
Parents: 485122c
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Oct 1 12:04:57 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../james/JamesCapabilitiesServerTest.java      | 155 ++++++-------------
 .../JamesServerWithRetryConnectionTest.java     |   4 +-
 2 files changed, 48 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c001475d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 5e60808..c1ba326 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -23,178 +23,113 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.io.IOException;
 import java.util.EnumSet;
 
-import org.apache.activemq.store.PersistenceAdapter;
-import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
-import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.jmap.methods.GetMessageListMethod;
 import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.modules.TestJMAPServerModule;
-import org.apache.james.server.core.configuration.Configuration;
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-import com.google.inject.Module;
+class JamesCapabilitiesServerTest {
+    private static final MailboxManager mailboxManager = mock(MailboxManager.class);
 
-public class JamesCapabilitiesServerTest {
+    private static final int LIMIT_MAX_MESSAGES = 10;
 
-    private GuiceJamesServer server;
-    private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
-
-    @ClassRule
-    public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
-    
-    @Rule
-    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
-
-    @After
-    public void teardown() {
-        server.stop();
-    }
-    
-    private GuiceJamesServer createCassandraJamesServer(final MailboxManager mailboxManager)
throws IOException {
-        Module mockMailboxManager = (binder) -> binder.bind(MailboxManager.class).toInstance(mailboxManager);
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(temporaryFolder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-        return GuiceJamesServer.forConfiguration(configuration)
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
-            .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
-            .overrideWith(new TestElasticSearchModule(embeddedElasticSearch),
-                cassandraServer.getModule(),
-                new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT),
-                mockMailboxManager);
-    }
-    
-    @Test
-    public void startShouldFailWhenNoMoveCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.MailboxCapabilities.Move)));
-        when(mailboxManager.getSupportedMessageCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
-        when(mailboxManager.getSupportedSearchCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_MAX_MESSAGES))
+            .overrideWith(binder -> binder.bind(MailboxManager.class).toInstance(mailboxManager)))
+        .disableAutoStart()
+        .build();
 
-        server = createCassandraJamesServer(mailboxManager);
-        
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
-    }
-    
     @Test
-    public void startShouldFailWhenNoACLCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.MailboxCapabilities.ACL)));
+    void startShouldFailWhenNoMoveCapability(GuiceJamesServer server) {
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(false);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
-
-        server = createCassandraJamesServer(mailboxManager);
         
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
     
     @Test
-    public void startShouldFailWhenNoAttachmentCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MailboxCapabilities.class));
+    void startShouldFailWhenNoACLCapability(GuiceJamesServer server) {
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(false);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
-
-        server = createCassandraJamesServer(mailboxManager);
-
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
     
     @Test
-    public void startShouldFailWhenNoAttachmentSearchCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MailboxCapabilities.class));
+    void startShouldFailWhenNoAttachmentSearchCapability(GuiceJamesServer server) {
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.Attachment)));
 
-        server = createCassandraJamesServer(mailboxManager);
-
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void startShouldFailWhenNoAttachmentFileNameSearchCapability() throws Exception
{
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MailboxCapabilities.class));
+    void startShouldFailWhenNoAttachmentFileNameSearchCapability(GuiceJamesServer server)
{
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.AttachmentFileName)));
 
-        server = createCassandraJamesServer(mailboxManager);
-
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
     
     @Test
-    public void startShouldFailWhenNoMultimailboxSearchCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MailboxCapabilities.class));
+    void startShouldFailWhenNoMultimailboxSearchCapability(GuiceJamesServer server) {
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.MultimailboxSearch)));
 
-        server = createCassandraJamesServer(mailboxManager);
-
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void startShouldFailWhenNoUniqueIDCapability() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.getSupportedMailboxCapabilities())
-            .thenReturn(EnumSet.allOf(MailboxManager.MailboxCapabilities.class));
+    void startShouldFailWhenNoUniqueIDCapability(GuiceJamesServer server) {
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.MessageCapabilities.UniqueID)));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
 
-        server = createCassandraJamesServer(mailboxManager);
-
-        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void startShouldSucceedWhenRequiredCapabilities() throws Exception {
-        MailboxManager mailboxManager = mock(MailboxManager.class);
-        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move))
-            .thenReturn(true);
-        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL))
-            .thenReturn(true);
+    void startShouldSucceedWhenRequiredCapabilities(GuiceJamesServer server) throws Exception
{
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move)).thenReturn(true);
+        when(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL)).thenReturn(true);
         when(mailboxManager.getSupportedMessageCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
 
-        server = createCassandraJamesServer(mailboxManager);
-
         server.start();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/c001475d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
index bc2d6cb..d7c8cde 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
@@ -44,6 +44,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.inject.Module;
 
@@ -89,9 +90,10 @@ class JamesServerWithRetryConnectionTest {
         .withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT);
     private static final DockerCassandraRule cassandraRule = new DockerCassandraRule();
 
+    @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
         .extension(new DockerElasticSearchRegistrableExtension(elasticSearchContainer))
-        .extension(new CassandraExtension())
+        .extension(new CassandraExtension(cassandraRule))
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
             .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))


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