james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/2] james-project git commit: JAMES-2553 migrate AbstractJamesServerTests to junit 5
Date Thu, 04 Oct 2018 07:11:51 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 8e9a0fd35 -> 9a5e1e51e


JAMES-2553 migrate AbstractJamesServerTests to junit 5

	This changeset leverage existing builders to create a JamesServerExtensionBuilder
	This JamesServerExtensionBuilder helps build a junit5 programmatic extension for
	Guice James and its related dependencies


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

Branch: refs/heads/master
Commit: 98c2921758c1a6895abd6c83db93447ae475ff92
Parents: 8e9a0fd
Author: Matthieu Baechler <matthieu@apache.org>
Authored: Mon Oct 1 15:11:16 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Oct 4 14:10:55 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraExtension.java    |  48 +++++++
 .../apache/james/CassandraJamesServerTest.java  |  42 +++----
 .../org/apache/james/CassandraWithTikaTest.java |  43 +++----
 .../james/EmbeddedElasticSearchExtension.java   |  60 +++++++++
 .../java/org/apache/james/GuiceTikaRule.java    |  53 --------
 .../java/org/apache/james/TikaExtension.java    |  49 ++++++++
 server/container/guice/guice-common/pom.xml     |   5 +
 .../apache/james/AbstractJamesServerTest.java   | 124 -------------------
 .../apache/james/AggregateJunitExtension.java   |  67 ++++++++++
 .../apache/james/GuiceModuleTestExtension.java  |  31 +++++
 .../org/apache/james/JamesServerContract.java   | 111 +++++++++++++++++
 .../org/apache/james/JamesServerExtension.java  |  85 +++++++++++++
 .../james/JamesServerExtensionBuilder.java      | 124 +++++++++++++++++++
 .../org/apache/james/RegistrableExtension.java  |  48 +++++++
 .../TemporaryFolderRegistrableExtension.java    |  43 +++++++
 .../org/apache/james/JPAJamesServerTest.java    |  57 ++++-----
 .../JPAJamesServerWithSqlValidationTest.java    |  27 ++--
 server/container/guice/memory-guice/pom.xml     |   9 +-
 .../org/apache/james/MemoryJamesServerTest.java |  28 ++---
 .../java/org/apache/james/util/Runnables.java   |   9 +-
 20 files changed, 771 insertions(+), 292 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/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
