You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/01/07 10:59:06 UTC

[james-project] branch master updated: JAMES-2543 Migrates MPT SMTP tests to fully use Junit 5

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e0f9af  JAMES-2543 Migrates MPT SMTP tests to fully use Junit 5
0e0f9af is described below

commit 0e0f9afe4f22925316e3bcc739ab479d271574bc
Author: Jean Helou <jh...@codamens.fr>
AuthorDate: Thu Dec 17 00:06:22 2020 +0100

    JAMES-2543 Migrates MPT SMTP tests to fully use Junit 5
---
 .../smtp/cassandra-rabbitmq-object-storage/pom.xml |  12 +++
 .../mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java     |  41 +++-----
 .../smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java |  17 ++--
 .../CassandraRabbitMQAwsS3SmtpTestRuleFactory.java | 104 ---------------------
 .../src/test/resources/imapserver.xml              |  25 +++++
 .../src/test/resources/lmtpserver.xml              |  23 +++++
 .../src/test/resources/mailetcontainer.xml         |   2 +
 .../src/test/resources/managesieveserver.xml       |  32 +++++++
 .../src/test/resources/pop3server.xml              |  24 +++++
 mpt/impl/smtp/cassandra/pom.xml                    |   6 ++
 .../james/mpt/smtp/CassandraForwardSmtpTest.java   |  45 ++++++---
 .../mpt/smtp/CassandraSmtpStarttlsCommandTest.java |  32 ++++++-
 .../mpt/smtp/CassandraSmtpTestRuleFactory.java     |  76 ---------------
 .../cassandra/src/test/resources/imapserver.xml    |  25 +++++
 .../cassandra/src/test/resources/lmtpserver.xml    |  23 +++++
 .../src/test/resources/mailetcontainer.xml         |   2 +
 .../src/test/resources/managesieveserver.xml       |  32 +++++++
 .../cassandra/src/test/resources/pop3server.xml    |  24 +++++
 mpt/impl/smtp/core/pom.xml                         |   5 +
 .../org/apache/james/mpt/smtp/ForwardSmtpTest.java |  31 +++---
 ...tpHostSystem.java => InMemoryDnsExtension.java} |  32 ++++++-
 .../org/apache/james/mpt/smtp/SmtpHostSystem.java  |   3 -
 .../apache/james/mpt/smtp/SmtpTestExtension.java   |  53 ++---------
 .../org/apache/james/utils/FakeSmtpExtension.java  |   4 +-
 24 files changed, 366 insertions(+), 307 deletions(-)

diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/pom.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/pom.xml
index cd15f7c..8996b73 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/pom.xml
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/pom.xml
@@ -39,6 +39,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-backends-es</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-backends-rabbitmq</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
@@ -65,6 +71,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-cassandra-guice</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-cassandra-rabbitmq-guice</artifactId>
         </dependency>
         <dependency>
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
index f6621a9..c4eaf02 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
@@ -21,41 +21,22 @@ package org.apache.james.mpt.smtp;
 
 import static org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_GLOBAL_SERVER;
 
-import org.apache.james.backends.cassandra.DockerCassandraExtension;
-import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
-import org.apache.james.blob.objectstorage.aws.DockerAwsS3Extension;
+import org.apache.james.CassandraRabbitMQJamesServerFixture;
+import org.apache.james.JamesServerExtension;
 import org.apache.james.modules.AwsS3BlobStoreExtension;
