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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4f852d631e JAMES-3775 Docker container for testing RSpamD
4f852d631e is described below

commit 4f852d631eebf79057d91d20e8de7b70afc08ffe
Author: Rene Cordier <[email protected]>
AuthorDate: Mon Jul 18 15:07:33 2022 +0700

    JAMES-3775 Docker container for testing RSpamD
---
 pom.xml                                            | 17 +++++
 .../org/apache/james/rate/limiter/DockerRedis.java |  8 +++
 third-party/pom.xml                                |  1 +
 third-party/rspamd/pom.xml                         | 75 ++++++++++++++++++++++
 .../java/org/apache/james/rspamd/DockerRSpamD.java | 56 +++++++---------
 .../apache/james/rspamd/DockerRSpamDExtension.java | 58 +++++++++++++++++
 .../james/rspamd/DockerRSpamDExtensionTest.java    | 51 +++++++++++++++
 7 files changed, 233 insertions(+), 33 deletions(-)

diff --git a/pom.xml b/pom.xml
index fe7e577487..1866a7521c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -934,6 +934,17 @@
                 <version>${project.version}</version>
                 <type>test-jar</type>
             </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-rspamd</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-rspamd</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+            </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
                 <artifactId>apache-james-spamassassin</artifactId>
@@ -1786,6 +1797,12 @@
                 <artifactId>james-server-rate-limiter-redis</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
+                <artifactId>james-server-rate-limiter-redis</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+            </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
                 <artifactId>james-server-spring</artifactId>
diff --git 
a/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
 
b/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
index 3dfcb5dc34..6c0bb4cd25 100644
--- 
a/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
+++ 
b/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
@@ -24,6 +24,7 @@ import java.net.URISyntaxException;
 
 import org.apache.http.client.utils.URIBuilder;
 import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
 import org.testcontainers.utility.DockerImageName;
 
 import io.lettuce.core.RedisClient;
@@ -41,6 +42,13 @@ public class DockerRedis {
             .withExposedPorts(DEFAULT_PORT);
     }
 
+    public DockerRedis(Network network) {
+        this.container = new 
GenericContainer<>(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG))
+            .withExposedPorts(DEFAULT_PORT)
+            .withNetwork(network)
+            .withNetworkAliases("redis");
+    }
+
     public Integer getPort() {
         return container.getMappedPort(DEFAULT_PORT);
     }
diff --git a/third-party/pom.xml b/third-party/pom.xml
index a8e6dc417a..49e33e340d 100644
--- a/third-party/pom.xml
+++ b/third-party/pom.xml
@@ -34,6 +34,7 @@
 
     <modules>
         <module>linshare</module>
+        <module>rspamd</module>
         <module>spamassassin</module>
     </modules>
 </project>
\ No newline at end of file
diff --git a/third-party/rspamd/pom.xml b/third-party/rspamd/pom.xml
new file mode 100644
index 0000000000..b19487faa5
--- /dev/null
+++ b/third-party/rspamd/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>third-party</artifactId>
+        <version>3.8.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>apache-james-rspamd</artifactId>
+    <name>Apache James :: Third Party :: RSpamD</name>
+    <description>RSpamD Java client (HTTP) and testing utilities</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-guice-common</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-rate-limiter-redis</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-webadmin-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-webadmin-core</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>testing-base</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
 b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamD.java
similarity index 61%
copy from 
server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
copy to 
third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamD.java
index 3dfcb5dc34..dcff4dde8d 100644
--- 
a/server/mailet/rate-limiter-redis/src/test/java/org/apache/james/rate/limiter/DockerRedis.java
+++ b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamD.java
@@ -17,47 +17,41 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.rate.limiter;
+package org.apache.james.rspamd;
 
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.http.client.utils.URIBuilder;
+import org.apache.james.rate.limiter.DockerRedis;
 import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
 import org.testcontainers.utility.DockerImageName;
 
