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 22d2851042a631a3fd8d345e5327169511a6af74
Author: Gautier DI FOLCO <gdifo...@linagora.com>
AuthorDate: Thu Mar 7 17:46:35 2019 +0100

    JAMES-2671 Add AwsS3 Test Rule
---
 .../mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java     |  53 ++++++++
 .../smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java |  55 +++++++++
 .../CassandraRabbitMQAwsS3SmtpTestRuleFactory.java |  75 +++++++++++
 .../org/apache/james/mpt/smtp/SmtpTestRule.java    |  14 +--
 .../james/blob/objectstorage/DockerAwsS3.java      |  35 ++++++
 .../james/blob/objectstorage/DockerAwsS3Rule.java  |  40 ++++++
 .../blob/objectstorage/DockerAwsS3Singleton.java   |  34 +++++
 .../aws/AwsS3ObjectStorageBlobsDAOBuilderTest.java |   4 +-
 .../objectstorage/aws/DockerAwsS3Container.java    |  22 +++-
 .../objectstorage/aws/s3/DockerAwsS3TestRule.java  | 137 +++++++++++++++++++++
 .../james/modules/TestAwsS3BlobStoreModule.java    |  47 +++++++
 11 files changed, 502 insertions(+), 14 deletions(-)

diff --git 
a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
new file mode 100644
index 0000000..6620839
--- /dev/null
+++ 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.mpt.smtp;
+
+import static 
org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_GLOBAL_SERVER;
+
+import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+
+public class AwsS3RabbitMQForwardSmtpTest extends ForwardSmtpTest {
+
+    @ClassRule public static DockerCassandraRule cassandraServer = new 
DockerCassandraRule();
+
+    @Rule
+    public SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule = 
CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_GLOBAL_SERVER, 
cassandraServer.getHost());
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        cassandraRabbitMQAwsS3SmtpTestRule.beforeTest();
+        super.setUp();
+    }
+
+    @Override
+    protected SmtpHostSystem createSmtpHostSystem() {
+        return cassandraRabbitMQAwsS3SmtpTestRule;
+    }
+
+    @After
+    public void tearDown() {
+        cassandraRabbitMQAwsS3SmtpTestRule.afterTest();
+    }
+}
diff --git 
a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
new file mode 100644
index 0000000..8faeed1
--- /dev/null
+++ 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.mpt.smtp;
+
+import static 
org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType.SMTP_START_TLS_SERVER;
+
+import org.apache.james.backends.cassandra.DockerCassandraRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+
+public class AwsS3RabbitMQSmtpStarttlsCommandTest extends 
SmtpStarttlsCommandTest {
+
+    @ClassRule public static DockerCassandraRule cassandraServer = new 
DockerCassandraRule();
+
+    @Rule
+    public SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule = 
CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_START_TLS_SERVER, 
cassandraServer.getHost());
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        cassandraRabbitMQAwsS3SmtpTestRule.beforeTest();
+        super.setUp();
+    }
+
+    @Override
+    protected SmtpHostSystem createSmtpHostSystem() {
+        return cassandraRabbitMQAwsS3SmtpTestRule;
+    }
+
+
+    @After
+    public void tearDown() {
+        cassandraRabbitMQAwsS3SmtpTestRule.afterTest();
+    }
+
+}
diff --git 
a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
new file mode 100644
index 0000000..51ee30f
--- /dev/null
+++ 
b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.mpt.smtp;
+
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.CassandraJamesServerMain;
+import org.apache.james.CleanupTasksPerformer;
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.backend.rabbitmq.DockerRabbitMQSingleton;
+import 
org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.modules.TestAwsS3BlobStoreModule;
+import org.apache.james.modules.TestRabbitMQModule;
+import org.apache.james.modules.blobstore.BlobStoreChoosingModule;
+import 
org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType;
+import org.apache.james.modules.rabbitmq.RabbitMQModule;
+import org.apache.james.modules.server.CamelMailetContainerModule;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
+import org.apache.james.server.core.configuration.Configuration;
+import org.apache.james.util.Host;
+import org.junit.rules.TemporaryFolder;
+
+public final class CassandraRabbitMQAwsS3SmtpTestRuleFactory {
+    public static SmtpTestRule create(SmtpServerConnectedType 
smtpServerConnectedType, Host cassandraHost) {
+        SmtpTestRule.ServerBuilder createJamesServer = (folder, dnsService) -> 
createJamesServer(cassandraHost, folder, dnsService);
+
+        return new SmtpTestRule(smtpServerConnectedType, createJamesServer);
+    }
+
+    private static GuiceJamesServer createJamesServer(Host cassandraHost, 
TemporaryFolder folder, DNSService dnsService) throws Exception {
+        Configuration configuration = Configuration.builder()
+            .workingDirectory(folder.newFolder())
+            .configurationFromClasspath()
+            .build();
+
+        return GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(CassandraJamesServerMain.CASSANDRA_SERVER_CORE_MODULE,
+                SmtpTestRule.SMTP_PROTOCOL_MODULE,
+                binder -> 
binder.bind(MailQueueItemDecoratorFactory.class).to(RawMailQueueItemDecoratorFactory.class),
+                binder -> 
binder.bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
+                    .toInstance(DefaultConfigurationBuilder::new))
+            .overrideWith(
+                new RabbitMQModule(),
+                new BlobStoreChoosingModule())
+            .overrideWith(
+                new TestRabbitMQModule(DockerRabbitMQSingleton.SINGLETON),
+                new TestAwsS3BlobStoreModule(),
+                binder -> binder.bind(ClusterConfiguration.class).toInstance(
+                    ClusterConfiguration.builder()
+                        .host(cassandraHost)
+                        .keyspace("testing")
+                        .replicationFactor(1)
+                        .build()),
+                binder -> binder.bind(DNSService.class).toInstance(dnsService),
+                binder -> 
binder.bind(CleanupTasksPerformer.class).asEagerSingleton());
+    }
+}
+
diff --git 
a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestRule.java 
b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestRule.java
index 551d86b..e7ded4b 100644
--- 
a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestRule.java
+++ 
b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpTestRule.java
@@ -18,10 +18,12 @@
  ****************************************************************/
 package org.apache.james.mpt.smtp;
 
