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 2018/10/04 10:49:21 UTC

[01/18] james-project git commit: JAMES-2553 Rewrite CassandraMailRepositoryIntegrationTest test in JUNIT 5

Repository: james-project
Updated Branches:
  refs/heads/master 76900c276 -> 6bfbc8ed4


JAMES-2553 Rewrite CassandraMailRepositoryIntegrationTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: dbb4833c8ec15a26b079d747a053d515b84b6d7a
Parents: 8a678c3
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 09:47:50 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../CassandraMailRepositoryIntegrationTest.java | 61 ++++++++------------
 1 file changed, 25 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/dbb4833c/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
index 97c021a..0c3797a 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
@@ -19,11 +19,15 @@
 
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.MailRepositoryProbeImpl;
@@ -31,47 +35,34 @@ import org.apache.james.utils.SMTPMessageSender;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
 import org.awaitility.core.ConditionFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class CassandraMailRepositoryIntegrationTest {
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
+class CassandraMailRepositoryIntegrationTest {
     private static final MailRepositoryUrl SENDER_DENIED_URL = MailRepositoryUrl.from("cassandra://var/mail/sender-denied/");
     private static final Duration ONE_MILLISECOND = new Duration(1, TimeUnit.MILLISECONDS);
+    private static ConditionFactory await = Awaitility.with()
+        .pollInterval(FIVE_HUNDRED_MILLISECONDS)
+        .and()
+        .with()
+        .pollDelay(ONE_MILLISECOND)
+        .await();
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-    @Rule
-    public SMTPMessageSender smtpMessageSender = new SMTPMessageSender("other.com");
-
-    private GuiceJamesServer server;
-    private ConditionFactory await;
+    private SMTPMessageSender smtpMessageSender = new SMTPMessageSender("other.com");
 
-    @Before
-    public void setup() throws Exception {
-        server = cassandraJmap.jmapServer(cassandra.getModule());
-        server.start();
-        await = Awaitility.with()
-            .pollInterval(FIVE_HUNDRED_MILLISECONDS)
-            .and()
-            .with()
-            .pollDelay(ONE_MILLISECOND)
-            .await();
-    }
-
-    @After
-    public void tearDown() {
-        server.stop();
-    }
+    @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(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)))
+        .build();
 
     @Test
-    public void deniedSenderMailShouldBeStoredInCassandraMailRepositoryWhenConfigured() throws Exception {
+    void deniedSenderMailShouldBeStoredInCassandraMailRepositoryWhenConfigured(GuiceJamesServer server) throws Exception {
         server.getProbe(DataProbeImpl.class)
             .fluent()
             .addDomain("domain.com")
@@ -83,6 +74,4 @@ public class CassandraMailRepositoryIntegrationTest {
         MailRepositoryProbeImpl repositoryProbe = server.getProbe(MailRepositoryProbeImpl.class);
         await.until(() -> repositoryProbe.getRepositoryMailCount(SENDER_DENIED_URL) == 1);
     }
-
-
 }


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


[18/18] james-project git commit: JAMES-2553 Rewrite CassandraVersionCheckingTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite CassandraVersionCheckingTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: a697f687a123c3e11feab29651b90947281ab42c
Parents: 4fa7952
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 10:54:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../james/CassandraVersionCheckingTest.java     | 123 +++++++------------
 1 file changed, 44 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a697f687/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
index 585bb4a..45e79fc 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
@@ -18,7 +18,9 @@
  ****************************************************************/
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -33,129 +35,93 @@ import java.util.concurrent.CompletableFuture;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
 import org.apache.james.backends.cassandra.versions.SchemaVersion;
+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.modules.protocols.ImapGuiceProbe;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class CassandraVersionCheckingTest {
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
+class CassandraVersionCheckingTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
     private static final String LOCAL_HOST = "127.0.0.1";
     private static final SchemaVersion MIN_VERSION = new SchemaVersion(2);
     private static final SchemaVersion MAX_VERSION = new SchemaVersion(4);
 
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = CassandraJmapTestRule.defaultTestRule();
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+    private static CassandraSchemaVersionDAO versionDAO = mock(CassandraSchemaVersionDAO.class);
+
+    @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(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> binder.bind(CassandraSchemaVersionDAO.class)
+                .toInstance(versionDAO))
+            .overrideWith(binder -> binder.bind(CassandraSchemaVersionManager.class)
+                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION))))
+        .disableAutoStart()
+        .build();
 
-    private GuiceJamesServer jamesServer;
     private SocketChannel socketChannel;
-    private CassandraSchemaVersionDAO versionDAO;
 
-    @Before
-    public void setUp() throws IOException {
+    @BeforeEach
+    void setUp() throws IOException {
         socketChannel = SocketChannel.open();
-        versionDAO = mock(CassandraSchemaVersionDAO.class);
     }
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         socketChannel.close();
-        if (jamesServer != null) {
-            jamesServer.stop();
-        }
     }
 
     @Test
-    public void serverShouldStartSuccessfullyWhenMaxVersion() throws Exception {
+    void serverShouldStartSuccessfullyWhenMaxVersion(GuiceJamesServer server) throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(MAX_VERSION)));
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            cassandra.getModule(),
-            binder -> binder.bind(CassandraSchemaVersionDAO.class)
-                .toInstance(versionDAO),
-            binder -> binder.bind(CassandraSchemaVersionManager.class)
-                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION)));
-
-        assertThatServerStartCorrectly();
+        assertThatServerStartCorrectly(server);
     }
 
     @Test
-    public void serverShouldStartSuccessfullyWhenBetweenMinAndMaxVersion() throws Exception {
+    void serverShouldStartSuccessfullyWhenBetweenMinAndMaxVersion(GuiceJamesServer server) throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION.next())));
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            cassandra.getModule(),
-            binder -> binder.bind(CassandraSchemaVersionDAO.class)
-                .toInstance(versionDAO),
-            binder -> binder.bind(CassandraSchemaVersionManager.class)
-                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION)));
-
-        assertThatServerStartCorrectly();
+        assertThatServerStartCorrectly(server);
     }
 
     @Test
-    public void serverShouldStartSuccessfullyWhenMinVersion() throws Exception {
+    void serverShouldStartSuccessfullyWhenMinVersion(GuiceJamesServer server) throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION)));
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            cassandra.getModule(),
-            binder -> binder.bind(CassandraSchemaVersionDAO.class)
-                .toInstance(versionDAO),
-            binder -> binder.bind(CassandraSchemaVersionManager.class)
-                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION)));
-
-        assertThatServerStartCorrectly();
+        assertThatServerStartCorrectly(server);
     }
 
     @Test
-    public void serverShouldNotStartWhenUnderMinVersion() throws Exception {
+    void serverShouldNotStartWhenUnderMinVersion(GuiceJamesServer server) {
         when(versionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION.previous())));
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            cassandra.getModule(),
-            binder -> binder.bind(CassandraSchemaVersionDAO.class)
-                .toInstance(versionDAO),
-            binder -> binder.bind(CassandraSchemaVersionManager.class)
-                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION)));
-
-        expectedException.expect(IllegalStateException.class);
-
-        jamesServer.start();
+        assertThatThrownBy(server::start).isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void serverShouldNotStartWhenAboveMaxVersion() throws Exception {
+    void serverShouldNotStartWhenAboveMaxVersion(GuiceJamesServer server) {
         when(versionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(MAX_VERSION.next())));
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            cassandra.getModule(),
-            binder -> binder.bind(CassandraSchemaVersionDAO.class)
-                .toInstance(versionDAO),
-            binder -> binder.bind(CassandraSchemaVersionManager.class)
-                .toInstance(new CassandraSchemaVersionManager(versionDAO, MIN_VERSION, MAX_VERSION)));
-
-        expectedException.expect(IllegalStateException.class);
-
-        jamesServer.start();
+        assertThatThrownBy(server::start).isInstanceOf(IllegalStateException.class);
     }
 
-    private void assertThatServerStartCorrectly() throws Exception {
-        jamesServer.start();
-        socketChannel.connect(new InetSocketAddress(LOCAL_HOST, jamesServer.getProbe(ImapGuiceProbe.class).getImapPort()));
+    private void assertThatServerStartCorrectly(GuiceJamesServer server) throws Exception {
+        server.start();
+        socketChannel.connect(new InetSocketAddress(LOCAL_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort()));
         assertThat(getServerConnectionResponse(socketChannel))
             .startsWith("* OK JAMES IMAP4rev1 Server");
     }
@@ -167,5 +133,4 @@ public class CassandraVersionCheckingTest {
 
         return new String(bytes, Charset.forName("UTF-8"));
     }
-
 }


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


[04/18] james-project git commit: JAMES-2553 JamesServerExtension should wire await

Posted by bt...@apache.org.
JAMES-2553 JamesServerExtension should wire await


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

Branch: refs/heads/master
Commit: a57a91db73ad6bd6d3b9fd6f527c7e0f22e55adc
Parents: 0cc7b27
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Oct 2 14:29:54 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/JamesServerExtension.java    | 13 ++++++++++++-
 .../org/apache/james/JamesServerExtensionBuilder.java  |  3 ++-
 2 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a57a91db/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
index 829e741..722826c 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
@@ -38,17 +38,24 @@ public class JamesServerExtension implements BeforeAllCallback, BeforeEachCallba
         T apply(P parameter) throws Exception;
     }
 
+    interface AwaitCondition {
+        void await();
+    }
+
     private final TemporaryFolderRegistrableExtension folderRegistrableExtension;
     private final ThrowingFunction<File, GuiceJamesServer> serverSupplier;
     private final RegistrableExtension registrableExtension;
     private final boolean autoStart;
