james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [james-project] 09/12: JAMES-2709 Use FakeSmtp to check mails sent by LinShare
Date Fri, 19 Apr 2019 07:43:02 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit e4fd6d64a4d349d8f8f04bfd536612e046030284
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Thu Apr 11 15:49:26 2019 +0700

    JAMES-2709 Use FakeSmtp to check mails sent by LinShare
---
 .../main/java/org/apache/james/utils/FakeSmtp.java | 23 ++++++++++++---------
 third-party/linshare/pom.xml                       |  5 +++++
 .../java/org/apache/james/linshare/Linshare.java   | 24 ++++++++++++++++++----
 .../apache/james/linshare/LinshareExtension.java   |  4 +++-
 .../linshare/src/test/resources/smtp/Dockerfile    |  3 ---
 .../src/test/resources/smtp/conf/smtpd.conf        | 14 -------------
 6 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
index c94e742..3215f23 100644
--- a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
+++ b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
@@ -43,6 +43,17 @@ import io.restassured.specification.RequestSpecification;
 import io.restassured.specification.ResponseSpecification;
 
 public class FakeSmtp implements TestRule {
+    public static void clean(RequestSpecification requestSpecification) {
+        given(requestSpecification, RESPONSE_SPECIFICATION)
+            .get("/api/email")
+            .jsonPath()
+            .getList("id", String.class)
+            .stream()
+            .mapToInt(Integer::valueOf)
+            .max()
+            .ifPresent(id -> given(requestSpecification, RESPONSE_SPECIFICATION)
+                .get("/api/email/purge/" + id));
+    }
 
     public static FakeSmtp withSmtpPort(Integer smtpPort) {
         DockerGenericContainer container = fakeSmtpContainer()
@@ -59,7 +70,7 @@ public class FakeSmtp implements TestRule {
     }
 
     private static final int SMTP_PORT = 25;
-    private static final ResponseSpecification RESPONSE_SPECIFICATION = new ResponseSpecBuilder().build();
+    public static final ResponseSpecification RESPONSE_SPECIFICATION = new ResponseSpecBuilder().build();
     private final DockerGenericContainer container;
     private final Integer smtpPort;
 
@@ -104,14 +115,6 @@ public class FakeSmtp implements TestRule {
     }
 
     public void clean() {
-        given(requestSpecification(), RESPONSE_SPECIFICATION)
-            .get("/api/email")
-            .jsonPath()
-            .getList("id", String.class)
-            .stream()
-            .mapToInt(Integer::valueOf)
-            .max()
-            .ifPresent(id -> given(requestSpecification(), RESPONSE_SPECIFICATION)
-                .get("/api/email/purge/" + id));
+        clean(requestSpecification());
     }
 }
diff --git a/third-party/linshare/pom.xml b/third-party/linshare/pom.xml
index e243509..fdb3266 100644
--- a/third-party/linshare/pom.xml
+++ b/third-party/linshare/pom.xml
@@ -38,6 +38,11 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>blob-export-api</artifactId>
         </dependency>
         <dependency>
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
index 694a4c3..4dec0f7 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
@@ -19,13 +19,22 @@
 
 package org.apache.james.linshare;
 
+import static io.restassured.config.EncoderConfig.encoderConfig;
+import static io.restassured.config.RestAssuredConfig.newConfig;
+
+import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 
+import org.apache.james.util.docker.Images;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.Network;
 import org.testcontainers.containers.wait.strategy.Wait;
 import org.testcontainers.images.builder.ImageFromDockerfile;
 
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+
 public class Linshare {
     private static final String WAIT_FOR_BACKEND_INIT_LOG = ".*Server startup.*";
     private static final String WAIT_FOR_DB_INIT_LOG = ".*/linshare/webservice/rest/admin/authentication/change_password.*";
@@ -102,10 +111,7 @@ public class Linshare {
     }
 
     private GenericContainer createDockerSmtp() {
-        return new GenericContainer<>(
-            new ImageFromDockerfile()
-                .withFileFromClasspath("conf/smtpd.conf", "smtp/conf/smtpd.conf")
-                .withFileFromClasspath("Dockerfile", "smtp/Dockerfile"))
+        return new GenericContainer<>(Images.FAKE_SMTP)
             .withNetworkAliases("smtp", "linshare_smtp")
             .withNetwork(network);
     }
@@ -133,4 +139,14 @@ public class Linshare {
                 .withStartupTimeout(Duration.ofMinutes(10)))
             .withNetwork(network);
     }
+
+    public RequestSpecification fakeSmtpRequestSpecification() {
+        return new RequestSpecBuilder()
+            .setContentType(ContentType.JSON)
+            .setAccept(ContentType.JSON)
+            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+            .setPort(linshareSmtp.getMappedPort(80))
+            .setBaseUri("http://" + linshareSmtp.getContainerIpAddress())
+            .build();
+    }
 }
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
index 6a5ec9b..620d8ee 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
@@ -27,6 +27,7 @@ import java.util.Optional;
 
 import org.apache.james.linshare.client.LinshareAPI;
 import org.apache.james.linshare.client.User;
+import org.apache.james.utils.FakeSmtp;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
@@ -69,8 +70,9 @@ public class LinshareExtension implements BeforeEachCallback {
     private final Linshare linshare = LinshareSingleton.singleton;
 
     @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
+    public void beforeEach(ExtensionContext context) {
         deleteAllUsersDocuments();
+        FakeSmtp.clean(linshare.fakeSmtpRequestSpecification());
     }
 
     public Linshare getLinshare() {
diff --git a/third-party/linshare/src/test/resources/smtp/Dockerfile b/third-party/linshare/src/test/resources/smtp/Dockerfile
deleted file mode 100644
index 3b4b81a..0000000
--- a/third-party/linshare/src/test/resources/smtp/Dockerfile
+++ /dev/null
@@ -1,3 +0,0 @@
-FROM linagora/opensmtpd
-
-COPY conf/smtpd.conf /etc/smtpd/smtpd.conf
diff --git a/third-party/linshare/src/test/resources/smtp/conf/smtpd.conf b/third-party/linshare/src/test/resources/smtp/conf/smtpd.conf
deleted file mode 100644
index f6afe25..0000000
--- a/third-party/linshare/src/test/resources/smtp/conf/smtpd.conf
+++ /dev/null
@@ -1,14 +0,0 @@
-# This is the smtpd server system-wide configuration file.
-# See smtpd.conf(5) for more information.
-
-# To accept external mail, replace with: listen on all
-listen on 0.0.0.0
-
-# If you edit the file, you have to run "smtpctl update table aliases"
-table aliases file:/etc/smtpd/aliases
-
-# Uncomment the following to accept external mail for domain "example.org"
-#accept from any for domain "example.org" alias <aliases> deliver to mbox
-
-#accept for local alias <aliases> deliver to mbox
-accept from any for any relay


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