You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/05/14 02:04:38 UTC

[james-project] 03/09: fixup! fixup! JAMES-3574 LMTP DATA processing errors should be propagated upstream

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

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

commit 659b56b907b5798cff941e92f079ecd5034a86ab
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed May 12 20:36:49 2021 +0700

    fixup! fixup! JAMES-3574 LMTP DATA processing errors should be propagated upstream
---
 .../org/apache/james/lmtpserver/LmtpServerTest.java | 18 +++++++++---------
 .../lmtpserver/MailetContainerHandlerTest.java      | 21 +++------------------
 2 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/LmtpServerTest.java b/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/LmtpServerTest.java
index 0de463c..8db8842 100644
--- a/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/LmtpServerTest.java
+++ b/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/LmtpServerTest.java
@@ -72,6 +72,14 @@ import com.google.inject.name.Names;
 import reactor.core.publisher.Flux;
 
 class LmtpServerTest {
+    static int getLmtpPort(LMTPServerFactory lmtpServerFactory) {
+        return lmtpServerFactory.getServers().stream()
+            .findFirst()
+            .flatMap(server -> server.getListenAddresses().stream().findFirst())
+            .map(InetSocketAddress::getPort)
+            .orElseThrow(() -> new IllegalStateException("LMTP server not defined"));
+    }
+
     private InMemoryMailboxManager mailboxManager;
     private LMTPServerFactory lmtpServerFactory;
 
@@ -136,7 +144,7 @@ class LmtpServerTest {
     @Test
     void emailsShouldWellBeReceived() throws Exception {
         SocketChannel server = SocketChannel.open();
-        server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort()));
+        server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort(lmtpServerFactory)));
 
         server.write(ByteBuffer.wrap(("LHLO <" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
         server.write(ByteBuffer.wrap(("MAIL FROM: <bob@" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
@@ -162,12 +170,4 @@ class LmtpServerTest {
                     .doesNotThrowAnyException();
             });
     }
-
-    public int getLmtpPort() {
-        return lmtpServerFactory.getServers().stream()
-            .findFirst()
-            .flatMap(server -> server.getListenAddresses().stream().findFirst())
-            .map(InetSocketAddress::getPort)
-            .orElseThrow(() -> new IllegalStateException("LMTP server not defined"));
-    }
 }
\ No newline at end of file
diff --git a/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/MailetContainerHandlerTest.java b/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/MailetContainerHandlerTest.java
index 39d5a98..2087d14 100644
--- a/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/MailetContainerHandlerTest.java
+++ b/server/protocols/protocols-lmtp/src/test/java/org/apache/james/lmtpserver/MailetContainerHandlerTest.java
@@ -21,6 +21,7 @@ package org.apache.james.lmtpserver;
 
 import static org.apache.james.jmap.JMAPTestingConstants.DOMAIN;
 import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP;
+import static org.apache.james.lmtpserver.LmtpServerTest.getLmtpPort;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.net.InetSocketAddress;
@@ -140,7 +141,7 @@ class MailetContainerHandlerTest {
         @Test
         void emailShouldTriggerTheMailProcessing() throws Exception {
             SocketChannel server = SocketChannel.open();
-            server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort()));
+            server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort(lmtpServerFactory)));
 
             server.write(ByteBuffer.wrap(("LHLO <" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
             server.write(ByteBuffer.wrap(("MAIL FROM: <bob@" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
@@ -156,14 +157,6 @@ class MailetContainerHandlerTest {
             Awaitility.await()
                 .untilAsserted(() -> assertThat(recordingMailProcessor.getMails()).hasSize(1));
         }
-
-        public int getLmtpPort() {
-            return lmtpServerFactory.getServers().stream()
-                .findFirst()
-                .flatMap(server -> server.getListenAddresses().stream().findFirst())
-                .map(InetSocketAddress::getPort)
-                .orElseThrow(() -> new IllegalStateException("LMTP server not defined"));
-        }
     }
 
     @Nested
@@ -219,7 +212,7 @@ class MailetContainerHandlerTest {
         @Test
         void emailShouldTriggerTheMailProcessing() throws Exception {
             SocketChannel server = SocketChannel.open();
-            server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort()));
+            server.connect(new InetSocketAddress(LOCALHOST_IP, getLmtpPort(lmtpServerFactory)));
 
             server.write(ByteBuffer.wrap(("LHLO <" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
             server.write(ByteBuffer.wrap(("MAIL FROM: <bob@" + DOMAIN + ">\r\n").getBytes(StandardCharsets.UTF_8)));
@@ -242,14 +235,6 @@ class MailetContainerHandlerTest {
             assertThat(new String(readBytes(buffer), StandardCharsets.UTF_8))
                 .startsWith("451 4.0.0 Temporary error deliver message");
         }
-
-        public int getLmtpPort() {
-            return lmtpServerFactory.getServers().stream()
-                .findFirst()
-                .flatMap(server -> server.getListenAddresses().stream().findFirst())
-                .map(InetSocketAddress::getPort)
-                .orElseThrow(() -> new IllegalStateException("LMTP server not defined"));
-        }
     }
 
     private byte[] readBytes(ByteBuffer line) {

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