-import java.util.Iterator;
 import java.util.Optional;
 
 import org.apache.james.GuiceJamesServer;
+import org.apache.james.core.Domain;
+import org.apache.james.core.User;
+import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.modules.protocols.ProtocolHandlerModule;
 import org.apache.james.modules.protocols.SMTPServerModule;
@@ -38,7 +40,6 @@ import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
 
@@ -72,12 +73,9 @@ public class SmtpTestRule implements TestRule, 
SmtpHostSystem {
 
     @Override
     public boolean addUser(String userAtDomain, String password) throws 
Exception {
-        Preconditions.checkArgument(userAtDomain.contains("@"), "The 'user' 
should contain the 'domain'");
-        Iterator<String> split = 
Splitter.on("@").split(userAtDomain).iterator();
-        split.next();
-        String domain = split.next();
-
-        createDomainIfNeeded(domain);
+        Optional<Domain> domain = 
User.fromUsername(userAtDomain).getDomainPart();
+        Preconditions.checkArgument(domain.isPresent(), "The 'user' should 
contain the 'domain'");
+        createDomainIfNeeded(domain.get().asString());
         jamesServer.getProbe(DataProbeImpl.class).addUser(userAtDomain, 
password);
         return true;
     }
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3.java
 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3.java
new file mode 100644
index 0000000..8465b19
--- /dev/null
+++ 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.blob.objectstorage;
+
+import java.net.URI;
+
+public class DockerAwsS3 {
+    private final URI awsS3Endpoint;
+
+    public DockerAwsS3(URI awsS3Endpoint) {
+        this.awsS3Endpoint = awsS3Endpoint;
+    }
+
+    public URI awsS3Endpoint() {
+        return awsS3Endpoint;
+    }
+}
+
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.java
 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.java
new file mode 100644
index 0000000..4031979
--- /dev/null
+++ 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.blob.objectstorage;
+
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.testcontainers.containers.GenericContainer;
+
+public class DockerAwsS3Rule {
+
+    public Statement apply(Statement base, Description description) {
+        return base;
+    }
+
+    public GenericContainer<?> getRawContainer() {
+        return DockerAwsS3Singleton.singleton.getRawContainer();
+    }
+
+    public DockerAwsS3 dockerAwsS3() {
+        return DockerAwsS3Singleton.singleton.dockerAwsS3();
+    }
+}
+
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Singleton.java
 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Singleton.java
new file mode 100644
index 0000000..22fff45
--- /dev/null
+++ 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Singleton.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.blob.objectstorage;
+
+import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
+
+public class DockerAwsS3Singleton {
+
+    public static final DockerAwsS3Container singleton = new 
DockerAwsS3Container();
+
+    static {
+        singleton.start();
+    }
+
+    // Cleanup will be performed by test container resource reaper
+}
+
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageBlobsDAOBuilderTest.java
 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageBlobsDAOBuilderTest.java
index afa6447..147c130 100644
--- 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageBlobsDAOBuilderTest.java
+++ 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageBlobsDAOBuilderTest.java
@@ -43,8 +43,8 @@ class AwsS3ObjectStorageBlobsDAOBuilderTest implements 
ObjectStorageBlobsDAOCont
         containerName = ContainerName.of(UUID.randomUUID().toString());
         configuration = AwsS3AuthConfiguration.builder()
             .endpoint(dockerAwsS3Container.getEndpoint())
-            .accessKeyId(DockerAwsS3Container.SCALITY_ACCESS_KEY_ID)
-            .secretKey(DockerAwsS3Container.SCALITY_SECRET_ACCESS_KEY)
+            .accessKeyId(DockerAwsS3Container.ACCESS_KEY_ID)
+            .secretKey(DockerAwsS3Container.SECRET_ACCESS_KEY)
             .build();
     }
 
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/DockerAwsS3Container.java
 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/DockerAwsS3Container.java
index bef1009..41ab6b4 100644
--- 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/DockerAwsS3Container.java
+++ 
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/DockerAwsS3Container.java
@@ -19,6 +19,9 @@
 
 package org.apache.james.blob.objectstorage.aws;
 
+import java.net.URI;
+
+import org.apache.james.blob.objectstorage.DockerAwsS3;
 import org.apache.james.util.Host;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.wait.strategy.Wait;
@@ -29,24 +32,27 @@ public class DockerAwsS3Container {
     private static final int AWS_S3_PORT = 8000;
     private static final int ONE_TIME = 1;
 
-    public static final String SCALITY_ACCESS_KEY_ID = "newAccessKey";
-    public static final String SCALITY_SECRET_ACCESS_KEY = "newSecretKey";
+    public static final String ACCESS_KEY_ID = "newAccessKey";
+    public static final String SECRET_ACCESS_KEY = "newSecretKey";
 
     private final GenericContainer<?> awsS3Container;
+    private DockerAwsS3 dockerAwsS3;
 
     public DockerAwsS3Container() {
         this.awsS3Container = new GenericContainer<>(AWS_S3_DOCKER_IMAGE);
         this.awsS3Container
             .withExposedPorts(AWS_S3_PORT)
             .withEnv("S3BACKEND", "mem")
-            .withEnv("SCALITY_ACCESS_KEY_ID", SCALITY_ACCESS_KEY_ID)
-            .withEnv("SCALITY_SECRET_ACCESS_KEY", SCALITY_SECRET_ACCESS_KEY)
+            .withEnv("SCALITY_ACCESS_KEY_ID", ACCESS_KEY_ID)
+            .withEnv("SCALITY_SECRET_ACCESS_KEY", SECRET_ACCESS_KEY)
             .withEnv("LOG_LEVEL", "trace")
             .waitingFor(Wait.forLogMessage(".*\"message\":\"server 
started\".*\\n", ONE_TIME));
     }
 
     public void start() {
         awsS3Container.start();
+
+        dockerAwsS3 = new DockerAwsS3(URI.create("http://"; + getHost() + "/"));
     }
 
     public void stop() {
@@ -68,4 +74,12 @@ public class DockerAwsS3Container {
     public String getEndpoint() {
         return "http://"; + getIp() + ":" + getPort() + "/";
     }
+
+    public DockerAwsS3 dockerAwsS3() {
+        return dockerAwsS3;
+    }
+
+    public GenericContainer<?> getRawContainer() {
+        return awsS3Container;
+    }
 }
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
new file mode 100644
index 0000000..a9fc3b6
--- /dev/null
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
@@ -0,0 +1,137 @@
+/*
+ * 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.modules.objectstorage.aws.s3;
+
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import org.apache.james.CleanupTasksPerformer;
+import org.apache.james.GuiceModuleTestRule;
+import org.apache.james.blob.objectstorage.ContainerName;
+import org.apache.james.blob.objectstorage.DockerAwsS3Rule;
+import org.apache.james.blob.objectstorage.DockerAwsS3Singleton;
+import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
+import org.apache.james.blob.objectstorage.PayloadCodec;
+import org.apache.james.blob.objectstorage.aws.AwsS3AuthConfiguration;
+import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
+import org.apache.james.modules.objectstorage.ObjectStorageBlobConfiguration;
+import org.apache.james.modules.objectstorage.ObjectStorageProvider;
+import org.apache.james.modules.objectstorage.PayloadCodecFactory;
+import org.apache.james.utils.GuiceProbe;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import com.google.inject.Module;
+import com.google.inject.multibindings.Multibinder;
+
+public class DockerAwsS3TestRule implements GuiceModuleTestRule {
+
+    public static class TestAwsS3BlobStoreProbe implements GuiceProbe {
+
+        private final ObjectStorageBlobsDAO awss3BlobStore;
+
+        @Inject
+        TestAwsS3BlobStoreProbe(ObjectStorageBlobsDAO awss3BlobStore) {
+            this.awss3BlobStore = awss3BlobStore;
+        }
+
+        public PayloadCodec getAwsS3PayloadCodec() {
+            return awss3BlobStore.getPayloadCodec();
+        }
+    }
+
+    private static class ContainerCleanUp implements 
CleanupTasksPerformer.CleanupTask {
+
+        private final ObjectStorageBlobsDAO blobsDAO;
+
+        @Inject
+        public ContainerCleanUp(ObjectStorageBlobsDAO blobsDAO) {
+            this.blobsDAO = blobsDAO;
+        }
+
+        @Override
+        public Result run() {
+            blobsDAO.deleteContainer();
+
+            return Result.COMPLETED;
+        }
+    }
+
+    private final PayloadCodecFactory payloadCodecFactory;
+    private DockerAwsS3Rule awss3Container = new DockerAwsS3Rule();
+
+    public DockerAwsS3TestRule() {
+        this(PayloadCodecFactory.DEFAULT);
+    }
+
+    public DockerAwsS3TestRule(PayloadCodecFactory payloadCodecFactory) {
+        this.payloadCodecFactory = payloadCodecFactory;
+    }
+
+    @Override
+    public Statement apply(Statement base, Description description) {
+        return awss3Container.apply(base, description);
+    }
+
+    @Override
+    public void await() {
+    }
+
+    @Override
+    public Module getModule() {
+        ContainerName containerName = 
ContainerName.of(UUID.randomUUID().toString());
+        AwsS3AuthConfiguration authConfiguration = 
AwsS3AuthConfiguration.builder()
+            .endpoint(DockerAwsS3Singleton.singleton.getEndpoint())
+            .accessKeyId(DockerAwsS3Container.ACCESS_KEY_ID)
+            .secretKey(DockerAwsS3Container.SECRET_ACCESS_KEY)
+            .build();
+
+        ObjectStorageBlobConfiguration configuration = 
ObjectStorageBlobConfiguration.builder()
+            .codec(payloadCodecFactory)
+            .provider(ObjectStorageProvider.AWSS3)
+            .container(containerName)
+            .authConfiguration(authConfiguration)
+            .aesSalt("c603a7327ee3dcbc031d8d34b1096c605feca5e1")
+            .aesPassword("dockerAwsS3SwiftEncryption".toCharArray())
+            .build();
+
+        return binder -> {
+            
binder.bind(ObjectStorageBlobConfiguration.class).toInstance(configuration);
+
+            Multibinder.newSetBinder(binder, 
CleanupTasksPerformer.CleanupTask.class)
+                .addBinding()
+                .to(ContainerCleanUp.class);
+
+            Multibinder.newSetBinder(binder, 
GuiceProbe.class).addBinding().to(TestAwsS3BlobStoreProbe.class);
+        };
+    }
+
+
+    public void start() {
+        awss3Container.start();
+    }
+
+    public void stop() {
+        awss3Container.stop();
+    }
+
+}
+
diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
new file mode 100644
index 0000000..8d0ef83
--- /dev/null
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.modules;
+
+import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
+import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+
+public class TestAwsS3BlobStoreModule extends AbstractModule {
+
+    private final DockerAwsS3TestRule dockerAwsS3TestRule;
+
+    public TestAwsS3BlobStoreModule() {
+        this.dockerAwsS3TestRule = new DockerAwsS3TestRule();
+    }
+
+    @Override
+    protected void configure() {
+        Module testAwsS3BlobStoreModule = Modules
+            .override(dockerAwsS3TestRule.getModule())
+            .with(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
+                    
.toInstance(BlobStoreChoosingConfiguration.objectStorage()));
+
+        install(testAwsS3BlobStoreModule);
+    }
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to