james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [7/7] james-project git commit: JAMES-2597 Using RabbitMQDockerSingleton in DockerRabbitMQRule
Date Mon, 26 Nov 2018 09:41:33 GMT
JAMES-2597 Using RabbitMQDockerSingleton in DockerRabbitMQRule


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

Branch: refs/heads/master
Commit: 92a41825d3cd252ea0559827ed22f4710a8c9392
Parents: d9169bb
Author: tran tien duc <dtran@linagora.com>
Authored: Fri Nov 23 12:01:10 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon Nov 26 16:41:05 2018 +0700

----------------------------------------------------------------------
 .../james/modules/DockerRabbitMQRule.java       | 21 +++--
 ...assandraRabbitMQLdapJmapJamesServerTest.java | 81 ++++++--------------
 2 files changed, 33 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/92a41825/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
index 5356b6c..3e701a6 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/DockerRabbitMQRule.java
@@ -21,22 +21,22 @@ package org.apache.james.modules;
 
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 
-import com.google.inject.Module;
-import com.google.inject.multibindings.Multibinder;
-import com.google.inject.util.Modules;
+import java.net.URISyntaxException;
+
 import org.apache.james.CleanupTasksPerformer;
 import org.apache.james.GuiceModuleTestRule;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQ;
+import org.apache.james.backend.rabbitmq.DockerRabbitMQSingleton;
 import org.apache.james.backend.rabbitmq.RabbitMQConfiguration;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