-import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
-import org.junit.Rule;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.extension.RegisterExtension;
-import org.junit.rules.RuleChain;
-import org.junit.rules.TestRule;
 
 public class AwsS3RabbitMQForwardSmtpTest implements ForwardSmtpTest {
-
-    @RegisterExtension
-    public static DockerCassandraExtension cassandraServer = new DockerCassandraExtension();
-
+    @Order(1)
     @RegisterExtension
-    public AwsS3BlobStoreExtension dockerAwsS3TestRule = new AwsS3BlobStoreExtension();
+    static JamesServerExtension testExtension = CassandraRabbitMQJamesServerFixture.baseExtensionBuilder()
+            .extension(new AwsS3BlobStoreExtension())
+            .extension(new InMemoryDnsExtension())
+            .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
+            .build();
 
+    @Order(2)
     @RegisterExtension
-    public SmtpTestExtension cassandraRabbitMQAwsS3SmtpTestRule =
-            CassandraRabbitMQAwsS3SmtpTestRuleFactory.createExtension(SMTP_GLOBAL_SERVER, () -> cassandraServer.getDockerCassandra().getHost(), dockerAwsS3TestRule);
-
-    private SmtpHostSystem hostSystem;
-
-    @BeforeEach
-    void setup(SmtpHostSystem hostSystem) {
-        this.hostSystem = hostSystem;
-    }
-
-
-    @Override
-    public SmtpHostSystem hostSystem() {
-        return hostSystem;
-    }
-
+    static SmtpTestExtension smtpTestExtension = new SmtpTestExtension(SMTP_GLOBAL_SERVER, testExtension);
 }
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
index d06d958..cae9ec3 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
@@ -21,19 +21,18 @@ package org.apache.james.mpt.smtp;
 
 import static org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_START_TLS_SERVER;
 