-import io.lettuce.core.RedisClient;
-import io.lettuce.core.api.sync.RedisCommands;
-
-public class DockerRedis {
-    private static final DockerImageName DEFAULT_IMAGE_NAME = 
DockerImageName.parse("redis");
-    private static final String DEFAULT_TAG = "6.2.6";
-    private static final int DEFAULT_PORT = 6379;
+public class DockerRSpamD {
+    private static final DockerImageName DEFAULT_IMAGE_NAME = 
DockerImageName.parse("a16bitsysop/rspamd");
+    private static final String DEFAULT_TAG = "3.2-r2-alpine3.16.0-r0";
+    private static final int DEFAULT_PORT = 11334;
 
+    private final DockerRedis dockerRedis;
     private final GenericContainer<?> container;
+    private Network network;
 
-    public DockerRedis() {
-        this.container = new 
GenericContainer<>(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG))
-            .withExposedPorts(DEFAULT_PORT);
+    public DockerRSpamD() {
+        this.network = Network.newNetwork();
+        this.dockerRedis = new DockerRedis(network);
+        this.container = createRspamD();
     }
 
-    public Integer getPort() {
-        return container.getMappedPort(DEFAULT_PORT);
+    private GenericContainer<?> createRspamD() {
+        return new GenericContainer<>(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG))
+            .withExposedPorts(DEFAULT_PORT)
+            .withEnv("REDIS", "redis")
+            .withNetwork(network);
     }
 
-    public URI redisURI() {
-        try {
-            return new URIBuilder()
-                .setScheme("redis")
-                .setHost(container.getHost())
-                .setPort(getPort())
-                .build();
-        } catch (URISyntaxException e) {
-            throw new RuntimeException("Error when build redis uri. ", e);
-        }
+    public Integer getPort() {
+        return container.getMappedPort(DEFAULT_PORT);
     }
 
     public void start() {
+        dockerRedis.start();
         if (!container.isRunning()) {
             container.start();
         }
@@ -65,14 +59,10 @@ public class DockerRedis {
 
     public void stop() {
         container.stop();
-    }
-
-    public RedisCommands<String, String> createClient() {
-        return RedisClient.create(redisURI().toString())
-            .connect().sync();
+        dockerRedis.stop();
     }
 
     public void flushAll() {
-        createClient().flushall();
+        dockerRedis.flushAll();
     }
 }
diff --git 
a/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtension.java
 
b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtension.java
new file mode 100644
index 0000000000..20f95f8d1a
--- /dev/null
+++ 
b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtension.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.rspamd;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+
+public class DockerRSpamDExtension implements GuiceModuleTestExtension {
+    private static final DockerRSpamD DOCKER_RSPAMD_SINGLETON = new 
DockerRSpamD();
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        DOCKER_RSPAMD_SINGLETON.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        DOCKER_RSPAMD_SINGLETON.stop();
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext extensionContext) throws Exception 
{
+        DOCKER_RSPAMD_SINGLETON.flushAll();
+    }
+
+    public DockerRSpamD dockerRSpamD() {
+        return DOCKER_RSPAMD_SINGLETON;
+    }
+
+    @Override
+    public boolean supportsParameter(ParameterContext parameterContext, 
ExtensionContext extensionContext) throws ParameterResolutionException {
+        return parameterContext.getParameter().getType() == DockerRSpamD.class;
+    }
+
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, 
ExtensionContext extensionContext) throws ParameterResolutionException {
+        return dockerRSpamD();
+    }
+}
diff --git 
a/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtensionTest.java
 
b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtensionTest.java
new file mode 100644
index 0000000000..3a8d606099
--- /dev/null
+++ 
b/third-party/rspamd/src/test/java/org/apache/james/rspamd/DockerRSpamDExtensionTest.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.rspamd;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.util.Port;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import io.restassured.specification.RequestSpecification;
+
+public class DockerRSpamDExtensionTest {
+    @RegisterExtension
+    static DockerRSpamDExtension rSpamDExtension = new DockerRSpamDExtension();
+
+    @Test
+    void dockerRSpamDExtensionShouldWork() {
+        RequestSpecification rspamdApi = 
WebAdminUtils.spec(Port.of(rSpamDExtension.dockerRSpamD().getPort()));
+
+        String response = rspamdApi
+            .get("ping")
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .extract()
+            .body()
+            .asString()
+            .trim();
+
+        assertThat(response).isEqualTo("pong");
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to