new file mode 100644
index 0000000..ef7280f
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+class CassandraExtension implements GuiceModuleTestExtension {
+
+    private final DockerCassandraRule cassandra;
+
+    CassandraExtension() {
+        this.cassandra = new DockerCassandraRule();
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        cassandra.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        cassandra.stop();
+    }
+
+    @Override
+    public Module getModule() {
+        return cassandra.getModule();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
index 61b04fb..886353f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
@@ -19,26 +19,24 @@
 
 package org.apache.james;
 
-import java.io.IOException;
-
-import org.junit.ClassRule;
-import org.junit.Rule;
-
-public class CassandraJamesServerTest extends AbstractJamesServerTest {
-
-    @ClassRule
-    public static DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        return cassandraJmap.jmapServer(cassandra.getModule(), DOMAIN_LIST_CONFIGURATION_MODULE);
-    }
-
-    @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 CassandraJamesServerTest implements JamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        .extension(EmbeddedElasticSearchExtension::new)
+        .extension(CassandraExtension::new)
+        .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/98c29217/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
index 47dfc82..9f30523 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
@@ -19,28 +19,23 @@
 
 package org.apache.james;
 
-import java.io.IOException;
-
-import org.junit.ClassRule;
-import org.junit.Rule;
-
-public class CassandraWithTikaTest extends AbstractJamesServerTest {
-
-    @ClassRule
-    public static final DockerCassandraRule cassandra = new DockerCassandraRule();
-    @ClassRule
-    public static final GuiceTikaRule guiceTikaRule = new GuiceTikaRule();
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        return cassandraJmap.jmapServer(guiceTikaRule.getModule(), cassandra.getModule(), DOMAIN_LIST_CONFIGURATION_MODULE);
-    }
-
-    @Override
-    protected void clean() {
-    }
-
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class CassandraWithTikaTest implements JamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    @RegisterExtension
+    static JamesServerExtension testExtension =
+        new JamesServerExtensionBuilder()
+            .extension(CassandraExtension::new)
+            .extension(TikaExtension::new)
+            .extension(EmbeddedElasticSearchExtension::new)
+            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+                .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+                .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
+            .build();
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
new file mode 100644
index 0000000..b3c61cf
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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.File;
+
+import org.apache.james.backends.es.EmbeddedElasticSearch;
+import org.apache.james.modules.TestElasticSearchModule;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+public class EmbeddedElasticSearchExtension implements GuiceModuleTestExtension {
+    private final EmbeddedElasticSearch embeddedElasticSearch;
+
+    public EmbeddedElasticSearchExtension(File temporaryFolder) {
+        this.embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder.toPath());
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) {
+        embeddedElasticSearch.before();
+    }
+
+    @Override
+    public void afterEach(ExtensionContext extensionContext) {
+        embeddedElasticSearch.after();
+    }
+
+    @Override
+    public Module getModule() {
+        return new TestElasticSearchModule(embeddedElasticSearch);
+    }
+
+    @Override
+    public void await() {
+        embeddedElasticSearch.awaitForElasticSearch();
+    }
+
+    public EmbeddedElasticSearch getEmbeddedElasticSearch() {
+        return embeddedElasticSearch;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/cassandra-guice/src/test/java/org/apache/james/GuiceTikaRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/GuiceTikaRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/GuiceTikaRule.java
deleted file mode 100644
index b14086f..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/GuiceTikaRule.java
+++ /dev/null
@@ -1,53 +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.tika.TikaContainer;
-import org.apache.james.modules.TestTikaModule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import com.google.inject.Module;
-
-
-public class GuiceTikaRule implements GuiceModuleTestRule {
-
-    private TikaContainer tika;
-
-    @Override
-    public Statement apply(Statement base, Description description) {
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                tika = new TikaContainer();
-                tika.start();
-                base.evaluate();
-            }
-        };
-    }
-
-    @Override
-    public void await() {
-    }
-
-    @Override
-    public Module getModule() {
-        return new TestTikaModule(tika);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/cassandra-guice/src/test/java/org/apache/james/TikaExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/TikaExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/TikaExtension.java
new file mode 100644
index 0000000..525c9a4
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/TikaExtension.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.tika.TikaContainer;
+import org.apache.james.modules.TestTikaModule;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+class TikaExtension implements GuiceModuleTestExtension {
+    private final TikaContainer tika;
+
+    TikaExtension() {
+        this.tika = new TikaContainer();
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        tika.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        tika.stop();
+    }
+
+    @Override
+    public Module getModule() {
+        return new TestTikaModule(tika);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/pom.xml b/server/container/guice/guice-common/pom.xml
index 8c85fef..b7bdd99 100644
--- a/server/container/guice/guice-common/pom.xml
+++ b/server/container/guice/guice-common/pom.xml
@@ -181,6 +181,11 @@
             <artifactId>awaitility</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
deleted file mode 100644
index 6ed341c..0000000
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
+++ /dev/null
@@ -1,124 +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 org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
-
-import org.apache.james.domainlist.lib.DomainListConfiguration;
-import org.apache.james.modules.protocols.ImapGuiceProbe;
-import org.apache.james.modules.protocols.LmtpGuiceProbe;
-import org.apache.james.modules.protocols.Pop3GuiceProbe;
-import org.apache.james.modules.protocols.SmtpGuiceProbe;
-import org.apache.james.utils.DataProbeImpl;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.inject.Module;
-
-public abstract class AbstractJamesServerTest {
-
-    protected static final String JAMES_SERVER_HOST = "127.0.0.1";
-
-    public static final Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class)
-        .toInstance(DomainListConfiguration.builder()
-            .autoDetect(true)
-            .autoDetectIp(false)
-            .build());
-
-    protected GuiceJamesServer server;
-    private SocketChannel socketChannel;
-
-    @Before
-    public void setup() throws Exception {
-        server = createJamesServer();
-        socketChannel = SocketChannel.open();
-        server.start();
-    }
-
-    protected abstract GuiceJamesServer createJamesServer() throws IOException;
-
-    protected abstract void clean();
-
-    @After
-    public void tearDown() throws Exception {
-        server.stop();
-        clean();
-    }
-
-    @Test
-    public void hostnameShouldBeUsedAsDefaultDomain() throws Exception {
-        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
-
-        assertThat(server.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
-    }
-
-    @Test
-    public void hostnameShouldBeRetrievedWhenRestarting() throws Exception {
-        server.stop();
-        server.start();
-        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
-
-        assertThat(server.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
-    }
-
-    @Test
-    public void connectIMAPServerShouldSendShabangOnConnect() throws Exception {
-        socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort()));
-        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
-    }
-
-    @Test
-    public void connectOnSecondaryIMAPServerIMAPServerShouldSendShabangOnConnect() throws Exception {
-        socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapsPort()));
-        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
-    }
-
-    @Test
-    public void connectPOP3ServerShouldSendShabangOnConnect() throws Exception {
-        socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, server.getProbe(Pop3GuiceProbe.class).getPop3Port()));
-        assertThat(getServerConnectionResponse(socketChannel)).contains("POP3 server (JAMES POP3 Server ) ready");
-    }
-
-    @Test
-    public void connectSMTPServerShouldSendShabangOnConnect() throws Exception {
-        socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort()));
-        assertThat(getServerConnectionResponse(socketChannel)).startsWith("220 JAMES Linagora's SMTP awesome Server");
-    }
-
-    @Test
-    public void connectLMTPServerShouldSendShabangOnConnect() throws Exception {
-        socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, server.getProbe(LmtpGuiceProbe.class).getLmtpPort()));
-        assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready");
-    }
-
-    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException {
-        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
-        socketChannel.read(byteBuffer);
-        byte[] bytes = byteBuffer.array();
-        return new String(bytes, Charset.forName("UTF-8"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/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
new file mode 100644
index 0000000..7dd7057
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/AggregateJunitExtension.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.util.List;
+import java.util.function.Supplier;
+
+import org.apache.james.util.Runnables;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.Lists;
+
+public class AggregateJunitExtension implements RegistrableExtension {
+
+    private final List<? extends RegistrableExtension> registrableExtensions;
+
+    public AggregateJunitExtension(List<? extends RegistrableExtension> registrableExtensions) {
+        this.registrableExtensions = registrableExtensions;
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        Runnables.runParrallelStream(registrableExtensions
+            .stream()
+            .map(ext -> Throwing.runnable(() -> ext.beforeAll(extensionContext))));
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) throws Exception {
+        Runnables.runParrallelStream(registrableExtensions
+            .stream()
+            .map(ext -> Throwing.runnable(() -> ext.beforeEach(extensionContext))));
+    }
+
+    @Override
+    public void afterEach(ExtensionContext extensionContext) {
+        Runnables.runParrallelStream(Lists.reverse(registrableExtensions)
+            .stream()
+            .map(ext -> Throwing.runnable(() -> ext.afterEach(extensionContext))));
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        Runnables.runParrallelStream(Lists.reverse(registrableExtensions)
+            .stream()
+            .map(ext -> Throwing.runnable(() -> ext.afterAll(extensionContext))));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/src/test/java/org/apache/james/GuiceModuleTestExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/GuiceModuleTestExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/GuiceModuleTestExtension.java
new file mode 100644
index 0000000..e51c0d7
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/GuiceModuleTestExtension.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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 com.google.inject.Module;
+
+public interface GuiceModuleTestExtension extends RegistrableExtension {
+
+    default Module getModule() {
+        return binder -> {};
+    }
+
+    default void await() {}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
new file mode 100644
index 0000000..0b48b10
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerContract.java
@@ -0,0 +1,111 @@
+/****************************************************************
+ * 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 org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+import org.apache.james.domainlist.lib.DomainListConfiguration;
+import org.apache.james.modules.protocols.ImapGuiceProbe;
+import org.apache.james.modules.protocols.LmtpGuiceProbe;
+import org.apache.james.modules.protocols.Pop3GuiceProbe;
+import org.apache.james.modules.protocols.SmtpGuiceProbe;
+import org.apache.james.utils.DataProbeImpl;
+import org.junit.jupiter.api.Test;
+
+import com.google.inject.Module;
+
+public interface JamesServerContract {
+
+    String JAMES_SERVER_HOST = "127.0.0.1";
+    Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class)
+        .toInstance(DomainListConfiguration.builder()
+            .autoDetect(true)
+            .autoDetectIp(false)
+            .build());
+
+    @Test
+    default void hostnameShouldBeUsedAsDefaultDomain(GuiceJamesServer jamesServer) throws Exception {
+        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
+
+        assertThat(jamesServer.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
+    }
+
+    @Test
+    default void hostnameShouldBeRetrievedWhenRestarting(GuiceJamesServer jamesServer) throws Exception {
+        jamesServer.stop();
+        jamesServer.start();
+        String expectedDefaultDomain = InetAddress.getLocalHost().getHostName();
+
+        assertThat(jamesServer.getProbe(DataProbeImpl.class).getDefaultDomain()).isEqualTo(expectedDefaultDomain);
+    }
+
+    @Test
+    default void connectIMAPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) throws Exception {
+        try (SocketChannel socketChannel = SocketChannel.open()) {
+            socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, jamesServer.getProbe(ImapGuiceProbe.class).getImapPort()));
+            assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
+        }
+    }
+
+    @Test
+    default void connectOnSecondaryIMAPServerIMAPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) throws Exception {
+        try (SocketChannel socketChannel = SocketChannel.open()) {
+            socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, jamesServer.getProbe(ImapGuiceProbe.class).getImapsPort()));
+            assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
+        }
+    }
+
+    @Test
+    default void connectPOP3ServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) throws Exception {
+        try (SocketChannel socketChannel = SocketChannel.open()) {
+            socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, jamesServer.getProbe(Pop3GuiceProbe.class).getPop3Port()));
+            assertThat(getServerConnectionResponse(socketChannel)).contains("POP3 server (JAMES POP3 Server ) ready");
+        }
+    }
+
+    @Test
+    default void connectSMTPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) throws Exception {
+        try (SocketChannel socketChannel = SocketChannel.open()) {
+            socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()));
+            assertThat(getServerConnectionResponse(socketChannel)).startsWith("220 JAMES Linagora's SMTP awesome Server");
+        }
+    }
+
+    @Test
+    default void connectLMTPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) throws Exception {
+        try (SocketChannel socketChannel = SocketChannel.open()) {
+            socketChannel.connect(new InetSocketAddress(JAMES_SERVER_HOST, jamesServer.getProbe(LmtpGuiceProbe.class).getLmtpPort()));
+            assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready");
+        }
+    }
+
+    static String getServerConnectionResponse(SocketChannel socketChannel) throws IOException {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
+        socketChannel.read(byteBuffer);
+        byte[] bytes = byteBuffer.array();
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/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
new file mode 100644
index 0000000..5551fcc
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtension.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.util.List;
+import java.util.function.Supplier;
+
+import org.apache.james.util.Runnables;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.Lists;
+
+public class JamesServerExtension implements BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback, ParameterResolver {
+
+    interface ThrowingSupplier<T> {
+        T get() throws Exception;
+    }
+
+    private final ThrowingSupplier<GuiceJamesServer> serverSupplier;
+    private final RegistrableExtension registrableExtension;
+    private GuiceJamesServer guiceJamesServer;
+
+    JamesServerExtension(RegistrableExtension registrableExtension, ThrowingSupplier<GuiceJamesServer> serverSupplier) {
+        this.registrableExtension = registrableExtension;
+        this.serverSupplier = serverSupplier;
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) throws Exception {
+        registrableExtension.beforeAll(extensionContext);
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) throws Exception {
+        registrableExtension.beforeEach(extensionContext);
+        guiceJamesServer = serverSupplier.get();
+        guiceJamesServer.start();
+    }
+
+    @Override
+    public void afterEach(ExtensionContext extensionContext) throws Exception {
+        guiceJamesServer.stop();
+        registrableExtension.afterEach(extensionContext);
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) throws Exception {
+        registrableExtension.afterAll(extensionContext);
+    }
+
+    @Override
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return (parameterContext.getParameter().getType() == GuiceJamesServer.class);
+    }
+
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return guiceJamesServer;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/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
new file mode 100644
index 0000000..7d305b3
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/JamesServerExtensionBuilder.java
@@ -0,0 +1,124 @@
+/****************************************************************
+ * 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.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Optional;
+import java.util.function.Supplier;
+
+import org.apache.james.server.core.configuration.Configuration;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Module;
+
+public class JamesServerExtensionBuilder {
+
+    @FunctionalInterface
+    interface ExtensionProvider {
+        GuiceModuleTestExtension buildExtension(File tempDirectory);
+    }
+
+    @FunctionalInterface
+    interface ConfigurationProvider {
+        Configuration buildConfiguration(File tempDirectory);
+    }
+
+    @FunctionalInterface
+    interface ServerProvider {
+        GuiceJamesServer buildServer(Configuration configuration);
+    }
+
+    private final ImmutableList.Builder<GuiceModuleTestExtension> extensions;
+    private final TemporaryFolderRegistrableExtension folderRegistrableExtension;
+    private ServerProvider server;
+    private Optional<ConfigurationProvider> configuration;
+
+    JamesServerExtensionBuilder() {
+        configuration = Optional.empty();
+        extensions = ImmutableList.builder();
+        folderRegistrableExtension = new TemporaryFolderRegistrableExtension();
+    }
+
+    public JamesServerExtensionBuilder extensions(GuiceModuleTestExtension... extensions) {
+        this.extensions.add(extensions);
+        return this;
+    }
+
+    public JamesServerExtensionBuilder extension(Supplier<GuiceModuleTestExtension> extension) {
+        this.extensions.add(extension.get());
+        return this;
+    }
+
+    public JamesServerExtensionBuilder extension(ExtensionProvider extension) {
+        this.extensions.add(extension.buildExtension(createTmpDir()));
+        return this;
+    }
+
+    public JamesServerExtensionBuilder configuration(ConfigurationProvider configuration) throws UncheckedIOException {
+        this.configuration = Optional.of(configuration);
+        return this;
+    }
+
+    public JamesServerExtensionBuilder server(ServerProvider server) {
+        this.server = server;
+        return this;
+    }
+
+    public JamesServerExtension build() {
+        Preconditions.checkNotNull(server);
+        ConfigurationProvider configuration = this.configuration.orElse(defaultConfigurationProvider());
+        return new JamesServerExtension(buildAggregateJunitExtension(), () -> overrideServerWithExtensionsModules(configuration));
+    }
+
+    private ConfigurationProvider defaultConfigurationProvider() {
+        return tmpDir ->
+            Configuration.builder()
+                .workingDirectory(tmpDir)
+                .configurationFromClasspath()
+                .build();
+    }
+
+    private File createTmpDir() {
+        try {
+            return folderRegistrableExtension.getTemporaryFolder().newFolder();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+
+    private AggregateJunitExtension buildAggregateJunitExtension() {
+        ImmutableList<GuiceModuleTestExtension> extensions = this.extensions.build();
+        return new AggregateJunitExtension(
+            ImmutableList.<RegistrableExtension>builder()
+                .addAll(extensions)
+                .add(folderRegistrableExtension)
+                .build());
+    }
+
+    private GuiceJamesServer overrideServerWithExtensionsModules(ConfigurationProvider configurationProvider) {
+        ImmutableList<Module> modules = extensions.build().stream().map(x -> x.getModule()).collect(Guavate.toImmutableList());
+        return server.buildServer(configurationProvider.buildConfiguration(createTmpDir())).overrideWith(modules);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/src/test/java/org/apache/james/RegistrableExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/RegistrableExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/RegistrableExtension.java
new file mode 100644
index 0000000..534ce49
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/RegistrableExtension.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+public interface RegistrableExtension extends BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {
+    @Override
+    default void afterAll(ExtensionContext extensionContext) throws Exception {
+
+    }
+
+    @Override
+    default void afterEach(ExtensionContext extensionContext) throws Exception {
+
+    }
+
+    @Override
+    default void beforeAll(ExtensionContext extensionContext) throws Exception {
+
+    }
+
+    @Override
+    default void beforeEach(ExtensionContext extensionContext) throws Exception {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/guice-common/src/test/java/org/apache/james/TemporaryFolderRegistrableExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/TemporaryFolderRegistrableExtension.java b/server/container/guice/guice-common/src/test/java/org/apache/james/TemporaryFolderRegistrableExtension.java
new file mode 100644
index 0000000..5bc52f2
--- /dev/null
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/TemporaryFolderRegistrableExtension.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.rules.TemporaryFolder;
+
+public class TemporaryFolderRegistrableExtension implements RegistrableExtension {
+
+    private TemporaryFolder temporaryFolder;
+
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) throws Exception {
+        temporaryFolder = new TemporaryFolder();
+        temporaryFolder.create();
+    }
+
+    @Override
+    public void afterEach(ExtensionContext extensionContext) {
+        temporaryFolder.delete();
+    }
+
+    public TemporaryFolder getTemporaryFolder() {
+        return temporaryFolder;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
index f428c51..7c5156f 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -21,70 +21,60 @@ package org.apache.james;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.IOException;
-
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.model.SerializableQuotaValue;
 import org.apache.james.modules.QuotaProbesImpl;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
-import org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
 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.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.base.Strings;
 
-public class JPAJamesServerTest extends AbstractJamesServerTest {
+class JPAJamesServerTest implements JamesServerContract {
+
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
+            .overrideWith(new TestJPAConfigurationModule(), DOMAIN_LIST_CONFIGURATION_MODULE))
+        .build();
 
     private static final ConditionFactory AWAIT = Awaitility.await()
         .atMost(Duration.ONE_MINUTE)
         .with()
         .pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS);
-    private static final String DOMAIN = "james.local";
+    static final String DOMAIN = "james.local";
     private static final String USER = "toto@" + DOMAIN;
     private static final String PASSWORD = "123456";
 
-    @Rule
-    public TemporaryFolder temporaryFolder = new TemporaryFolder();
-    @Rule
-    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
-    @Rule
-    public SMTPMessageSender smtpMessageSender = new SMTPMessageSender(DOMAIN);
+    private IMAPMessageReader imapMessageReader;
+    private SMTPMessageSender smtpMessageSender;
 
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(temporaryFolder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-        return GuiceJamesServer.forConfiguration(configuration)
-            .combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
-            .overrideWith(new TestJPAConfigurationModule(), DOMAIN_LIST_CONFIGURATION_MODULE);
+    @BeforeEach
+    void setUp() {
+        this.imapMessageReader = new IMAPMessageReader();
+        this.smtpMessageSender = new SMTPMessageSender(DOMAIN);
     }
-
-    @Override
-    protected void clean() {
-    }
-
+    
     @Test
-    public void jpaGuiceServerShouldUpdateQuota() throws Exception {
-        server.getProbe(DataProbeImpl.class)
+    void jpaGuiceServerShouldUpdateQuota(GuiceJamesServer jamesServer) throws Exception {
+        jamesServer.getProbe(DataProbeImpl.class)
             .fluent()
             .addDomain(DOMAIN)
             .addUser(USER, PASSWORD);
-        server.getProbe(QuotaProbesImpl.class).setGlobalMaxStorage(new SerializableQuotaValue<>(QuotaSize.size(50 * 1024)));
+        jamesServer.getProbe(QuotaProbesImpl.class).setGlobalMaxStorage(new SerializableQuotaValue<>(QuotaSize.size(50 * 1024)));
 
         // ~ 12 KB email
-        int imapPort = server.getProbe(ImapGuiceProbe.class).getImapPort();
-        smtpMessageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+        int imapPort = jamesServer.getProbe(ImapGuiceProbe.class).getImapPort();
+        smtpMessageSender.connect(JAMES_SERVER_HOST, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
             .sendMessageWithHeaders(USER, USER, "header: toto\\r\\n\\r\\n" + Strings.repeat("0123456789\n", 1024));
         AWAIT.until(() -> imapMessageReader.connect(JAMES_SERVER_HOST, imapPort)
             .login(USER, PASSWORD)
@@ -99,5 +89,4 @@ public class JPAJamesServerTest extends AbstractJamesServerTest {
                 "* QUOTA #private&toto@james.local (STORAGE 12 50)\r\n")
             .endsWith("OK GETQUOTAROOT completed.\r\n");
     }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
index aafddad..355bf95 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
@@ -19,27 +19,20 @@
 
 package org.apache.james;
 
-import java.io.IOException;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-import org.apache.james.server.core.configuration.Configuration;
-import org.junit.Ignore;
+class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
 
-public class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(temporaryFolder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-        return GuiceJamesServer.forConfiguration(configuration)
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
-            .overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE);
-    }
+            .overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE))
+        .build();
 
     @Override
-    @Ignore("Failing to create the domain: duplicate with test in JPAJamesServerTest")
-    public void jpaGuiceServerShouldUpdateQuota() {
+    @Disabled("Failing to create the domain: duplicate with test in JPAJamesServerTest")
+    void jpaGuiceServerShouldUpdateQuota(GuiceJamesServer jamesServer) {
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/memory-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml
index 8be7a8a..661634c 100644
--- a/server/container/guice/memory-guice/pom.xml
+++ b/server/container/guice/memory-guice/pom.xml
@@ -157,8 +157,13 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.vintage</groupId>
+            <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/98c29217/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java
index f617921..3874851 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java
@@ -19,20 +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 MemoryJamesServerTest implements JamesServerContract {
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-public class MemoryJamesServerTest extends AbstractJamesServerTest {
-    @Rule
-    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
-
-    @Override
-    protected GuiceJamesServer createJamesServer() throws IOException {
-        return memoryJmap.jmapServer(DOMAIN_LIST_CONFIGURATION_MODULE);
-    }
-
-    @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/98c29217/server/container/util/src/main/java/org/apache/james/util/Runnables.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/Runnables.java b/server/container/util/src/main/java/org/apache/james/util/Runnables.java
index c199f31..0d4bc91 100644
--- a/server/container/util/src/main/java/org/apache/james/util/Runnables.java
+++ b/server/container/util/src/main/java/org/apache/james/util/Runnables.java
@@ -22,11 +22,16 @@ package org.apache.james.util;
 import java.util.Arrays;
 import java.util.concurrent.CompletableFuture;
 import java.util.function.Supplier;
+import java.util.stream.Stream;
 
 public class Runnables {
     public static void runParallel(Runnable... runnables) {
-        FluentFutureStream.of(
-            Arrays.stream(runnables)
+        Stream<Runnable> stream = Arrays.stream(runnables);
+        runParrallelStream(stream);
+    }
+
+    public static void runParrallelStream(Stream<Runnable> stream) {
+        FluentFutureStream.of(stream
                 .map(runnable -> CompletableFuture.supplyAsync(toVoidSupplier(runnable))))
             .join();
     }


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


Mime
View raw message