-import org.apache.james.backends.cassandra.DockerCassandraExtension;
+import org.apache.james.CassandraRabbitMQJamesServerFixture;
+import org.apache.james.JamesServerExtension;
 import org.apache.james.modules.AwsS3BlobStoreExtension;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class AwsS3RabbitMQSmtpStarttlsCommandTest extends SmtpStarttlsCommandTest {
-
-    @RegisterExtension
-    public static DockerCassandraExtension cassandraServer = new DockerCassandraExtension();
-
     @RegisterExtension
-    public AwsS3BlobStoreExtension dockerAwsS3TestRule = new AwsS3BlobStoreExtension();
-
+    static JamesServerExtension testExtension = CassandraRabbitMQJamesServerFixture.baseExtensionBuilder()
+            .extension(new AwsS3BlobStoreExtension())
+            .extension(new InMemoryDnsExtension())
+            .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
+            .build();
     @RegisterExtension
-    public SmtpTestExtension cassandraRabbitMQAwsS3SmtpTestRule =
-            CassandraRabbitMQAwsS3SmtpTestRuleFactory.createExtension(SMTP_START_TLS_SERVER, () -> cassandraServer.getDockerCassandra().getHost(), dockerAwsS3TestRule);
+    static SmtpTestExtension smtpTestExtension = new SmtpTestExtension(SMTP_START_TLS_SERVER, testExtension);
 }
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
deleted file mode 100644
index bd625dd..0000000
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
+++ /dev/null
@@ -1,104 +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.mpt.smtp;
-
-import java.util.function.Supplier;
-
-import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
-import org.apache.james.CassandraJamesServerMain;
-import org.apache.james.CleanupTasksPerformer;
-import org.apache.james.GuiceJamesServer;
-import org.apache.james.backends.cassandra.DockerCassandra;
-import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
-import org.apache.james.backends.rabbitmq.DockerRabbitMQSingleton;
-import org.apache.james.blob.api.BlobStore;
-import org.apache.james.blob.api.BlobStoreDAO;
-import org.apache.james.blob.api.MetricableBlobStore;
-import org.apache.james.blob.objectstorage.aws.S3BlobStoreDAO;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.modules.AwsS3BlobStoreExtension;
-import org.apache.james.modules.TestRabbitMQModule;
-import org.apache.james.modules.mailbox.KeyspacesConfiguration;
-import org.apache.james.modules.objectstorage.DefaultBucketModule;
-import org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType;
-import org.apache.james.modules.queue.rabbitmq.RabbitMQModule;
-import org.apache.james.modules.server.CamelMailetContainerModule;
-import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
-import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
-import org.apache.james.server.blob.deduplication.DeDuplicationBlobStore;
-import org.apache.james.server.core.configuration.Configuration;
-import org.apache.james.util.Host;
-import org.junit.rules.TemporaryFolder;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Module;
-import com.google.inject.name.Names;
-
-public final class CassandraRabbitMQAwsS3SmtpTestRuleFactory {
-    public static SmtpTestExtension createExtension(SmtpServerConnectedType smtpGlobalServer, Supplier<Host> host, AwsS3BlobStoreExtension dockerAwsS3TestRule) {
-        SmtpTestExtension.ServerBuilder createJamesServer = (folder, dnsService) -> createJamesServer(host, dockerAwsS3TestRule.getModule(), folder, dnsService);
-
-        return new SmtpTestExtension(smtpGlobalServer, createJamesServer);
-    }
-
-
-    private static Module BLOB_STORE_MODULE = new AbstractModule() {
-        @Override
-        protected void configure() {
-            bind(BlobStore.class)
-                .annotatedWith(Names.named(MetricableBlobStore.BLOB_STORE_IMPLEMENTATION))
-                .to(DeDuplicationBlobStore.class);
-            bind(BlobStoreDAO.class).to(S3BlobStoreDAO.class);
-        }
-    };
-
-    private static GuiceJamesServer createJamesServer(Supplier<Host> cassandraHost, Module awsS3Module , TemporaryFolder folder, DNSService dnsService) throws Exception {
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(folder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-
-        return GuiceJamesServer.forConfiguration(configuration)
-            .combineWith(CassandraJamesServerMain.CASSANDRA_SERVER_CORE_MODULE,
-                new DefaultBucketModule(),
-                SmtpTestExtension.SMTP_PROTOCOL_MODULE,
-                binder -> binder.bind(MailQueueItemDecoratorFactory.class).to(RawMailQueueItemDecoratorFactory.class),
-                binder -> binder.bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
-                    .toInstance(BaseHierarchicalConfiguration::new))
-            .overrideWith(new RabbitMQModule(), BLOB_STORE_MODULE)
-            .overrideWith(
-                new TestRabbitMQModule(DockerRabbitMQSingleton.SINGLETON),
-                    awsS3Module,
-                binder -> binder.bind(KeyspacesConfiguration.class)
-                    .toInstance(KeyspacesConfiguration.builder()
-                        .keyspace(DockerCassandra.KEYSPACE)
-                        .cacheKeyspace(DockerCassandra.CACHE_KEYSPACE)
-                        .replicationFactor(1)
-                        .disableDurableWrites()
-                        .build()),
-                binder -> binder.bind(ClusterConfiguration.class).toInstance(
-                    DockerCassandra.configurationBuilder(cassandraHost.get())
-                        .build()),
-                binder -> binder.bind(DNSService.class).toInstance(dnsService),
-                binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton());
-    }
-
-}
-
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/imapserver.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/imapserver.xml
new file mode 100644
index 0000000..7d64639
--- /dev/null
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/imapserver.xml
@@ -0,0 +1,25 @@
+<?xml version="1.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.
+-->
+
+
+<imapservers>
+    <imapserver enabled="false"/>
+</imapservers>
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/lmtpserver.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/lmtpserver.xml
new file mode 100644
index 0000000..5f54473
--- /dev/null
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/lmtpserver.xml
@@ -0,0 +1,23 @@
+<?xml version="1.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.                                           
+ -->
+
+<lmtpservers>
+    <lmtpserver enabled="false"/>
+</lmtpservers>
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/mailetcontainer.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/mailetcontainer.xml
index 7c58ed0..1995265 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/mailetcontainer.xml
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/mailetcontainer.xml
@@ -58,6 +58,8 @@
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
             </mailet>
+            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>
+            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
             <mailet match="All" class="RecipientRewriteTable">
                 <errorProcessor>rrt-error</errorProcessor>
             </mailet>
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/managesieveserver.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/managesieveserver.xml
new file mode 100644
index 0000000..4047f9f
--- /dev/null
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/managesieveserver.xml
@@ -0,0 +1,32 @@
+<?xml version="1.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.                                           
+ -->
+ 
+<!--
+   This template file can be used as example for James Server configuration
+   DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+-->
+ 
+<!-- See http://james.apache.org/server/3/config.html for usage -->
+
+<managesieveservers>
+   <managesieveserver enabled="false"/>
+</managesieveservers>
+
+
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/pop3server.xml b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/pop3server.xml
new file mode 100644
index 0000000..e277325
--- /dev/null
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/resources/pop3server.xml
@@ -0,0 +1,24 @@
+<?xml version="1.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.                                           
+ -->
+
+
+<pop3servers>
+    <pop3server enabled="false"/>
+</pop3servers>
diff --git a/mpt/impl/smtp/cassandra/pom.xml b/mpt/impl/smtp/cassandra/pom.xml
index 0fefef4..275c43a 100644
--- a/mpt/impl/smtp/cassandra/pom.xml
+++ b/mpt/impl/smtp/cassandra/pom.xml
@@ -39,6 +39,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-backends-es</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mpt-smtp-core</artifactId>
         </dependency>
         <dependency>
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
index e2c8cdb..d04f76d 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraForwardSmtpTest.java
@@ -21,29 +21,46 @@ package org.apache.james.mpt.smtp;
 
 import static org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_GLOBAL_SERVER;
 
-import org.apache.james.backends.cassandra.DockerCassandraExtension;
+import org.apache.james.CassandraExtension;
+import org.apache.james.CassandraJamesServerMain;
+import org.apache.james.DockerElasticSearchExtension;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.SearchConfiguration;
+import org.apache.james.TestingDistributedJamesServerBuilder;
+import org.apache.james.backends.cassandra.DockerCassandra;
+import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class CassandraForwardSmtpTest implements ForwardSmtpTest {
 
-    @RegisterExtension
-    public static DockerCassandraExtension cassandraServer = new DockerCassandraExtension();
 
+    private static final CassandraExtension cassandraExtension = new CassandraExtension();
+
+    @BeforeAll
+    static void setUp() {
+        Thread.currentThread().setContextClassLoader(CassandraForwardSmtpTest.class.getClassLoader());
+    }
+    @Order(1)
     @RegisterExtension
-    public SmtpTestExtension smtpTestExtension =
-            CassandraSmtpTestRuleFactory.createExtension(SMTP_GLOBAL_SERVER, () -> cassandraServer.getDockerCassandra().getHost());
+    static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.elasticSearch())
+            .extension(new DockerElasticSearchExtension())
+            .extension(cassandraExtension)
+            .extension(new InMemoryDnsExtension())
+            .server(CassandraJamesServerMain::createServer)
+            .overrideServerModule(binder -> binder.bind(ClusterConfiguration.class)
+                    .toInstance(DockerCassandra.configurationBuilder(cassandraExtension.getCassandra().getHost())
+                            .username(DockerCassandra.CASSANDRA_TESTING_USER)
+                            .password(DockerCassandra.CASSANDRA_TESTING_PASSWORD)
+                            .build()))
+            .build();
 
-    private SmtpHostSystem hostSystem;
 
-    @BeforeEach
-    void setup(SmtpHostSystem hostSystem) {
-        this.hostSystem = hostSystem;
-    }
+    @Order(2)
+    @RegisterExtension
+    static SmtpTestExtension smtpTestExtension = new SmtpTestExtension(SMTP_GLOBAL_SERVER, testExtension);
 
-    @Override
-    public SmtpHostSystem hostSystem() {
-        return hostSystem;
-    }
 
 }
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
index 511a2ba..3fe34f0 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpStarttlsCommandTest.java
@@ -21,16 +21,38 @@ package org.apache.james.mpt.smtp;
 
 import static org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_START_TLS_SERVER;
 