+    private final AwaitCondition awaitCondition;
     private GuiceJamesServer guiceJamesServer;
 
-    JamesServerExtension(RegistrableExtension registrableExtension, ThrowingFunction<File, GuiceJamesServer> serverSupplier, boolean autoStart) {
+    JamesServerExtension(RegistrableExtension registrableExtension, ThrowingFunction<File, GuiceJamesServer> serverSupplier,
+                         AwaitCondition awaitCondition, boolean autoStart) {
         this.registrableExtension = registrableExtension;
         this.serverSupplier = serverSupplier;
         this.folderRegistrableExtension = new TemporaryFolderRegistrableExtension();
         this.autoStart = autoStart;
+        this.awaitCondition = awaitCondition;
     }
 
     @Override
@@ -95,4 +102,8 @@ public class JamesServerExtension implements BeforeAllCallback, BeforeEachCallba
             throw new UncheckedIOException(e);
         }
     }
+
+    public void await() {
+        awaitCondition.await();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a57a91db/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
index 9981ce1..7caa047 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
@@ -83,9 +83,10 @@ public class JamesServerExtensionBuilder {
     public JamesServerExtension build() {
         Preconditions.checkNotNull(server);
         ConfigurationProvider configuration = this.configuration.orElse(defaultConfigurationProvider());
+        JamesServerExtension.AwaitCondition awaitCondition = () -> extensions.build().forEach(GuiceModuleTestExtension::await);
 
         return new JamesServerExtension(buildAggregateJunitExtension(), file -> overrideServerWithExtensionsModules(file, configuration),
-            autoStart.orElse(DEFAULT_AUTO_START));
+            awaitCondition, autoStart.orElse(DEFAULT_AUTO_START));
     }
 
     private ConfigurationProvider defaultConfigurationProvider() {


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


[12/18] james-project git commit: JAMES-2553 Rewrite GuiceJamesServerTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite GuiceJamesServerTest test in JUNIT 5

Needs for a way to not start automatically James server extension


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

Branch: refs/heads/master
Commit: 8080ee48c03433eb0fc447356999877ac93b5637
Parents: b03b2a6
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 10:35:55 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/GuiceJamesServerTest.java  | 156 ++++++++-----------
 1 file changed, 66 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8080ee48/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerTest.java
index 0752504..7edf781 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerTest.java
@@ -1,127 +1,103 @@
 package org.apache.james;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import java.io.IOException;
 import java.util.List;
 
 import org.apache.james.lifecycle.api.Configurable;
+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.utils.ConfigurationPerformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
 import com.google.inject.multibindings.Multibinder;
 
-public class GuiceJamesServerTest {
+class GuiceJamesServerTest {
     private static final Logger LOGGER = LoggerFactory.getLogger(GuiceJamesServerTest.class);
 
-    public static final ConfigurationPerformer THROWING_CONFIGURATION_PERFORMER = new ConfigurationPerformer() {
-        @Override
-        public void initModule() {
-            throw new RuntimeException();
-        }
-
-        @Override
-        public List<Class<? extends Configurable>> forClasses() {
-            return ImmutableList.of();
-        }
-    };
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Rule
-    public MemoryJmapTestRule memoryJmapTestRule = new MemoryJmapTestRule();
-    private GuiceJamesServer guiceJamesServer;
-
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-    @Before
-    public void setUp() throws IOException {
-        guiceJamesServer = memoryJmapTestRule.jmapServer();
-    }
-
-    @After
-    public void tearDown() {
-        guiceJamesServer.stop();
-    }
+    @Nested
+    class NormalBehaviour {
+        @RegisterExtension
+        JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)))
+            .disableAutoStart()
+            .build();
 
-    @Test
-    public void serverShouldBeStartedAfterCallingStart() throws Exception {
-        guiceJamesServer.start();
-
-        assertThat(guiceJamesServer.isStarted()).isTrue();
-    }
+        @Test
+        void serverShouldBeStartedAfterCallingStart(GuiceJamesServer server) throws Exception {
+            server.start();
 
-    @Test
-    public void serverShouldNotBeStartedAfterCallingStop() throws Exception {
-        guiceJamesServer.start();
+            assertThat(server.isStarted()).isTrue();
+        }
 
-        guiceJamesServer.stop();
+        @Test
+        void serverShouldNotBeStartedAfterCallingStop(GuiceJamesServer server) throws Exception {
+            server.start();
 
-        assertThat(guiceJamesServer.isStarted()).isFalse();
-    }
+            server.stop();
 
-    @Test
-    public void serverShouldNotBeStartedBeforeCallingStart() throws Exception {
-        assertThat(guiceJamesServer.isStarted()).isFalse();
-    }
+            assertThat(server.isStarted()).isFalse();
+        }
 
-    @Test
-    public void serverShouldPropagateUncaughtConfigurationException() throws Exception {
-        expectedException.expect(RuntimeException.class);
-
-        GuiceJamesServer overWrittenServer = null;
-
-        try {
-            overWrittenServer = this.guiceJamesServer.overrideWith(
-                binder -> Multibinder.newSetBinder(binder, ConfigurationPerformer.class).addBinding().toInstance(
-                    new ConfigurationPerformer() {
-                        @Override
-                        public void initModule() {
-                            throw new RuntimeException();
-                        }
-
-                        @Override
-                        public List<Class<? extends Configurable>> forClasses() {
-                            return ImmutableList.of();
-                        }
-                    }
-                )
-            );
-            overWrittenServer.start();
-        } finally {
-            if (overWrittenServer != null) {
-                overWrittenServer.stop();
-            }
+        @Test
+        void serverShouldNotBeStartedBeforeCallingStart(GuiceJamesServer server) {
+            assertThat(server.isStarted()).isFalse();
         }
     }
 
-    @Test
-    public void serverShouldNotBeStartedOnUncaughtException() throws Exception {
-        GuiceJamesServer overWrittenServer = null;
+    @Nested
+    class InitFailed {
+        private final ConfigurationPerformer THROWING_CONFIGURATION_PERFORMER = new ConfigurationPerformer() {
+            @Override
+            public void initModule() {
+                throw new RuntimeException();
+            }
 
-        try {
-            overWrittenServer = this.guiceJamesServer.overrideWith(
-                binder -> Multibinder.newSetBinder(binder, ConfigurationPerformer.class)
+            @Override
+            public List<Class<? extends Configurable>> forClasses() {
+                return ImmutableList.of();
+            }
+        };
+
+        @RegisterExtension
+        JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(binder -> Multibinder.newSetBinder(binder, ConfigurationPerformer.class)
                     .addBinding()
-                    .toInstance(THROWING_CONFIGURATION_PERFORMER));
+                    .toInstance(THROWING_CONFIGURATION_PERFORMER)))
+            .disableAutoStart()
+            .build();
+
+        @Test
+        void serverShouldPropagateUncaughtConfigurationException(GuiceJamesServer server) {
+            assertThatThrownBy(server::start)
+                .isInstanceOf(RuntimeException.class);
+        }
 
+        @Test
+        void serverShouldNotBeStartedOnUncaughtException(GuiceJamesServer server) throws Exception {
             try {
-                overWrittenServer.start();
+                server.start();
             } catch (RuntimeException e) {
                 LOGGER.info("Ignored expected exception", e);
             }
 
-            assertThat(overWrittenServer.isStarted()).isFalse();
-        } finally {
-            if (overWrittenServer != null) {
-                overWrittenServer.stop();
-            }
+            assertThat(server.isStarted()).isFalse();
         }
     }
 }


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


[14/18] james-project git commit: JAMES-2553 Rewrite JamesCapabilitiesServerTest test in JUNIT 5

Posted by bt...@apache.org.
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 <bt...@linagora.com>
Authored: Mon Oct 1 12:04:57 2018 +0700
Committer: Benoit Tellier <bt...@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


[17/18] james-project git commit: JAMES-2553 Rewrite DefaultCassandraJamesServerTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite DefaultCassandraJamesServerTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: e6ab27c01610ab6ac2bc7d07cc539041d25c77a8
Parents: 64c11d0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 11:24:52 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../james/DefaultCassandraJamesServerTest.java  | 55 ++++++++------------
 1 file changed, 22 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e6ab27c0/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
index d4b2b75..7e6b6a9 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
@@ -19,47 +19,36 @@
 
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.IOException;
-
 import org.apache.commons.configuration.HierarchicalConfiguration;
+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.ConfigurationProvider;
 import org.apache.james.utils.FailingPropertiesProvider;
 import org.apache.james.utils.PropertiesProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class DefaultCassandraJamesServerTest {
-
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-
-    private GuiceJamesServer guiceJamesServer;
-
-    @Before
-    public void setUp() throws IOException {
-        guiceJamesServer = cassandraJmap.jmapServer(cassandra.getModule())
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class DefaultCassandraJamesServerTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @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(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
             .overrideWith(binder -> binder.bind(PropertiesProvider.class).to(FailingPropertiesProvider.class))
-            .overrideWith(binder -> binder.bind(ConfigurationProvider.class).toInstance(s -> new HierarchicalConfiguration()));
-    }
-
-    @After
-    public void clean() {
-        guiceJamesServer.stop();
-    }
+            .overrideWith(binder -> binder.bind(ConfigurationProvider.class).toInstance(s -> new HierarchicalConfiguration())))
+        .build();
 
     @Test
-    public void memoryJamesServerShouldStartWithNoConfigurationFile() throws Exception {
-        guiceJamesServer.start();
-
-        assertThat(guiceJamesServer.isStarted()).isTrue();
+    void cassandraJamesServerShouldStartWithNoConfigurationFile(GuiceJamesServer server) {
+        assertThat(server.isStarted()).isTrue();
     }
-
 }


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


[03/18] james-project git commit: JAMES-2553 Rewrite AbstractJmapJamesServer test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite AbstractJmapJamesServer test in JUNIT 5


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

Branch: refs/heads/master
Commit: dedcf9de044b83672851ee1439492a5cf4c133d6
Parents: a57a91d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 09:34:16 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../james/CassandraJmapJamesServerTest.java     | 42 ++++-----
 .../james/CassandraLdapJamesServerTest.java     | 65 +++++--------
 .../james/CassandraLdapJmapJamesServerTest.java | 45 +++------
 .../apache/james/CassandraLdapJmapTestRule.java | 97 --------------------
 .../org/apache/james/LdapTestExtention.java     | 73 +++++++++++++++
 .../apache/james/MemoryJmapJamesServerTest.java | 29 +++---
 .../james/AbstractJmapJamesServerTest.java      | 86 -----------------
 .../apache/james/JmapJamesServerContract.java   | 66 +++++++++++++
 .../apache/james/utils/IMAPMessageReader.java   |  9 +-
 9 files changed, 217 insertions(+), 295 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
index f2d9d91..f85f1d4 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
@@ -19,26 +19,24 @@
 
 package org.apache.james;
 
-import java.io.IOException;
-
-import org.junit.ClassRule;
-import org.junit.Rule;
-
-public class CassandraJmapJamesServerTest extends AbstractJmapJamesServerTest {
-
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        return cassandraJmap.jmapServer(cassandra.getModule());
-    }
-
-    @Override
-    protected void clean() {
-    }
-
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class CassandraJmapJamesServerTest implements JmapJamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @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(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
+        .build();
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
index 9009a21..c198fc6 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
@@ -22,28 +22,24 @@ package org.apache.james;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
 
-import java.io.IOException;
-
 import org.apache.commons.net.imap.IMAPClient;
 import org.apache.james.core.Domain;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
-import org.apache.james.user.ldap.LdapGenericContainer;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
 import org.apache.james.utils.SpoolerProbe;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
 import org.awaitility.core.ConditionFactory;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest {
+class CassandraLdapJamesServerTest implements JmapJamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
     private static final String JAMES_USER = "james-user";
     private static final String PASSWORD = "secret";
-    private static final String DOMAIN = "james.org";
-    private static final String ADMIN_PASSWORD = "mysecretpassword";
     private static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
     private static ConditionFactory calmlyAwait = Awaitility.with()
         .pollInterval(slowPacedPollInterval)
@@ -51,50 +47,32 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest {
         .with()
         .pollDelay(slowPacedPollInterval)
         .await();
-
-    private LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
-        .domain(DOMAIN)
-        .password(ADMIN_PASSWORD)
-        .build();
-    private CassandraLdapJmapTestRule cassandraLdapJmap = CassandraLdapJmapTestRule.defaultTestRule();
     private IMAPClient imapClient = new IMAPClient();
 
-    @Rule
-    public RuleChain ruleChain = RuleChain.outerRule(ldapContainer).around(cassandraLdapJmap);
-
-    @Rule
-    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
-    @Rule
-    public SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString());
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        ldapContainer.start();
-        return cassandraLdapJmap.jmapServer(ldapContainer.getLdapHost(), DOMAIN_LIST_CONFIGURATION_MODULE);
-    }
-
-    @Override
-    protected void clean() {
-        if (ldapContainer != null) {
-            ldapContainer.stop();
-        }
-
-        try {
-            imapClient.disconnect();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
+    @RegisterExtension
+    IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString());
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .extension(new LdapTestExtention())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
+        .build();
 
     @Test
-    public void userFromLdapShouldLoginViaImapProtocol() throws Exception {
+    void userFromLdapShouldLoginViaImapProtocol(GuiceJamesServer server) throws Exception {
         imapClient.connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort());
 
         assertThat(imapClient.login(JAMES_USER, PASSWORD)).isTrue();
     }
 
     @Test
-    public void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap() throws Exception {
+    void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap(GuiceJamesServer server) throws Exception {
         messageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort())
             .sendMessage("bob@any.com", JAMES_USER + "@localhost");
 
@@ -105,5 +83,4 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest {
             .select("INBOX")
             .awaitMessage(calmlyAwait);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
index 14a965d..c604b23 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
@@ -19,35 +19,20 @@
 
 package org.apache.james;
 
-import java.io.IOException;
-
-import org.apache.james.user.ldap.LdapGenericContainer;
-import org.junit.Rule;
-import org.junit.rules.RuleChain;
-
-public class CassandraLdapJmapJamesServerTest extends AbstractJmapJamesServerTest {
-    private static final String DOMAIN = "james.org";
-    private static final String ADMIN_PASSWORD = "mysecretpassword";
-
-    private LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
-        .domain(DOMAIN)
-        .password(ADMIN_PASSWORD)
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class CassandraLdapJmapJamesServerTest implements JmapJamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .extension(new LdapTestExtention())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
         .build();
-    private CassandraLdapJmapTestRule cassandraLdapJmap = CassandraLdapJmapTestRule.defaultTestRule();
-
-    @Rule
-    public RuleChain ruleChain = RuleChain.outerRule(ldapContainer).around(cassandraLdapJmap);
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        ldapContainer.start();
-        return cassandraLdapJmap.jmapServer(ldapContainer.getLdapHost());
-    }
-
-    @Override
-    protected void clean() {
-        if (ldapContainer != null) {
-            ldapContainer.stop();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
deleted file mode 100644
index 58da40a..0000000
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
+++ /dev/null
@@ -1,97 +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;
-
-import java.io.IOException;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.modules.TestJMAPServerModule;
-import org.apache.james.server.core.configuration.Configuration;
-import org.apache.james.user.ldap.LdapRepositoryConfiguration;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import com.google.inject.Module;
-
-public class CassandraLdapJmapTestRule implements TestRule {
-    private static final int LIMIT_TO_3_MESSAGES = 3;
-
-    public static CassandraLdapJmapTestRule defaultTestRule() {
-        return new CassandraLdapJmapTestRule(
-            AggregateGuiceModuleTestRule.of(new EmbeddedElasticSearchRule(), new DockerCassandraRule()));
-    }
-
-    private final TemporaryFolder temporaryFolder;
-    private final GuiceModuleTestRule guiceModuleTestRule;
-
-    public CassandraLdapJmapTestRule(GuiceModuleTestRule... guiceModuleTestRule) {
-        TempFilesystemTestRule tempFilesystemTestRule = new TempFilesystemTestRule();
-        temporaryFolder = tempFilesystemTestRule.getTemporaryFolder();
-        this.guiceModuleTestRule =
-            AggregateGuiceModuleTestRule
-                .of(guiceModuleTestRule)
-                .aggregate(tempFilesystemTestRule);
-    }
-
-    public GuiceJamesServer jmapServer(String ldapIp, Module... additionals) throws IOException {
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(temporaryFolder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-        return GuiceJamesServer.forConfiguration(configuration)
-            .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule)
-            .overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
-            .overrideWith(guiceModuleTestRule.getModule())
-            .overrideWith(additionals)
-            .overrideWith(binder -> binder.bind(LdapRepositoryConfiguration.class)
-                .toInstance(computeConfiguration(ldapIp)));
-    }
-
-    private LdapRepositoryConfiguration computeConfiguration(String ldapIp) {
-        try {
-            return LdapRepositoryConfiguration.builder()
-                .ldapHost(ldapIp)
-                .principal("cn=admin,dc=james,dc=org")
-                .credentials("mysecretpassword")
-                .userBase("ou=People,dc=james,dc=org")
-                .userIdAttribute("uid")
-                .userObjectClass("inetOrgPerson")
-                .maxRetries(4)
-                .retryStartInterval(0)
-                .retryMaxInterval(8)
-                .scale(1000)
-                .build();
-        } catch (ConfigurationException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    @Override
-    public Statement apply(Statement base, Description description) {
-        return guiceModuleTestRule.apply(base, description);
-    }
-
-    public void await() {
-        guiceModuleTestRule.await();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java
new file mode 100644
index 0000000..a0aaea5
--- /dev/null
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.user.ldap.LdapGenericContainer;
+import org.apache.james.user.ldap.LdapRepositoryConfiguration;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+public class LdapTestExtention implements GuiceModuleTestExtension {
+    private static final String DOMAIN = "james.org";
+    private static final String ADMIN_PASSWORD = "mysecretpassword";
+
+    private LdapGenericContainer ldapContainer;
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        ldapContainer = LdapGenericContainer.builder()
+            .domain(DOMAIN)
+            .password(ADMIN_PASSWORD)
+            .build();
+        ldapContainer.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        ldapContainer.stop();
+    }
+
+    @Override
+    public Module getModule() {
+        return binder -> binder.bind(LdapRepositoryConfiguration.class)
+            .toInstance(computeConfiguration(ldapContainer.getLdapHost()));
+    }
+
+    private LdapRepositoryConfiguration computeConfiguration(String ldapIp) {
+        try {
+            return LdapRepositoryConfiguration.builder()
+                .ldapHost(ldapIp)
+                .principal("cn=admin,dc=james,dc=org")
+                .credentials("mysecretpassword")
+                .userBase("ou=People,dc=james,dc=org")
+                .userIdAttribute("uid")
+                .userObjectClass("inetOrgPerson")
+                .maxRetries(4)
+                .retryStartInterval(0)
+                .retryMaxInterval(8)
+                .scale(1000)
+                .build();
+        } catch (ConfigurationException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java
index eb3ca00..a1d551d 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java
@@ -19,21 +19,20 @@
 
 package org.apache.james;
 
-import java.io.IOException;
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-import org.junit.Rule;
+class MemoryJmapJamesServerTest implements JmapJamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-public class MemoryJmapJamesServerTest extends AbstractJmapJamesServerTest {
-
-    @Rule
-    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        return memoryJmap.jmapServer();
-    }
-
-    @Override
-    protected void clean() {
-    }
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
+        .build();
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
deleted file mode 100644
index 318e15b..0000000
--- a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
+++ /dev/null
@@ -1,86 +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;
-
-import static io.restassured.RestAssured.given;
-import static io.restassured.config.EncoderConfig.encoderConfig;
-import static io.restassured.config.RestAssuredConfig.newConfig;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.james.domainlist.lib.DomainListConfiguration;
-import org.apache.james.utils.JmapGuiceProbe;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.inject.Module;
-
-import io.restassured.RestAssured;
-import io.restassured.builder.RequestSpecBuilder;
-import io.restassured.http.ContentType;
-
-public abstract class AbstractJmapJamesServerTest {
-
-    public static final Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class)
-        .toInstance(DomainListConfiguration.builder()
-            .autoDetect(true)
-            .autoDetectIp(false)
-            .build());
-
-    protected static final String JAMES_SERVER_HOST = "127.0.0.1";
-
-    protected GuiceJamesServer server;
-
-    @Before
-    public void setup() throws Exception {
-        server = createJamesServer();
-        server.start();
-
-        RestAssured.requestSpecification = new RequestSpecBuilder()
-            .setContentType(ContentType.JSON)
-            .setAccept(ContentType.JSON)
-            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
-            .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort())
-            .build();
-    }
-
-    protected abstract GuiceJamesServer createJamesServer() throws IOException;
-
-    protected abstract void clean();
-
-    @After
-    public void tearDown() throws Exception {
-        if (server != null) {
-            server.stop();
-        }
-        clean();
-    }
-
-    @Test
-    public void connectJMAPServerShouldRespondBadRequest() throws Exception {
-        given()
-            .body("{\"badAttributeName\": \"value\"}")
-        .when()
-            .post("/authentication")
-        .then()
-            .statusCode(400);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java
new file mode 100644
index 0000000..5562871
--- /dev/null
+++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.config.EncoderConfig.encoderConfig;
+import static io.restassured.config.RestAssuredConfig.newConfig;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.james.domainlist.lib.DomainListConfiguration;
+import org.apache.james.utils.JmapGuiceProbe;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.inject.Module;
+
+import io.restassured.RestAssured;
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.http.ContentType;
+
+public interface JmapJamesServerContract {
+    Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class)
+        .toInstance(DomainListConfiguration.builder()
+            .autoDetect(true)
+            .autoDetectIp(false)
+            .build());
+    String JAMES_SERVER_HOST = "127.0.0.1";
+
+    @BeforeEach
+    default void setup(GuiceJamesServer server) throws Exception {
+
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+            .setContentType(ContentType.JSON)
+            .setAccept(ContentType.JSON)
+            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+            .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort())
+            .build();
+    }
+
+    @Test
+    default void connectJMAPServerShouldRespondBadRequest() {
+        given()
+            .body("{\"badAttributeName\": \"value\"}")
+        .when()
+            .post("/authentication")
+        .then()
+            .statusCode(400);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
index 078b583..7e80983 100644
--- a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
+++ b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
@@ -25,12 +25,14 @@ import java.util.List;
 
 import org.apache.commons.net.imap.IMAPClient;
 import org.awaitility.core.ConditionFactory;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.rules.ExternalResource;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Splitter;
 
-public class IMAPMessageReader extends ExternalResource implements Closeable {
+public class IMAPMessageReader extends ExternalResource implements Closeable, AfterEachCallback {
 
     public static final String INBOX = "INBOX";
 
@@ -189,6 +191,11 @@ public class IMAPMessageReader extends ExternalResource implements Closeable {
         }
     }
 
+    @Override
+    public void afterEach(ExtensionContext extensionContext) {
+        after();
+    }
+
     public void copyFirstMessage(String destMailbox) throws IOException {
         imapClient.copy("1", destMailbox);
     }


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


[11/18] james-project git commit: JAMES-2553 Rewrite JamesServerWithRetryConnectionTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite JamesServerWithRetryConnectionTest test in JUNIT 5

Note that we need to use custom extensions


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

Branch: refs/heads/master
Commit: 89d723418668c3279e922f493770eba6166b9aa6
Parents: a697f68
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 11:10:20 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../apache/james/DockerElasticSearchRule.java   |  81 -------------
 .../JamesServerWithRetryConnectionTest.java     | 115 +++++++++++++------
 2 files changed, 80 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/89d72341/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
deleted file mode 100644
index ff56488..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
+++ /dev/null
@@ -1,81 +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;
-
-import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-import org.apache.james.modules.mailbox.ElasticSearchConfiguration;
-import org.apache.james.util.Host;
-import org.apache.james.util.docker.Images;
-import org.apache.james.util.docker.RateLimiters;
-import org.apache.james.util.docker.SwarmGenericContainer;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
-
-import com.google.inject.Module;
-
-public class DockerElasticSearchRule implements GuiceModuleTestRule {
-
-    private static final int ELASTIC_SEARCH_PORT = 9300;
-    public static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
-
-    public ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
-        return ElasticSearchConfiguration.builder()
-            .addHost(Host.from(getIp(), elasticSearchContainer.getMappedPort(ELASTIC_SEARCH_PORT)))
-            .indexAttachment(IndexAttachments.NO)
-            .build();
-    }
-
-    private SwarmGenericContainer elasticSearchContainer = new SwarmGenericContainer(Images.ELASTICSEARCH)
-        .withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT)
-        .waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.DEFAULT));
-
-    @Override
-    public Statement apply(Statement base, Description description) {
-        return elasticSearchContainer.apply(base, description);
-    }
-
-    @Override
-    public void await() {
-    }
-
-    @Override
-    public Module getModule() {
-        return (binder) ->
-                binder.bind(ElasticSearchConfiguration.class)
-                    .toInstance(getElasticSearchConfigurationForDocker());
-    }
-
-    public String getIp() {
-        return elasticSearchContainer.getHostIp();
-    }
-
-    public SwarmGenericContainer getElasticSearchContainer() {
-        return elasticSearchContainer;
-    }
-
-    public void pause() {
-        elasticSearchContainer.pause();
-    }
-
-    public void unpause() {
-        elasticSearchContainer.unpause();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/89d72341/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 075c8a0..bc2d6cb 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
@@ -19,6 +19,7 @@
 
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
@@ -30,66 +31,110 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+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.modules.mailbox.ElasticSearchConfiguration;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.apache.james.util.Host;
+import org.apache.james.util.docker.Images;
+import org.apache.james.util.docker.SwarmGenericContainer;
+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 com.google.inject.Module;
+
+class JamesServerWithRetryConnectionTest {
+    private static class DockerElasticSearchRegistrableExtension implements GuiceModuleTestExtension {
+        private final SwarmGenericContainer elasticSearchContainer;
+
+        private DockerElasticSearchRegistrableExtension(SwarmGenericContainer elasticSearchContainer) {
+            this.elasticSearchContainer = elasticSearchContainer;
+        }
+
+        @Override
+        public void beforeEach(ExtensionContext extensionContext) {
+            elasticSearchContainer.start();
+        }
+
+        @Override
+        public void afterEach(ExtensionContext extensionContext) {
+            elasticSearchContainer.stop();
+        }
+
+        @Override
+        public Module getModule() {
+            return binder -> binder.bind(ElasticSearchConfiguration.class)
+                    .toInstance(getElasticSearchConfigurationForDocker());
+        }
+
+        private ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
+            return ElasticSearchConfiguration.builder()
+                .addHost(Host.from(elasticSearchContainer.getHostIp(), elasticSearchContainer.getMappedPort(ELASTIC_SEARCH_PORT)))
+                .indexAttachment(IndexAttachments.NO)
+                .build();
+        }
+    }
 
-public class JamesServerWithRetryConnectionTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
     private static final long WAITING_TIME = TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS);
 
-    @ClassRule
-    public static DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
-    private final DockerElasticSearchRule dockerElasticSearchRule = new DockerElasticSearchRule();
+    private static final int ELASTIC_SEARCH_PORT = 9300;
+    private static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
+
+    private static SwarmGenericContainer elasticSearchContainer = new SwarmGenericContainer(Images.ELASTICSEARCH)
+        .withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT);
+    private static final DockerCassandraRule cassandraRule = new DockerCassandraRule();
 
-    @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerElasticSearchRule);
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(new DockerElasticSearchRegistrableExtension(elasticSearchContainer))
+        .extension(new CassandraExtension())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)))
+        .disableAutoStart()
+        .build();
 
-    private GuiceJamesServer jamesServer;
     private SocketChannel socketChannel;
     private ExecutorService executorService;
 
-    @Before
-    public void setUp() throws IOException {
+    @BeforeEach
+    void setUp() throws IOException {
         executorService = Executors.newFixedThreadPool(1);
         socketChannel = SocketChannel.open();
     }
 
-    @After
-    public void after() throws IOException {
+    @AfterEach
+    void after() throws IOException {
         socketChannel.close();
-        if (jamesServer != null) {
-            jamesServer.stop();
-        }
         executorService.shutdownNow();
     }
 
     @Test
-    public void serverShouldStartAtDefault() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
-        assertThatServerStartCorrectly();
+    void serverShouldStartAtDefault(GuiceJamesServer server) throws Exception {
+        assertThatServerStartCorrectly(server);
     }
 
     @Test
-    public void serverShouldRetryToConnectToCassandraWhenStartService() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
-        dockerCassandraRule.pause();
+    void serverShouldRetryToConnectToCassandraWhenStartService(GuiceJamesServer server) throws Exception {
+        cassandraRule.pause();
 
-        waitToStartContainer(WAITING_TIME, dockerCassandraRule::unpause);
+        waitToStartContainer(WAITING_TIME, cassandraRule::unpause);
 
-        assertThatServerStartCorrectly();
+        assertThatServerStartCorrectly(server);
     }
 
     @Test
-    public void serverShouldRetryToConnectToElasticSearchWhenStartService() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
-        dockerElasticSearchRule.pause();
+    void serverShouldRetryToConnectToElasticSearchWhenStartService(GuiceJamesServer server) throws Exception {
+        elasticSearchContainer.pause();
 
-        waitToStartContainer(WAITING_TIME, dockerElasticSearchRule::unpause);
+        waitToStartContainer(WAITING_TIME, elasticSearchContainer::unpause);
 
-        assertThatServerStartCorrectly();
+        assertThatServerStartCorrectly(server);
     }
 
     interface StartAction {
@@ -107,9 +152,9 @@ public class JamesServerWithRetryConnectionTest {
         });
     }
 
-    private void assertThatServerStartCorrectly() throws Exception {
-        jamesServer.start();
-        socketChannel.connect(new InetSocketAddress("127.0.0.1", jamesServer.getProbe(ImapGuiceProbe.class).getImapPort()));
+    private void assertThatServerStartCorrectly(GuiceJamesServer server) throws Exception {
+        server.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", server.getProbe(ImapGuiceProbe.class).getImapPort()));
         assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
     }
 


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


[13/18] james-project git commit: JAMES-2553 Rewrite FixingGhostMailboxTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite FixingGhostMailboxTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: 485122c526728efb68000336a9e769a7e1c98b78
Parents: e6ab27c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 11:58:13 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraExtension.java    |   6 +-
 .../apache/james/FixingGhostMailboxTest.java    | 134 +++++++++----------
 2 files changed, 70 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/485122c5/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
index ef7280f..41767e3 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
@@ -28,7 +28,11 @@ class CassandraExtension implements GuiceModuleTestExtension {
     private final DockerCassandraRule cassandra;
 
     CassandraExtension() {
-        this.cassandra = new DockerCassandraRule();
+        this(new DockerCassandraRule());
+    }
+
+    public CassandraExtension(DockerCassandraRule cassandra) {
+        this.cassandra = cassandra;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/485122c5/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
index e5f5f42..51e1e7d 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
@@ -25,6 +25,7 @@ import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
 import static io.restassured.config.EncoderConfig.encoderConfig;
 import static io.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
 import static org.apache.james.jmap.JmapURIBuilder.baseUri;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -45,16 +46,18 @@ import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.cassandra.mail.task.MailboxMergingTask;
 import org.apache.james.mailbox.cassandra.table.CassandraMailboxPathV2Table;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.probe.ACLProbe;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.modules.ACLProbeImpl;
 import org.apache.james.modules.MailboxProbeImpl;
-import org.apache.james.probe.DataProbe;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.CassandraProbe;
 import org.apache.james.task.TaskManager;
 import org.apache.james.utils.DataProbeImpl;
@@ -64,11 +67,9 @@ import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.routes.CassandraMailboxMergingRoutes;
 import org.apache.james.webadmin.routes.TasksRoutes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.Session;
@@ -79,23 +80,33 @@ import io.restassured.http.ContentType;
 import io.restassured.specification.RequestSpecification;
 
 public class FixingGhostMailboxTest {
-
+    private static final int LIMIT_TO_10_MESSAGES = 10;
     private static final String NAME = "[0][0]";
     private static final String ARGUMENTS = "[0][1]";
     private static final String FIRST_MAILBOX = ARGUMENTS + ".list[0]";
 
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-
-    @Rule
-    public CassandraJmapTestRule rule = CassandraJmapTestRule.defaultTestRule();
+    private static final String DOMAIN = "domain.tld";
+    private static final String CEDRIC = "cedric@" + DOMAIN;
+    private static final String BOB = "bob@" + DOMAIN;
+    private static final String ALICE = "alice@" + DOMAIN;
+    private static final String ALICE_SECRET = "aliceSecret";
+    private static final String BOB_SECRET = "bobSecret";
+
+    public static final DockerCassandraRule cassandra = new DockerCassandraRule();
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new CassandraExtension(cassandra))
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> binder.bind(WebAdminConfiguration.class)
+                .toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+        .build();
 
     private AccessToken accessToken;
-    private String domain;
-    private String alice;
-    private String bob;
-    private String cedric;
-    private GuiceJamesServer jmapServer;
     private MailboxProbeImpl mailboxProbe;
     private ACLProbe aclProbe;
     private Session session;
@@ -103,45 +114,35 @@ public class FixingGhostMailboxTest {
     private MailboxId aliceGhostInboxId;
     private MailboxPath aliceInboxPath;
     private ComposedMessageId message2;
-    private WebAdminGuiceProbe webAdminProbe;
     private RequestSpecification webadminSpecification;
 
-    @Before
-    public void setup() throws Throwable {
-        jmapServer = rule.jmapServer(cassandra.getModule(),
-            binder -> binder.bind(WebAdminConfiguration.class)
-            .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
-        jmapServer.start();
-        webAdminProbe = jmapServer.getProbe(WebAdminGuiceProbe.class);
-        mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
-        aclProbe = jmapServer.getProbe(ACLProbeImpl.class);
+    @BeforeEach
+    void setup(GuiceJamesServer server) throws Throwable {
+        WebAdminGuiceProbe webAdminProbe = server.getProbe(WebAdminGuiceProbe.class);
+        mailboxProbe = server.getProbe(MailboxProbeImpl.class);
+        aclProbe = server.getProbe(ACLProbeImpl.class);
 
         RestAssured.requestSpecification = new RequestSpecBuilder()
             .setContentType(ContentType.JSON)
             .setAccept(ContentType.JSON)
             .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
-            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort())
+            .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort())
             .build();
         RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
         webadminSpecification = WebAdminUtils.buildRequestSpecification(webAdminProbe.getWebAdminPort())
             .build();
 
-        domain = "domain.tld";
-        alice = "alice@" + domain;
-        String alicePassword = "aliceSecret";
-        bob = "bob@" + domain;
-        cedric = "cedric@" + domain;
-        DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
-        dataProbe.addDomain(domain);
-        dataProbe.addUser(alice, alicePassword);
-        dataProbe.addUser(bob, "bobSecret");
-        accessToken = authenticateJamesUser(baseUri(jmapServer), alice, alicePassword);
+        server.getProbe(DataProbeImpl.class).fluent()
+            .addDomain(DOMAIN)
+            .addUser(ALICE, ALICE_SECRET)
+            .addUser(BOB, BOB_SECRET);
+        accessToken = authenticateJamesUser(baseUri(server), ALICE, ALICE_SECRET);
 
         session = Cluster.builder()
             .addContactPoint(cassandra.getIp())
             .withPort(cassandra.getMappedPort(9042))
             .build()
-            .connect(jmapServer.getProbe(CassandraProbe.class).getKeyspace());
+            .connect(server.getProbe(CassandraProbe.class).getKeyspace());
 
         simulateGhostMailboxBug();
     }
@@ -149,16 +150,16 @@ public class FixingGhostMailboxTest {
     private void simulateGhostMailboxBug() throws MailboxException, IOException {
         // State before ghost mailbox bug
         // Alice INBOX is delegated to Bob and contains one message
-        aliceInboxPath = MailboxPath.forUser(alice, MailboxConstants.INBOX);
-        aliceGhostInboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
-        aclProbe.addRights(aliceInboxPath, bob, MailboxACL.FULL_RIGHTS);
-        message1 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
-        rule.await();
+        aliceInboxPath = MailboxPath.forUser(ALICE, MailboxConstants.INBOX);
+        aliceGhostInboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+        aclProbe.addRights(aliceInboxPath, BOB, MailboxACL.FULL_RIGHTS);
+        message1 = mailboxProbe.appendMessage(ALICE, aliceInboxPath, AppendCommand.from(generateMessageContent()));
+        testExtension.await();
 
         // Simulate ghost mailbox bug
         session.execute(delete().from(CassandraMailboxPathV2Table.TABLE_NAME)
             .where(eq(CassandraMailboxPathV2Table.NAMESPACE, MailboxConstants.USER_NAMESPACE))
-            .and(eq(CassandraMailboxPathV2Table.USER, alice))
+            .and(eq(CassandraMailboxPathV2Table.USER, ALICE))
             .and(eq(CassandraMailboxPathV2Table.MAILBOX_NAME, MailboxConstants.INBOX)));
 
         // trigger provisioning
@@ -171,8 +172,8 @@ public class FixingGhostMailboxTest {
             .statusCode(200);
 
         // Received a new message
-        message2 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
-        rule.await();
+        message2 = mailboxProbe.appendMessage(ALICE, aliceInboxPath, AppendCommand.from(generateMessageContent()));
+        testExtension.await();
     }
 
     private Message generateMessageContent() throws IOException {
@@ -182,21 +183,16 @@ public class FixingGhostMailboxTest {
             .build();
     }
 
-    @After
-    public void teardown() {
-        jmapServer.stop();
-    }
-
     @Test
-    public void ghostMailboxBugShouldChangeMailboxId() throws Exception {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+    void ghostMailboxBugShouldChangeMailboxId() {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
 
         assertThat(aliceGhostInboxId).isNotEqualTo(newAliceInbox);
     }
 
     @Test
-    public void ghostMailboxBugShouldDiscardOldContent() throws Exception {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+    void ghostMailboxBugShouldDiscardOldContent() {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -212,8 +208,8 @@ public class FixingGhostMailboxTest {
     }
 
     @Test
-    public void webadminCanMergeTwoMailboxes() throws Exception {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+    void webadminCanMergeTwoMailboxes() {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
 
         fixGhostMailboxes(newAliceInbox);
 
@@ -232,9 +228,9 @@ public class FixingGhostMailboxTest {
     }
 
     @Test
-    public void webadminCanMergeTwoMailboxesRights() throws Exception {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
-        aclProbe.addRights(aliceInboxPath, cedric, MailboxACL.FULL_RIGHTS);
+    void webadminCanMergeTwoMailboxesRights() throws Exception {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+        aclProbe.addRights(aliceInboxPath, CEDRIC, MailboxACL.FULL_RIGHTS);
 
         fixGhostMailboxes(newAliceInbox);
 
@@ -246,14 +242,14 @@ public class FixingGhostMailboxTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("mailboxes"))
-            .body(FIRST_MAILBOX + ".sharedWith", hasKey(bob))
-            .body(FIRST_MAILBOX + ".sharedWith", hasKey(cedric));
+            .body(FIRST_MAILBOX + ".sharedWith", hasKey(BOB))
+            .body(FIRST_MAILBOX + ".sharedWith", hasKey(CEDRIC));
     }
 
     @Test
-    public void oldGhostedMailboxShouldNoMoreBeAccessible() throws Exception {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
-        aclProbe.addRights(aliceInboxPath, cedric, MailboxACL.FULL_RIGHTS);
+    void oldGhostedMailboxShouldNoMoreBeAccessible() throws Exception {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+        aclProbe.addRights(aliceInboxPath, CEDRIC, MailboxACL.FULL_RIGHTS);
 
         fixGhostMailboxes(newAliceInbox);
 
@@ -269,8 +265,8 @@ public class FixingGhostMailboxTest {
     }
 
     @Test
-    public void mergingMailboxTaskShouldBeInformative() {
-        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+    void mergingMailboxTaskShouldBeInformative() {
+        MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
 
         String taskId = fixGhostMailboxes(newAliceInbox);
 
@@ -308,7 +304,7 @@ public class FixingGhostMailboxTest {
             .spec(webadminSpecification)
             .basePath(TasksRoutes.BASE)
             .get(taskId + "/await");
-        rule.await();
+        testExtension.await();
         return taskId;
     }
 


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


[06/18] james-project git commit: JAMES-2553 Fix warnings in AggregateJunitExtension

Posted by bt...@apache.org.
JAMES-2553 Fix warnings in AggregateJunitExtension


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

Branch: refs/heads/master
Commit: 17692d90559ee898d9f7ea946d0918eee700ccba
Parents: 76900c2
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Oct 2 11:52:05 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../src/test/java/org/apache/james/AggregateJunitExtension.java   | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/17692d90/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java
index 7dd7057..15ad8c4 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java
@@ -20,7 +20,6 @@
 package org.apache.james;
 
 import java.util.List;
-import java.util.function.Supplier;
 
 import org.apache.james.util.Runnables;
 import org.junit.jupiter.api.extension.ExtensionContext;
@@ -44,7 +43,7 @@ public class AggregateJunitExtension implements RegistrableExtension {
     }
 
     @Override
-    public void beforeEach(ExtensionContext extensionContext) throws Exception {
+    public void beforeEach(ExtensionContext extensionContext) {
         Runnables.runParrallelStream(registrableExtensions
             .stream()
             .map(ext -> Throwing.runnable(() -> ext.beforeEach(extensionContext))));


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


[10/18] james-project git commit: JAMES-2553 Rewrite DefaultMemoryJamesServerTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite DefaultMemoryJamesServerTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: d79c499e4236f025b673a51cb2cb91f9d0da9e35
Parents: dbb4833
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 09:51:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../james/DefaultMemoryJamesServerTest.java     | 48 ++++++++------------
 1 file changed, 19 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d79c499e/server/container/guice/memory-guice/src/test/java/org/apache/james/DefaultMemoryJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/DefaultMemoryJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/DefaultMemoryJamesServerTest.java
index 9f82501..fdd2196 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/DefaultMemoryJamesServerTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/DefaultMemoryJamesServerTest.java
@@ -21,41 +21,31 @@ package org.apache.james;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.IOException;
-
 import org.apache.commons.configuration.HierarchicalConfiguration;
+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.ConfigurationProvider;
 import org.apache.james.utils.FailingPropertiesProvider;
 import org.apache.james.utils.PropertiesProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class DefaultMemoryJamesServerTest {
-
-    @Rule
-    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
-
-    private GuiceJamesServer guiceJamesServer;
-
-    @Before
-    public void setUp() throws IOException {
-        guiceJamesServer = memoryJmap.jmapServer()
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class DefaultMemoryJamesServerTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
             .overrideWith(binder -> binder.bind(PropertiesProvider.class).to(FailingPropertiesProvider.class))
-            .overrideWith(binder -> binder.bind(ConfigurationProvider.class).toInstance(s -> new HierarchicalConfiguration()));
-    }
-
-    @After
-    public void clean() {
-        guiceJamesServer.stop();
-    }
+            .overrideWith(binder -> binder.bind(ConfigurationProvider.class).toInstance(s -> new HierarchicalConfiguration())))
+        .build();
 
     @Test
-    public void memoryJamesServerShouldStartWithNoConfigurationFile() throws Exception {
-        guiceJamesServer.start();
-
-        assertThat(guiceJamesServer.isStarted()).isTrue();
+    void memoryJamesServerShouldStartWithNoConfigurationFile(GuiceJamesServer server) {
+        assertThat(server.isStarted()).isTrue();
     }
-
 }


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


[02/18] james-project git commit: JAMES-2553 Rewrite JamesCapabilitiesServerTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite JamesCapabilitiesServerTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: 8a678c37e42aa9086f049581b2cbb5c726f27c20
Parents: dedcf9d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 09:47:17 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../james/JamesCapabilitiesServerTest.java      | 57 ++++++--------------
 1 file changed, 16 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8a678c37/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 12db521..49612f7 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -21,48 +21,14 @@ package org.apache.james;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.io.IOException;
 import java.util.EnumSet;
 
 import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.server.core.configuration.Configuration;
-import org.junit.After;
-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;
-
-public class JamesCapabilitiesServerTest {
-
-    private GuiceJamesServer server;
-    private TemporaryFolder temporaryFolder = new TemporaryFolder();
-
-    @Rule
-    public RuleChain chain = RuleChain.outerRule(temporaryFolder);
-
-    @After
-    public void teardown() {
-        server.stop();
-    }
-    
-    private GuiceJamesServer createJPAJamesServer(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)
-            .combineWith(JPAJamesServerMain.JPA_SERVER_MODULE)
-            .overrideWith(
-                new TestJPAConfigurationModule(),
-                mockMailboxManager);
-    }
-    
-    @Test
-    public void startShouldSucceedWhenRequiredCapabilities() throws Exception {
+class JamesCapabilitiesServerTest {
+    private static MailboxManager mailboxManager() {
         MailboxManager mailboxManager = mock(MailboxManager.class);
         when(mailboxManager.getSupportedMailboxCapabilities())
             .thenReturn(EnumSet.noneOf(MailboxManager.MailboxCapabilities.class));
@@ -70,10 +36,19 @@ public class JamesCapabilitiesServerTest {
             .thenReturn(EnumSet.noneOf(MailboxManager.MessageCapabilities.class));
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.noneOf(MailboxManager.SearchCapabilities.class));
+        return mailboxManager;
+    }
 
-        server = createJPAJamesServer(mailboxManager);
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
+            .overrideWith(new TestJPAConfigurationModule())
+            .overrideWith(binder -> binder.bind(MailboxManager.class).toInstance(mailboxManager())))
+        .build();
+    
+    @Test
+    void startShouldSucceedWhenRequiredCapabilities(GuiceJamesServer server) {
 
-        server.start();
     }
-
 }


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


[08/18] james-project git commit: JAMES-2553 Rewrite CassandraMessageIdManagerInjectionTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite CassandraMessageIdManagerInjectionTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: 4fa7952f8d5543f72a606b4950e5591e8627517d
Parents: 8080ee4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 10:42:37 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../CassandraMessageIdManagerInjectionTest.java | 74 +++++++-------------
 1 file changed, 27 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4fa7952f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
index a2135a7..da58fad 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
@@ -19,60 +19,48 @@
 
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
 import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.mailbox.MessageIdManager;
+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.utils.ConfigurationPerformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.collect.ImmutableList;
-import com.google.inject.AbstractModule;
-import com.google.inject.Module;
 import com.google.inject.multibindings.Multibinder;
 
-public class CassandraMessageIdManagerInjectionTest {
-
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-    
-    private GuiceJamesServer server;
-
-    @Before
-    public void setup() throws Exception {
-        Module module = new AbstractModule() {
-            @Override
-            protected void configure() {
-                Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(CallMe.class);
-            }
-        };
-        server = cassandraJmap.jmapServer(module, cassandra.getModule());
-        server.start();
-    }
+class CassandraMessageIdManagerInjectionTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @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(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> Multibinder.newSetBinder(binder, ConfigurationPerformer.class)
+                .addBinding()
+                .to(CallMe.class)))
+        .disableAutoStart()
+        .build();
 
     @Test
-    public void messageIdManagerShouldBeInjected() {
-
-    }
-
-    @After
-    public void tearDown() {
-        server.stop();
+    void messageIdManagerShouldBeInjected(GuiceJamesServer server) {
+        assertThatCode(server::start).doesNotThrowAnyException();
     }
 
     public static class CallMe implements ConfigurationPerformer {
-
         @Inject
         public CallMe(MessageIdManager messageIdManager) {
         }
@@ -84,15 +72,7 @@ public class CassandraMessageIdManagerInjectionTest {
 
         @Override
         public List<Class<? extends Configurable>> forClasses() {
-            return ImmutableList.of(MyConfigurable.class);
+            return ImmutableList.of();
         }
     }
-
-    public static class MyConfigurable implements Configurable {
-        @Override
-        public void configure(HierarchicalConfiguration config) throws ConfigurationException {
-
-        }
-    }
-
 }


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


[09/18] james-project git commit: JAMES-2553 Rewrite ESReporterTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite ESReporterTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: 64c11d0d86e2c0dae8348792a397da0be2512db5
Parents: 89d7234
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 11:22:31 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/ESReporterTest.java   | 62 ++++++++++----------
 1 file changed, 32 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/64c11d0d/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
index a25a7b4..ecd37a2 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
@@ -21,6 +21,7 @@ package org.apache.james;
 import static io.restassured.RestAssured.given;
 import static io.restassured.config.EncoderConfig.encoderConfig;
 import static io.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
 import static org.apache.james.jmap.JmapURIBuilder.baseUri;
 import static org.awaitility.Awaitility.await;
@@ -34,18 +35,20 @@ import java.util.stream.Collectors;
 
 import org.apache.commons.net.imap.IMAPClient;
 import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.modules.TestESMetricReporterModule;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.JmapGuiceProbe;
 import org.awaitility.Duration;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,34 +56,36 @@ import io.restassured.RestAssured;
 import io.restassured.builder.RequestSpecBuilder;
 import io.restassured.http.ContentType;
 
-public class ESReporterTest {
+class ESReporterTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ESReporterTest.class);
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+
+    static final EmbeddedElasticSearchExtension embeddedElasticSearchExtension = new EmbeddedElasticSearchExtension();
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(embeddedElasticSearchExtension)
+        .extension(new CassandraExtension())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+            .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(new TestESMetricReporterModule()))
+        .build();
 
     private static final int DELAY_IN_MS = 100;
     private static final int PERIOD_IN_MS = 100;
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(ESReporterTest.class);
-
     private static final String DOMAIN = "james.org";
     private static final String USERNAME = "user1@" + DOMAIN;
     private static final String PASSWORD = "secret";
 
-    @ClassRule
-    public static final DockerCassandraRule cassandra = new DockerCassandraRule();
-
-    private EmbeddedElasticSearchRule embeddedElasticSearchRule = new EmbeddedElasticSearchRule();
-
     private Timer timer;
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = new CassandraJmapTestRule(embeddedElasticSearchRule);
-
-    private GuiceJamesServer server;
     private AccessToken accessToken;
 
-    @Before
-    public void setup() throws Exception {
-        server = cassandraJmap.jmapServer(cassandra.getModule());
-        server.start();
+    @BeforeEach
+    void setup(GuiceJamesServer server) throws Exception {
         server.getProbe(DataProbeImpl.class)
             .fluent()
             .addDomain(DOMAIN)
@@ -97,16 +102,13 @@ public class ESReporterTest {
         timer = new Timer();
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() {
         timer.cancel();
-        if (server != null) {
-            server.stop();
-        }
     }
 
     @Test
-    public void timeMetricsShouldBeReportedWhenImapCommandsReceived() throws Exception {
+    void timeMetricsShouldBeReportedWhenImapCommandsReceived(GuiceJamesServer server) throws Exception {
         IMAPClient client = new IMAPClient();
         client.connect(InetAddress.getLocalHost(), server.getProbe(ImapGuiceProbe.class).getImapPort());
         client.login(USERNAME, PASSWORD);
@@ -128,7 +130,7 @@ public class ESReporterTest {
     }
 
     @Test
-    public void timeMetricsShouldBeReportedWhenJmapRequestsReceived() throws Exception {
+    void timeMetricsShouldBeReportedWhenJmapRequestsReceived() {
         TimerTask timerTask = new TimerTask() {
             @Override
             public void run() {
@@ -150,7 +152,7 @@ public class ESReporterTest {
     }
 
     private boolean checkMetricRecordedInElasticSearch() {
-        try (Client client = embeddedElasticSearchRule.getNode().client()) {
+        try (Client client = embeddedElasticSearchExtension.getEmbeddedElasticSearch().getNode().client()) {
             return !Arrays.stream(client.prepareSearch()
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get().getHits().getHits())


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


[16/18] james-project git commit: JAMES-2553 Rewrite GuiceLifecycleHeathCheckTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite GuiceLifecycleHeathCheckTest test in JUNIT 5

Specific difficulties for launching a different James server in each test.


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

Branch: refs/heads/master
Commit: b03b2a68e45405a40d043fa30c406baba98eba30
Parents: d79c499
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 10:03:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../james/GuiceLifecycleHeathCheckTest.java     | 104 ++++++++++---------
 1 file changed, 56 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b03b2a68/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
index a0ea030..1268c63 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
@@ -27,13 +27,16 @@ import java.nio.charset.StandardCharsets;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 
+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.task.Task;
 import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.WebAdminConfiguration;
 import org.eclipse.jetty.http.HttpStatus;
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.inject.multibindings.Multibinder;
 
@@ -41,9 +44,11 @@ import io.restassured.RestAssured;
 import io.restassured.builder.RequestSpecBuilder;
 import io.restassured.http.ContentType;
 
-public class GuiceLifecycleHeathCheckTest {
-    private void configureRequestSpecification() {
-        WebAdminGuiceProbe webAdminGuiceProbe = guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
+class GuiceLifecycleHeathCheckTest {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    private static void configureRequestSpecification(GuiceJamesServer server) {
+        WebAdminGuiceProbe webAdminGuiceProbe = server.getProbe(WebAdminGuiceProbe.class);
 
         RestAssured.requestSpecification = new RequestSpecBuilder()
                 .setContentType(ContentType.JSON)
@@ -53,35 +58,30 @@ public class GuiceLifecycleHeathCheckTest {
                 .build();
     }
 
-    @Rule
-    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
-    private GuiceJamesServer guiceJamesServer;
+    @Nested
+    class Healthy {
+        @RegisterExtension
+        JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+            .build();
+
+        @Test
+        void startedJamesServerShouldBeHealthy(GuiceJamesServer server) {
+            configureRequestSpecification(server);
 
-    @After
-    public void cleanUp() {
-        if (guiceJamesServer != null) {
-            guiceJamesServer.stop();
+            when()
+                .get("/healthcheck")
+                .then()
+                .statusCode(HttpStatus.OK_200);
         }
     }
 
-    @Test
-    public void startedJamesServerShouldBeHealthy() throws Exception {
-        guiceJamesServer = memoryJmap.jmapServer()
-            .overrideWith(binder -> binder.bind(WebAdminConfiguration.class)
-                .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
-
-
-        guiceJamesServer.start();
-        configureRequestSpecification();
-
-        when()
-            .get("/healthcheck")
-        .then()
-            .statusCode(HttpStatus.OK_200);
-    }
-
-    @Test
-    public void stoppingJamesServerShouldBeUnhealthy() throws Exception {
+    @Nested
+    class Unhealthy {
         CountDownLatch latch = new CountDownLatch(1);
         CleanupTasksPerformer.CleanupTask awaitCleanupTask = () -> {
             try {
@@ -91,28 +91,36 @@ public class GuiceLifecycleHeathCheckTest {
             }
             return Task.Result.COMPLETED;
         };
-        CompletableFuture<Void> stopCompletedFuture = CompletableFuture.completedFuture(null);
 
-        try {
-            guiceJamesServer = memoryJmap.jmapServer(
-                binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class)
+        @RegisterExtension
+        JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION))
+                .overrideWith(binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class)
                     .addBinding()
-                    .toInstance(awaitCleanupTask))
-                .overrideWith(binder -> binder.bind(WebAdminConfiguration.class)
-                    .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
+                    .toInstance(awaitCleanupTask)))
+            .build();
 
-            guiceJamesServer.start();
-            configureRequestSpecification();
+        @Test
+        void stoppingJamesServerShouldBeUnhealthy(GuiceJamesServer server) {
+            CompletableFuture<Void> stopCompletedFuture = CompletableFuture.completedFuture(null);
 
-            stopCompletedFuture = CompletableFuture.runAsync(() -> guiceJamesServer.stop());
+            try {
+                configureRequestSpecification(server);
 
-            when()
-                .get("/healthcheck")
-            .then()
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
-        } finally {
-            latch.countDown();
-            stopCompletedFuture.join();
+                stopCompletedFuture = CompletableFuture.runAsync(server::stop);
+
+                when()
+                    .get("/healthcheck")
+                    .then()
+                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+            } finally {
+                latch.countDown();
+                stopCompletedFuture.join();
+            }
         }
     }
 }


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


[15/18] james-project git commit: JAMES-2553 Rewrite CassandraNodeConfTest test in JUNIT 5

Posted by bt...@apache.org.
JAMES-2553 Rewrite CassandraNodeConfTest test in JUNIT 5


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

Branch: refs/heads/master
Commit: 2b17c9209ba4ace78bfe3724a6ed35eb6d777f49
Parents: c001475
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 13:23:02 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraNodeConfTest.java | 123 ++++++++++++-------
 1 file changed, 77 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2b17c920/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
index 81cadcc..9c12467 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james;
 
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
@@ -27,82 +28,113 @@ import java.nio.channels.SocketChannel;
 import java.nio.charset.Charset;
 
 import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
+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.modules.protocols.ImapGuiceProbe;
 import org.apache.james.util.Host;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.testcontainers.DockerClientFactory;
 
-public class CassandraNodeConfTest {
-
+class CassandraNodeConfTest {
     private static final int CASSANDRA_PORT = 9042;
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
     private static String getDockerHostIp() {
-        return DockerClientFactory.instance().dockerHostIpAddress();
+        DockerClientFactory clientFactory = DockerClientFactory.instance();
+        clientFactory.client();
+        return clientFactory.dockerHostIpAddress();
     }
 
-    @ClassRule
-    public static final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = CassandraJmapTestRule.defaultTestRule();
-
-    private GuiceJamesServer jamesServer;
     private SocketChannel socketChannel;
 
-    @Before
-    public void setUp() throws IOException {
+    @BeforeEach
+    void setUp() throws IOException {
         socketChannel = SocketChannel.open();
     }
 
-    @After
-    public void after() throws IOException {
+    @AfterEach
+    void after() throws IOException {
         socketChannel.close();
-        if (jamesServer != null) {
-            jamesServer.stop();
-        }
     }
 
-    @Test
-    public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
+    @Nested
+    class NormalBehaviour {
+        @RegisterExtension
+        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(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)))
+            .disableAutoStart()
+            .build();
 
-        assertThatServerStartCorrectly();
+        @Test
+        void serverShouldStartServiceWhenNodeIsReachable (GuiceJamesServer server) throws Exception {
+            assertThatServerStartCorrectly(server);
+        }
     }
 
-    @Test
-    public void serverShouldStartWhenOneCassandraNodeIsUnreachable() throws Exception {
+    @Nested
+    class OneFailedNode {
         String unreachableNode = "10.2.3.42";
 
-
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule())
-            .overrideWith(
-                (binder) -> binder.bind(ClusterConfiguration.class)
+        private final DockerCassandraRule cassandra = new DockerCassandraRule();
+
+        @RegisterExtension
+        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new CassandraExtension(cassandra))
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(ClusterConfiguration.class)
                     .toInstance(clusterWithHosts(
                         Host.from(unreachableNode, 9042),
-                        dockerCassandraRule.getHost())));
+                        cassandra.getHost()))))
+            .disableAutoStart()
+            .build();
 
-        assertThatServerStartCorrectly();
+        @Test
+        void serverShouldStartServiceWhenNodeIsReachable (GuiceJamesServer server) throws Exception {
+            assertThatServerStartCorrectly(server);
+        }
     }
 
-
-    @Test
-    public void configShouldWorkWithNonDefaultPort() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule())
-            .overrideWith(
-                (binder) -> binder.bind(ClusterConfiguration.class)
+    @Nested
+    class UseMappedPort {
+        private final DockerCassandraRule cassandra = new DockerCassandraRule();
+
+        @RegisterExtension
+        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new CassandraExtension(cassandra))
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+                .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(binder -> binder.bind(ClusterConfiguration.class)
                     .toInstance(clusterWithHosts(
-                        Host.from(getDockerHostIp(), dockerCassandraRule.getMappedPort(CASSANDRA_PORT)))));
+                        Host.from(getDockerHostIp(), cassandra.getMappedPort(CASSANDRA_PORT))))))
+            .disableAutoStart()
+            .build();
 
-        assertThatServerStartCorrectly();
+        @Test
+        void configShouldWorkWithNonDefaultPort(GuiceJamesServer server) throws Exception {
+            assertThatServerStartCorrectly(server);
+        }
     }
 
-    private void assertThatServerStartCorrectly() throws Exception {
-        jamesServer.start();
-        socketChannel.connect(new InetSocketAddress("127.0.0.1", jamesServer.getProbe(ImapGuiceProbe.class).getImapPort()));
+    private void assertThatServerStartCorrectly(GuiceJamesServer server) throws Exception {
+        server.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", server.getProbe(ImapGuiceProbe.class).getImapPort()));
         assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
     }
 
@@ -122,5 +154,4 @@ public class CassandraNodeConfTest {
         byte[] bytes = byteBuffer.array();
         return new String(bytes, Charset.forName("UTF-8"));
     }
-
 }


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


[07/18] james-project git commit: JAMES-2553 StartAction is more a runnable in JamesServerWithRetryConnectionTest

Posted by bt...@apache.org.
JAMES-2553 StartAction is more a runnable in JamesServerWithRetryConnectionTest


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

Branch: refs/heads/master
Commit: 6bfbc8ed464d4900d6c5650d1efc34c9c6740e23
Parents: 2b17c92
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Oct 4 09:53:32 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/JamesServerWithRetryConnectionTest.java | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6bfbc8ed/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 d7c8cde..a9e3c52 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
@@ -138,19 +138,15 @@ class JamesServerWithRetryConnectionTest {
 
         assertThatServerStartCorrectly(server);
     }
-
-    interface StartAction {
-        void execute();
-    }
     
-    private void waitToStartContainer(long waitingTime, StartAction action) {
+    private void waitToStartContainer(long waitingTime, Runnable action) {
         executorService.submit(() -> {
             try {
                 Thread.sleep(waitingTime);
             } catch (InterruptedException e) {
                 throw new RuntimeException(e);
             }
-            action.execute();
+            action.run();
         });
     }
 


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


[05/18] james-project git commit: JAMES-2553 Enable to not automatically start James server via the extension

Posted by bt...@apache.org.
JAMES-2553 Enable to not automatically start James server via the extension


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

Branch: refs/heads/master
Commit: 0cc7b27c7544f39ace88ece43f6e9cd512911bb8
Parents: 17692d9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Oct 2 11:37:26 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:42 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/JamesServerExtension.java    |  8 ++++++--
 .../org/apache/james/JamesServerExtensionBuilder.java  | 13 +++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0cc7b27c/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
index 6ba6b0a..829e741 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
@@ -41,12 +41,14 @@ public class JamesServerExtension implements BeforeAllCallback, BeforeEachCallba
     private final TemporaryFolderRegistrableExtension folderRegistrableExtension;
     private final ThrowingFunction<File, GuiceJamesServer> serverSupplier;
     private final RegistrableExtension registrableExtension;
+    private final boolean autoStart;
     private GuiceJamesServer guiceJamesServer;
 
-    JamesServerExtension(RegistrableExtension registrableExtension, ThrowingFunction<File, GuiceJamesServer> serverSupplier) {
+    JamesServerExtension(RegistrableExtension registrableExtension, ThrowingFunction<File, GuiceJamesServer> serverSupplier, boolean autoStart) {
         this.registrableExtension = registrableExtension;
         this.serverSupplier = serverSupplier;
         this.folderRegistrableExtension = new TemporaryFolderRegistrableExtension();
+        this.autoStart = autoStart;
     }
 
     @Override
@@ -59,7 +61,9 @@ public class JamesServerExtension implements BeforeAllCallback, BeforeEachCallba
         folderRegistrableExtension.beforeEach(extensionContext);
         registrableExtension.beforeEach(extensionContext);
         guiceJamesServer = serverSupplier.apply(createTmpDir());
-        guiceJamesServer.start();
+        if (autoStart) {
+            guiceJamesServer.start();
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/0cc7b27c/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
index 1831f72..9981ce1 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
@@ -31,6 +31,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.inject.Module;
 
 public class JamesServerExtensionBuilder {
+    private static final boolean DEFAULT_AUTO_START = true;
 
     @FunctionalInterface
     interface ConfigurationProvider {
@@ -46,11 +47,13 @@ public class JamesServerExtensionBuilder {
     private final TemporaryFolderRegistrableExtension folderRegistrableExtension;
     private ServerProvider server;
     private Optional<ConfigurationProvider> configuration;
+    private Optional<Boolean> autoStart;
 
     JamesServerExtensionBuilder() {
         configuration = Optional.empty();
         extensions = ImmutableList.builder();
         folderRegistrableExtension = new TemporaryFolderRegistrableExtension();
+        autoStart = Optional.empty();
     }
 
     public JamesServerExtensionBuilder extensions(GuiceModuleTestExtension... extensions) {
@@ -72,11 +75,17 @@ public class JamesServerExtensionBuilder {
         return this;
     }
 
+    public JamesServerExtensionBuilder disableAutoStart() {
+        this.autoStart = Optional.of(false);
+        return this;
+    }
+
     public JamesServerExtension build() {
         Preconditions.checkNotNull(server);
         ConfigurationProvider configuration = this.configuration.orElse(defaultConfigurationProvider());
-        return new JamesServerExtension(buildAggregateJunitExtension(),
-            file -> overrideServerWithExtensionsModules(file, configuration));
+
+        return new JamesServerExtension(buildAggregateJunitExtension(), file -> overrideServerWithExtensionsModules(file, configuration),
+            autoStart.orElse(DEFAULT_AUTO_START));
     }
 
     private ConfigurationProvider defaultConfigurationProvider() {


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