james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [3/6] james-project git commit: JAMES-2441 Test that a user can receive emails before her first connection
Date Tue, 03 Jul 2018 02:48:21 GMT
JAMES-2441 Test that a user can receive emails before her first connection


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

Branch: refs/heads/master
Commit: dd31a8219d6942a74587b2df4f396bab88c26ef2
Parents: ce6a5d6
Author: benwa <btellier@linagora.com>
Authored: Wed Jun 27 11:16:28 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Jul 3 09:47:14 2018 +0700

----------------------------------------------------------------------
 .../james/CassandraLdapJamesServerTest.java     | 35 ++++++++++++++++++
 .../server/CamelMailetContainerModule.java      |  4 ++-
 .../org/apache/james/utils/SpoolerProbe.java    | 37 ++++++++++++++++++++
 .../james/AbstractJmapJamesServerTest.java      |  2 +-
 4 files changed, 76 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/dd31a821/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
index c6a8eca..60840da 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
@@ -19,21 +19,37 @@
 
 package org.apache.james;
 
+import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
 
 import org.apache.commons.net.imap.IMAPClient;
+import org.apache.james.core.Domain;
 import org.apache.james.user.ldap.LdapGenericContainer;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.SpoolerProbe;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
 
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.Duration;
+import com.jayway.awaitility.core.ConditionFactory;
+
 public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest {
     private static final String JAMES_USER = "james-user";
     private static final String PASSWORD = "secret";
     private static final String DOMAIN = "james.org";
     private static final String ADMIN_PASSWORD = "mysecretpassword";
+    private static Duration slowPacedPollInterval = FIVE_HUNDRED_MILLISECONDS;
+    private static ConditionFactory calmlyAwait = Awaitility.with()
+        .pollInterval(slowPacedPollInterval)
+        .and()
+        .with()
+        .pollDelay(slowPacedPollInterval)
+        .await();
 
     private LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
         .domain(DOMAIN)
@@ -45,6 +61,11 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest
{
     @Rule
     public RuleChain ruleChain = RuleChain.outerRule(ldapContainer).around(cassandraLdapJmap);
 
+    @Rule
+    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString());
+
     @Override
     protected GuiceJamesServer createJamesServer() throws IOException {
         ldapContainer.start();
@@ -70,4 +91,18 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest
{
 
         assertThat(imapClient.login(JAMES_USER, PASSWORD)).isTrue();
     }
+
+    @Test
+    public void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap() throws Exception
{
+        messageSender.connect("127.0.0.1", 1025)
+            .sendMessage("bob@any.com", JAMES_USER + "@localhost");
+
+        calmlyAwait.until(() -> server.getProbe(SpoolerProbe.class).processingFinished());
+
+        imapMessageReader.connect("127.0.0.1", 1143)
+            .login(JAMES_USER, PASSWORD)
+            .select("INBOX")
+            .awaitMessage(calmlyAwait);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/dd31a821/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
index d96d2ab..0d41d59 100644
--- a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
+++ b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
@@ -47,7 +47,9 @@ import org.apache.james.user.api.UsersRepository;
 import org.apache.james.utils.ConfigurationPerformer;
 import org.apache.james.utils.GuiceMailetLoader;
 import org.apache.james.utils.GuiceMatcherLoader;
+import org.apache.james.utils.GuiceProbe;
 import org.apache.james.utils.MailetConfigurationOverride;
+import org.apache.james.utils.SpoolerProbe;
 import org.apache.mailet.MailetContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -79,7 +81,7 @@ public class CamelMailetContainerModule extends AbstractModule {
         bind(MatcherLoader.class).to(GuiceMatcherLoader.class);
 
         Multibinder.newSetBinder(binder(), MailetConfigurationOverride.class);
-
+        Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(SpoolerProbe.class);
         Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(MailetModuleConfigurationPerformer.class);
 
         Multibinder<CamelMailetContainerModule.TransportProcessorCheck> transportProcessorChecks
= Multibinder.newSetBinder(binder(), CamelMailetContainerModule.TransportProcessorCheck.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/dd31a821/server/container/guice/mailet/src/main/java/org/apache/james/utils/SpoolerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/main/java/org/apache/james/utils/SpoolerProbe.java
b/server/container/guice/mailet/src/main/java/org/apache/james/utils/SpoolerProbe.java
new file mode 100644
index 0000000..322a11b
--- /dev/null
+++ b/server/container/guice/mailet/src/main/java/org/apache/james/utils/SpoolerProbe.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.utils;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailetcontainer.impl.JamesMailSpooler;
+
+public class SpoolerProbe implements GuiceProbe {
+    private final JamesMailSpooler spooler;
+
+    @Inject
+    public SpoolerProbe(JamesMailSpooler spooler) {
+        this.spooler = spooler;
+    }
+
+    public boolean processingFinished() {
+        return spooler.getCurrentSpoolCount() == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/dd31a821/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
index 27f01eb..fb510be 100644
--- a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
+++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java
@@ -51,7 +51,7 @@ public abstract class AbstractJmapJamesServerTest {
     protected static final String JAMES_SERVER_HOST = "127.0.0.1";
     protected static final int IMAP_PORT = 1143; // You need to be root (superuser) to bind
to ports under 1024.
 
-    private GuiceJamesServer server;
+    protected GuiceJamesServer server;
     private SocketChannel socketChannel;
 
     @Before


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