-import org.apache.james.backends.cassandra.DockerCassandraExtension;
+import org.apache.james.CassandraExtension;
+import org.apache.james.CassandraJamesServerMain;
+import org.apache.james.DockerElasticSearchExtension;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.SearchConfiguration;
+import org.apache.james.TestingDistributedJamesServerBuilder;
+import org.apache.james.backends.cassandra.DockerCassandra;
+import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class CassandraSmtpStarttlsCommandTest extends SmtpStarttlsCommandTest {
 
-    @RegisterExtension
-    public static DockerCassandraExtension cassandraServer = new DockerCassandraExtension();
 
+    private static final CassandraExtension cassandraExtension = new CassandraExtension();
+
+    @Order(1)
     @RegisterExtension
-    public SmtpTestExtension smtpTestExtension =
-            CassandraSmtpTestRuleFactory.createExtension(SMTP_START_TLS_SERVER, () -> cassandraServer.getDockerCassandra().getHost());
+    static JamesServerExtension testExtension = TestingDistributedJamesServerBuilder.withSearchConfiguration(SearchConfiguration.elasticSearch())
+            .extension(new DockerElasticSearchExtension())
+            .extension(cassandraExtension)
+            .extension(new InMemoryDnsExtension())
+            .server(CassandraJamesServerMain::createServer)
+            .overrideServerModule(binder -> binder.bind(ClusterConfiguration.class)
+                    .toInstance(DockerCassandra.configurationBuilder(cassandraExtension.getCassandra().getHost())
+                            .username(DockerCassandra.CASSANDRA_TESTING_USER)
+                            .password(DockerCassandra.CASSANDRA_TESTING_PASSWORD)
+                            .build()))
+            .build();
 
+
+    @Order(2)
+    @RegisterExtension
+    static SmtpTestExtension smtpTestExtension = new SmtpTestExtension(SMTP_START_TLS_SERVER, testExtension);
 }
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java
deleted file mode 100644
index a5a5954..0000000
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java
+++ /dev/null
@@ -1,76 +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.mpt.smtp;
-
-import java.util.function.Supplier;
-
-import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
-import org.apache.james.CassandraJamesServerMain;
-import org.apache.james.GuiceJamesServer;
-import org.apache.james.backends.cassandra.DockerCassandra;
-import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.modules.mailbox.CassandraBlobStoreModule;
-import org.apache.james.modules.mailbox.CassandraBucketModule;
-import org.apache.james.modules.mailbox.KeyspacesConfiguration;
-import org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType;
-import org.apache.james.modules.server.CamelMailetContainerModule;
-import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
-import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
-import org.apache.james.server.core.configuration.Configuration;
-import org.apache.james.util.Host;
-import org.junit.rules.TemporaryFolder;
-
-public final class CassandraSmtpTestRuleFactory {
-
-    public static SmtpTestExtension createExtension(SmtpServerConnectedType smtpServerConnectedType, Supplier<Host> cassandraHost) {
-        SmtpTestExtension.ServerBuilder createJamesServer = (folder, dnsService) -> createJamesServer(cassandraHost, folder, dnsService);
-
-        return new SmtpTestExtension(smtpServerConnectedType, createJamesServer);
-    }
-
-    private static GuiceJamesServer createJamesServer(Supplier<Host> cassandraHost, TemporaryFolder folder, DNSService dnsService) throws Exception {
-        Configuration configuration = Configuration.builder()
-            .workingDirectory(folder.newFolder())
-            .configurationFromClasspath()
-            .build();
-
-        return GuiceJamesServer.forConfiguration(configuration)
-            .combineWith(CassandraJamesServerMain.CASSANDRA_SERVER_CORE_MODULE,
-                new CassandraBlobStoreModule(),
-                new CassandraBucketModule(),
-                SmtpTestExtension.SMTP_PROTOCOL_MODULE,
-                binder -> binder.bind(MailQueueItemDecoratorFactory.class).to(RawMailQueueItemDecoratorFactory.class),
-                binder -> binder.bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
-                    .toInstance(BaseHierarchicalConfiguration::new))
-            .overrideWith(
-                binder -> binder.bind(ClusterConfiguration.class).toInstance(
-                    DockerCassandra.configurationBuilder(cassandraHost.get())
-                        .build()),
-                binder -> binder.bind(KeyspacesConfiguration.class)
-                    .toInstance(KeyspacesConfiguration.builder()
-                        .keyspace(DockerCassandra.KEYSPACE)
-                        .cacheKeyspace(DockerCassandra.CACHE_KEYSPACE)
-                        .replicationFactor(1)
-                        .disableDurableWrites()
-                        .build()),
-                binder -> binder.bind(DNSService.class).toInstance(dnsService));
-    }
-}
-
diff --git a/mpt/impl/smtp/cassandra/src/test/resources/imapserver.xml b/mpt/impl/smtp/cassandra/src/test/resources/imapserver.xml
new file mode 100644
index 0000000..7d64639
--- /dev/null
+++ b/mpt/impl/smtp/cassandra/src/test/resources/imapserver.xml
@@ -0,0 +1,25 @@
+<?xml version="1.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.
+-->
+
+
+<imapservers>
+    <imapserver enabled="false"/>
+</imapservers>
diff --git a/mpt/impl/smtp/cassandra/src/test/resources/lmtpserver.xml b/mpt/impl/smtp/cassandra/src/test/resources/lmtpserver.xml
new file mode 100644
index 0000000..5f54473
--- /dev/null
+++ b/mpt/impl/smtp/cassandra/src/test/resources/lmtpserver.xml
@@ -0,0 +1,23 @@
+<?xml version="1.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.                                           
+ -->
+
+<lmtpservers>
+    <lmtpserver enabled="false"/>
+</lmtpservers>
diff --git a/mpt/impl/smtp/cassandra/src/test/resources/mailetcontainer.xml b/mpt/impl/smtp/cassandra/src/test/resources/mailetcontainer.xml
index 7c58ed0..97035c5 100644
--- a/mpt/impl/smtp/cassandra/src/test/resources/mailetcontainer.xml
+++ b/mpt/impl/smtp/cassandra/src/test/resources/mailetcontainer.xml
@@ -61,6 +61,8 @@
             <mailet match="All" class="RecipientRewriteTable">
                 <errorProcessor>rrt-error</errorProcessor>
             </mailet>