-import java.net.URISyntaxException;
+import com.google.inject.Module;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.util.Modules;
 
 public class DockerRabbitMQRule implements GuiceModuleTestRule {
 
-    private DockerRabbitMQ rabbitMQ = DockerRabbitMQ.withoutCookie();
-
     @Override
     public Statement apply(Statement base, Description description) {
         return base;
@@ -52,8 +52,8 @@ public class DockerRabbitMQRule implements GuiceModuleTestRule {
                 try {
                     binder.bind(RabbitMQConfiguration.class)
                         .toInstance(RabbitMQConfiguration.builder()
-                            .amqpUri(rabbitMQ.amqpUri())
-                            .managementUri(rabbitMQ.managementUri())
+                            .amqpUri(DockerRabbitMQSingleton.SINGLETON.amqpUri())
+                            .managementUri(DockerRabbitMQSingleton.SINGLETON.managementUri())
                             .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
                             .build());
                 } catch (URISyntaxException e) {
@@ -66,14 +66,13 @@ public class DockerRabbitMQRule implements GuiceModuleTestRule {
     }
 
     public DockerRabbitMQ dockerRabbitMQ() {
-        return rabbitMQ;
+        return DockerRabbitMQSingleton.SINGLETON;
     }
 
     public void start() {
-        rabbitMQ.start();
+        DockerRabbitMQSingleton.SINGLETON.start();
     }
 
     public void stop() {
-        rabbitMQ.stop();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/92a41825/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
index 62284a5..7fdb315 100644
--- a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
@@ -20,25 +20,19 @@
 package org.apache.james;
 
 import static org.apache.james.JmapJamesServerContract.JAMES_SERVER_HOST;
+import static org.apache.james.user.ldap.DockerLdapSingleton.JAMES_USER;
+import static org.apache.james.user.ldap.DockerLdapSingleton.PASSWORD;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
 
 import java.io.IOException;
 
 import org.apache.commons.net.imap.IMAPClient;
-import org.apache.james.core.Domain;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.SwiftBlobStoreExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
-import org.apache.james.modules.protocols.SmtpGuiceProbe;
-import org.apache.james.utils.IMAPMessageReader;
-import org.apache.james.utils.SMTPMessageSender;
-import org.apache.james.utils.SpoolerProbe;
-import org.awaitility.Awaitility;
-import org.awaitility.Duration;
-import org.awaitility.core.ConditionFactory;
+import org.apache.james.server.core.configuration.Configuration;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
@@ -46,33 +40,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 class CassandraRabbitMQLdapJmapJamesServerTest {
     private static final int LIMIT_TO_10_MESSAGES = 10;
-    private static final String JAMES_USER = "james-user";
-    private static final String PASSWORD = "secret";
-    private static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
-
-    private static ConditionFactory calmlyAwait = Awaitility
-        .with().pollInterval(slowPacedPollInterval)
-        .and().with().pollDelay(slowPacedPollInterval)
-        .await();
-
-    interface MailsShouldBeWellReceived {
-        @RegisterExtension
-        IMAPMessageReader imapMessageReader = new IMAPMessageReader();
-        SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString());
-
-        @Test
-        default void mailsShouldBeWellReceived(GuiceJamesServer server) throws Exception
{
-            messageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort())
-                .sendMessage("bob@any.com", JAMES_USER + "@localhost");
-
-            calmlyAwait.until(() -> server.getProbe(SpoolerProbe.class).processingFinished());
-
-            imapMessageReader.connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort())
-                .login(JAMES_USER, PASSWORD)
-                .select("INBOX")
-                .awaitMessage(calmlyAwait);
-        }
-    }
 
     interface UserFromLdapShouldLogin {
 
@@ -85,25 +52,15 @@ class CassandraRabbitMQLdapJmapJamesServerTest {
         }
     }
 
-    interface ContractSuite extends JmapJamesServerContract, MailsShouldBeWellReceived,
-        UserFromLdapShouldLogin, JamesServerContract {}
+    interface ContractSuite extends JmapJamesServerContract, UserFromLdapShouldLogin, JamesServerContract
{}
 
     @Nested
     @TestInstance(TestInstance.Lifecycle.PER_CLASS)
     class WithSwift implements ContractSuite {
         @RegisterExtension
-        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
-            .extension(new CassandraExtension())
-            .extension(new RabbitMQExtension())
-            .extension(new LdapTestExtension())
+        JamesServerExtension testExtension = baseJamesServerExtensionBuilder()
             .extension(new SwiftBlobStoreExtension())
-            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
-                .combineWith(CassandraRabbitMQLdapJamesServerMain.MODULES)
-                .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
-                    .toInstance(BlobStoreChoosingConfiguration.objectStorage()))
-                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-                .overrideWith(JmapJamesServerContract.DOMAIN_LIST_CONFIGURATION_MODULE))
+            .server(configuration -> buildGuiceServer(configuration, BlobStoreChoosingConfiguration.objectStorage()))
             .build();
     }
 
@@ -111,17 +68,25 @@ class CassandraRabbitMQLdapJmapJamesServerTest {
     @TestInstance(TestInstance.Lifecycle.PER_CLASS)
     class WithoutSwift implements ContractSuite {
         @RegisterExtension
-        JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+        JamesServerExtension testExtension = baseJamesServerExtensionBuilder()
+            .server(configuration -> buildGuiceServer(configuration, BlobStoreChoosingConfiguration.cassandra()))
+            .build();
+    }
+
+    JamesServerExtensionBuilder baseJamesServerExtensionBuilder() {
+        return new JamesServerExtensionBuilder()
             .extension(new EmbeddedElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
-            .extension(new LdapTestExtension())
-            .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
-                .combineWith(CassandraRabbitMQLdapJamesServerMain.MODULES)
-                .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
-                    .toInstance(BlobStoreChoosingConfiguration.cassandra()))
-                .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-                .overrideWith(JmapJamesServerContract.DOMAIN_LIST_CONFIGURATION_MODULE))
-            .build();
+            .extension(new LdapTestExtension());
+    }
+
+    GuiceJamesServer buildGuiceServer(Configuration configuration, BlobStoreChoosingConfiguration
choosingConfiguration) {
+        return GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(CassandraRabbitMQLdapJamesServerMain.MODULES)
+            .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
+                .toInstance(choosingConfiguration))
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(JmapJamesServerContract.DOMAIN_LIST_CONFIGURATION_MODULE);
     }
 }


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