james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [19/44] james-project git commit: JAMES-2267 Easy awaitSent for Smtp client
Date Fri, 05 Jan 2018 02:56:38 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/fe92484c/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
index f8c0f14..14173f9 100644
--- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
@@ -37,6 +37,7 @@ import org.apache.mailet.Mail;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Throwables;
+import com.jayway.awaitility.core.ConditionFactory;
 
 public class SMTPMessageSender implements Closeable {
 
@@ -64,7 +65,7 @@ public class SMTPMessageSender implements Closeable {
         this.senderDomain = senderDomain;
     }
 
-    public void sendMessage(String from, String recipient) {
+    public SMTPMessageSender sendMessage(String from, String recipient) {
         try {
             smtpClient.helo(senderDomain);
             smtpClient.setSender(from);
@@ -77,9 +78,10 @@ public class SMTPMessageSender implements Closeable {
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
+        return this;
     }
 
-    public void sendMessageNoBracket(String from, String recipient) {
+    public SMTPMessageSender sendMessageNoBracket(String from, String recipient) {
         try {
             smtpClient.helo(senderDomain);
             smtpClient.setSender(from);
@@ -92,9 +94,10 @@ public class SMTPMessageSender implements Closeable {
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
+        return this;
     }
 
-    public void sendMessageWithHeaders(String from, String recipient, String message) {
+    public SMTPMessageSender sendMessageWithHeaders(String from, String recipient, String
message) {
         try {
             smtpClient.helo(senderDomain);
             smtpClient.setSender(from);
@@ -103,9 +106,10 @@ public class SMTPMessageSender implements Closeable {
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
+        return this;
     }
 
-    public void sendMessage(Mail mail) throws MessagingException {
+    public SMTPMessageSender sendMessage(Mail mail) throws MessagingException {
         try {
             String from = mail.getSender().asString();
             smtpClient.helo(senderDomain);
@@ -117,6 +121,7 @@ public class SMTPMessageSender implements Closeable {
         } catch (IOException e) {
             throw Throwables.propagate(e);
         }
+        return this;
     }
 
     private String asString(Message message) throws IOException, MessagingException {
@@ -130,6 +135,10 @@ public class SMTPMessageSender implements Closeable {
             .contains("250 2.6.0 Message received");
     }
 
+    public void awaitSent(ConditionFactory conditionFactory) {
+        conditionFactory.until(this::messageHasBeenSent);
+    }
+
     public boolean messageSendingFailed() throws IOException {
         String replyString = smtpClient.getReplyString().trim();
         return replyString.startsWith("4") || replyString.startsWith("5");


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