+            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>
+            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5 minutes</delayTime>
diff --git a/mpt/impl/smtp/cassandra/src/test/resources/managesieveserver.xml b/mpt/impl/smtp/cassandra/src/test/resources/managesieveserver.xml
new file mode 100644
index 0000000..4047f9f
--- /dev/null
+++ b/mpt/impl/smtp/cassandra/src/test/resources/managesieveserver.xml
@@ -0,0 +1,32 @@
+<?xml version="1.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.                                           
+ -->
+ 
+<!--
+   This template file can be used as example for James Server configuration
+   DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+-->
+ 
+<!-- See http://james.apache.org/server/3/config.html for usage -->
+
+<managesieveservers>
+   <managesieveserver enabled="false"/>
+</managesieveservers>
+
+
diff --git a/mpt/impl/smtp/cassandra/src/test/resources/pop3server.xml b/mpt/impl/smtp/cassandra/src/test/resources/pop3server.xml
new file mode 100644
index 0000000..e277325
--- /dev/null
+++ b/mpt/impl/smtp/cassandra/src/test/resources/pop3server.xml
@@ -0,0 +1,24 @@
+<?xml version="1.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.                                           
+ -->
+
+
+<pop3servers>
+    <pop3server enabled="false"/>
+</pop3servers>
diff --git a/mpt/impl/smtp/core/pom.xml b/mpt/impl/smtp/core/pom.xml
index eb02165..9982a4f 100644
--- a/mpt/impl/smtp/core/pom.xml
+++ b/mpt/impl/smtp/core/pom.xml
@@ -49,6 +49,11 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-guice-common</artifactId>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-guice-smtp</artifactId>
         </dependency>
         <dependency>
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
index 8092e07..70856fc 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.equalTo;
 
 import java.util.Locale;
 
+import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.mpt.script.SimpleScriptedTestProtocol;
 import org.apache.james.utils.FakeSmtpExtension;
 import org.awaitility.Awaitility;
@@ -41,30 +42,30 @@ public interface ForwardSmtpTest {
     String PASSWORD = "secret";
     Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
     ConditionFactory calmlyAwait = Awaitility.with()
-        .pollInterval(slowPacedPollInterval)
-        .await();
+            .pollInterval(slowPacedPollInterval)
+            .await();
 
     @RegisterExtension
     FakeSmtpExtension fakeSmtp = FakeSmtpExtension.withDefaultPort();
 
-    SmtpHostSystem hostSystem();
-
     @Test
-    default void forwardingAnEmailShouldWork(FakeSmtpExtension.FakeSmtp fakeSmtp) throws Exception {
-        SimpleScriptedTestProtocol scriptedTest = new SimpleScriptedTestProtocol("/org/apache/james/smtp/scripts/", hostSystem())
-                .withLocale(Locale.US)
-                .withUser(USER_AT_DOMAIN, PASSWORD);
+    default void forwardingAnEmailShouldWork(SmtpHostSystem hostSystem,
+                                             FakeSmtpExtension.FakeSmtp fakeSmtp,
+                                             InMemoryDNSService dnsService) throws Exception {
+        SimpleScriptedTestProtocol scriptedTest =
+                new SimpleScriptedTestProtocol("/org/apache/james/smtp/scripts/", hostSystem)
+                        .withLocale(Locale.US)
+                        .withUser(USER_AT_DOMAIN, PASSWORD);
 
-        hostSystem().getInMemoryDnsService()
-                .registerMxRecord("yopmail.com", fakeSmtp.getContainerIp());
-        hostSystem().addAddressMapping(USER, DOMAIN, "ray@yopmail.com");
+        dnsService.registerMxRecord("yopmail.com", fakeSmtp.getContainerIp());
+        hostSystem.addAddressMapping(USER, DOMAIN, "ray@yopmail.com");
 
         scriptedTest.run("helo");
 
         calmlyAwait.atMost(TWO_MINUTES).untilAsserted(() ->
-            fakeSmtp.assertEmailReceived(response -> response
-                .body("[0].from", equalTo("matthieu@yopmail.com"))
-                .body("[0].subject", equalTo("test"))
-                .body("[0].text", equalTo("content"))));
+                fakeSmtp.assertEmailReceived(response -> response
+                        .body("[0].from", equalTo("matthieu@yopmail.com"))
+                        .body("[0].subject", equalTo("test"))
+                        .body("[0].text", equalTo("content"))));
     }
 }
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/InMemoryDnsExtension.java
similarity index 54%
copy from mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java
copy to mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/InMemoryDnsExtension.java
index a0c7c06..652bc38 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/InMemoryDnsExtension.java
@@ -19,13 +19,37 @@
 
 package org.apache.james.mpt.smtp;
 
+import java.util.Optional;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
-import org.apache.james.mpt.api.HostSystem;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+
+import com.google.inject.Module;
+
+public class InMemoryDnsExtension implements GuiceModuleTestExtension {
+    private InMemoryDNSService inMemoryDns;
 
-public interface SmtpHostSystem extends HostSystem {
+    @Override
+    public Module getModule() {
+        return binder -> binder.bind(DNSService.class).toInstance(inMemoryDns);
+    }
 
-    void addAddressMapping(String user, String domain, String address) throws Exception;
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) throws Exception {
+        inMemoryDns = new InMemoryDNSService();
+    }
 
-    InMemoryDNSService getInMemoryDnsService();
+    @Override
+    public Optional<Class<?>> supportedParameterClass() {
+        return Optional.of(InMemoryDNSService.class);
+    }
 
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return inMemoryDns;
+    }
 }
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java
index a0c7c06..d44cbdf 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpHostSystem.java
@@ -19,13 +19,10 @@
 
 package org.apache.james.mpt.smtp;
 
-import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.mpt.api.HostSystem;
 
 public interface SmtpHostSystem extends HostSystem {
 
     void addAddressMapping(String user, String domain, String address) throws Exception;
 
-    InMemoryDNSService getInMemoryDnsService();
-
 }
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestExtension.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestExtension.java
index aef6692..c17b9be 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestExtension.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestExtension.java
@@ -21,12 +21,10 @@ package org.apache.james.mpt.smtp;
 import java.util.Optional;
 
 import org.apache.james.GuiceJamesServer;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.RegistrableExtension;
 import org.apache.james.core.Domain;
 import org.apache.james.core.Username;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.dnsservice.api.InMemoryDNSService;
-import org.apache.james.modules.protocols.ProtocolHandlerModule;
-import org.apache.james.modules.protocols.SMTPServerModule;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.mpt.api.Continuation;
 import org.apache.james.mpt.api.Session;
@@ -34,59 +32,31 @@ import org.apache.james.mpt.monitor.SystemLoggingMonitor;
 import org.apache.james.mpt.session.ExternalSessionFactory;
 import org.apache.james.util.Port;
 import org.apache.james.utils.DataProbeImpl;
-import org.junit.jupiter.api.extension.AfterEachCallback;
-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 org.junit.rules.TemporaryFolder;
 
 import com.google.common.base.Preconditions;
-import com.google.inject.Module;
-import com.google.inject.util.Modules;
 
 
-public class SmtpTestExtension implements
-        BeforeEachCallback,
-        AfterEachCallback,
-        ParameterResolver {
-
-    @FunctionalInterface
-    public interface ServerBuilder {
-        GuiceJamesServer build(TemporaryFolder folder, DNSService dnsService) throws Exception;
-    }
-
-    public static final Module SMTP_PROTOCOL_MODULE = Modules.combine(
-            new ProtocolHandlerModule(),
-            new SMTPServerModule());
+public class SmtpTestExtension implements RegistrableExtension {
 
     private final SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType;
-    private final ServerBuilder createJamesServer;
-    private TemporaryFolder folder;
-    private InMemoryDNSService inMemoryDNSService;
-    private GuiceJamesServer jamesServer;
+    private final JamesServerExtension testExtension;
     private SmtpHostSystem smtpHostSystem;
 
-    public SmtpTestExtension(SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType, ServerBuilder createJamesServer) {
+    public SmtpTestExtension(SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType, JamesServerExtension testExtension) {
         this.smtpServerConnectedType = smtpServerConnectedType;
-        this.createJamesServer = createJamesServer;
+        this.testExtension = testExtension;
     }
 
     @Override
     public void beforeEach(ExtensionContext context) throws Exception {
-        inMemoryDNSService = new InMemoryDNSService();
-        folder = new TemporaryFolder();
-        folder.create();
-        jamesServer = createJamesServer.build(folder, inMemoryDNSService);
-        jamesServer.start();
-        smtpHostSystem = new HostSystem(jamesServer, smtpServerConnectedType, inMemoryDNSService);
+        smtpHostSystem = new HostSystem(testExtension.getGuiceJamesServer(), smtpServerConnectedType);
     }
 
     @Override
     public void afterEach(ExtensionContext context) throws Exception {
-        jamesServer.stop();
-        folder.delete();
     }
 
     @Override
@@ -104,13 +74,11 @@ public class SmtpTestExtension implements
 
         private final ExternalSessionFactory sessionFactory;
         private final SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType;
-        private final InMemoryDNSService inMemoryDNSService;
         private final GuiceJamesServer jamesServer;
 
-        public HostSystem(GuiceJamesServer jamesServer, SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType, InMemoryDNSService inMemoryDNSService) {
+        public HostSystem(GuiceJamesServer jamesServer, SmtpGuiceProbe.SmtpServerConnectedType smtpServerConnectedType) {
             this.jamesServer = jamesServer;
             this.smtpServerConnectedType = smtpServerConnectedType;
-            this.inMemoryDNSService = inMemoryDNSService;
             SmtpGuiceProbe smtpProbe = jamesServer.getProbe(SmtpGuiceProbe.class);
             Port smtpPort = this.smtpServerConnectedType.getPortExtractor().apply(smtpProbe);
             sessionFactory = new ExternalSessionFactory("localhost", smtpPort, new SystemLoggingMonitor(), "220 mydomain.tld smtp");
@@ -150,10 +118,5 @@ public class SmtpTestExtension implements
         public void afterTest() throws Exception {
 
         }
-
-        @Override
-        public InMemoryDNSService getInMemoryDnsService() {
-            return inMemoryDNSService;
-        }
     }
 }
diff --git a/server/testing/src/main/java/org/apache/james/utils/FakeSmtpExtension.java b/server/testing/src/main/java/org/apache/james/utils/FakeSmtpExtension.java
index 5eb554d..0eb0df3 100644
--- a/server/testing/src/main/java/org/apache/james/utils/FakeSmtpExtension.java
+++ b/server/testing/src/main/java/org/apache/james/utils/FakeSmtpExtension.java
@@ -76,11 +76,11 @@ public class FakeSmtpExtension implements
     }
 
     private final GenericContainer<?> container;
-    private final FakeSmtp fakeSmtp;
+    private final FakeSmtpExtension.FakeSmtp fakeSmtp;
 
     private FakeSmtpExtension(GenericContainer<?> container) {
         this.container = container;
-        this.fakeSmtp = new FakeSmtp(container);
+        this.fakeSmtp = new FakeSmtpExtension.FakeSmtp(container);
     }
 
     @Override


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